def main(): orbitDict = { orbiter: orbitee for i in x.split() for orbitee, orbiter in [i.split(")")] } myDistances = dict() currentBody = "YOU" i = 0 while currentBody != "COM": myDistances[currentBody] = i currentBody = orbitDict[currentBody] i += 1 sanDistances = dict() currentBody = "SAN" i = 0 while currentBody != "COM": if currentBody in myDistances: sanDistances[currentBody] = i currentBody = orbitDict[currentBody] i += 1 min = -1 for each in sanDistances: if min == -1 or sanDistances[each] + myDistances[each] < min: min = sanDistances[each] + myDistances[each] print( min - 2 ) # minus two because it's not orbit distance, but hops, so hopping to the first orbit isn't counted
def main(): inp = int(input("Enter your system ID: ")) pos = 0 currentIntcodeList = list(map(int, x.split(","))) while True: pos = intcodeDriver(currentIntcodeList, pos, inp) if pos == 0: print("Received halt code.") return if pos == -1: return
def main(): orig = list(map(int, x.split(","))) orig = orig + [0] * 3000000 pos = 0 while True: #print(orig[:16], orig[100], orig[101], relativeBase) pos = intcodeDriver(orig, pos, 1) if pos == -2: break if pos == -1: print("Finished") break
def main(): intcodeList = list(map(int, x.split(","))) intcodeList[1] = 12 intcodeList[2] = 2 pos = 0 while True: pos = intcodeDriver(intcodeList, pos) #-1 means unexpected intcode operation if pos == -1: print("Unexpected intcode operation. Unable to continue") return #0 Means it has returned to the start, i.e. the halt code was given if pos == 0: #Print the first value for task 1 print("Done. First value is", intcodeList[0]) return
def main(): global lastVal orig = list(map(int, x.split(","))) max = -1 for each in permutations([1, 2, 3, 4, 0]): lastVal = 0 for i in each: currentIntcodeList = orig + [] pos = intcodeDriver(currentIntcodeList, 0, i) while True: pos = intcodeDriver(currentIntcodeList, pos, lastVal) if pos == 0: #print("Received halt code.") break if pos == -1: break if lastVal > max: max = lastVal print(max)
def main(): orig = list(map(int, x.split(","))) for i in range(100): for j in range(100): currentList = orig + [] currentList[1] = i currentList[2] = j pos = 0 while True: pos = intcodeDriver(currentList, pos) #-1 means unexpected intcode operation if pos == -1: print("Unexpected intcode operation. Unable to continue") break #0 Means it has returned to the start, i.e. the halt code was given if pos == 0: break if currentList[0] == 19690720: print("Found the solution:", 100 * i + j) return print("No solution found. Double check input")
def main(): global lastVal orig = list(map(int, x.split(","))) max = -1 answerPermutation = [] for each in permutations([5,6,7,8,9]): lastVal = 0 a = orig + [] b = orig + [] c = orig + [] d = orig + [] e = orig + [] phase = each amp = 0 amps = {0:a, 1:b, 2:c, 3:d, 4:e} posDict = {0:0, 1:0, 2:0, 3:0, 4:0} #Seed the initial phase state for each amplifier for i in range(5): posDict[i], _ = intcodeDriver(amps[i], 0, phase[i]) #Give the initial input to amp A, i.e. last val is 0 posDict[0], _ = intcodeDriver(amps[0], posDict[0], 0) done = False while not done: while True: posDict[amp], next = intcodeDriver(amps[amp], posDict[amp], lastVal) if next: if amp == 4 and posDict[amp] == -1: #-1 means it halted. If the 4th amp, the final one, halted, it means the output is done #print("Final amp halted") done = True break amp += 1 amp %= 5 if lastVal > max: max = lastVal answerPermutation = each print(max, answerPermutation)
def part2(): #A way to write an anonymous recursive lambda function print(sum(map((lambda a: lambda v: a(a,v))(lambda s,i: (i//3)-2 + s(s, (i//3)-2) if i>8 else 0), map(int, x.split()))))
def main(): orbitDict = { orbiter: orbitee for i in x.split() for orbitee, orbiter in [i.split(")")] } print(sum(howManyOrbits(orbitDict, body) for body in orbitDict))
def main(): print(sum([(i // 3) - 2 for i in map(int, x.split())]))