summary refs log tree commit diff stats
path: root/day5.py
blob: f0eb48395a16d669d50969c4bbb1d82fc7d0b983 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python

import numpy as np
import re

with open("day5.txt") as data:
    coords = []
    xMax = yMax = 0
    for line in data:
        x1, y1, x2, y2 = map(int, re.split(r'\D+', line.strip()))
        xMax = max(xMax, max(x1, x2))
        yMax = max(yMax, max(y1, y2))
        if x1 == x2:
            ystep = 1 if y1 < y2 else -1
            coords.extend([(x1, y) for y in range(y1, y2 + ystep, ystep)])
        elif y1 == y2:
            xstep = 1 if x1 < x2 else -1
            coords.extend([(x, y1) for x in range(x1, x2 + xstep, xstep)])
        else:
            xstep = 1 if x1 < x2 else -1
            ystep = 1 if y1 < y2 else -1
            coords.extend([coord for coord in zip(range(x1, x2 + xstep, xstep), range(y1, y2 + ystep, ystep))])

    vents = np.zeros((xMax+1, yMax+1)).astype(int)
    for x, y in coords:
        vents[x, y] += 1
    print(np.count_nonzero(vents > 1))
n class="n">shell=True).decode('utf-8').replace('\r', '').replace('\n', '')) except ValueError: numparts = 0 if numparts == 0: # no partition, mount the whole device fm.execute_console("map {key}{0} chain shell pmount sd{0}; cd /media/sd{0}".format( disk, key=MOUNT_KEY)) fm.execute_console("map {key}{0} chain cd; chain shell pumount sd{0}".format( disk, key=UMOUNT_KEY)) elif numparts == 1: # only one partition, mount the partition fm.execute_console( "map {key}{0} chain shell pmount sd{0}1; cd /media/sd{0}1".format( disk, key=MOUNT_KEY)) fm.execute_console("map {key}{0} chain cd; shell pumount sd{0}1".format( disk, key=UMOUNT_KEY)) else: # use range start 1, /dev/sd{device}0 doesn't exist for part in range(1, numparts + 1): fm.execute_console( "map {key}{0}{1} chain shell pmount sd{0}{1}; cd /media/sd{0}{1}".format( disk, part, key=MOUNT_KEY)) fm.execute_console("map {key}{0}{1} chain cd; shell pumount sd{0}{1}".format( disk, part, key=UMOUNT_KEY)) return HOOK_INIT_OLD(fm) ranger.api.hook_init = hook_init