Difference between revisions of "Talk:Euler problems/1 to 10"

From HaskellWiki
Jump to navigation Jump to search
m
Line 6: Line 6:
   
 
The solution for problem 7 has an off-by-one error, no? Doesn't (!!) start indexing at 0?
 
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.
  +
<haskell>
  +
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,0,9,9]
  +
  +
max3 = maximum $ map product $ groupsOf 3 digits -- 81 (wrong)
  +
max3' = maximum $ map product $ groupsOf' 3 digits -- 1 (correct)
  +
</haskell>

Revision as of 15:12, 7 January 2009

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,0,9,9]

max3 = maximum $ map product $ groupsOf 3 digits   -- 81 (wrong)
max3' = maximum $ map product $ groupsOf' 3 digits -- 1 (correct)