September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,11 +1,21 @@
|
|||
import Data.List
|
||||
import Control.Arrow
|
||||
import Control.Monad
|
||||
import Data.List (permutations, inits)
|
||||
|
||||
derangements = filter (and . zipWith (/=) [1..] ). permutations
|
||||
topswop = ((uncurry (++). first reverse).). splitAt
|
||||
topswopIter = takeWhile((/=1).head). iterate (topswop =<< head)
|
||||
swops = map (length. topswopIter). derangements
|
||||
import Control.Arrow (first)
|
||||
|
||||
derangements :: [Int] -> [[Int]]
|
||||
derangements = (filter . (and .) . zipWith (/=)) <*> permutations
|
||||
|
||||
topswop :: Int -> [a] -> [a]
|
||||
topswop = ((uncurry (++) . first reverse) .) . splitAt
|
||||
|
||||
topswopIter :: [Int] -> [[Int]]
|
||||
topswopIter = takeWhile ((/= 1) . head) . iterate (topswop =<< head)
|
||||
|
||||
swops :: [Int] -> [Int]
|
||||
swops = fmap (length . topswopIter) . derangements
|
||||
|
||||
topSwops :: [Int] -> [(Int, Int)]
|
||||
topSwops = zip [1..]. map (maximum. (0:). swops). tail. inits
|
||||
topSwops = zip [1 ..] . fmap (maximum . (0 :) . swops) . tail . inits
|
||||
|
||||
main :: IO ()
|
||||
main = mapM_ print $ take 10 $ topSwops [1 ..]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue