Deal cards for FreeCell: Difference between revisions
Content added Content deleted
m (J: deck can be a noun, now) |
(bugfix -- J: include rng! (and code cleanup)) |
||
Line 82: | Line 82: | ||
<lang j>deck=: ,/ 'KQJT98765432A' ,"0/ 7 u: '♠♥♦♣' |
<lang j>deck=: ,/ 'KQJT98765432A' ,"0/ 7 u: '♠♥♦♣' |
||
srnd=: 3 :'SEED=:{.y,11982' |
|||
srnd '' |
|||
seed=: do bind 'SEED' |
|||
rnd=: (2^16) <.@%~ (2^31) srnd@| 2531011 + 214013 * seed |
|||
pairs=: i. <@<@~."1@,. <: - ] (| rnd)@- i. |
pairs=: i. <@<@~."1@,. <: - ] (| rnd)@- i. |
||
swaps=: [: > C.&.>/@|.@; |
swaps=: [: > C.&.>/@|.@; |
||
deal=: |
deal=: (swaps pairs@#) bind deck |
||
show=: (,"2)@:(_8 ]\ ' '&,.)</lang> |
show=: (,"2)@:(_8 ]\ ' '&,.)</lang> |
||
Example use: |
Example use: |
||
<lang j> show deal 1 |
<lang j> show deal srnd 1 |
||
J♦ 2♦ 9♥ J♣ 5♦ 7♥ 7♣ 5♥ |
J♦ 2♦ 9♥ J♣ 5♦ 7♥ 7♣ 5♥ |
||
K♦ K♣ 9♠ 5♠ A♦ Q♣ K♥ 3♥ |
K♦ K♣ 9♠ 5♠ A♦ Q♣ K♥ 3♥ |
||
Line 97: | Line 104: | ||
6♦ 8♠ 8♦ Q♠ 6♣ 3♦ 8♣ T♣ |
6♦ 8♠ 8♦ Q♠ 6♣ 3♦ 8♣ T♣ |
||
6♠ 9♣ 2♥ 6♥</lang> |
6♠ 9♣ 2♥ 6♥</lang> |
||
Note that this version ignores the special case handling of game 11982, which is not currently documented in the task. |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |