Added 2019 work.

This commit is contained in:
Gheiserton 2022-12-02 18:19:22 -05:00
parent 3a0106d097
commit 0b874c5839
9 changed files with 286 additions and 0 deletions

13
2019/day01A.py Normal file
View file

@ -0,0 +1,13 @@
import math
inputs = []
fuelneeded = 0
with open ('day01input.txt', 'r') as infile:
inputs = [current_input.rstrip() for current_input in infile.readlines()]
for item in inputs:
module_fuel = math.floor(int(item) / 3) - 2
fuelneeded += module_fuel
print(fuelneeded)

19
2019/day01B.py Normal file
View file

@ -0,0 +1,19 @@
import math
inputs = []
fuelneeded = 0
with open ('day01input.txt', 'r') as infile:
inputs = [current_input.rstrip() for current_input in infile.readlines()]
for item in inputs:
working_mass = int(item)
while working_mass > 0:
module_fuel = math.floor(int(working_mass) / 3) - 2
if module_fuel > 0:
fuelneeded += module_fuel
working_mass = module_fuel
else:
break
print(fuelneeded)

100
2019/day01input.txt Normal file
View file

@ -0,0 +1,100 @@
60566
53003
132271
130557
109138
64818
123247
148493
98275
67155
132365
133146
88023
92978
122790
84429
93421
76236
104387
135953
131379
125949
133614
94647
64289
87972
97331
132327
53913
79676
143110
79269
52366
62793
69437
97749
83596
147597
115883
82062
63800
61521
139314
127619
85790
132960
141289
86146
146104
128708
133054
116777
128402
85043
117344
107915
108669
108304
105300
75186
111352
112936
117177
93812
97737
61835
77529
145406
93489
75642
69806
109845
79133
60950
67797
111806
50597
50481
88338
102136
65377
55982
82754
68901
89232
63118
95534
98264
147706
80050
104953
146758
122884
122024
129236
113818
58099
134318
136312
75124

15
2019/day02A.py Normal file
View file

@ -0,0 +1,15 @@
op_list = [1,12,2,3,1,1,2,3,1,3,4,3,1,5,0,3,2,13,1,19,1,19,10,23,1,23,13,27,1,6,27,31,1,9,31,35,2,10,35,39,1,39,6,43,1,6,43,47,2,13,47,51,1,51,6,55,2,6,55,59,2,59,6,63,2,63,13,67,1,5,67,71,2,9,71,75,1,5,75,79,1,5,79,83,1,83,6,87,1,87,6,91,1,91,5,95,2,10,95,99,1,5,99,103,1,10,103,107,1,107,9,111,2,111,10,115,1,115,9,119,1,13,119,123,1,123,9,127,1,5,127,131,2,13,131,135,1,9,135,139,1,2,139,143,1,13,143,0,99,2,0,14,0]
i = 0
break_code = 0
while break_code == 0:
if op_list[i] == 1:
op_list[op_list[i+3]] = op_list[op_list[i+1]] + op_list[op_list[i+2]]
i += 4
if op_list[i] == 2:
op_list[op_list[i+3]] = op_list[op_list[i+1]] * op_list[op_list[i+2]]
i += 4
if op_list[i] == 99:
break_code = 1
print(op_list[0])

27
2019/day02B.py Normal file
View file

