Mind boggling card trick: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: fixed code to not shuffle the same card.)
(→‎{{header|Javascript}}: (Slight simplification of threeStacks function by currying))
Line 374: Line 374:
// threeStacks :: [Chars] -> ([Chars], [Chars], [Chars])
// threeStacks :: [Chars] -> ([Chars], [Chars], [Chars])
const threeStacks = cards => {
const threeStacks = cards => {
const go = ([rs, bs, ds], xs) => {
const go = ([rs, bs, ds]) => xs => {
const lng = xs.length;
const lng = xs.length;
return 0 < lng ? (
return 0 < lng ? (
1 < lng ? (() => {
1 < lng ? (() => {
const
const
rest = drop(2, xs),
[x, y] = take(2, xs),
[x, y] = take(2, xs);
ds_ = cons(x, ds);
return 'R' === x ? (
return (
go([cons(y, rs), bs, cons(x, ds)], rest)
'R' === x ? (
) : go([rs, cons(y, bs), cons(x, ds)], rest)
go([cons(y, rs), bs, ds_])
})() : [rs, bs, cons(x, ds)]
) : go([rs, cons(y, bs), ds_])
)(drop(2, xs))
})() : [rs, bs, ds_]
) : [rs, bs, ds];
) : [rs, bs, ds];
};
};
Line 391: Line 393:
[],
[],
[]
[]
], cards)
])(cards);
};
};