in reply to Re^2: Perl6 Contest: Test your Skills
in thread Perl6 Contest: Test your Skills
# Assumption: @hand[0]<val> == 5; sub is_good( @hand ) returns Bool { # If you have a 10, J, Q, or K anywhere in @hand, you win. if any(@hand<val>) == 10 { return true; } # If you have more than one of anything, you win. my %cardvals; %cardvals{ @hand[0..4]<num> }++; if any( %cardvals.values ) > 1 { return true; } # If you have 3+ cards in a row, you win. for 1 .. 11 -> $start { if all( @cardvals{ ($start, $start+1, $start+2) } ) { return true; } } # If +%suit{@hand[0..3]} == 1, you win. # Note: The suit of the cut-card is irrelevant. my %suits; %suits{ @hand[0..3]<suit> }++; if +%suit == 1 { return true; } # Alternately, this could have been written: # if all( @hand[0..3]<suit> ) == any( @hand[0..3]<suit> ) { # return true; # } return false; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Perl6 Contest: Test your Skills
by Limbic~Region (Chancellor) on May 19, 2005 at 19:45 UTC | |
by thor (Priest) on May 19, 2005 at 20:13 UTC | |
by Limbic~Region (Chancellor) on May 20, 2005 at 12:02 UTC | |
by thor (Priest) on May 20, 2005 at 21:47 UTC | |
by blokhead (Monsignor) on May 23, 2005 at 20:29 UTC | |
|