Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

PHP Function

A person starts from the uppermost, leftmost corner of a grid. Each cell of grid is 0,1,2,3,4,5,6 or 7. From any cell, he can only go to right cell if this cell is 1, he can only go to lower cell if this cell is 2, he can only go to its diagonally opposite cell if this cell is 3, he can go to right and lower cell if this cell is 4, he can go to right and diagonally opposite cell if this cell is 5, he can go to lower and diagonally opposite cell if this cell is 6, he can go to right and lower and diagonally opposite cell if this cell is 7 and he can not move from this cell if this cell is 0.

view the image here:

http://www.techgig.com/files/nicUploads/849880829644419.png

Person wants to go to the lowermost, rightmost corner of the grid.

Input1: An Integer array having two elements: m, n that depict rows and columns of the grid respectively

Input2: An Integer array containing m*n elements

Examples:

Input1: {4,6}

Input2: {1,3,0,0,0,0,0,0,4,5,1,0,0,0,0,6,7,6,0,0,0,0,5,0}

http://www.techgig.com/files/nicUploads/791576448995418.png

Need to write a function to calculate the total no. of paths which can be found.

function no_of_path($input1,$input2) { //Write code here }

3 Answers

Jeff Lemay
Jeff Lemay
14,268 Points

Sounds like you don't actually have a specific question or issue you've come across... well, other than "can someone do my job?"

Jeff...its not a job. Its a challenge for the students learning here. Please take it positively and let others do it. Thanks.

Michael Timbs
Michael Timbs
15,761 Points

Sounds like a typical interview question for a PHP position? Is this one you were asked and need help with?

Yes Michael, Can you help???

Michael Timbs
Michael Timbs
15,761 Points

There is a useful treehouse course on OOP with javascript where you write a program / algorithm that solves a maze. Some of the logic behind that would probably benefit you in solving this problem.

In the maze problem you check the squares in each direction around you and make a decision based on the result. You'd be doing something similar here no doubt.

While it isn't in PHP once you have the pseudo code or logic of the algorithm the language you implement it in is irrelevant.