all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
13
Task/Topswops/Haskell/topswops-1.hs
Normal file
13
Task/Topswops/Haskell/topswops-1.hs
Normal 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]
|
||||
12
Task/Topswops/Haskell/topswops-2.hs
Normal file
12
Task/Topswops/Haskell/topswops-2.hs
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue