Deal cards for FreeCell: Difference between revisions

Updated to work with Nim 1.4.
(Added Delphi example)
(Updated to work with Nim 1.4.)
Line 2,262:
{{trans|Python}}
<lang nim>import sequtils, strutils, os
 
proc randomGenerator(seed: int): iterator: int =
var seedstate = seed
return iterator: int =
while true:
seedstate = (seed.int64state * 214013 + 2531011) and int32.high
yield seedstate shr 16
 
proc deal(seed: int): seq[int] =
const nc = 52
result = toSeq countdown(nc - 1, 0)
var rnd = randomGenerator seed
for i in 0 .. < nc:
let r = rnd()
let j = (nc - 1) - r mod (nc - i)
swap result[i], result[j]
 
proc show(cards: seq[int]) =
var l = newSeq[string]()
for c in cards:
Line 2,285:
for i in countup(0, cards.high, 8):
echo " ", l[i..min(i+7, l.high)].join(" ")
 
let seed = if paramCount() == 1: paramStr(1).parseInt else: 11982
echo "Hand ", seed
Anonymous user