Exemplo n.º 1
0
def new_universe():
    fn = "./in.txt"
    l2 = util.filetowordlist(fn)
    l = []
    idval = 0
    for ln in l2:
        sp = ln.split(",")
        x = int(sp[0].split("=")[1])
        y = int(sp[1].split("=")[1])
        z = int(sp[2].split("=")[1][:-1])
        l.append([idval, [x, y, z], [0, 0, 0]])
        idval += 1
    return l
Exemplo n.º 2
0
#!/usr/bin/python3
import sys
sys.path.append("..")
import util
import math

# Solving the feeding into each other problem was interesting-- my first
# thought was how threads in Golang talk to each other and use channels.
# Wasn't an option here though, so I just fed as much input as possible into
# each computer, and took its output and fed it into the next computer.
# I got stuck and was tired, so I went to bed and didn't finish. Found my
# bug the next day-- I'd initialized the computer array in the wrong place.

fn = "./in.txt"
l = util.filetowordlist("./in.txt")


def calc_with_input(list_inputs, state, currindex):
    liindex = 0
    opcodes = state
    i = currindex
    outputs = []
    while True:
        nakedstr = str(opcodes[i])
        letters = "0" * (5 - len(nakedstr)) + str(opcodes[i])
        code = int("".join(letters[3:]))
        par1imm = letters[2] == "1"
        par2imm = letters[1] == "1"
        par3imm = letters[0] == "1"
        if code > 0 and code < 9:
            if code == 1 or code == 2:
Exemplo n.º 3
0
        return False

    def num_orbits(self, acc):
        tot = 0
        # for self
        tot += acc
        # for children
        for c in self.children:
            tot += self.children[c].num_orbits(acc + 1)

        return tot


fn = "./in.txt"

l = [(x.split(")")[0], x.split(")")[1]) for x in util.filetowordlist(fn)]

t = Tree("COM")

while len(l) > 0:
    print(len(l))
    notdone = []
    for p in l:
        if not t.insert(p[0], p[1]):
            notdone.append(p)
    l = notdone

linetoyou = []
linetosanta = []
child_parent_map = {}
for p in [(x.split(")")[0], x.split(")")[1]) for x in util.filetowordlist(fn)]: