Permalink
Browse files

solved 24

  • Loading branch information...
Eric Wilson
Eric Wilson committed Feb 17, 2011
1 parent 941a38c commit 3edf1c2c63e454e05743b7a53f30e02211f5bed3
Showing with 12 additions and 5 deletions.
  1. +12 −5 024.hs
View
17 024.hs
@@ -1,19 +1,26 @@
import EulerMath.BigNum
import Data.List
-facts = map fact [10,9..1]
+facts = map fact [9,8..1]
+digits :: [Int]
digits = [0..9]
-linComb :: (Integral a) => a -> [a] -> [a]
+linComb :: Int -> [Int] -> [Int]
linComb _ [] = []
linComb n (x:xs) = quot n x : (linComb (mod n x) xs)
---permute :: (Integral a) => [a] -> [a] -> [a]
---permute xs (y:ys) = inc xs y : (permute rem
+permute :: [Int] -> [Int] -> [Int]
+permute xs [] = xs
+permute xs (y:ys) = head increment : (permute (tail increment) ys)
+ where
+ increment = inc xs y
inc :: [Int] -> Int -> [Int]
inc xs y = newHead : (filter (/=newHead) sorted)
where
sorted = sort xs
- newHead = sorted !! y
+ newHead = sorted !! y
+
+euler24 :: Int -> [Int]
+euler24 n = permute digits (linComb (n-1) facts)

0 comments on commit 3edf1c2

Please sign in to comment.