More solutions
This commit is contained in:
26
2021/01.py
Normal file
26
2021/01.py
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
with open('01.txt', 'r') as input_file:
|
||||
input_list = input_file.readlines()
|
||||
|
||||
# A
|
||||
for i in range(0, len(input_list)):
|
||||
input_list[i] = int(input_list[i].replace(r'\n', ''))
|
||||
|
||||
greater_counter = 0
|
||||
for i in range(1, len(input_list)):
|
||||
if input_list[i] > input_list[i - 1]:
|
||||
greater_counter += 1
|
||||
|
||||
print(greater_counter)
|
||||
|
||||
# B
|
||||
greater_counter = 0
|
||||
for i in range(3, len(input_list)):
|
||||
# Get sum of current 3
|
||||
current = sum(input_list[i-3:i])
|
||||
previous = sum(input_list[i-4:i-1])
|
||||
|
||||
if current > previous:
|
||||
greater_counter += 1
|
||||
print(greater_counter)
|
||||
|
||||
2000
2021/01.txt
Normal file
2000
2021/01.txt
Normal file
File diff suppressed because it is too large
Load Diff
33
2021/02.py
Normal file
33
2021/02.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import pandas as pd
|
||||
|
||||
instruction_df = pd.read_csv('02.txt', sep=" ")
|
||||
# instruction_df = pd.read_csv('02.test', sep=" ")
|
||||
|
||||
instruction_list = instruction_df.to_dict('records')
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
for one_instruction in instruction_list:
|
||||
if one_instruction['direction'] == 'forward':
|
||||
x += one_instruction['amount']
|
||||
if one_instruction['direction'] == 'down':
|
||||
y += one_instruction['amount']
|
||||
if one_instruction['direction'] == 'up':
|
||||
y -= one_instruction['amount']
|
||||
|
||||
print(x, y, x*y)
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
aim = 0
|
||||
for one_instruction in instruction_list:
|
||||
if one_instruction['direction'] == 'forward':
|
||||
x += one_instruction['amount']
|
||||
y += one_instruction['amount'] * aim
|
||||
if one_instruction['direction'] == 'down':
|
||||
aim += one_instruction['amount']
|
||||
if one_instruction['direction'] == 'up':
|
||||
aim -= one_instruction['amount']
|
||||
|
||||
|
||||
print(x, y, x*y)
|
||||
7
2021/02.test
Normal file
7
2021/02.test
Normal file
@@ -0,0 +1,7 @@
|
||||
direction amount
|
||||
forward 5
|
||||
down 5
|
||||
forward 8
|
||||
up 3
|
||||
down 8
|
||||
forward 2
|
||||
1001
2021/02.txt
Normal file
1001
2021/02.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user