@ -0,0 +1,27 @@
start_list = [1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,13,1,19,1,19,10,23,1,23,13,27,1,6,27,31,1,9,31,35,2,10,35,39,1,39,6,43,1,6,43,47,2,13,47,51,1,51,6,55,2,6,55,59,2,59,6,63,2,63,13,67,1,5,67,71,2,9,71,75,1,5,75,79,1,5,79,83,1,83,6,87,1,87,6,91,1,91,5,95,2,10,95,99,1,5,99,103,1,10,103,107,1,107,9,111,2,111,10,115,1,115,9,119,1,13,119,123,1,123,9,127,1,5,127,131,2,13,131,135,1,9,135,139,1,2,139,143,1,13,143,0,99,2,0,14,0]
op_list = []
for noun in range(0, 100):
for verb in range (0, 100):
op_list = start_list.copy()
op_list[1] = noun
op_list[2] = verb
i = 0
break_code = 0
error_code = 0
while break_code == 0 and error_code == 0:
if op_list[i] == 1:
op_list[op_list[i+3]] = op_list[op_list[i+1]] + op_list[op_list[i+2]]
i += 4
if op_list[i] == 2:
op_list[op_list[i+3]] = op_list[op_list[i+1]] * op_list[op_list[i+2]]
i += 4
if op_list[i] == 99:
break_code = 1
print(f'i: {i}; break: {break_code}; error: {error_code}')
print(f'Output: {op_list[0]}, Noun: {noun}, Verb: {verb}, Result: {100*noun+verb}')
if op_list[0] == 19690720:
break
if op_list[0] == 19690720:
break

42
2019/day03A.py Normal file
View file

