Skip to content

Commit 497bb73

Browse files
authored
Add files via upload
1 parent 67f892a commit 497bb73

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

7a.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#Advent of code 2021
2+
# 12/20/21 day 7a
3+
# Joe McFarland
4+
# import sys
5+
# import re
6+
# import copy
7+
8+
filename = "data7.txt"
9+
10+
file = open(filename)
11+
filestr = file.read()
12+
a_list = filestr.split("\n")
13+
maxrows = len(a_list)
14+
print(a_list)
15+
#maxcols = len(a_list[0])
16+
a_str = a_list[0].split(",")
17+
mylist = [int(elem) for elem in a_str]
18+
19+
maxpos = max(mylist)
20+
print(f"maxpos={maxpos}")
21+
22+
print(f"{mylist}")
23+
24+
lowest_fuel = 10000000
25+
#lowest_pos = maxpos
26+
for hpos in range(1,maxpos+1):
27+
per_pos_fuel = 0
28+
for crab_pos in mylist:
29+
fuelcost = max(crab_pos, hpos) - min(crab_pos, hpos)
30+
#print(f"hpos: {hpos}, crab_pos: {crab_pos}, fuelcost: {fuelcost}")
31+
per_pos_fuel += fuelcost
32+
if per_pos_fuel < lowest_fuel:
33+
lowest_fuel = per_pos_fuel
34+
lowest_pos = hpos
35+
print(f"updated low(pos,fuel): {lowest_pos}, {lowest_fuel}")
36+
#print(f"hpos {hpos}, per_pos_fuel {per_pos_fuel}")
37+
print(f"lowest_pos = {lowest_pos}, lowest_fuel = {lowest_fuel}")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy