Skip to content

Commit 62b1b30

Browse files
committed
day 2 and 3
1 parent 4244258 commit 62b1b30

File tree

7 files changed

+2121
-14
lines changed

7 files changed

+2121
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__

2021/01/main.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
# https://adventofcode.com/2021/day/1
22

3-
import os
4-
import pathlib
3+
from utils import read_input_gen
54

6-
7-
def read_input():
8-
with open(
9-
os.path.join(pathlib.Path(__file__).parent.resolve(), "input.txt"), "r"
10-
) as file:
11-
for line in file:
12-
yield int(line.strip())
5+
file_path = "2021/01/input.txt"
136

147

158
def part_one():
169
increment_count = 0
1710
last_number = None
18-
for line in read_input():
19-
next_number = line
11+
for line in read_input_gen(file_path):
12+
next_number = int(line)
2013
if last_number is None:
2114
last_number = next_number
2215
continue
@@ -29,11 +22,10 @@ def part_one():
2922
def part_two():
3023
increment_count = 0
3124
num_list = []
32-
for num in read_input():
25+
for num in read_input_gen(file_path):
3326
if len(num_list) < 4:
34-
num_list.append(num)
27+
num_list.append(int(num))
3528
if len(num_list) == 4:
36-
print(num_list)
3729
if sum(num_list[:3]) < sum(num_list[1:4]):
3830
increment_count += 1
3931
num_list.pop(0)

0 commit comments

Comments
 (0)