Talk:Euler problems/1 to 10

From HaskellWiki
< Talk:Euler problems
Revision as of 20:31, 16 August 2014 by WillNess (talk | contribs) (The removed Euler #3 code doesn't work for 875)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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)
Or just take and tails:
maximum [product . take 5 $ d | d <- take 995 $ tails digits]
--Gorlum0 17:00, 25 February 2011 (UTC)


The removed Euler #3 code doesn't work e.g. for 875. -- WillNess (talk) 20:31, 16 August 2014 (UTC)