@ -0,0 +1,42 @@
wire1 = ["R1009", "U286", "L371", "U985", "R372", "D887", "R311", "U609", "L180", "D986", "L901", "D592", "R298", "U955", "R681", "D68", "R453", "U654", "L898", "U498", "R365", "D863", "L974", "U333", "L267", "D230", "R706", "D67", "L814", "D280", "R931", "D539", "R217", "U384", "L314", "D162", "L280", "U484", "L915", "D512", "L974", "D220", "R292", "U465", "L976", "U837", "R28", "U68", "L98", "D177", "L780", "U732", "R696", "D412", "L715", "U993", "L617", "U999", "R304", "D277", "R889", "D604", "R199", "U498", "R302", "U958", "R443", "U957", "R453", "U362", "R704", "U301", "R813", "U404", "L150", "D673", "L407", "D233", "L901", "D965", "R602", "U615", "R496", "U467", "R849", "U530", "L205", "D43", "R709", "U127", "L35", "U801", "L565", "D890", "R90", "D763", "R95", "D542", "R84", "D421", "L298", "D58", "R794", "U722", "R205", "U830", "L149", "D759", "L950", "D708", "L727", "U401", "L187", "D598", "L390", "D469", "R375", "U985", "L723", "U63", "L983", "D39", "L160", "U276", "R822", "D504", "L298", "D484", "L425", "U228", "L984", "D623", "L936", "U624", "L851", "D748", "L266", "D576", "L898", "U783", "L374", "D276", "R757", "U89", "L649", "U73", "L447", "D11", "L539", "U291", "L507", "U208", "R167", "D874", "L596", "D235", "R334", "U328", "R41", "D212", "L544", "D72", "L972", "D790", "L282", "U662", "R452", "U892", "L830", "D86", "L252", "U701", "L215", "U179", "L480", "U963", "L897", "U489", "R223", "U757", "R804", "U373", "R844", "D518", "R145", "U304", "L24", "D988", "R605", "D644", "R415", "U34", "L889", "D827", "R854", "U836", "R837", "D334", "L664", "D883", "L900", "U448", "R152", "U473", "R243", "D147", "L711", "U642", "R757", "U272", "R192", "U741", "L522", "U785", "L872", "D128", "L161", "D347", "L967", "D295", "R831", "U535", "R329", "D752", "R720", "D806", "R897", "D320", "R391", "D737", "L719", "U652", "L54", "D271", "L855", "D112", "R382", "U959", "R909", "D687", "L699", "U892", "L96", "D537", "L365", "D182", "R886", "U566", "R929", "U532", "L255", "U823", "R833", "U542", "R234", "D339", "R409", "U100", "L466", "U572", "L162", "U843", "L635", "D153", "L704", "D317", "L534", "U205", "R611", "D672", "L462", "D506", "L243", "U509", "L819", "D787", "R448", "D353", "R162", "U108", "R850", "D919", "R259", "U877", "R50", "D733", "L875", "U106", "L890", "D275", "L904", "U849", "L855", "U314", "L291", "U170", "L627", "U608", "R783", "U404", "R294"]
wire2 = ["L1010", "D347", "R554", "U465", "L30", "D816", "R891", "D778", "R184", "U253", "R694", "U346", "L743", "D298", "L956", "U703", "R528", "D16", "L404", "D818", "L640", "D50", "R534", "D99", "L555", "U974", "L779", "D774", "L690", "U19", "R973", "D588", "L631", "U35", "L410", "D332", "L74", "D858", "R213", "U889", "R977", "U803", "L624", "U627", "R601", "U499", "L213", "U692", "L234", "U401", "L894", "U733", "R414", "D431", "R712", "D284", "R965", "D624", "R848", "D17", "R86", "D285", "R502", "U516", "L709", "U343", "L558", "D615", "L150", "D590", "R113", "D887", "R469", "U584", "L434", "D9", "L994", "D704", "R740", "D541", "R95", "U219", "L634", "D184", "R714", "U81", "L426", "D437", "R927", "U232", "L361", "D756", "R685", "D206", "R116", "U844", "R807", "U811", "L382", "D338", "L660", "D997", "L551", "D294", "L895", "D208", "R37", "D90", "R44", "D131", "R77", "U883", "R449", "D24", "R441", "U659", "R826", "U259", "R98", "D548", "R118", "D470", "L259", "U170", "R518", "U731", "L287", "U191", "L45", "D672", "L691", "U117", "R156", "U308", "R230", "U112", "L938", "U644", "R911", "U110", "L1", "U162", "R943", "U433", "R98", "U610", "R428", "U231", "R35", "U590", "R554", "U612", "R191", "U261", "R793", "U3", "R507", "U632", "L571", "D535", "R30", "U281", "L613", "U199", "R168", "D948", "R486", "U913", "R534", "U131", "R974", "U399", "L525", "D174", "L595", "D567", "L394", "D969", "L779", "U346", "L969", "D943", "L845", "D727", "R128", "U241", "L616", "U117", "R791", "D419", "L913", "D949", "R628", "D738", "R776", "D294", "L175", "D708", "R568", "U484", "R589", "D930", "L416", "D114", "L823", "U16", "R260", "U450", "R534", "D94", "R695", "D982", "R186", "D422", "L789", "D886", "L761", "U30", "R182", "U930", "L483", "U863", "L318", "U343", "L380", "U650", "R542", "U92", "L339", "D390", "L55", "U343", "L641", "D556", "R616", "U936", "R118", "D997", "R936", "D979", "L594", "U326", "L975", "U52", "L89", "U679", "L91", "D969", "R878", "D798", "R193", "D858", "R95", "D989", "R389", "U960", "R106", "D564", "R48", "D151", "L121", "D241", "L369", "D476", "L24", "D229", "R601", "U849", "L632", "U894", "R27", "U200", "L698", "U788", "L330", "D73", "R405", "D526", "L154", "U942", "L504", "D579", "L815", "D643", "L81", "U172", "R879", "U28", "R715", "U367", "L366", "D964", "R16", "D415", "L501", "D176", "R641", "U523", "L979", "D556", "R831"]
def wire_trace(traceroute = []):
origin = [0,0]
current_location = origin.copy()
route = []
for instruction in traceroute:
direction = instruction[0]
magnitude = int(instruction[1:])
while magnitude > 0:
if direction == "U":
current_location[1] += 1
magnitude -= 1
if direction == "D":
current_location[1] -= 1
magnitude -= 1
if direction == "L":
current_location[0] -= 1
magnitude -= 1
if direction == "R":
current_location[0]+= 1
magnitude -= 1
route.append(tuple((current_location[0], current_location[1])))
return route
route1 = wire_trace(wire1)
route2 = wire_trace(wire2)
intersect = list(set(route1).intersection(route2))
closest_pair = intersect[1]
closest_dist = abs(closest_pair[0]) + abs(closest_pair[1])
for item in intersect:
distance = abs(item[0]) + abs(item[1])
if distance < closest_dist:
closest_dist = distance
closest_pair = item
print(closest_dist)

