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] |
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 |
||
[x, y] = take(2, xs), |
|||
ds_ = cons(x, ds); |
|||
return |
return ( |
||
'R' === x ? ( |
|||
go([cons(y, rs), bs, ds_]) |
|||
) : go([rs, cons(y, bs), ds_]) |
|||
)(drop(2, xs)) |
|||
})() : [rs, bs, ds_] |
|||
) : [rs, bs, ds]; |
) : [rs, bs, ds]; |
||
}; |
}; |
||
Line 391: | Line 393: | ||
[], |
[], |
||
[] |
[] |
||
] |
])(cards); |
||
}; |
}; |
||