Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: compute paths in Pascal's triangle (aka Tartaglia's one)

by LanX (Saint)
on Mar 22, 2018 at 16:29 UTC ( [id://1211549]=note: print w/replies, xml ) Need Help??


in reply to Re: compute paths in Pascal's triangle (aka Tartaglia's one)
in thread compute paths in Pascal's triangle (aka Tartaglia's one)

So what if the start is not "0-0" ? ;-)

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery

  • Comment on Re^2: compute paths in Pascal's triangle (aka Tartaglia's one)

Replies are listed 'Best First'.
Re^3: compute paths in Pascal's triangle (aka Tartaglia's one)
by tybalt89 (Monsignor) on Mar 23, 2018 at 19:48 UTC

    Here's the functional version Re: compute paths in Pascal's triangle (aka Tartaglia's one) modified to allow a top other than 0-0.

    #!/usr/bin/perl # http://perlmonks.org/?node_id=1211497 use strict; use warnings; sub up { my ($row, $col) = split /-/, $_[0]; my ($startrow, $startcol) = split /-/, $_[-1]; return $_[0] eq $_[-1] ? "@_[0..@_-2]\n" : ($row - $startrow > 0 && $col - $startcol > 0 && up( ~-$row . '-' . ~-$col, @_ ) ) . ($row - $startrow > $col - $startcol && up( ~-$row . '-' . $col, @_ ) ); } print up( '3-1', '1-0' ); # bottom, top
      I think you could just have sticked with your first program, and solve it by a coordinate transformation.

      3-1 to 1-0 is essentially the same like 2-1 to 0-0

      0-0 1-0 1-1 2-0 2-1 2-2 3-0 3-1 3-2 3-3 4-0 4-1 4-2 4-3 4-4 5-0 5-1 5-2 5-3 5-4 5-5

      Though you would have ended with more readable code ... nah forget it! ;-)

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Wikisyntax for the Monastery

Re^3: compute paths in Pascal's triangle (aka Tartaglia's one)
by tybalt89 (Monsignor) on Mar 22, 2018 at 17:33 UTC

    That would be an entirely different problem altogether </Airplane joke>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-24 23:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found