Exemplo n.º 1
0
def main():
    ex21_0 = get_input_by_lines(21)
    ex21 = dictify(ex21_0)

    pixelgrid = PixelGrid(key_=ex21, arr_=INIT_ARR)
    pixelgrid.iterate(5)
    print(pixelgrid.get_count())
Exemplo n.º 2
0
def main():
    ex16_0 = get_input_by_lines(16)
    ex16 = ex16_0[0].split(',')

    starting = 'abcdefghijklmnop'
    line = Danceline(starting)
    print(''.join(line.acts(ex16)))
Exemplo n.º 3
0
def main():
    ex22_0 = get_input_by_lines(22)
    ex22 = np.array([list(x) for x in ex22_0])

    virusgrid = VirusGrid(ex22)
    for i in range(10000):
        virusgrid.burst()
    print(virusgrid.infect_cnt)
Exemplo n.º 4
0
def main():
    def listrange(mylist):
        mylist = sorted(mylist)
        return mylist[-1] - mylist[0]

    ex2_0 = get_input_by_lines(2)
    ex2 = np.array([x.split(',') for x in ex2_0]).astype(np.int32)

    print(np.apply_along_axis(listrange, axis=1, arr=ex2).sum())
Exemplo n.º 5
0
def main():
    print("This code takes about 7s to run. Ctrl+C to break before then.")

    ex25_0 = get_input_by_lines(25)
    ex25 = encode_instr(ex25_0)

    tm25 = TM(ex25)
    tm25.step(NUM_STEPS)
    print(tm25.checksum())
Exemplo n.º 6
0
def main():
    print("This code takes about 6min to run. Ctrl+C to break before then.")

    ex24_0 = get_input_by_lines(24)
    ex24 = [tuple(map(int, x.split('/'))) for x in ex24_0]

    bridges24 = make_bridges(ex24)
    sum24 = [np.array(x).flatten().sum() for x in bridges24]
    print(max(sum24))
Exemplo n.º 7
0
def main():
    print("This code takes about 75s to run. Ctrl+C to break before then.")

    ex21_0 = get_input_by_lines(21)
    ex21 = dictify(ex21_0)

    pixelgrid = PixelGrid(key_=ex21, arr_=INIT_ARR)
    pixelgrid.iterate(18)
    print(pixelgrid.get_count())
Exemplo n.º 8
0
def main():
    ex16_0 = get_input_by_lines(16)
    ex16 = ex16_0[0].split(',')

    starting = 'abcdefghijklmnop'
    line = Danceline(starting)

    # Cycle repeats after 60 dances; hardcoded 1e9 % 60
    print(''.join(line.repeat(ex16, 40)))
Exemplo n.º 9
0
def main():
    def isanagram(str1, str2):
        return sorted(list(str1)) == sorted(list(str2))

    ex4_0 = get_input_by_lines(4)
    ex4 = [x.split(' ') for x in ex4_0]

    print(len(ex4) - sum([reduce((lambda x, y: x or y),
                                 [isanagram(*x) for x in combinations(elem, 2)])
                          for elem in ex4]))
Exemplo n.º 10
0
def main():
    def get_repeat_sum(num):
        numlist = str(num) + str(num)[0]
        sum_ = 0
        for idx, digit in enumerate(numlist[:-1]):
            sum_ += int(digit == numlist[idx + 1]) * int(digit)
        return sum_

    ex1 = ','.join(get_input_by_lines(1))
    print(get_repeat_sum(ex1))
Exemplo n.º 11
0
def main():
    print("This code takes about 55s to run. Ctrl+C to break before then.")

    ex22_0 = get_input_by_lines(22)
    ex22 = np.array([list(x) for x in ex22_0])

    virusgrid = VirusGrid(ex22)
    for i in range(10000000):
        virusgrid.burstv2()
    print(virusgrid.infect_cnt)
Exemplo n.º 12
0
def main():
    ex19_0 = get_input_by_lines(19, strip=False)
    ex19 = np.array(list(map(list, ex19_0)))

    map19 = Map(ex19)
    map19.set_pos(map19.find_start())

    finished = False
    while not finished:
        finished = map19.step()

    print(''.join(map19.letters))
