Playing cards: Difference between revisions

Added Wren
m (Corrected a spelling mistake.)
(Added Wren)
Line 6,966:
Reg_ins(9) // insert the cards here
Return</lang>
 
=={{header|Wren}}==
{{trans|Kotlin}}
<lang ecmascript>import "random" for Random
 
var FACES = "23456789TJQKA"
var SUITS = "shdc"
 
var createDeck = Fn.new {
var cards = []
SUITS.each { |suit| FACES.each { |face| cards.add("%(face)%(suit)") } }
return cards
}
 
var dealTopDeck = Fn.new { |deck, n| deck.take(n).toList }
 
var dealBottomDeck = Fn.new { |deck, n| deck[-n..-1][-1..0] }
 
var printDeck = Fn.new { |deck|
for (i in 0...deck.count) {
System.write("%(deck[i]) ")
if ((i + 1) % 13 == 0 || i == deck.count - 1) System.print()
}
}
 
var deck = createDeck.call()
System.print("After creation, deck consists of:")
printDeck.call(deck)
Random.new().shuffle(deck)
System.print("\nAfter shuffling, deck consists of:")
printDeck.call(deck)
var dealtTop = dealTopDeck.call(deck, 10)
System.print("\nThe 10 cards dealt from the top of the deck are:")
printDeck.call(dealtTop)
var dealtBottom = dealBottomDeck.call(deck, 10)
System.print("\nThe 10 cards dealt from the bottom of the deck are:")
printDeck.call(dealtBottom)</lang>
 
{{out}}
<pre>
After creation, deck consists of:
2s 3s 4s 5s 6s 7s 8s 9s Ts Js Qs Ks As
2h 3h 4h 5h 6h 7h 8h 9h Th Jh Qh Kh Ah
2d 3d 4d 5d 6d 7d 8d 9d Td Jd Qd Kd Ad
2c 3c 4c 5c 6c 7c 8c 9c Tc Jc Qc Kc Ac
 
After shuffling, deck consists of:
Qs 9c 3c Qd 2h 5h As 5c 7s 7d 6s Qh Jc
Td 9s 6h Ad 5d 2d 4c 8d Kh Kc 8s Tc 7c
Ts 9h 3d 9d 7h 2s 3s 4d 5s Ac Kd 4s Ks
4h 8c Qc 6d Th 6c Jh 8h 2c 3h Ah Js Jd
 
The 10 cards dealt from the top of the deck are:
Qs 9c 3c Qd 2h 5h As 5c 7s 7d
 
The 10 cards dealt from the bottom of the deck are:
Jd Js Ah 3h 2c 8h Jh 6c Th 6d
</pre>
 
=={{header|XPL0}}==
9,479

edits