Mind boggling card trick: Difference between revisions
→{{header|Haskell}}: Wrapped the swap of n cards in an exchange function
m (→{{header|Javascript}}: minor tidying) |
(→{{header|Haskell}}: Wrapped the swap of n cards in an exchange function) |
||
Line 273:
-- SWAPPED
nSwap <- randomRIO (1, min (length rs_) (length bs_))
let (rs, bs) =
-- CHECKED
Line 290 ⟶ 289:
]
return ns
-- RED vs BLACK ----------------------------------------
Line 307 ⟶ 305:
| 'R' == x = go (y : rs, bs, x : ds) xs
| otherwise = go (rs, y : bs, x : ds) xs
exchange :: Int -> [a] -> [a] -> ([a], [a])
exchange n xs ys =
let [xs_, ys_] = splitAt n <$> [xs, ys]
in (fst ys_ <> snd xs_, fst xs_ <> snd ys_)
-- SHUFFLE -----------------------------------------------
|