add solution 8, parts 1 and 2

This commit is contained in:
randomuser 2021-07-20 12:56:08 -05:00
parent c273962081
commit 34d996c2c1
3 changed files with 723 additions and 0 deletions

638
2020/8/input Normal file
View File

@ -0,0 +1,638 @@
acc +8
acc +37
jmp +328
jmp +574
nop +321
acc +17
jmp +450
acc +46
acc -15
nop -5
acc +48
jmp +358
jmp +29
acc +23
jmp +11
acc -14
jmp +561
acc +9
acc +17
jmp +136
jmp +394
acc +24
acc +37
acc +19
jmp +241
acc +38
acc +44
acc -5
jmp -8
acc +50
acc -9
acc +5
jmp +424
acc -15
nop +93
acc -1
jmp +414
jmp +548
jmp +454
acc +39
jmp +490
jmp +103
jmp +214
acc +37
jmp +164
acc +34
jmp +362
acc +24
acc +32
jmp +375
jmp +500
acc +23
nop -1
nop +463
jmp +108
acc +14
jmp +106
acc +20
nop +298
nop -39
jmp +321
jmp +1
jmp +515
nop +6
acc +3
acc +18
acc -10
jmp +353
jmp -43
jmp +1
acc +0
acc +7
jmp +507
nop +396
jmp -62
acc +30
acc -13
jmp +466
jmp +137
acc +6
jmp +211
acc +33
acc +4
jmp +269
acc +50
nop -65
acc +18
jmp -54
jmp -68
nop +38
acc -6
jmp +165
nop +342
acc +31
acc +30
nop +465
jmp +273
acc +35
jmp +201
acc +13
acc +18
acc +28
acc +40
jmp +244
nop -63
acc +25
acc +16
jmp -32
acc -6
acc +17
jmp +298
jmp +358
acc +28
jmp +1
acc +27
jmp +204
jmp +4
acc +17
acc +47
jmp +83
acc -14
jmp -42
acc +0
acc +14
acc -9
acc +13
jmp +108
acc +1
acc -8
acc +44
jmp +420
acc -1
acc +24
jmp +101
acc -10
nop +493
nop +140
acc -12
jmp -134
acc +21
nop +385
acc +38
acc +4
jmp +349
jmp +225
nop +432
jmp +421
acc +33
acc +11
jmp +462
acc +21
acc +11
acc +5
acc +15
jmp +260
nop +308
acc -6
acc -14
acc -3
jmp +178
nop -33
jmp +80
acc +33
acc -11
acc +39
jmp +145
jmp +64
acc +49
acc +47
acc +13
jmp +331
acc +1
jmp -10
acc +37
nop +276
jmp +259
acc +16
acc +38
jmp +121
acc +11
nop +301
acc +2
jmp +94
nop +186
nop +255
jmp -106
nop -171
acc +35
acc -1
acc +44
jmp +129
acc +27
acc -6
jmp -150
acc +12
acc +19
acc +15
jmp +247
nop +309
nop +429
nop -131
jmp +410
jmp +187
acc -4
acc +45
acc +3
acc -16
jmp -166
acc +41
jmp +276
acc -2
nop +23
acc +11
acc +19
jmp +271
acc +35
jmp +136
acc +46
acc -9
nop +189
jmp +1
jmp -201
acc -11
nop -190
acc +9
jmp +175
acc +25
acc +10
acc -12
jmp -50
acc +44
jmp +132
acc -14
jmp -71
acc +47
acc -9
jmp -125
jmp +1
acc -5
acc +47
jmp +184
nop -26
jmp -48
acc +24
acc +33
acc +38
jmp +246
acc +38
nop -114
nop +42
nop +131
jmp +256
acc +48
nop -126
acc +20
jmp +189
acc +39
nop +206
acc +2
acc +8
jmp +279
acc +31
acc +8
acc -14
jmp +221
acc -14
acc +4
jmp +161
jmp +188
acc +13
acc +50
acc -10
acc +42
jmp -169
acc +25
jmp +292
acc +40
jmp +53
acc -1
acc +29
acc +20
jmp -240
jmp +4
acc +28
acc -9
jmp -158
jmp +305
acc +47
nop -250
nop -155
jmp +321
acc +24
acc +48
acc +41
acc -2
jmp -61
acc +40
jmp +1
jmp -209
jmp +231
acc +28
acc +13
jmp +45
nop +147
nop -35
jmp -36
acc +33
acc +12
acc +7
jmp -62
nop +1
acc +3
acc +18
jmp +320
acc +9
acc -19
acc -3
acc +11
jmp -151
acc +11
acc +31
jmp -296
acc -10
acc +21
jmp +104
acc +46
acc +22
jmp +29
jmp +1
jmp +187
acc -7
acc +28
acc +1
acc +8
jmp +74
acc +45
jmp +114
acc +21
nop -204
jmp -327
acc +5
acc +36
jmp -148
jmp +285
acc +2
jmp +1
jmp +197
jmp +271
nop +137
nop +279
acc +41
jmp +1
acc +43
jmp +214
nop -307
jmp +245
acc -13
nop -210
jmp +56
acc -7
acc +18
acc +12
jmp +88
acc -18
acc +32
jmp +1
jmp -199
acc -9
jmp -317
acc -17
acc +2
nop +202
acc +20
jmp +227
jmp -44
jmp -28
acc -9
acc +12
acc -10
acc +3
jmp -115
acc +19
acc +22
jmp -340
acc -7
acc +7
acc +32
acc -11
jmp -19
acc +7
jmp +1
acc +14
jmp -89
acc +39
jmp +75
acc +32
nop +215
acc +40
jmp +83
jmp +204
acc +1
acc +29
acc -2
jmp +70
acc -15
acc -1
nop -381
jmp +27
nop +65
acc +40
jmp -299
acc +16
acc +13
jmp -24
acc +26
jmp -20
acc +36
acc +10
nop -274
jmp -394
jmp +165
acc +33
acc -7
jmp -419
jmp -386
nop -298
nop -406
jmp -108
acc +10
acc +46
acc +0
nop +50
jmp -343
jmp -5
acc -8
jmp -233
acc +13
acc +43
jmp +87
jmp +24
acc +35
nop -421
acc +46
jmp -35
jmp -55
acc +24
acc +17
acc -16
acc +26
jmp +128
nop -11
jmp +167
acc +25
acc +14
nop -59
jmp -108
acc +50
acc -18
acc +45
jmp -390
acc -2
acc +16
jmp +123
acc +41
jmp -242
nop -338
acc -15
acc +44
jmp -227
nop +159
acc +10
jmp -298
jmp -338
acc +10
acc +9
acc +24
nop -173
jmp -330
nop -453
acc +2
jmp +1
jmp -138
acc +21
acc +50
jmp -451
acc +19
acc -7
nop -454
jmp +85
acc -11
acc +19
jmp -394
acc +27
acc +4
acc +42
jmp -491
acc +36
acc +33
acc -5
acc +39
jmp -425
acc +46
acc +10
jmp -452
acc -1
acc +36
jmp -339
acc +26
acc +24
acc -8
jmp -376
acc +35
jmp +1
acc -4
acc +24
jmp -71
acc +46
acc -4
acc -8
jmp -289
acc +11
acc +32
acc +32
acc +26
jmp -214
acc +46
nop -485
acc +16
jmp -287
jmp -95
acc +36
nop -376
acc -13
jmp -406
nop -278
acc +22
acc +21
acc +33
jmp -463
jmp +11
nop -346
acc +33
jmp -86
acc -17
nop -350
nop +83
jmp -299
acc +31
acc +28
jmp -516
acc -13
acc +15
acc -19
jmp -338
acc +21
acc +10
jmp -309
jmp -473
nop -150
jmp +44
acc +45
acc +41
acc +41
nop -139
jmp -448
jmp +1
jmp -103
nop -433
acc +1
acc -1
acc +0
jmp -289
jmp -531
jmp -134
acc +21
acc +14
jmp -51
jmp -520
jmp -275
acc +6
acc +42
jmp -256
acc +26
acc +36
jmp -17
acc +11
acc +32
nop -244
acc +42
jmp -546
jmp -565
acc +31
acc -12
nop -496
jmp -531
acc +25
nop -196
acc -18
acc +10
jmp -22
nop -231
jmp -41
jmp -555
acc +37
acc -14
acc +43
jmp -462
acc -11
acc +43
acc +15
jmp -229
acc +0
acc +20
acc -18
nop -3
jmp -240
acc +37
jmp -520
nop -424
jmp +1
jmp +1
nop -158
jmp -19
acc +0
nop -591
acc +29
nop -192
jmp -24
nop -55
jmp -364
acc +5
acc +33
jmp -176
acc +25
acc +6
acc +21
acc +16
jmp +1

