Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6235443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:40:10+00:00 2026-05-24T10:40:10+00:00

You probably know about project Euler question 5: get the smallest number divisble by

  • 0

You probably know about project Euler question 5: get the smallest number divisble by all numbers 1 to 20.

The logic I applied was “start with the first number greater than the largest of the list(20) and also divisible by it which is 40” and stepsize of 20 (largest number)

I did this using list comprehension but it’s pretty lame.

pe5 = head    [x|x<-[40,60..],x`mod`3==0,x`mod`4==0,x`mod`6==0,x`mod`7==0,x`mod`8==0,x`mod`9==0,x`mod`11==0,x`mod`12==0,x`mod`13==0,x`mod`14==0,x`mod`15==0,x`mod`16==0,x`mod`17==0,x`mod`18==0,x`mod`19==0] 

Can we do this better perhaps using zipWith and filter maybe?

Just to clarify, this is not a homework assignment. I’m doing this to wrap my brain around Haskell. (So far I’m losing!)

:Thanx all

I think this is a saner way (there may be thousand more better ways but this would suffice) to do it

listlcm'::(Integral a)=> [a] -> a
listlcm' [x] = x
listlcm' (x:xs) = lcm x (listlcm' xs)  
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:40:11+00:00Added an answer on May 24, 2026 at 10:40 am

    Yes, you can do much better. For starters, rewrite to something like

    head [x | x<-[40,60..], all (\y -> x`mod`y == 0) [2..20] ]
    

    But what you really need here is not slicker Haskell, but a smarter algorithm. Hint: use the Fundamental Theorem of Arithmetic. Your Haskell solution would then start with the standard sieve-of-Eratosthenes example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From the question you can probably tell that I don't know much about code!
I'm about to start working on a rich-internet-application project for a student organization at
I am about to start a project that I hope will some day require
I'm working on a project which is just about to start, and since I
Some of you may or may not (probably not) know about my framework .
I know about the XLWT library, which I've used before on a Django project.
Let me start off by saying I know this is probably not the correct
As many of you probably know, online banks nowadays have a security system whereby
As you probably know, Derek Sivers is the guy who created CD Baby and
Most of you probably know the following problem: You edit an HTML, view the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.