Mind boggling card trick: Difference between revisions
Content deleted Content added
m →{{header|zkl}}: tweak comment |
→{{header|Haskell}}: (Some tidying of the threeStack function, refreshed sample output) |
||
Line 290:
]
return ns
-- RED vs BLACK ----------------------------------------
rb :: Int -> Char
Line 299 ⟶ 300:
-- THREE STACKS ----------------------------------------
threeStacks :: String -> (String, String, String)
threeStacks
where
go tpl [] = tpl
go (rs, bs, ds)
go (rs, bs, ds) (x:
| 'R' == x = go (y : rs, bs, x : ds) xs
| otherwise = go (rs, y : bs, x : ds) xs
-- SHUFFLE -----------------------------------------------
-- (See Knuth Shuffle task)
knuthShuffle :: [a] -> IO [a]
knuthShuffle xs = (foldr swapElems xs . zip [1 ..]) <$> randoms (length xs)
Line 326:
in a ++ c : drop 1 b</lang>
{{Out}}
<pre>Discarded:
Swapped:
Red pile:
Black pile:
True</pre>
|