Exemplo n.º 13
0
def main():
    print("This code takes about 5s to run. Ctrl+C to break before then.")

    ex20_0 = get_input_by_lines(20, strip=False)
    ex20 = list(map(lambda x: x.split(', '), ex20_0))

    ps = ParticleSet(infostrs=ex20)

    for i in range(50):
        ps.step(collisions=True)

    print(len(ps.particles))
Exemplo n.º 14
0
def main():
    ex8_0 = get_input_by_lines(8)
    ex8 = ex8_0 

    instr_list = [x.split() for x in ex8]
    reg_list = [x[0] for x in instr_list]
    regs = dict(zip(set(reg_list), [0]*len(set(reg_list))))

    for i in instr_list:
        i_new = [x.replace('inc', '+').replace('dec', '-') for x in i]
        exec("regs['{0}'] = regs['{0}'] {1} {2} {3} regs['{4}'] {5} {6} else regs['{0}']".format(*i_new))

    print(max(regs.values()))
Exemplo n.º 15
0
def main():
    print("This code takes about 70s to run. Ctrl+C to break before then.")

    ex15_0 = get_input_by_lines(15)
    a, b = int((ex15_0[0].split())[-1]), int((ex15_0[1].split())[-1])

    count = 0
    for it in range(40000000):
        a = a * afac % n
        b = b * bfac % n
        if bit16(a) == bit16(b):
            count += 1
    print(count)
Exemplo n.º 16
0
def main():
    baselist = np.arange(256)

    ex14_0 = get_input_by_lines(14)
    ex14 = ex14_0[0]

    used = 0

    for i in range(128):
        used += ((np.array(list(hash_row(baselist, '{0}-{1}'.format(
            ex14, i)))).astype(np.int32)) == 1).sum()

    print(used)
Exemplo n.º 17
0
def main():
    print("This code takes about 6min to run. Ctrl+C to break before then.")

    ex24_0 = get_input_by_lines(24)
    ex24 = [tuple(map(int, x.split('/'))) for x in ex24_0]

    bridges24 = make_bridges(ex24)

    len24 = [len(x) for x in bridges24]
    max_length = max(len24)

    long24 = [x for x in bridges24 if len(x) == max_length]
    print(max([np.array(x).flatten().sum() for x in long24]))
Exemplo n.º 18
0
def main():
    ex13_0 = get_input_by_lines(13)
    ex13 = init_stack(ex13_0)

    ex13_new = [(x, 2*ex13[x]['range_']-2) for x in ex13.keys()]

    # Currently hardcoded because starting at 1 takes too long
    # TODO: implement with Chinese Remainder Theorem
    for i in range(3890000, 20000000):
        rr = np.array(ex13_new)[:, 0] + i
        if (rr % np.array(ex13_new)[:, 1]).min() > 0:
            print(i)
            break
Exemplo n.º 19
0
def main():
    ex19_0 = get_input_by_lines(19, strip=False)
    ex19 = np.array(list(map(list, ex19_0)))

    map19 = Map(ex19)
    map19.set_pos(map19.find_start())

    finished = False
    cnt = 0
    while not finished:
        finished = map19.step()
        if not finished:
            cnt += 1

    print(cnt)
Exemplo n.º 20
0
def main():
    ex10_0 = get_input_by_lines(10)
    ex10 = [int(x) for x in ex10_0[0].split(',')]

    curr_idx = 0
    skip_size = 0

    mylist = list(range(256))

    for val in ex10:
        mylist = reverse_list(mylist, curr_idx, val)
        curr_idx += (val + skip_size)
        skip_size += 1

    print(mylist[0] * mylist[1])
