forked from sinievanderben/advent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvent7_a.py
34 lines (21 loc) · 798 Bytes
/
advent7_a.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# horizontal position of each crab
# each change of 1 step in horizontal position of a single crab takes 1 fuel
# determine the least fuel posiion
import numpy as np
import math
with open('/Users/sinievanderben/Documents/advent/test_day7.txt', 'r') as f:
lines = f.readlines()
splitted_lines = lines[0].split(',')
splitted_numbers = [int(x) for x in splitted_lines]
max_fuel = math.inf
best_fuel = 0
for fuel in range(max(splitted_numbers)):
fuel_temp = 0
for number in splitted_numbers:
for steps in range(abs(fuel-number)+1):
fuel_temp = fuel_temp + steps
if fuel_temp < max_fuel:
max_fuel = fuel_temp
best_fuel = fuel
print(max_fuel)
print(best_fuel)