Topswops: Difference between revisions

29 bytes removed ,  11 years ago
m
Line 444:
import Control.Monad
 
derangements [1]= filter (and . zipWith (/=) [[1..]] ). permutations
derangements xs = filter (and . zipWith (/=) [1..] ). permutations $ xs
topswop = ((uncurry (++). first reverse).). splitAt
topswopIter = takeWhile((/=1).head). iterate (topswop =<< head)
Line 451 ⟶ 450:
 
topSwops :: [Int] -> [(Int, Int)]
topSwops = zip [1..]. map (maximum. swops(0:). dropswops). 1tail. inits</lang>
'''Output'''
<pre>*Main> mapM_ print $ take 10 $ topSwops [1..]
Anonymous user