Day 7 done in python
This commit is contained in:
parent
7f9614953a
commit
2ac18fcb7e
1
2021/7/.gitignore
vendored
Normal file
1
2021/7/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
input
|
12
2021/7/crabs.py
Normal file
12
2021/7/crabs.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
with open("input", "r") as input:
|
||||||
|
input = list(map(int, input.read().strip().split(",")))
|
||||||
|
fuel = []
|
||||||
|
|
||||||
|
for i in range(min(input), max(input)):
|
||||||
|
total_fuel = 0
|
||||||
|
for x in input:
|
||||||
|
total_fuel += abs(i - x)
|
||||||
|
fuel.append(total_fuel)
|
||||||
|
|
||||||
|
fuel.sort()
|
||||||
|
print(fuel[0])
|
13
2021/7/crabs2.py
Normal file
13
2021/7/crabs2.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
with open("input", "r") as input:
|
||||||
|
input = list(map(int, input.read().strip().split(",")))
|
||||||
|
fuel = []
|
||||||
|
|
||||||
|
for i in range(min(input), max(input)):
|
||||||
|
total_fuel = 0
|
||||||
|
for x in input:
|
||||||
|
for y in range(1, abs(i - x) + 1):
|
||||||
|
total_fuel += y
|
||||||
|
fuel.append(total_fuel)
|
||||||
|
|
||||||
|
fuel.sort()
|
||||||
|
print(fuel[0])
|
Loading…
Reference in New Issue
Block a user