41
2019/day03B.py Normal file
View file

@ -0,0 +1,41 @@
wire1 = ["R1009", "U286", "L371", "U985", "R372", "D887", "R311", "U609", "L180", "D986", "L901", "D592", "R298", "U955", "R681", "D68", "R453", "U654", "L898", "U498", "R365", "D863", "L974", "U333", "L267", "D230", "R706", "D67", "L814", "D280", "R931", "D539", "R217", "U384", "L314", "D162", "L280", "U484", "L915", "D512", "L974", "D220", "R292", "U465", "L976", "U837", "R28", "U68", "L98", "D177", "L780", "U732", "R696", "D412", "L715", "U993", "L617", "U999", "R304", "D277", "R889", "D604", "R199", "U498", "R302", "U958", "R443", "U957", "R453", "U362", "R704", "U301", "R813", "U404", "L150", "D673", "L407", "D233", "L901", "D965", "R602", "U615", "R496", "U467", "R849", "U530", "L205", "D43", "R709", "U127", "L35", "U801", "L565", "D890", "R90", "D763", "R95", "D542", "R84", "D421", "L298", "D58", "R794", "U722", "R205", "U830", "L149", "D759", "L950", "D708", "L727", "U401", "L187", "D598", "L390", "D469", "R375", "U985", "L723", "U63", "L983", "D39", "L160", "U276", "R822", "D504", "L298", "D484", "L425", "U228", "L984", "D623", "L936", "U624", "L851", "D748", "L266", "D576", "L898", "U783", "L374", "D276", "R757", "U89", "L649", "U73", "L447", "D11", "L539", "U291", "L507", "U208", "R167", "D874", "L596", "D235", "R334", "U328", "R41", "D212", "L544", "D72", "L972", "D790", "L282", "U662", "R452", "U892", "L830", "D86", "L252", "U701", "L215", "U179", "L480", "U963", "L897", "U489", "R223", "U757", "R804", "U373", "R844", "D518", "R145", "U304", "L24", "D988", "R605", "D644", "R415", "U34", "L889", "D827", "R854", "U836", "R837", "D334", "L664", "D883", "L900", "U448", "R152", "U473", "R243", "D147", "L711", "U642", "R757", "U272", "R192", "U741", "L522", "U785", "L872", "D128", "L161", "D347", "L967", "D295", "R831", "U535", "R329", "D752", "R720", "D806", "R897", "D320", "R391", "D737", "L719", "U652", "L54", "D271", "L855", "D112", "R382", "U959", "R909", "D687", "L699", "U892", "L96", "D537", "L365", "D182", "R886", "U566", "R929", "U532", "L255", "U823", "R833", "U542", "R234", "D339", "R409", "U100", "L466", "U572", "L162", "U843", "L635", "D153", "L704", "D317", "L534", "U205", "R611", "D672", "L462", "D506", "L243", "U509", "L819", "D787", "R448", "D353", "R162", "U108", "R850", "D919", "R259", "U877", "R50", "D733", "L875", "U106", "L890", "D275", "L904", "U849", "L855", "U314", "L291", "U170", "L627", "U608", "R783", "U404", "R294"]
wire2 = ["L1010", "D347", "R554", "U465", "L30", "D816", "R891", "D778", "R184", "U253", "R694", "U346", "L743", "D298", "L956", "U703", "R528", "D16", "L404", "D818", "L640", "D50", "R534", "D99", "L555", "U974", "L779", "D774", "L690", "U19", "R973", "D588", "L631", "U35", "L410", "D332", "L74", "D858", "R213", "U889", "R977", "U803", "L624", "U627", "R601", "U499", "L213", "U692", "L234", "U401", "L894", "U733", "R414", "D431", "R712", "D284", "R965", "D624", "R848", "D17", "R86", "D285", "R502", "U516", "L709", "U343", "L558", "D615", "L150", "D590", "R113", "D887", "R469", "U584", "L434", "D9", "L994", "D704", "R740", "D541", "R95", "U219", "L634", "D184", "R714", "U81", "L426", "D437", "R927", "U232", "L361", "D756", "R685", "D206", "R116", "U844", "R807", "U811", "L382", "D338", "L660", "D997", "L551", "D294", "L895", "D208", "R37", "D90", "R44", "D131", "R77", "U883", "R449", "D24", "R441", "U659", "R826", "U259", "R98", "D548", "R118", "D470", "L259", "U170", "R518", "U731", "L287", "U191", "L45", "D672", "L691", "U117", "R156", "U308", "R230", "U112", "L938", "U644", "R911", "U110", "L1", "U162", "R943", "U433", "R98", "U610", "R428", "U231", "R35", "U590", "R554", "U612", "R191", "U261", "R793", "U3", "R507", "U632", "L571", "D535", "R30", "U281", "L613", "U199", "R168", "D948", "R486", "U913", "R534", "U131", "R974", "U399", "L525", "D174", "L595", "D567", "L394", "D969", "L779", "U346", "L969", "D943", "L845", "D727", "R128", "U241", "L616", "U117", "R791", "D419", "L913", "D949", "R628", "D738", "R776", "D294", "L175", "D708", "R568", "U484", "R589", "D930", "L416", "D114", "L823", "U16", "R260", "U450", "R534", "D94", "R695", "D982", "R186", "D422", "L789", "D886", "L761", "U30", "R182", "U930", "L483", "U863", "L318", "U343", "L380", "U650", "R542", "U92", "L339", "D390", "L55", "U343", "L641", "D556", "R616", "U936", "R118", "D997", "R936", "D979", "L594", "U326", "L975", "U52", "L89", "U679", "L91", "D969", "R878", "D798", "R193", "D858", "R95", "D989", "R389", "U960", "R106", "D564", "R48", "D151", "L121", "D241", "L369", "D476", "L24", "D229", "R601", "U849", "L632", "U894", "R27", "U200", "L698", "U788", "L330", "D73", "R405", "D526", "L154", "U942", "L504", "D579", "L815", "D643", "L81", "U172", "R879", "U28", "R715", "U367", "L366", "D964", "R16", "D415", "L501", "D176", "R641", "U523", "L979", "D556", "R831"]
def wire_trace(traceroute = []):
origin = [0,0]
current_location = origin.copy()
route = []
for instruction in traceroute:
direction = instruction[0]
magnitude = int(instruction[1:])
while magnitude > 0:
if direction == "U":
current_location[1] += 1
magnitude -= 1
if direction == "D":
current_location[1] -= 1
magnitude -= 1
if direction == "L":
current_location[0] -= 1
magnitude -= 1
if direction == "R":
current_location[0]+= 1
magnitude -= 1
route.append(tuple((current_location[0], current_location[1])))
return route
route1 = wire_trace(wire1)
route2 = wire_trace(wire2)
intersect = list(set(route1).intersection(route2))
closest_pair = intersect[1]
closest_dist = route1.index(closest_pair) + route2.index(closest_pair) + 2
for item in intersect:
distance = route1.index(item) + route2.index(item) + 2
if distance < closest_dist:
closest_dist = distance
closest_pair = item
print(closest_dist)

29
2019/day04A.py Normal file
View file

@ -0,0 +1,29 @@
from collections import Counter
minVal = 353096
maxVal = 843212
matchingVals = []
def testForSequence(inputVal):
stringVal = str(inputVal)
tallyList = Counter(stringVal)
for digit, quant in tallyList.items():
if quant == 2:
return True
return False
def testForAscend(inputVal):
stringVal = str(inputVal)
i = 0
while i + 1 < len(stringVal):
if int(stringVal[i]) <= int(stringVal[i+1]):
i += 1
else:
return False
return True
for testVal in range(minVal, maxVal):
if testForSequence(testVal) and testForAscend(testVal):
matchingVals.append(testVal)
print(f'{len(matchingVals)}')

0
2019/day05a.py Normal file
View file