# Print Paths of Number Grid

Page 1 of 1

## 2 Replies - 1875 Views - Last Post: 11 February 2009 - 10:08 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=86236&amp;s=febb36e6c1fccafdaae7a3aad71e3856&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Everlong

Reputation: 0
• Posts: 4
• Joined: 11-February 09

# Print Paths of Number Grid

Posted 11 February 2009 - 07:09 PM

I need some help with a project. I'm trying to print out all possible combinations of a number grid.

For example:

1 3 2 5 4
2 4 3 1 5
5 3 4 2 3
4 3 1 5 2
5 3 4 1 2

The numbers are randomly generated. You start at the top of each column and then can either move down or diagonally down until you reach the bottom of any column. I need to find all of the possible number combinations. I'm stumped, any ideas?

EDIT: The numbers would probably be passed into the function as an array of nodes. And these nodes contain pointers to each of its 3 childs (center, left, and right) and its respective int value.

This post has been edited by Everlong: 11 February 2009 - 07:13 PM

Is This A Good Question/Topic? 0

## Replies To: Print Paths of Number Grid

### #2 KYA

• Wubba lubba dub dub!

Reputation: 3202
• Posts: 19,233
• Joined: 14-September 07

## Re: Print Paths of Number Grid

Posted 11 February 2009 - 09:13 PM

Unless I'm misreading, a string permutation would solve this problem nicely: see here

### #3 Everlong

Reputation: 0
• Posts: 4
• Joined: 11-February 09

## Re: Print Paths of Number Grid

Posted 11 February 2009 - 10:08 PM

Hi KYA,

I think you might have misread. The only combinations allowed begin at the top of a column and then move either down or diagonally down until it reaches the bottom row. I can't see a way to use permutations.
It is essentially like printing out all of the possible paths (from root to leaves) of a tree in which each node has three children (left-down, down, right-down).

If you did understand the problem correctly, could you elaborate on how to use a permutation with this problem?

This post has been edited by Everlong: 11 February 2009 - 10:09 PM