Jump to content

Deal cards for FreeCell: Difference between revisions

Added Wren
m (added related tasks)
(Added Wren)
Line 3,540:
KS AC KD 9C 9H 6C JC 2D
4C 8H TS 6S</pre>
 
=={{header|Wren}}==
{{trans|Kotlin}}
<lang ecmascript>class Lcg {
construct new(a, c, m, d, s) {
_a = a
_c = c
_m = m
_d = d
_s = s
}
 
nextInt() {
_s = (_a * _s + _c) % _m
return _s / _d
}
}
 
var CARDS = "A23456789TJQK"
var SUITS = "♣♦♥♠".toList
 
var deal = Fn.new {
var cards = List.filled(52, null)
for (i in 0...52) {
var card = CARDS[(i/4).floor]
var suit = SUITS[i%4]
cards[i] = card + suit
}
return cards
}
 
var game = Fn.new { |n|
if (n.type != Num || !n.isInteger || n <= 0) {
Fiber.abort("Game number must be a positive integer.")
}
System.print("Game #%(n):")
var msc = Lcg.new(214013, 2531011, 1<<31, 1<<16, n)
var cards = deal.call()
for (m in 52..1) {
var index = (msc.nextInt() % m).floor
var temp = cards[index]
cards[index] = cards[m - 1]
System.write("%(temp) ")
if ((53 - m) % 8 == 0) System.print()
}
System.print("\n")
}
 
game.call(1)
game.call(617)</lang>
 
{{out}}
<pre>
Game #1:
J♦ 2♦ 9♥ J♣ 5♦ 7♥ 7♣ 5♥
K♦ K♣ 9♠ 5♠ A♦ Q♣ K♥ 3♥
2♠ K♠ 9♦ Q♦ J♠ A♠ A♥ 3♣
4♣ 5♣ T♠ Q♥ 4♥ A♣ 4♦ 7♠
3♠ T♦ 4♠ T♥ 8♥ 2♣ J♥ 7♦
6♦ 8♠ 8♦ Q♠ 6♣ 3♦ 8♣ T♣
6♠ 9♣ 2♥ 6♥
 
Game #617:
7♦ A♦ 5♣ 3♠ 5♠ 8♣ 2♦ A♥
T♦ 7♠ Q♦ A♣ 6♦ 8♥ A♠ K♥
T♥ Q♣ 3♥ 9♦ 6♠ 8♦ 3♦ T♣
K♦ 5♥ 9♠ 3♣ 8♠ 7♥ 4♦ J♠
4♣ Q♠ 9♣ 9♥ 7♣ 6♥ 2♣ 2♠
4♠ T♠ 2♥ 5♦ J♣ 6♣ J♥ Q♥
J♦ K♠ K♣ 4♥
</pre>
 
=={{header|XPL0}}==
9,483

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.