Skip to content

Commit f4f12b3

Browse files
committed
2 parents b169339 + ad622af commit f4f12b3

File tree

21 files changed

+705
-33
lines changed

21 files changed

+705
-33
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ __pycache__
22
config.py
33
*/inputs/*.txt
44
Completed.md
5-
*.dump.*
5+
*.dump.*
6+
debug.html

2015/18.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def part1(data):
4343
# Now we have to go though 100 steps
4444
for _ in range(100):
4545
# First we make a new grid
46-
new_grid = np.zeros(grid_shape, np.bool)
46+
new_grid = np.zeros(grid_shape, bool)
4747
# Next we loop though the grid lights
4848
for row in range(grid_shape[0]):
4949
for col in range(grid_shape[1]):
@@ -56,7 +56,6 @@ def part1(data):
5656
new_grid[row, col] = True
5757
# Set the new grid to the old grid, update counter
5858
grid = new_grid
59-
print(_,end='\r')
6059
return np.sum(grid)
6160

6261
def part2(data):
@@ -69,7 +68,7 @@ def part2(data):
6968
# Now we have to go though 100 steps
7069
for _ in range(100):
7170
# First we make a new grid
72-
new_grid = np.zeros(grid_shape, np.bool)
71+
new_grid = np.zeros(grid_shape, bool)
7372
# Next we loop though the grid lights
7473
for row in range(grid_shape[0]):
7574
for col in range(grid_shape[1]):
@@ -87,7 +86,6 @@ def part2(data):
8786
new_grid[row, col] = True
8887
# Set the new grid to the old grid, update counter
8988
grid = new_grid
90-
print(_,end='\r')
9189
return np.sum(grid)
9290

9391
# THIS ONE WAS A LOT OF WORK

2015/20.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
def factor_sum(num):
66
# returns a list of factors of num
7-
factors = [i+1 for i in range(num) if num % (i+1) == 0]
7+
factors = [i for i in range(1, num+1//2) if num % i == 0]
8+
89
return sum(factors)
910

1011
def part1(data):

2015/6.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def proccess(line):
1212

1313
def part1(data):
1414
"""The Code is supposed to run here"""
15-
grid = np.zeros((1000, 1000), dtype=np.bool) # True represents lit and False represents off
15+
grid = np.zeros((1000, 1000), dtype=bool) # True represents lit and False represents off
1616
for line in data:
1717
if line.startswith('toggle'):
1818
x1, y1, x2, y2 = proccess(line.lstrip('toggle '))

2016/20.py

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,58 @@
11
import numpy as np
22

3-
split_data = True
3+
def parse(data):
4+
processed = []
5+
for line in data.strip().split('\n'):
6+
num1, num2 = line.split('-')
7+
processed.append((int(num1), int(num2)))
8+
9+
return sorted(processed, key=lambda x: x[0])
10+
11+
split_data = parse
412
completed = True
513
raw_data = None # Not To be touched
614

715
def part1(data):
8-
nums = np.zeros(4294967295+1, dtype=np.bool8)
9-
for line in data:
10-
num1, num2 = line.split('-')
11-
nums[int(num1):int(num2)+1] = True
12-
return np.where(nums == False)[0][0]
16+
lowest = 0
17+
18+
for low, high in data:
19+
if low <= lowest <= high:
20+
lowest = high + 1
21+
22+
return lowest
1323

1424
def part2(data):
15-
nums = np.zeros(4294967295+1, dtype=np.bool8)
16-
for line in data:
17-
num1, num2 = line.split('-')
18-
nums[int(num1):int(num2)+1] = True
19-
return np.sum(nums == False)
25+
allowedRange = [(0, 4294967295)]
26+
27+
for low, high in data:
28+
newRange = []
29+
for Al_low, Al_high in allowedRange:
30+
if Al_low < low and Al_high > high:
31+
# The middle part of the range is in the black-list
32+
newRange.append((Al_low, low-1))
33+
newRange.append((high+1, Al_high))
34+
elif low <= Al_low <= high:
35+
# The lower part of the range is in the black-list
36+
if Al_high <= high:
37+
# Then the whole range is in the black-list
38+
continue
39+
else:
40+
# The above part of the range is not in the black-list
41+
newRange.append((high+1, Al_high))
42+
elif low <= Al_high <= high:
43+
# The above part of the range is in the black-list
44+
if Al_low < low:
45+
# The below part of the range is not in blacklist
46+
newRange.append((Al_low, low-1))
47+
else:
48+
# The below part of the range is in the black-list
49+
continue
50+
else:
51+
# The whole range is not in the black-list
52+
newRange.append((Al_low, Al_high))
53+
54+
allowedRange = newRange
55+
if len(allowedRange) == 0:
56+
break
57+
58+
return sum([high - low + 1 for low, high in allowedRange])

2016/21.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ def part2(data):
6363
# then we know what the password is
6464

6565
scrambled = "fbgdceah"
66-
possible = []
6766
for i in permutations(scrambled):
6867
if scramble(i, data) == scrambled:
69-
possible.append(''.join(i))
70-
# There can be multiple possibilities, so we return the first one
71-
return possible[0]
68+
return ''.join(i)

2016/22.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def part2(data):
9797
# Pretty printing the data
9898
with open("2016/day 22.dump.txt", "w") as f:
9999
# Printing the display into the console
100-
display = grid.astype(np.str)
100+
display = grid.astype(str)
101101
display[display == '1'] = '#'
102102
display[display == '0'] = '_'
103103
display[display == '-1'] = '.'

2016/8.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def part2(data):
4242
display[int(x),:] = np.roll(display[int(x),:],int(y))
4343
# Code for part 2 begins here
4444
# Printing the display into the console
45-
display = display.astype(np.str)
45+
display = display.astype(str)
4646
display[display == '1'] = '\u2588' # Full block, makes it easier to read
4747
display[display == '0'] = ' '
4848
for row in display:

2022/10.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ def part2(data):
6262
ins += 1
6363

6464
for row in screen: print(''.join(row))
65-
return 'This time, there will be no returned output as its super hard to guess all the letter patterns. However, a human can read the above display and figure out the output!'
65+
print('This time, there will be no returned output as its super hard to guess all the letter patterns. However, a human can read the above display and figure out the output!')

2022/18.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
split_data = True
5+
completed = True
6+
raw_data = None # Not To be touched
7+
8+
def part1(data):
9+
# One easy way is to just calculate the laviathan distance and if its 1 then subtract 2 from the upper limit
10+
limit = len(data) * 6
11+
12+
checks = [(-1, 0, 0), (1, 0, 0), (0, -1, 0), (0, 1, 0), (0, 0, -1), (0, 0, 1)]
13+
14+
for cube in data:
15+
x, y, z = map(int, cube.split(','))
16+
17+
for dx, dy, dz in checks:
18+
nx, ny, nz = x + dx, y + dy, z + dz
19+
if f"{nx},{ny},{nz}" in data:
20+
limit -= 1
21+
22+
return limit
23+
24+
def part2(data):
25+
# Will be solved using flood-fill
26+
cubes = []
27+
maxX = float('-inf')
28+
maxY = float('-inf')
29+
maxZ = float('-inf')
30+
31+
for cube in data:
32+
x, y, z = map(int, cube.split(','))
33+
maxX = max(maxX, x)
34+
maxY = max(maxY, y)
35+
maxZ = max(maxZ, z)
36+
cubes.append((x, y, z))
37+
38+
maxX, maxY, maxZ = maxX + 2, maxY + 2, maxZ + 2 # <- God knows why I have a two off error!
39+
40+
# print(f'{maxX}x{maxY}x{maxZ} grid')
41+
42+
surface = 0 # The number of times we hit the cube during the flood fill
43+
44+
checks = [(-1, 0, 0), (1, 0, 0), (0, -1, 0), (0, 1, 0), (0, 0, -1), (0, 0, 1)]
45+
queue = [(-1, -1, -1)]
46+
visited = set()
47+
48+
while queue:
49+
x, y, z = queue.pop(0)
50+
51+
for dx, dy, dz in checks:
52+
nx, ny, nz = x + dx, y + dy, z + dz
53+
if not (-1 <= nx < maxX and -1 <= ny < maxY and -1 <= nz < maxZ): continue
54+
if f"{nx},{ny},{nz}" in visited: continue
55+
if (nx, ny, nz) in cubes:
56+
surface += 1
57+
continue
58+
queue.append((nx, ny, nz))
59+
visited.add(f"{nx},{ny},{nz}")
60+
61+
return surface

0 commit comments

Comments
 (0)