http://projecteuler.net/index.php?section=problems&id=43
戻り値の型の違いで、数字のリストから数にする関数を2パターン書いているのですが、一つにまとまらないのでしょうか。
let to_number a = List.fold (fun x y -> x * 10 + y) 0 a
let to_numberL a = List.fold (fun x y -> x * 10L + (int64 y)) 0L a
let primes = [ 1; 1; 17; 13; 11; 7; 5; 3; 2; 1 ]
let not_exists a e = not (List.exists (fun n -> n = e) a)
let rec slice a n = if n = 0 || a = [] then []
else List.head a :: (slice (List.tail a) (n - 1))
let rec pan (a : (int list) list) = function
| [] -> a
| p :: ps ->
[ for e in a do
for e' in (List.filter
(fun e' -> (to_number (slice e' 3)) % p = 0)
[ for d in List.filter (not_exists e) [0..9]
-> d :: e ]) do
for e'' in pan [e'] ps -> e'' ]
let a = pan [ [ ] ] primes
printfn "%d" (List.sum (List.map to_numberL a))