Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Write any natural number as sum of three triangular numbers

by ambrus (Abbot)
on Sep 25, 2011 at 11:00 UTC ( [id://927735]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    =begin output
    
  2. or download this
    50 = 28 + 1 + 21
    51 = 0 + 15 + 36
    52 = 21 + 3 + 28
    53 = 10 + 28 + 15
    54 = 6 + 3 + 45
    
  3. or download this
    
    =cut 
    ...
    use warnings; use 5.010; use strict;
    use POSIX qw"floor";
    
  4. or download this
    sub triang_decompose_1 {
        my($goal, $found, $n0, $n1, $n2);
    ...
        }
    }
    
  5. or download this
    sub triang_decompose_2 {
        my($goal, $found, $n0, $n1, $n2);
    ...
        }
    }
    
  6. or download this
    sub triang_decompose_3 {
        my($goal, $found, $n0, $n1, $n2, $rem2, $rem1);
    ...
            }
        }
    }
    
  7. or download this
    
    say "Solution 1:";
    ...
    triang_decompose_3();
    
    __END__
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://927735]
Approved by ww
Front-paged by Corion
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-03-19 07:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found