9
2020/8/sample_input Normal file
View File

@ -0,0 +1,9 @@
nop +0
acc +1
jmp +4
acc +3
jmp -3
acc -99
acc +1
jmp -4
acc +6

76
2020/8/solution.py Normal file
View File

@ -0,0 +1,76 @@
#!/usr/bin/python
def uniqexists(l):
exists = {}
for i in l:
try:
exists[i] += 1
except KeyError:
exists[i] = 1
for i in exists:
if exists[i] > 1: return exists[i]
fd = open('input', 'r')
o = [i.rstrip() for i in fd.readlines()]
def sol1():
pc = 0
acc = 0
ins_hist = []
ops = o
while uniqexists(ins_hist) == None:
split = ops[pc].split(' ')
ins = split[0]
arg = split[1]
ins_hist.append(pc)
if ins == "nop":
pc += 1
elif ins == "acc":
pc += 1
acc += int(arg)
elif ins == "jmp":
if int(arg) == 0: acc += 1
pc += int(arg)
print(acc)
def sol2():
realops = o
for i in range(len(realops)):
ops = []
for j in realops:
ops.append(j)
split = ops[i].split(' ')
mod_ins = split[0]
mod_arg = split[1]
if mod_ins == "jmp":
ops[i] = "{} {}".format("nop", mod_arg)
elif mod_ins == "nop":
ops[i] = "{} {}".format("jmp", mod_arg)
pc = 0
acc = 0
ins_hist = []
try:
while uniqexists(ins_hist) == None:
split = ops[pc].split(' ')
ins = split[0]
arg = split[1]
ins_hist.append(pc)
if ins == "nop":
pc += 1
elif ins == "acc":
pc += 1
acc += int(arg)
elif ins == "jmp":
if int(arg) == 0: acc += 1
pc += int(arg)
except IndexError:
print("-!- MACHINE HALT -!-")
print(acc)
sol1()
sol2()