Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: calculating cribbage points

by zer (Deacon)
on Mar 30, 2006 at 19:06 UTC ( [id://540248]=note: print w/replies, xml ) Need Help??


in reply to calculating cribbage points

#!/usr/bin/perl -w use strict; use warnings; sub fifteens { my $card = shift; $card =~ tr/SCHD//; $card =~ s/[JQK]/10/g; $card =~ s/A/1/g; my ($i,$o,$p,$k,$l); my ( @cards) = split /,/, $card; $_ = 0; # count the 2 card combinations that add up to 15 for ($i = 0; $i<=$#cards;$i++){ for ($o = $i+1; $o<=$#cards;$o++){ $_ += 2 if (( $cards[$i] + $cards[$o])== 15 ); for ($p=$o+1; $p<=$#cards;$p++){ $_ += 2 if ($cards[$i] + $cards[$o]+ $cards[$p]==15); for ($k=$p+1;$k<=$#cards;$k++){ $_ += 2 if ($cards[$i] + $cards[$o]+ $cards[$p] + +$cards[$k] ==15); $_ += 2 if ($cards[$i] + $cards[$o]+ $cards[$p] + +$cards[$k] + $cards[4] ==15); } } } } # count the 3 card combinations that add up to 15 $_; } ## end sub fifteens print "hand = A,2,3,4,5 \tTotal =", fifteens ( "A,2,3,4,5"), "\n"; print "hand = 5,5,5,J,5 \tTotal =", fifteens ( "5,5,5,J,5"), "\n"; print "hand = 6,7,8,9,5 \tTotal =", fifteens ( "6,7,8,9,5"), "\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://540248]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-23 20:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found