Initial import
This commit is contained in:
commit
6ae48855c2
6 changed files with 3085 additions and 0 deletions
16
1/1.py
Executable file
16
1/1.py
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env python
|
||||
# 2021 - Advent Of Code 1
|
||||
|
||||
|
||||
count = 0
|
||||
|
||||
with open('input.txt') as f:
|
||||
previous_value = int(f.readline())
|
||||
|
||||
for line in f:
|
||||
current_value = int(line)
|
||||
if current_value > previous_value:
|
||||
count += 1
|
||||
previous_value = current_value
|
||||
|
||||
print(f'count: {count}')
|
23
1/1_2.py
Executable file
23
1/1_2.py
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env python
|
||||
# 2021 - Advent Of Code 1 - part 2
|
||||
|
||||
|
||||
count = 0
|
||||
|
||||
with open('input.txt') as f:
|
||||
n2_value = int(f.readline())
|
||||
n1_value = int(f.readline())
|
||||
n_value = int(f.readline())
|
||||
previous_sum = n2_value + n1_value + n_value
|
||||
|
||||
for line in f:
|
||||
n2_value = n1_value
|
||||
n1_value = n_value
|
||||
n_value = int(line)
|
||||
current_sum = n2_value + n1_value + n_value
|
||||
|
||||
if current_sum > previous_sum:
|
||||
count += 1
|
||||
previous_sum = current_sum
|
||||
|
||||
print(f'count: {count}')
|
2000
1/input.txt
Normal file
2000
1/input.txt
Normal file
File diff suppressed because it is too large
Load diff
22
2/2.py
Executable file
22
2/2.py
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env python
|
||||
# 2021 - Advent Of Code - 2
|
||||
|
||||
import re
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
|
||||
re_parse = re.compile('(forward|up|down) (\d+)')
|
||||
|
||||
with open('input.txt') as f:
|
||||
for line in f:
|
||||
m = re_parse.match(line)
|
||||
direction, unit = m.group(1), int(m.group(2))
|
||||
if direction == 'up':
|
||||
y -= unit
|
||||
elif direction == 'down':
|
||||
y += unit
|
||||
elif direction == 'forward':
|
||||
x += unit
|
||||
|
||||
print(f'position: ({x}, {y}) => {x*y}')
|
24
2/2_2.py
Executable file
24
2/2_2.py
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python
|
||||
# 2021 - Advent Of Code - 2 part 2
|
||||
|
||||
import re
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
aim = 0
|
||||
|
||||
re_parse = re.compile('(forward|up|down) (\d+)')
|
||||
|
||||
with open('input.txt') as f:
|
||||
for line in f:
|
||||
m = re_parse.match(line)
|
||||
direction, unit = m.group(1), int(m.group(2))
|
||||
if direction == 'up':
|
||||
aim -= unit
|
||||
elif direction == 'down':
|
||||
aim += unit
|
||||
elif direction == 'forward':
|
||||
x += unit
|
||||
y += aim * unit
|
||||
|
||||
print(f'position: ({x}, {y}) => {x*y}')
|
1000
2/input.txt
Normal file
1000
2/input.txt
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue