Talk:Euler problems/1 to 10

From HaskellWiki
Jump to navigation Jump to search

Should the "solution" of problem 10 not contain a way how the primes are constructed? In itself its no solution. hk

  • It's in problem 3 earlier on the page. The primes function is needed for the solution of many problems. Quale 16:55, 26 February 2008 (UTC)
It's barely a solution anyway, IMHO. They've changed the problems to all primes below *two* million now, and it takes about 3 minutes to run for me (Athlon64 3200+). Exscape 18:29, 27 May 2008 (UTC)


The solution for problem 7 has an off-by-one error, no? Doesn't (!!) start indexing at 0?


The solution for problem 8 is not generic and requires check the last digits. Below shows the problem and suggested correction for groupsOf.

groupsOf _ [] = []
groupsOf n xs = 
    take n xs : groupsOf n ( tail xs )

groupsOf' n xs 
  | length group < n = []
  | otherwise        = group : groupsOf' n ( tail xs )
    where group = take n xs 

digits = [1,1,1,1,1,0,9,9,9,9]

max5 = maximum $ map product $ groupsOf 5 digits   -- 6561 (wrong)
max5' = maximum $ map product $ groupsOf' 5 digits --  1 (correct)
Why not use tails and pattern matching like below?
maximum [product xs | xs@[_,_,_,_,_] <- map (take 5) (tails digits)]
-- RayNbow 22:08, 24 January 2010 (UTC)