OH MY GOD IT'S JAWS!
Your best bet is to make a flowchart. This is what I usually do when I'm trying to solve complex but recursive problems.Also, are there any restrictions to your program?
Forbidding the use of certain functions, certain data types, etc...Our instructor pisses us off that way. >.<
lines = int(raw_input("Number of lines: "))start = raw_input("Start line: ")firstline = startnextline = []print firstlinefor i in range(lines-1): for j in range(len(start)-1): if (firstline[j-1] == "*" and firstline[j+1] == "."): nextline.append("*") elif (firstline[j-1] == "." and firstline[j+1] == "*"): nextline.append("*") else: nextline.append(".") firstline = "".join(nextline) print firstline nextline = []
def getnextrow(oldrow): size = len(oldrow) newrow = "." * size for i in range(0, size): char = "." if (oldrow[i - 1] == "*") != (oldrow[(i + 1) % size] == "*"): # modulo size so that the index wraps around char = "*" newrow[i] = char return newrowfirstrow = "..*.**.."nextrow = getnextrow(firstrow)print(nextrow)
lines = int(raw_input("Number of lines: "))start = raw_input("Start line: ")firstline = startnextline = []print firstlinefor i in range(lines-1): for j in range(len(start)): if (firstline[j-1] == "*" and firstline[j-len(start)+1] == "."): nextline.append("*") elif (firstline[j-1] == "." and firstline[j-len(start)+1] == "*"): nextline.append("*") else: nextline.append(".") firstline = "".join(nextline) print firstline nextline = []
Oh, no I know what you mean by the modulo and how the neighbours worked, I meant when I looked at your code, i didn't quite understand what you were doing
//what does def do?//def getnextrow(oldrow): size = len(oldrow) newrow = "." * size for i in range(0, size): char = "." //and what happens here?// if (oldrow[i - 1] == "*") != (oldrow[(i + 1) % size] == "*"): # modulo size so that the index wraps around char = "*" newrow[i] = char return newrowfirstrow = "..*.**.."nextrow = getnextrow(firstrow)print(nextrow)
def function_name(argument1, argument2): # code here
def add_one(number): return number + 1print(add_one(4)) # this will print out 5
if (oldrow[i - 1] == "*") != (oldrow[(i + 1) % size] == "*"):