Skip to content

Commit

Permalink
work on Day5
Browse files Browse the repository at this point in the history
  • Loading branch information
ace510 committed Dec 5, 2019
0 parents commit f22c259
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 0 deletions.
97 changes: 97 additions & 0 deletions day2p1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import random

''' (1,0,0,3,99)
[0] is opcode (1 Add, 2 multi, 99 Halt)
[1] is operand 1
[2] is operand 2
[3] output location
add 1(0) t0 1(0) and store in 3
[3] = 1
'''
input_clean = [1,12,2,3, # 3 1, 12, 2, 3
1,1,2,3, # 7
1,3,4,3, # 11
1,5,0,3, # 15
2,13,1,19, # 19
1,9,19,23, # 23
2,23,13,27,# 27
1,27,9,31, #
2,31,6,35, #
1,5,35,39, #
1,10,39,43, #
2,43,6,47, #
1,10,47,51, #
2,6,51,55, #
1,5,55,59, #
1,59,9,63, #
1,13,63,67, #
2,6,67,71, #
1,5,71,75, #
2,6,75,79, #
2,79,6,83, #
1,13,83,87, #
1,9,87,91, #
1,9,91,95, #
1,5,95,99, #
1,5,99,103, #
2,13,103,107, #
1,6,107,111, #
1,9,111,115, #
2,6,115,119, #
1,13,119,123, #
1,123,6,127, #
1,127,5,131, #
2,10,131,135, #
2,135,10,139, #
1,13,139,143, #
1,10,143,147, #
1,2,147,151, #
1,6,151,0,
99,2,14,0,
0]



# 1202 program alarm
# input[1] = 12
# input[2] = 2

def orbital_comp(noun, verb):
input_dirty = input_clean[:]
halting = False
index = 0
input_dirty[1] = int(noun)
input_dirty[2] = int(verb)
while not halting:
output = 0
op_code, output_loc = input_dirty[0+index], input_dirty[3+ index]
operand1, operand2 = input_dirty[input_dirty[1+ index]], input_dirty[input_dirty[2+ index]]
# op_code = input_dirty[0+index]
# operand1 = input_dirty[input_dirty[1+ index] ]
# operand2 = input_dirty[input_dirty[2+ index] ]
# output_loc = input_dirty[3+ index]

if op_code == 1:
output = operand1 + operand2
elif op_code == 2:
output = operand1 * operand2
elif op_code == 99:
halting = True
break
else:
halting = True
input_dirty[output_loc] = output
index += 4
return input_dirty[0]


return_value = 42069
while return_value != 19690720:
noun = random.randrange(0,100)
verb = random.randrange(0,100)
return_value = orbital_comp(noun, verb)
print(noun,verb)

90 changes: 90 additions & 0 deletions day3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
with open('day3data.txt','r') as input_file:
payload1 = input_file.readline()
payload2 = input_file.readline()

payload1lines = payload1.split(',')
payload2lines = payload2.split(',')

'''
U is up
D is down
R is right
L is left
'''



def calc_line(payloadlines):
x=0
y=0
wire_length = 0
payloadpoints = set()
payloaddict = {}
for i in payloadlines:
x_vec= 0
y_vec= 0

if i[0] == 'U':
y_vec = 1
elif i[0] == 'D':
y_vec = -1
elif i[0] == 'R':
x_vec = 1
elif i[0] == 'L':
x_vec = -1
else:
raise ValueError

magnitude =int(i[1:])

# print(f"moving {magnitude} with x equalling {x_vec} and y equalling {y_vec}")

for _ in range(magnitude):
x += x_vec
y += y_vec
wire_length += 1
payloaddict[(x,y)] = wire_length

# print(f"current coordinates are {x},{y}")

return payloaddict
print('simulating Gibson routes')

payload1dict = calc_line(payload1lines)
payload2dict = calc_line(payload2lines)

