File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
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 } " )
You can’t perform that action at this time.
0 commit comments