Skip to content

Commit 8251c33

Browse files
author
Joth
committed
clean up
1 parent 7953456 commit 8251c33

File tree

30 files changed

+116
-281
lines changed

30 files changed

+116
-281
lines changed

2019/Day 01/Part 1/AoC_2019_D1_P1.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

2019/Day 01/Part 1/__main__.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Advent of Code 2019, Day 1, Part 1
2+
3+
from os import path
4+
from math import floor
5+
6+
7+
def main():
8+
text_input = get_raw_input()
9+
masses = [int(x) for x in text_input.splitlines()]
10+
11+
fuel_sum = 0
12+
for mass in masses:
13+
fuel_sum += floor(mass/3) - 2
14+
15+
print('Total fuel:', fuel_sum)
16+
17+
18+
def get_raw_input():
19+
return open(retrieve_input_file_path(), 'r').read()
20+
21+
22+
def retrieve_input_file_path():
23+
return path.join(path.dirname(__file__), 'input.txt')
24+
25+
26+
if __name__ == '__main__':
27+
main()

2019/Day 01/Part 2/AoC_2019_D1_P2.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

2019/Day 01/Part 2/__main__.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Advent of Code 2019, Day 1, Part 2
2+
3+
from os import path
4+
from math import floor
5+
6+
7+
def calculate_total_fuel_by_mass(mass):
8+
calculate_fuel_by_mass = lambda m: floor(m/3) - 2
9+
10+
fuel = calculate_fuel_by_mass(mass)
11+
fuel_sum = 0
12+
13+
while fuel > 0:
14+
fuel_sum += fuel
15+
fuel = calculate_fuel_by_mass(fuel)
16+
17+
return fuel_sum
18+
19+
20+
def main():
21+
text_input = get_raw_input()
22+
masses = [int(x) for x in text_input.splitlines()]
23+
fuel_sum = 0
24+
for mass in masses:
25+
fuel_sum += calculate_total_fuel_by_mass(mass)
26+
27+
print('Total fuel:', fuel_sum)
28+
29+
30+
def get_raw_input():
31+
return open(retrieve_input_file_path(), 'r').read()
32+
33+
34+
def retrieve_input_file_path():
35+
return path.join(path.dirname(__file__), 'input.txt')
36+
37+
38+
if __name__ == '__main__':
39+
main()

2019/Day 02/Part 1/AoC_2019_D2_P1.py renamed to 2019/Day 02/Part 1/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Advent of Code 2019, Day 2, Part 1
2-
# Author: Joth (https://github.com/joth00)
32

43
from os import path
54

@@ -33,4 +32,5 @@ def retrieve_input_file_path():
3332
return path.join(path.dirname(__file__), 'input.txt')
3433

3534

36-
main()
35+
if __name__ == '__main__':
36+
main()

2019/Day 02/Part 2/AoC_2019_D2_P2.py renamed to 2019/Day 02/Part 2/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Advent of Code 2019, Day 2, Part 2
2-
# Author: Joth (https://github.com/joth00)
32

43
from os import path
54

@@ -51,4 +50,5 @@ def retrieve_input_file_path():
5150
return path.join(path.dirname(__file__), 'input.txt')
5251

5352

54-
main()
53+
if __name__ == '__main__':
54+
main()

2019/Day 03/Part 1/AoC_2019_D3_P1_clean.py renamed to 2019/Day 03/Part 1/__main__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Advent of Code 2019, Day 3, Part 1
2-
# Author: Joth (https://github.com/joth00)
32

43
from os import path
54

@@ -103,11 +102,12 @@ def intersects(horizontal_line, vertical_line):
103102

104103

105104
def get_raw_input():
106-
return open(get_input_file_path(), 'r').read()
105+
return open(retrieve_input_file_path(), 'r').read()
107106

108107

109-
def get_input_file_path():
108+
def retrieve_input_file_path():
110109
return path.join(path.dirname(__file__), 'input.txt')
111110

112111

113-
main()
112+
if __name__ == '__main__':
113+
main()

2019/Day 03/Part 1/AoC_2019_D3_P1.py renamed to 2019/Day 03/Part 1/v1.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Advent of Code 2019, Day 3, Part 1
2-
# Author: Joth (https://github.com/joth00)
32

43
from os import path
54

@@ -39,7 +38,7 @@ def main():
3938
if (0, 0) in intersections:
4039
intersections.remove((0, 0))
4140

42-
closest_intersection = min(intersections, key=calculateManhattanDistanceFromOrigin)
41+
closest_intersection = min(intersections, key=get_manhattan_distance_from_origin)
4342
lowest_distance = get_manhattan_distance_from_origin(closest_intersection)
4443

4544
print('closest_intersection:', closest_intersection)
@@ -79,4 +78,5 @@ def retrieve_input_file_path():
7978
return path.join(path.dirname(__file__), 'input.txt')
8079

8180

82-
main()
81+
if __name__ == '__main__':
82+
main()

2019/Day 03/Part 2/AoC_2019_D3_P2_clean.py renamed to 2019/Day 03/Part 2/__main__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# Advent of Code 2019, Day 3, Part 1
2-
# Author: Joth (https://github.com/joth00)
1+
# Advent of Code 2019, Day 3, Part 2
32

43
from os import path
54

@@ -129,11 +128,12 @@ def intersects(horizontal_line, vertical_line):
129128

130129

131130
def get_raw_input():
132-
return open(get_input_file_path(), 'r').read()
131+
return open(retrieve_input_file_path(), 'r').read()
133132

134133

135-
def get_input_file_path():
134+
def retrieve_input_file_path():
136135
return path.join(path.dirname(__file__), 'input.txt')
137136

138137

139-
main()
138+
if __name__ == '__main__':
139+
main()

2019/Day 03/Part 2/AoC_2019_D3_P2.py renamed to 2019/Day 03/Part 2/v1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Advent of Code 2019, Day 3, Part 2
2-
# Author: Joth (https://github.com/joth00)
32

43
from os import path
54

@@ -101,4 +100,5 @@ def retrieve_input_file_path():
101100
return path.join(path.dirname(__file__), 'input.txt')
102101

103102

104-
main()
103+
if __name__ == '__main__':
104+
main()

0 commit comments

Comments
 (0)