Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

#! perl -slw use strict; my @trinums = map $_ * ($_-1) /2, 1 .. 15; my %trinums; undef @trinums{ @trinums }; sub triSum { my $n = shift; for my $f ( 0 .. $#trinums ) { my $first = $trinums[ $f ]; for my $s ( 0 .. $first - 1, $first + 1 .. $#trinums ) { my $second = $trinums[ $s ]; my $third = $n - ( $first + $second ); return $first, $second, $third if exists $trinums{ $third +}; } } } print "$_ : ", join ' + ', triSum( $_ ) for 1 .. 80; __END__ c:\test>trinums 1 : 0 + 1 + 0 2 : 0 + 1 + 1 3 : 0 + 3 + 0 4 : 0 + 1 + 3 5 : 1 + 3 + 1 6 : 0 + 3 + 3 7 : 0 + 1 + 6 8 : 1 + 6 + 1 9 : 0 + 3 + 6 10 : 0 + 10 + 0 11 : 0 + 1 + 10 12 : 0 + 6 + 6 13 : 0 + 3 + 10 14 : 1 + 3 + 10 15 : 0 + 15 + 0 16 : 0 + 1 + 15 17 : 1 + 6 + 10 18 : 0 + 3 + 15 19 : 1 + 3 + 15 20 : 0 + 10 + 10 21 : 0 + 6 + 15 22 : 0 + 1 + 21 23 : 1 + 21 + 1 24 : 0 + 3 + 21 25 : 0 + 10 + 15 26 : 1 + 10 + 15 27 : 0 + 6 + 21 28 : 0 + 28 + 0 29 : 0 + 1 + 28 30 : 0 + 15 + 15 31 : 0 + 3 + 28 32 : 1 + 3 + 28 33 : 3 + 15 + 15 34 : 0 + 6 + 28 35 : 1 + 6 + 28 36 : 0 + 15 + 21 37 : 0 + 1 + 36 38 : 0 + 10 + 28 39 : 0 + 3 + 36 40 : 1 + 3 + 36 41 : 3 + 10 + 28 42 : 0 + 6 + 36 43 : 0 + 15 + 28 44 : 1 + 15 + 28 45 : 0 + 45 + 0 46 : 0 + 1 + 45 47 : 1 + 10 + 36 48 : 0 + 3 + 45 49 : 0 + 21 + 28 50 : 1 + 21 + 28 51 : 0 + 6 + 45 52 : 1 + 6 + 45 53 : 10 + 15 + 28 54 : 3 + 15 + 36 55 : 0 + 10 + 45 56 : 0 + 1 + 55 57 : 0 + 21 + 36 58 : 0 + 3 + 55 59 : 1 + 3 + 55 60 : 0 + 15 + 45 61 : 0 + 6 + 55 62 : 1 + 6 + 55 63 : 3 + 15 + 45 64 : 0 + 28 + 36 65 : 0 + 10 + 55 66 : 0 + 21 + 45 67 : 0 + 1 + 66 68 : 1 + 66 + 1 69 : 0 + 3 + 66 70 : 0 + 15 + 55 71 : 1 + 15 + 55 72 : 0 + 6 + 66 73 : 0 + 28 + 45 74 : 1 + 28 + 45 75 : 3 + 36 + 36 76 : 0 + 10 + 66 77 : 1 + 10 + 66 78 : 0 + 78 + 0 79 : 0 + 1 + 78 80 : 1 + 78 + 1

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Write any natural number as sum of three triangular numbers by BrowserUk
in thread Write any natural number as sum of three triangular numbers by ambrus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found