print('Gibson routes simulated, hacking Gibson')
def mergeDict(dict1, dict2):
dict3 = {**dict1, **dict2}
for key, value in dict3.items():
if key in dict1 and key in dict2:
dict3[key] = [value , dict1[key]]

return dict3

overlay_dict = mergeDict(payload1dict, payload2dict)

search_space = len(overlay_dict)
search_index = 0.0
skinny_dict = {}

for key, value in overlay_dict.items():
search_index += 1
try:
if len(value) > 1:
skinny_dict[key] = value
else:
print(search_index/ search_space)
except TypeError:
pass
distance=9999999
distance_pair = 0

for key,value in skinny_dict.items():
trial_value = value[0] + value[1]
if trial_value < distance:
distance = trial_value
distance_pair = (key, value)

print(distance_pair)
print(distance)
2 changes: 2 additions & 0 deletions day3data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
R990,U803,R777,U157,R629,D493,R498,D606,R344,U241,L708,D403,R943,U961,L107,D755,R145,D77,L654,D297,L263,D904,R405,U676,R674,U139,L746,U935,R186,U433,L739,D774,R470,D459,R865,D209,L217,U525,R747,D218,R432,U769,L876,D477,R606,D161,R991,D338,R647,D958,R777,D148,R593,D873,L95,U707,R468,U518,R845,U285,R221,U771,R989,D107,R44,U833,L343,D420,R468,D954,L604,D270,L691,U401,R850,U70,R441,U461,R638,D743,R65,U673,L999,U110,R266,U759,R768,U569,L250,D577,R247,U420,L227,U437,L80,D647,L778,U935,R585,U35,L735,D201,R694,U635,L597,U215,R743,D542,L701,U946,L503,U589,R836,D687,L444,U409,L473,U132,L570,U374,R193,D908,L800,U294,L252,U851,R947,D647,L37,D20,L27,U620,L534,D356,L291,U611,L128,D670,L364,U200,L749,D708,R776,U99,R606,D999,L810,D373,R212,D138,R856,D966,L206,D23,L860,D731,L914,U716,L212,U225,R766,U348,L220,D69,L766,D15,L557,U71,R734,D295,R884,D822,R300,D152,L986,D170,R764,U24,R394,D710,L860,U830,L305,U431,R201,D44,R882,U667,R37,D727,R916,U460,L834,D771,R373,U96,L707,D576,R607,D351,R577,D200,L402,U364,L32,D512,L152,D283,L232,U804,R827,U352,R104,D323,L254,U273,L451,D967,R739,D53,L908,D866,R998,U897,L581,U538,R206,U644,L70,D17,L481,U912,L377,D922,L286,U547,R35,U292,L318,U256,R79,D52,R92,U160,R763,U428,R663,D634,R212,D325,R460,U142,L375,U382,R20,D321,L220,D578,R915,D465,L797,D849,L281,D491,L911,D624,R800,U629,L675,U428,L219,U694,R680,U350,R113,D903,L22,D683,L787,D1,R93,U315,L562,U756,R622,D533,L587,D216,L933,U972,R506,U536,R797,U828,L12,D965,L641,U165,R937,D675,R259
L998,D197,L301,D874,L221,U985,L213,D288,R142,D635,R333,D328,R405,D988,L23,D917,R412,D971,R876,U527,R987,D884,R39,D485,L971,U200,R931,U79,L271,U183,R354,D18,R346,D866,L752,D204,L863,U784,R292,U676,R811,U721,L53,U983,L993,U822,R871,U539,L782,D749,R417,U667,R882,U467,R321,U894,R912,U756,L102,U154,L57,D316,R200,U372,L44,U406,L426,D613,R847,U977,R303,U469,R509,U839,L633,D267,L487,D976,R325,U399,L359,U161,L305,U935,R522,D848,R784,D273,L337,D55,L266,U406,L858,D650,L176,D124,R231,U513,L462,U328,L674,D598,R568,D742,L39,D438,L643,D254,R577,U519,R325,U124,R91,U129,L79,D52,R480,D46,R129,D997,R452,D992,L721,U490,L595,D666,R372,D198,R813,U624,L469,U59,R578,U184,R117,D749,L745,U302,R398,D951,L683,D360,R476,D788,R70,U693,R295,D547,L61,U782,R440,D818,L330,D321,L968,U622,R160,U571,L886,D43,L855,U272,R530,D267,L312,D519,L741,D697,R206,U148,L445,U857,R983,D192,L788,U826,R805,U932,R888,D250,L682,D52,R406,D176,R984,D637,L947,D416,L687,U699,L544,D710,L933,D171,L357,D134,L968,D538,R496,D240,L730,U771,R554,U708,R265,D748,L839,U668,L333,U335,R526,U809,L653,D6,R234,D130,R871,U911,R538,U372,L960,D535,L196,U236,L966,D185,L166,U789,L885,U453,R627,D586,R501,U222,L280,U124,R755,D159,L759,U78,R669,D889,L150,D888,L71,D917,L126,D97,L138,U726,R160,D971,R527,D988,R455,D413,R539,U923,R258,U734,L459,D954,R877,U613,R343,D98,R238,U478,R514,U814,L274,U119,L958,U698,R761,U693,R367,D111,L800,D531,L91,U616,R208,D255,R169,U145,R671,U969,L468,U566,R589,D455,R323,D303,R374,D890,R377,D262,L40,U85,L719
42 changes: 42 additions & 0 deletions day4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

