Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 483d82c85c
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 26 lines (20 sloc) 0.57 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
import EulerMath.BigNum
import Data.List

facts = map fact [9,8..1]

digits :: [Int]
digits = [0..9]

linComb :: Int -> [Int] -> [Int]
linComb _ [] = []
linComb n (x:xs) = quot n x : (linComb (mod n x) xs)

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

euler24 :: Int -> [Int]
euler24 n = permute digits (linComb (n-1) facts)
Something went wrong with that request. Please try again.