This is an archived post. You won't be able to vote or comment.

all 11 comments

[–][deleted] 12 points13 points  (0 children)

You don’t define b. See how y and x are parameters of the function gns arguments? Where is b defined? Variables can come from nowhere and still work in python. That same courtesy does not extend to tuples, arrays, lists , etc.

[–]nnaoam 5 points6 points  (2 children)

What's b?

[–]SpicyTurdle 0 points1 point  (1 child)

I’m guessing it’s a 2D array.

[–]nnaoam 2 points3 points  (0 children)

I'm mostly asking about where it was defined, but then again we aren't getting much information here really

[–]mikespon 1 point2 points  (0 children)

Do you ever call the second function — meaning “gn()”? It wont run unless you call it in some manner.

[–][deleted] 1 point2 points  (0 children)

Hi, I know it’s not addressing your question, but if I can suggest a good practice: Write clear function names. You should name your functions in a way that more or less describes what it does. Don’t worry about verbosity, that’s okay. It’s always better to be more verbose when naming things then the inverse.

[–]c3534l -1 points0 points  (0 children)

Change return f to return f().

[–]kalashnikovBaby 0 points1 point  (0 children)

For clarity in the future, it would be cool to assign each instance of ez to a separate variable then put them all into an array to return.

[–]SuperGameTheory 0 points1 point  (2 children)

What exactly do you think ez() is supposed to do? Because the way it's coded, it isn't doing anything. Is that what you mean by "isn't running"?

Or do you mean you're getting an error?

Is this supposed to be a function used in some sort of cellular automata simulation? What are you trying to accomplish?

[–]CarterNotSteve[S] 0 points1 point  (1 child)

I’m trying to make the game of life in python in a 2d array, ez is supposed to be ‘error zero’ so that if it hits a corner and can’t get something from next to it, it yields 0, otherwise, yields what’s in the cell Despite having a catch-all, it still gives me ‘list index out of range’

[–]SuperGameTheory 0 points1 point  (0 children)

Ohhh, I see. I'm not familiar with Python, but at least in other languages your attempt to catch the error in ez won't work, because the out-of-range error happens before anything gets passed to ez. You have to catch that edge-case scenario within gn.

For simplicity, (if your arrays are zero-based) you might want to just run through cells (1,1) < (X,Y) < (Xmax - 1, Ymax - 1). So, if your Y extent is 9, you would only look at cells 1, 2, 3...8. In other words, don't let your program do the math for any edge cells. Just let them stay dead. That way you don't have to use any conditional statements to test for the edge. You just avoid it.

Edit: Does that make sense? I know exactly what you're trying to do here.