start = 357253
end = 892942
decrease_set = list()
subsequent_set = list()


for i in range(start, end + 1):
digits_increase = True
first_num = 0
i_str = str(i)

while digits_increase and first_num < 6:
for second_num in range(first_num+1,6):
if i_str[first_num] > i_str[second_num]:
# print(f"{i_str} does not suffice")
# print(f'{i_str[first_num]} is less than {i_str[second_num]}')
digits_increase = False
first_num += 1

if digits_increase:
decrease_set.append(i_str)

for i in decrease_set:
subsequent_same = False
index = 0
while not subsequent_same and index < 5:
if index == 0 and i[index] == i[index+1] and i[index] != i[index+2]:
subsequent_same = True
elif index == 4 and i[index] == i[index+1] and i[index] != i[index-1]:
subsequent_same = True
elif i[index] == i[index+1] and i[index] != i[index-1] and i[index] != i[index+2]:
subsequent_same = True
index += 1

if subsequent_same:
subsequent_set.append(i)

for i in subsequent_set:
print(i)

print(len(subsequent_set))
78 changes: 78 additions & 0 deletions day5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
input_clean = [3,225,1,225,6,6,1100,1,238,225,104,0,1102,35,92,225,1101,25,55,225,1102,47,36,225,1102,17,35,225,1,165,18,224,1001,224,-106,224,4,224,102,8,223,223,1001,224,3,224,1,223,224,223,1101,68,23,224,101,-91,224,224,4,224,102,8,223,223,101,1,224,224,1,223,224,223,2,217,13,224,1001,224,-1890,224,4,224,102,8,223,223,1001,224,6,224,1,224,223,223,1102,69,77,224,1001,224,-5313,224,4,224,1002,223,8,223,101,2,224,224,1,224,223,223,102,50,22,224,101,-1800,224,224,4,224,1002,223,8,223,1001,224,5,224,1,224,223,223,1102,89,32,225,1001,26,60,224,1001,224,-95,224,4,224,102,8,223,223,101,2,224,224,1,223,224,223,1102,51,79,225,1102,65,30,225,1002,170,86,224,101,-2580,224,224,4,224,102,8,223,223,1001,224,6,224,1,223,224,223,101,39,139,224,1001,224,-128,224,4,224,102,8,223,223,101,3,224,224,1,223,224,223,1102,54,93,225,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1106,0,265,1105,1,99999,1006,0,99999,1006,227,274,1105,1,99999,1105,1,280,1105,1,99999,1,225,225,225,1101,294,0,0,105,1,0,1105,1,99999,1106,0,300,1105,1,99999,1,225,225,225,1101,314,0,0,106,0,0,1105,1,99999,1008,677,677,224,1002,223,2,223,1005,224,329,101,1,223,223,7,677,677,224,102,2,223,223,1006,224,344,101,1,223,223,108,677,677,224,1002,223,2,223,1006,224,359,1001,223,1,223,7,677,226,224,1002,223,2,223,1005,224,374,1001,223,1,223,1107,677,226,224,1002,223,2,223,1005,224,389,1001,223,1,223,107,226,677,224,102,2,223,223,1005,224,404,1001,223,1,223,1108,226,677,224,1002,223,2,223,1006,224,419,101,1,223,223,107,226,226,224,102,2,223,223,1005,224,434,1001,223,1,223,108,677,226,224,1002,223,2,223,1006,224,449,101,1,223,223,108,226,226,224,102,2,223,223,1006,224,464,1001,223,1,223,1007,226,226,224,1002,223,2,223,1005,224,479,101,1,223,223,8,677,226,224,1002,223,2,223,1006,224,494,101,1,223,223,1007,226,677,224,102,2,223,223,1006,224,509,101,1,223,223,7,226,677,224,1002,223,2,223,1005,224,524,101,1,223,223,107,677,677,224,102,2,223,223,1005,224,539,101,1,223,223,1008,677,226,224,1002,223,2,223,1005,224,554,1001,223,1,223,1008,226,226,224,1002,223,2,223,1006,224,569,1001,223,1,223,1108,226,226,224,102,2,223,223,1005,224,584,101,1,223,223,1107,226,677,224,1002,223,2,223,1005,224,599,1001,223,1,223,8,226,677,224,1002,223,2,223,1006,224,614,1001,223,1,223,1108,677,226,224,102,2,223,223,1005,224,629,1001,223,1,223,8,226,226,224,1002,223,2,223,1005,224,644,1001,223,1,223,1107,677,677,224,1002,223,2,223,1005,224,659,1001,223,1,223,1007,677,677,224,1002,223,2,223,1005,224,674,101,1,223,223,4,223,99,226]
input_var = 1

