コード例 #1
0
ファイル: main.py プロジェクト: hyoputer/AdventOfCode
def part1():
  code = parse_input()
  com = intcom.intcomProgram(code[:])
  
  inventory = ['sand', 'space heater', 'loom', 'wreath', 'space law space brochure', 'pointer', 'planetoid', 'festive hat']
  
  com.put_Input(to_ascii('north')+to_ascii('north')+to_ascii('take sand')+to_ascii('south')+to_ascii('south')+to_ascii('south')+to_ascii('take space heater')+
                to_ascii('south')+to_ascii('east')+to_ascii('take loom')+to_ascii('west')+to_ascii('north')+to_ascii('west')+to_ascii('take wreath')+to_ascii('south')+
               to_ascii('take space law space brochure')+to_ascii('south')+to_ascii('take pointer')+to_ascii('north')+to_ascii('north')+to_ascii('east')+to_ascii('north')+
               to_ascii('west')+to_ascii('south')+to_ascii('take planetoid')+to_ascii('north')+to_ascii('west')+to_ascii('take festive hat')+to_ascii('south')+to_ascii('west')+
               to_ascii('inv'))
  
  for i in range(8+1):
    for combinations in itertools.combinations(inventory, i):
      for e in combinations:
        com.put_Input(to_ascii('drop '+e))
        
      com.put_Input(to_ascii('north'))
      com.run()

      o = com.get_Output()
      print(to_string(list(o.queue)))
      
      for e in combinations:
        com.put_Input(to_ascii('take '+e))
コード例 #2
0
ファイル: main.py プロジェクト: hyoputer/AdventOfCode
def make_map(code, rng):
    m = [[0 for i in range(rng)] for i in range(rng)]
    for x in range(rng):
        for y in range(rng):
            com = intcom.intcomProgram(code[:])
            com.put_Input([x, y])
            com.run()
            m[x][y] = com.get_Last_Output()
    return m
コード例 #3
0
ファイル: main.py プロジェクト: hyoputer/AdventOfCode
def part2(code):
    x = 99
    y = 0
    while True:
        f = False
        while True:
            com = intcom.intcomProgram(code[:])
            com.put_Input([x, y])
            #print([x,y])
            com.run()
            if com.get_Last_Output() == 1:
                com2 = intcom.intcomProgram(code[:])
                com2.put_Input([x - 99, y + 99])
                com2.run()
                if com2.get_Last_Output() == 1:
                    return (x - 99) * 10000 + y
                else:
                    break
            y += 1

        x += 1
コード例 #4
0
ファイル: main.py プロジェクト: hyoputer/AdventOfCode
def problem(part2=False):
    code = parse_input()

    coms = []

    for i in range(50):
        com = intcom.intcomProgram(code[:])
        com.put_Input([i])
        com.run()
        coms.append(com)

    last_nat_y = 0.5

    while True:
        idle_flag = True
        for i in range(50):
            if coms[i].Input.empty():
                coms[i].put_Input([-1])
            else:
                idle_flag = False

            coms[i].run()

            output = coms[i].get_Output()
            while not output.empty():
                address = output.get()
                output_x = output.get()
                output_y = output.get()

                if address < 50:
                    coms[address].put_Input([output_x, output_y])

                if address == 255:
                    if not part2:
                        return output_y
                    else:
                        NAT = [output_x, output_y]

        if idle_flag:
            if NAT[1] == last_nat_y:
                return last_nat_y
            else:
                last_nat_y = NAT[1]

            coms[0].put_Input(NAT)
コード例 #5
0
ファイル: main.py プロジェクト: hyoputer/AdventOfCode
def part1():
    code = parse_input()

    com = intcom.intcomProgram(code)
    com.put_Input(make_input('NOT A J'))
    com.put_Input(make_input('NOT B T'))
    com.put_Input(make_input('OR T J'))
    com.put_Input(make_input('NOT C T'))
    com.put_Input(make_input('OR T J'))
    com.put_Input(make_input('AND D J'))
    com.put_Input(make_input('WALK'))

    com.run()

    #o = com.get_Output()

    #print(''.join(list(map(lambda x : chr(x), list(o.queue) ))))
    return com.get_Last_Output()
コード例 #6
0
ファイル: main_2.py プロジェクト: hyoputer/AdventOfCode
import intcom

inline = input()

code_str = inline.split(',')

code = list(map(int, code_str))
code[0] = 2

com = intcom.intcomProgram(code)

res = 0
while not com.is_done():
    com.run()

    ball_p = 0
    paddle_p = 0

    o = com.get_Output()
    t = list(o.queue)

    idx = 0
    while True:
        if idx + 2 >= len(t):
            break
        if t[idx] == -1 and t[idx + 1] == 0:
            res = t[idx + 2]
        if t[idx + 2] == 3:
            paddle_p = t[idx]
        elif t[idx + 2] == 4:
            ball_p = t[idx]
コード例 #7
0
ファイル: main.py プロジェクト: hyoputer/AdventOfCode
    com.put_Input(make_input('R6R10L10'))
    com.put_Input(make_input('R10L10L12R6'))
    com.put_Input(make_input('n'))

    com.run()

    return com.get_Last_Output()


inline = input()

code_str = inline.split(',')

code = list(map(int, code_str))

com = intcom.intcomProgram(code[:])
com.run()

o = com.get_Output()
ASCII_OUTPUT = [chr(e) for e in list(o.queue)]
m = make_map(ASCII_OUTPUT)

print(''.join(ASCII_OUTPUT))
print(part1(m))

code[0] = 2

print('com2')
com2 = intcom.intcomProgram(code[:])

print(part2(com2, m))