2021 start

This commit is contained in:
a 2021-12-05 21:19:11 -06:00
parent 8566841ccc
commit b7dd9e5f1c
9 changed files with 4111 additions and 0 deletions

20
2021/01/01.py Normal file
View file

@ -0,0 +1,20 @@
sweep = []
with open("input.txt") as f:
lines = f.readlines()
for line in lines:
sweep.append(int(line))
comparison = zip(sweep[1:],sweep)
differences = [(d2 - d1) for d2, d1 in comparison]
increases = [(d > 0) for d in differences]
part1 = sum(increases)
print(part1)
window = zip(sweep,sweep[1:],sweep[2:])
sums = [(d1 + d2 + d3) for d1, d2, d3 in window]
comparison = zip(sums[1:],sums)
differences = [(d2 - d1) for d2, d1 in comparison]
increases = [(d > 0) for d in differences]
part2 = sum(increases)
print(part2)

2000
2021/01/input.txt Normal file

File diff suppressed because it is too large Load diff

10
2021/01/sample.txt Normal file
View file

@ -0,0 +1,10 @@
199
200
208
210
200
207
240
269
260
263

35
2021/02/02.py Normal file
View file

@ -0,0 +1,35 @@
commands = []
with open("input.txt") as f:
lines = f.readlines()
for line in lines:
commands.append(line)
horizontal = depth = 0
for command in commands:
instruction, amount = command.split(' ')
amount = int(amount)
if instruction == 'forward':
horizontal += amount
elif instruction == 'down':
depth += amount
elif instruction == 'up':
depth -= amount
part1 = horizontal * depth
print(part1)
horizontal = depth = aim = 0
for command in commands:
instruction, amount = command.split(' ')
amount = int(amount)
if instruction == 'down':
aim += amount
elif instruction == 'up':
aim -= amount
elif instruction == 'forward':
horizontal += amount
depth += amount*aim
part2 = horizontal * depth
print(part2)

1000
2021/02/input.txt Normal file

File diff suppressed because it is too large Load diff

6
2021/02/sample.txt Normal file
View file

@ -0,0 +1,6 @@
forward 5
down 5
forward 8
up 3
down 8
forward 2

28
2021/03/03.py Normal file
View file

@ -0,0 +1,28 @@
report = []
with open("input.txt") as f:
lines = f.read().split('\n')
for line in lines:
report.append(line)
gamma = ''
power = 2 ** len(report[0]) - 1
for i in range(len(report[0])):
ones_count = 0
for number in report:
if number[i] == '1':
ones_count += 1
half = len(report) / 2
if ones_count > half:
gamma += '1'
else:
gamma += '0'
gamma = int(gamma, 2)
epsilon = power - gamma
part1 = gamma * epsilon
print(part1)
o2 = co2 = 0

1000
2021/03/input.txt Normal file

File diff suppressed because it is too large Load diff

12
2021/03/sample.txt Normal file
View file

@ -0,0 +1,12 @@
00100
11110
10110
10111
10101
01111
00111
11100
10000
11001
00010
01010