input_dirty = input_clean[:]
halting = False
index = 0

def reverse(string):
output = "".join(reversed(string))
return output



while not halting:
output = 0
instruction_length = 4


opcode_and_param = reverse(str(input_dirty[0+index]))
print(f'the whole parameter bundle is{opcode_and_param}')

op_code = opcode_and_param[:1].rstrip('0')
print(f'the opcode is {op_code}')

try:
operand1_mode = opcode_and_param[2]
except IndexError:
operand1_mode = 0
try:
operand2_mode = opcode_and_param[3]
except IndexError:
operand2_mode = 0
try:
output_loc_mode = opcode_and_param[4]
except IndexError:
output_loc_mode = 0

if operand1_mode ==1:
operand1 = input_dirty[1+ index]
else:
operand1 = input_dirty[input_dirty[1+ index] ]

if operand2_mode ==1:
operand2 = input_dirty[1+ index]
else:
operand2 = input_dirty[input_dirty[2+ index] ]

if output_loc_mode == 1:

output_loc = input_dirty[3+ index]







if op_code == 1:
output = operand1 + operand2
elif op_code == 2:
output = operand1 * operand2
elif op_code == 3:
instruction_length = 2
output_loc = input_dirty[1+ index]
output = input_var
elif op_code == 4:
instruction_length = 2
print(input_var)
output = None
elif op_code == 99:
halting = True
break
else:
print(f'opcode {op_code} not found halting')
halting = True
if output:
input_dirty[output_loc] = output
index += instruction_length

0 comments on commit f22c259

Please sign in to comment.