Added 2017/25 Part 1
This commit is contained in:
+24
-2
@@ -93,7 +93,29 @@ appears on the tape. In the above example, the *diagnostic checksum* is
|
||||
Recreate the Turing machine and save the computer! *What is the
|
||||
diagnostic checksum* it produces once it\'s working again?
|
||||
|
||||
To begin, [get your puzzle input](25/input).
|
||||
Your puzzle answer was `633`.
|
||||
|
||||
Answer:
|
||||
The first half of this puzzle is complete! It provides one gold star: \*
|
||||
|
||||
## \-\-- Part Two \-\-- {#part2}
|
||||
|
||||
The Turing machine, and soon the entire computer, springs back to life.
|
||||
A console glows dimly nearby, awaiting your command.
|
||||
|
||||
> reboot printer
|
||||
Error: That command requires priority 50. You currently have priority 0.
|
||||
You must deposit 50 stars to increase your priority to the required level.
|
||||
|
||||
The console flickers for a moment, and then prints another message:
|
||||
|
||||
Star accepted.
|
||||
You must deposit 49 stars to increase your priority to the required level.
|
||||
|
||||
The *garbage collector* winks at you, then continues sweeping.
|
||||
|
||||
You don\'t have enough stars to reboot the printer, though. You need 3
|
||||
more.
|
||||
|
||||
Although it hasn\'t changed, you can still [get your puzzle
|
||||
input](25/input).
|
||||
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
#!/bin/python3
|
||||
import sys,re
|
||||
from pprint import pprint
|
||||
sys.path.insert(0, '../../')
|
||||
from fred import list2int,get_re,nprint,lprint
|
||||
|
||||
input_f = 'test'
|
||||
|
||||
part = 1
|
||||
#########################################
|
||||
# #
|
||||
# Part 1 #
|
||||
# #
|
||||
#########################################
|
||||
|
||||
max_steps = 12302209
|
||||
begin_state = 'A'
|
||||
|
||||
states = {
|
||||
'A': {
|
||||
0: {
|
||||
'W': 1,
|
||||
'M': 'R',
|
||||
'C': 'B'
|
||||
},
|
||||
1: {
|
||||
'W': 0,
|
||||
'M': 'L',
|
||||
'C': 'D'
|
||||
}
|
||||
},
|
||||
'B': {
|
||||
0: {
|
||||
'W': 1,
|
||||
'M': 'R',
|
||||
'C': 'C'
|
||||
},
|
||||
1: {
|
||||
'W': 0,
|
||||
'M': 'R',
|
||||
'C': 'F'
|
||||
}
|
||||
},
|
||||
'C': {
|
||||
0: {
|
||||
'W': 1,
|
||||
'M': 'L',
|
||||
'C': 'C'
|
||||
},
|
||||
1: {
|
||||
'W': 1,
|
||||
'M': 'L',
|
||||
'C': 'A'
|
||||
}
|
||||
},
|
||||
'D': {
|
||||
0: {
|
||||
'W': 0,
|
||||
'M': 'L',
|
||||
'C': 'E'
|
||||
},
|
||||
1: {
|
||||
'W': 1,
|
||||
'M': 'R',
|
||||
'C': 'A'
|
||||
}
|
||||
},
|
||||
'E': {
|
||||
0: {
|
||||
'W': 1,
|
||||
'M': 'L',
|
||||
'C': 'A'
|
||||
},
|
||||
1: {
|
||||
'W': 0,
|
||||
'M': 'R',
|
||||
'C': 'B'
|
||||
}
|
||||
},
|
||||
'F': {
|
||||
0: {
|
||||
'W': 0,
|
||||
'M': 'R',
|
||||
'C': 'C'
|
||||
},
|
||||
1: {
|
||||
'W': 0,
|
||||
'M': 'R',
|
||||
'C': 'E'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if part == 1:
|
||||
end = False
|
||||
steps = 0
|
||||
|
||||
line = [0,0,0,0,0,0,0,0,0]
|
||||
idx = 4
|
||||
state = begin_state
|
||||
while not end:
|
||||
|
||||
if idx-1 <= 0:
|
||||
line.insert(0, [0])
|
||||
idx += 1
|
||||
if idx+2 > len(line):
|
||||
line.append(0)
|
||||
line.append(0)
|
||||
cur = line[idx]
|
||||
line[idx] = states[state][cur]['W']
|
||||
if states[state][cur]['M'] == 'L':
|
||||
idx -= 1
|
||||
else:
|
||||
idx += 1
|
||||
state = states[state][cur]['C']
|
||||
steps += 1
|
||||
if steps == max_steps:
|
||||
end = True
|
||||
|
||||
print(line.count(1))
|
||||
|
||||
#########################################
|
||||
# #
|
||||
# Part 2 #
|
||||
# #
|
||||
#########################################
|
||||
if part == 2:
|
||||
exit()
|
||||
Reference in New Issue
Block a user