Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Challenge: Number of unique ways to reach target sum

by ambrus (Abbot)
on Feb 14, 2006 at 22:20 UTC ( [id://530251]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    ruby -we '@a = (0 .. 10).map { (0 .. 667).map { (0 .. 101).map { (); }
    +; }; }; def res c = 10, t = 667, m = 101; if t < 0; 0; else @a[c][t][
    +m] ||= if 0 == c && 0 == t; 1; elsif 0 == c; 0; elsif 0 == t; 0; else
    + (1 ... m).inject(0) {|r, x| r + res(c - 1, t - x, x); } end; end; en
    +d; (1 .. 10).each {|c| res c; warn "[c=#{c}]"; }; p res;'
    
  2. or download this
     ruby -we '@a = (0 .. 10).map { (0 .. 667).map { (0 .. 101).map { (); 
    +}; }; }; def res c = 10, t = 667, m = 101; if t < 0; 0; else @a[c][t]
    +[m] ||= if 0 == c && 0 == t; 1; elsif 0 == c; 0; elsif 0 == t; 0; els
    +e (1 ... m).inject(0) {|r, x| r + res(c - 1, t - x, x); } end; end; e
    +nd; p res;'
    14479062752
    

Log In?
Username:
Password:

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

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

    No recent polls found