Skip to content

Instantly share code, notes, and snippets.

@tadzik
tadzik / bj.pl
Created September 28, 2010 13:44
my @s=<♠ ♣ ♥ ♦>;my @r=2..10,<j q k a>;my %v=j=>10,:q(10),k=>10,a=>1|11;my @d=map {[$^a,$^b]},(@s X @r);@d.=pick(*);my @p=[],[];sub a(@c is rw){@c.unshift(@d.shift)};sub b(@c){my [email protected]({%v{.[1]}||.[1]}).reduce(*+*);$($v.grep({$_ <21}))||$v[0]};for @p {a($_);a($_);say '-'x 33;loop {if b($_)>21 {say $_~' is over 21';last};say b($_);say ~$_;last if prompt('(h) hit (s) sit? ')~~'s';a($_)}};say 'Winner: ',[max]@p.grep({b($_)<=21})