diff options
| author | Gustav Sörnäs <gusso230@student.liu.se> | 2019-12-08 11:06:56 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gusso230@student.liu.se> | 2019-12-08 11:06:56 +0100 |
| commit | 29e33f8f6a31565f5a2671b1c459ff1b829630f7 (patch) | |
| tree | c051274a9e9a895049a077a6bdce9056dfb9afb1 /solutions/py/d08.py | |
| parent | d16fc72a33fced8c8623bea6cf9cdd9cf8999024 (diff) | |
| download | aoc-29e33f8f6a31565f5a2671b1c459ff1b829630f7.tar.gz | |
Refactor and create main.py
Diffstat (limited to 'solutions/py/d08.py')
| -rw-r--r-- | solutions/py/d08.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/solutions/py/d08.py b/solutions/py/d08.py new file mode 100644 index 0000000..659bc3a --- /dev/null +++ b/solutions/py/d08.py @@ -0,0 +1,31 @@ +def count(layer, num): + return sum([row.count(num) for row in layer]) + + +def pt1(input): + img = [] + least_zeroes = 150 # max + n = 0 + for l in range(100): + #print("l", l) + layer = [[int(input[0][l*25*6 + y*25 + x]) for x in range(25)] for y in range(6)] + if count(layer, 0) < least_zeroes: + least_zeroes = count(layer, 0) + n = count(layer, 1) * count(layer, 2) + img.append(layer) + return n + +def pt2(input): + img = [[[int(input[0][l*25*6 + y*25 + x]) for x in range(25)] for y in range(6)] for l in range(100)] + result = img[0] + for layer in img[1:]: + for x in range(25): + for y in range(6): + if result[y][x] == 2: + result[y][x] = layer[y][x] + str_res = [] + for row in result: + for c in row: + str_res.append('\u2588' if c == 1 else ' ') + str_res.append("\n") + return "\n" + ("".join(str_res)) |
