Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Forced Indentation of Paths

Name: Anonymous 2010-07-26 7:34

Hey /prog/ Can you help me out with this plox? I'm a noob and don't understand why this isn't working. :( I just want it to return the paths, but it only does one right one and then two horribly wrong ones and then stops.


area = [[1,0,0,0],
    [0,0,0,0],
    [0,0,0,0],
    [0,0,0,1]]

start = { "x" : 0, "y" : 0}
end = { "x" : 3, "y" : 3}
path = []

def findPaths(start, end, path, area):
    # Goal Reached
    if end == start:
        path.append(start)
        drawPath(path, area)
        return True
   
    # Validate Move
    if start["x"] < 0:
        return False
    if start["y"] < 0:
        return False
    if start["y"] >= len(area):
        return False
    if start["x"] >= len(area[0]):
        return False
    if start in path:
        return False
   
    # Append Path
    path.append(start)
   
    # Paths - Clockwise
    findPaths({"x" : start["x"], "y" : start["y"] + 1}, end, path, area)
    findPaths({"x" : start["x"] + 1, "y" : start["y"] + 1}, end, path, area)
    findPaths({"x" : start["x"] + 1, "y" : start["y"]}, end, path, area)
    findPaths({"x" : start["x"] + 1, "y" : start["y"] - 1}, end, path, area)
    findPaths({"x" : start["x"], "y" : start["y"] - 1}, end, path, area)
    findPaths({"x" : start["x"] - 1, "y" : start["y"] - 1}, end, path, area)
    findPaths({"x" : start["x"] - 1, "y" : start["y"]}, end, path, area)
    findPaths({"x" : start["x"] - 1, "y" : start["y"] - 1}, end, path, area)

def drawPath(path, area):
    for n in range(len(path)):
        area[path[n]["x"]][path[n]["y"]] = n
    for y in range(len(area)):
        for x in range(len(area[0])):
            print area[x][y],
        print
   
    print "\n".join([str(x) for x in path])
    print "===="

findPaths(start, end, path, area)



0 0 0 0
1 0 0 0
2 0 0 0
3 4 5 6
{'y': 0, 'x': 0}
{'y': 1, 'x': 0}
{'y': 2, 'x': 0}
{'y': 3, 'x': 0}
{'y': 3, 'x': 1}
{'y': 3, 'x': 2}
{'y': 3, 'x': 3}
====
0 0 0 0
1 0 0 0
2 0 0 7
3 4 5 8
{'y': 0, 'x': 0}
{'y': 1, 'x': 0}
{'y': 2, 'x': 0}
{'y': 3, 'x': 0}
{'y': 3, 'x': 1}
{'y': 3, 'x': 2}
{'y': 3, 'x': 3}
{'y': 2, 'x': 3}
{'y': 3, 'x': 3}
====
0 0 11 10
1 0 12 9
2 0 13 7
3 4 5 14
{'y': 0, 'x': 0}
{'y': 1, 'x': 0}
{'y': 2, 'x': 0}
{'y': 3, 'x': 0}
{'y': 3, 'x': 1}
{'y': 3, 'x': 2}
{'y': 3, 'x': 3}
{'y': 2, 'x': 3}
{'y': 3, 'x': 3}
{'y': 1, 'x': 3}
{'y': 0, 'x': 3}
{'y': 0, 'x': 2}
{'y': 1, 'x': 2}
{'y': 2, 'x': 2}
{'y': 3, 'x': 3}
====

Name: Anonymous 2010-07-26 7:47


def findPaths(start, end, path, area):


HAHAHA.


I stopped reading right there

Name: Anonymous 2010-07-26 8:06

this looks like homework

Name: Anonymous 2010-07-26 8:50

if start in path:

Name: Anonymous 2010-07-26 8:58

As much as I hate to bring this up, you should read Xarn's blag.

Name: Anonymous 2010-07-26 11:04

... What oh God no. No, fuck this shit.

Name: Anonymous 2010-07-26 13:38

Why are you using dictionaries.

Name: Anonymous 2010-07-26 14:11

The more I read this, the more amazed I am that it gets as far as it does.

Name: Anonymous 2010-07-26 14:41

>>1

if
if
if
if
if

findPaths
findPaths
findPaths
findPaths
findPaths
findPaths
findPaths
findPaths

Surely to god no TC language forces you to do this? Why are you doing it?

Name: Anonymous 2010-07-26 23:16

I sort of want whatshisface to slink back in here an explain himself

Name: Anonymous 2010-07-27 2:26

What are you trying to do, this Euler problem?
http://projecteuler.net/index.php?section=problems&id=15

If so, this isn't how you should be doing it. The number of paths is essentially the sum of the first n binomial coefficients. I'm not going to bother explaining why because by the looks of it you are far too stupid, but this sequence should help: http://www.research.att.com/~njas/sequences/A000984

What's more you fail to understand the distinction between a reference and a value; and it doesn't look like you have ever seen a clock either.

Name: Anonymous 2010-07-27 3:06

>>11
That problem is trivial and requires only a simple multiplication, and certainly not a program that is over one line of code.

Name: Anonymous 2010-07-27 13:01

I'll be slightly helpful and tell you how to write a program that does it. That's not the best way, although you might actually learn something.

f(x, y) is the number of possible routes to get from (x, y) to (20, 20).

f(20, 20) = 1
f(x, y) = f(x + 1, y) + f(x, y + 1)
(but you need to make sure that x < 20 and y < 20)

You should be able to figure it out from that.

Name: ​​​​​​​​​​ 2010-10-22 2:18

Name: Anonymous 2010-11-26 1:12

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List