Mind boggling card trick: Difference between revisions

m
(Realize in F#)
Line 37:
//Be boggled? Nigel Galloway: September 19th., 2018
let N=System.Random()
let fN=List.unfold(function |(0,0)->None |(n,g)->let ng=N.Next n+g in if ng>=n then Some("Black",(n,g-1)) else Some("Red",(n-1,g)))(26,26)
let fG n=let (n,n')::(g,g')::_=List.countBy(fun (n::g::_)->if n=g then n else g) n in sprintf "%d %s cards and %d %s cards" n' n g' g
printf "A well shuffled deck -> "; List.iter (printf "%s ") fN; printfn ""
Line 48:
The Red pile contains 3 Black cards and 10 Red cards
</pre>
 
=={{header|Factor}}==
<lang factor>USING: accessors combinators.extras formatting fry
2,172

edits