Topswops: Difference between revisions

m
→‎Searching derangements: Tidying, updated output.
m (→‎Searching permutations: hindent, tidying)
m (→‎Searching derangements: Tidying, updated output.)
Line 995:
<br>Uses only permutations with all elements out of place.
<lang Haskell>import Data.List (permutations, inits)
 
import Control.Arrow (first)
 
derangements :: [Int] -> [[Int]]
derangements = (\x -> filter . (and .) . zipWith (/=) x)) <*> permutations
 
topswop :: Int -> [a] -> [a]
topswop x xs = ((uncurry (++) . (first reverse) .)(splitAt .x splitAtxs))
 
topswopIter :: [Int] -> [[Int]]
Line 1,016 ⟶ 1,015:
main = mapM_ print $ take 10 $ topSwops [1 ..]</lang>
'''Output'''
<pre>(1,0)
<pre>*Main> mapM_ print $ take 10 $ topSwops [1..]
(1,0)
(2,1)
(3,2)
9,659

edits