Mind boggling card trick: Difference between revisions

→‎{{header|Haskell}}: (Some tidying of the threeStack function, refreshed sample output)
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 cards = go ([], [], []) cards
where
go tpl [] = tpl
go (rs, bs, ds) ([x:[]) = (rs, bs, x : ds)
go (rs, bs, ds) (x: y: xs)
| '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: RBRRRRBRRBRRRBBBBRBBBRRBBBRRRRRBBBBBRBBBRBBRBRRBRRRB
Swapped: 37
Red pile: BRBBBBRRRBRRRBBBRRBRBRBBRR
Black pile: RRRBBRBBRBBBRBRRRRRBBRBBRB
RRRRRRRRRRRRR = Red cards in the red pile
BBBBBBBBBBBBB = Black cards in the black pile
True</pre>
 
9,659

edits