Exemplo n.º 21
0
def main():
    def get_repeat_sum2(num):
        numlen = len(num)
        assert not numlen & 1
        
        numlist = str(num) + str(num)[0]
        
        sum_ = 0
        for idx, digit in enumerate(numlist[:-1]):
            goal = (idx+numlen//2) % numlen
            sum_ += int(digit == numlist[goal])*int(digit)
        
        return sum_

    ex1 = ','.join(get_input_by_lines(1))
    print(get_repeat_sum2(ex1))
Exemplo n.º 22
0
def main():
    ex12_0 = get_input_by_lines(12)
    ex12 = dictify(ex12_0)

    groups = []
    for key in ex12.keys():
        pass_ = False
        for g in groups:
            if key in g:
                pass_ = True
        if pass_:
            continue
        group = get_nbrs(ex12, key, [])
        groups.append(group)

    print(len(groups))
Exemplo n.º 23
0
def main():
    ex17_0 = get_input_by_lines(17)
    ex17 = int(ex17_0[0])

    count = 0
    idx = 0
    mylist = []

    while count <= 2017:
        if mylist:
            idx = (idx + ex17) % len(mylist) + 1
        mylist.insert(idx, count)
        count += 1

    idx0 = mylist.index(2017)
    print(mylist[idx0 + 1])
Exemplo n.º 24
0
def main():
    def listdiv(mylist):
        mylist = np.array(sorted(mylist))
        thresh = mylist[-1] // 2

        idx = 0
        while mylist[idx] <= thresh:
            filtlist = mylist[mylist / mylist[idx] == mylist // mylist[idx]]
            if len(filtlist) > 1:
                val = filtlist[-1] / mylist[idx]
                break
            idx += 1
        return val

    ex2_0 = get_input_by_lines(2)
    ex2 = np.array([x.split(',') for x in ex2_0]).astype(np.int32)

    print(np.apply_along_axis(listdiv, axis=1, arr=ex2).sum())
Exemplo n.º 25
0
def main():
    ex5_0 = get_input_by_lines(5)
    ex5 = [int(x) for x in ex5_0]

    idx = 0
    count = 0
    errors = False

    while not errors:
        try:
            jump_val = ex5[idx]
            ex5[idx] += 1
            idx += jump_val
            count += 1
        except:
            errors = True
            continue

    print(count)
Exemplo n.º 26
0
def main():
    print("This code takes about 15s to run. Ctrl+C to break before then.")

    ex17_0 = get_input_by_lines(17)
    ex17 = int(ex17_0[0])

    count = 0
    idx = 0
    recent = 0

    while count <= 50e6:
        if count >= 1:
            idx = (idx + ex17) % (count + 1) + 1
        else:
            idx = 1
        if idx == 1:
            recent = count + 1
        count += 1

    print(recent)
Exemplo n.º 27
0
def main():
    def rule(grid, new_coord):
        new_coord = np.array(new_coord)
        total = 0
        for i in [-1, 0, 1]:
            for j in [-1, 0, 1]:
                try:
                    total += grid[tuple(new_coord + np.array((i, j)))]
                except:
                    pass
        return total

    def part2(input_, rule):
        grid = SpiralGrid(rule)
        x = 0
        while x <= input_:
            x = grid.step()
        return x

    ex3 = int(get_input_by_lines(3)[0])
    print(part2(ex3, rule))
Exemplo n.º 28
0
def main():
    ex6_0 = get_input_by_lines(6)
    ex6 = [int(x) for x in ex6_0[0].split(',')]

    seen = []
    current = ex6
    count = 0

    while (current not in seen) and (count <= 2000000):
        seen.append(current.copy())
        idx = np.argmax(current)
        maxval = current[idx]
        current[idx] = 0

        while maxval > 0:
            idx = (idx + 1) % len(current)
            current[idx] += 1
            maxval -= 1

        count += 1

    print(count)
Exemplo n.º 29
0
def main():
    ex11_0 = get_input_by_lines(11)
    ex11 = ex11_0[0].split(',')

    print(simplify_coords(*make_coords(ex11)[:3]))
Exemplo n.º 30
0
def main():
    ex9_0 = get_input_by_lines(9)
    ex9 = ex9_0[0]

    print(score_group(ex9)[1])