Problem 24

http://projecteuler.net/index.php?section=problems&id=24
「0〜9」までの順列の中で100万番目の数

import Combination (perm)

main = print $ concatMap show $ perm [0..9] !! (1 * 1000 * 1000 - 1)
module Combination(comb, perm) where

import Data.List (inits, tails, delete)

comb :: [a] -> Int -> [[a]]
comb _ 0     = [[]]
comb [] _     = []
comb (x:xs) n = map (x:) (comb xs (n-1)) ++ comb xs n

perm :: [a] -> [[a]]
perm []   = []
perm [x]  = [[x]]
perm xs = [t : ys | (h, t:ts) <- init $ divid xs, ys <- perm (h ++ ts)]

divid :: [a] -> [([a], [a])]
divid xs = zip (inits xs) (tails xs)