Bathroom Security (Code Advent | Day 2)


firstLine = "ULL" secondLine = "RRDDD" thirdLine = "LURDL" fourthLine = "UUUUD" currentLoc = 5 rightBoundaries = [3, 6, 9] leftBoundaries = [1,4,7] combo1 = 0 combo2 = 0 combo3 = 0 combo4 = 0 #first combo for x in range (0,len(firstLine)): originalLoc = currentLoc z = firstLine[x] if (z == "U"): currentLoc = currentLoc - 3 elif (z == "D"): currentLoc = currentLoc + 3 elif (z == "L"): if (z in leftBoundaries): pass; else: currentLoc = currentLoc - 1 elif (z == "R"): if (z in rightBoundaries): pass; else: currentLoc = currentLoc + 1 if (currentLoc < 1 or currentLoc > 9): currentLoc = originalLoc combo1 = currentLoc print ("Combo 1 : ", str(combo1)) #second combo for x in range (0,len(secondLine)): originalLoc = currentLoc z = secondLine [x] if (z == "U"): currentLoc = currentLoc - 3 elif (z == "D"): currentLoc = currentLoc + 3 elif (z == "L"): if (z in leftBoundaries): pass; else: currentLoc = currentLoc - 1 elif (z == "R"): if (z in rightBoundaries): pass; else: currentLoc = currentLoc + 1 if (currentLoc < 1 or currentLoc > 9): currentLoc = originalLoc combo2 = currentLoc print ("Combo 2 : ", str(combo2)) #third combo for x in range (0,len(thirdLine)): originalLoc = currentLoc z = thirdLine[x] if (z == "U"): currentLoc = currentLoc - 3 elif (z == "D"): currentLoc = currentLoc + 3 elif (z == "L"): if (z in leftBoundaries): pass; else: currentLoc = currentLoc - 1 elif (z == "R"): if (z in rightBoundaries): pass; else: currentLoc = currentLoc + 1 if (currentLoc < 1 or currentLoc > 9): currentLoc = originalLoc combo3 = currentLoc print ("Combo 3 : ", str(combo3)) #fourth combo for x in range (0,len(fourthLine)): originalLoc = currentLoc z = fourthLine[x] if (z == "U"): currentLoc = currentLoc - 3 elif (z == "D"): currentLoc = currentLoc + 3 elif (z == "L"): if (z in leftBoundaries): pass; else: currentLoc = currentLoc - 1 elif (z == "R"): if (z in rightBoundaries): pass; else: currentLoc = currentLoc + 1 if (currentLoc < 1 or currentLoc > 9): currentLoc = originalLoc combo4 = currentLoc print ("Combo 4 : ", str(combo4))

Loading Please Wait...