Jump to content

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) = takeexchange nSwap rs_ <> drop nSwap bs_
let rs = take nSwap bs_ <> drop nSwap rs_
-- 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 -----------------------------------------------
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.