Mind boggling card trick: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: Swapped to a more direct (recursive) formulation of threeStacks) |
|||
Line 264: | Line 264: | ||
import Data.Monoid ((<>)) |
import Data.Monoid ((<>)) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
let cut = quot (length cards) 2 |
|||
discards = take cut cards |
|||
pairs = (zip discards $ drop cut cards) |
|||
(rs, bs) = partition (('R' ==) . fst) pairs |
|||
in (snd <$> rs, snd <$> bs, discards) |
|||
-- TEST ------------------------------------------------ |
|||
main :: IO [Int] |
main :: IO [Int] |
||
main = do |
main = do |
||
Line 306: | Line 290: | ||
] |
] |
||
return ns |
return ns |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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 ----------------------------------------------- |
-- SHUFFLE ----------------------------------------------- |