all tasks

This commit is contained in:
Ingy döt Net 2013-04-11 01:07:29 -07:00
parent b83f433714
commit 68f8f3e56b
14735 changed files with 178959 additions and 0 deletions

View file

@ -0,0 +1,13 @@
import Data.List (permutations)
topswops :: Int -> Int
topswops n = maximum $ map tops $ permutations [1 .. n]
where
tops (1 : _) = 0
tops xa@(x : _) = 1 + tops reordered
where
reordered = reverse (take x xa) ++ drop x xa
main = mapM_
(\x -> putStrLn $ show x ++ ":\t" ++ show (topswops x))
[1 .. 10]

View file

@ -0,0 +1,12 @@
import Data.List
import Control.Arrow
import Control.Monad
derangements [1] = [[1]]
derangements xs = filter (and . zipWith (/=) [1..] ). permutations $ xs
topswop = ((uncurry (++). first reverse).). splitAt
topswopIter = takeWhile((/=1).head). iterate (topswop =<< head)
swops = map (length. topswopIter). derangements
topSwops :: [Int] -> [(Int, Int)]
topSwops = zip [1..]. map (maximum. swops). drop 1. inits