Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Keep It Simple, Stupid
 
PerlMonks  

Re: calculating cribbage points

by Roy Johnson (Monsignor)
on Mar 31, 2006 at 12:18 UTC ( [id://540506]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to calculating cribbage points

Just for variety, a recursive solution suggests itself.
use strict; use warnings; sub add_to { my ($target, $first_card, @others) = @_; # Base cases return [$first_card] if $first_card == $target; return () if @others == 0; # The set of cards adding up to target is # the set of cards adding up to target that include first_card, AND # the set of cards adding up to target that don't include first_card return (map([$first_card, @$_], add_to($target-$first_card, @others) +) , add_to($target, @others)); } my @hand = map 1+int(rand(10)), 1..7; print "Hand is @hand\n"; print "@$_\n" for add_to(15, @hand);

Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://540506]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.