Created
October 18, 2015 17:29
-
-
Save csm10495/e9a0584bfdd7bddd8722 to your computer and use it in GitHub Desktop.
Bomb Defusal Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
bdm241.py - Bomb Defusal Manual Version 1. Verification Code 241. | |
This file contains functions to solve various challenges faster than using the guide for 'Keep Talking and Nobody Explodes' | |
(C) - Charles Machalow - MIT License | |
""" | |
import itertools | |
words = ["about", "after", "again", "below", "could", "every", "first", "found", "great", "house", "large", "learn", "never", "other", "place", "plant", "point", "right", "small", "sound", "spell", "still", "study", "their", "there", "these", "thing", "think", "three", "water", "where", "which", "world", "would", "write"] | |
morse_seqs = { | |
'.-' : 'A', | |
'-...' : 'B', | |
'-.-.' : 'C', | |
'-..' : 'D', | |
'.' : 'E', | |
'..-.' : 'F', | |
'--.' : 'G', | |
'....' : 'H', | |
'..' : 'I', | |
'.----' : 'J', | |
'-.-' : 'K', | |
'.-..' : 'L', | |
'--' : 'M', | |
'-.' : 'N', | |
'---' : 'O', | |
'.--.' : 'P', | |
'--.-' : 'Q', | |
'.-.' : 'R', | |
'...' : 'S', | |
'-' : 'T', | |
'..-' : 'U', | |
'...-' : 'V', | |
'.--' : 'W', | |
'-..-' : 'X', | |
'-.--' : 'Y', | |
'--..' : 'Z', | |
} | |
morse_words = { | |
'shell' : 3.505 , | |
'halls' : 3.515 , | |
'slick' : 3.522 , | |
'trick' : 3.532 , | |
'boxes' : 3.535 , | |
'leaks' : 3.542 , | |
'strobe' : 3.545 , | |
'bistro' : 3.552 , | |
'flick' : 3.555 , | |
'bombs' : 3.565 , | |
'break' : 3.572 , | |
'brick' : 3.575 , | |
'steak' : 3.582 , | |
'sting' : 3.592 , | |
'vector' : 3.595 , | |
'beats' : 3.600 , | |
} | |
whos_on_first_step_1 = { | |
"YES" : "MIDDLE LEFT", | |
"FIRST" : "UPPER RIGHT", | |
'DISPLAY' : 'BOTTOM RIGHT', | |
'OKAY' : 'UPPER RIGHT', | |
'SAYS' : 'BOTTOM RIGHT', | |
'NOTHING' : 'MIDDLE LEFT', | |
'' : 'BOTTOM LEFT', | |
'BLANK' : 'MIDDLE RIGHT', | |
'NO' : 'BOTTOM RIGHT', | |
'LED' : 'MIDDLE LEFT', | |
'LEAD' : 'BOTTOM RIGHT', | |
'READ' : 'MIDDLE RIGHT', | |
'RED' : 'MIDDLE RIGHT', | |
'REED' : 'BOTTOM LEFT', | |
'LEED' : 'BOTTOM LEFT', | |
'HOLD ON' : 'BOTTOM RIGHT', | |
'YOU' : 'MIDDLE RIGHT', | |
'YOU ARE' : 'BOTTOM RIGHT', | |
'YOUR' : 'MIDDLE RIGHT', | |
"YOU'RE" : 'MIDDLE RIGHT', | |
'UR' : 'UPPER LEFT', | |
'THERE' : 'BOTTOM RIGHT', | |
"THEY'RE" : 'BOTTOM LEFT', | |
'THEIR' : 'MIDDLE RIGHT', | |
'THEY ARE': 'MIDDLE LEFT', | |
'SEE' : 'BOTTOM RIGHT', | |
'C' : 'TOP RIGHT', | |
'CEE' : 'BOTTOM RIGHT', | |
} | |
whos_on_first_step_2 = { | |
"READY" : "YES, OKAY, WHAT, MIDDLE, LEFT, PRESS, RIGHT, BLANK, READY, NO, FIRST, UHHH, NOTHING, WAIT", | |
"FIRST" : "LEFT, OKAY, YES, MIDDLE, NO, RIGHT, NOTHING, UHHH, WAIT, READY, BLANK, WHAT, PRESS, FIRST", | |
"NO" : "BLANK, UHHH, WAIT, FIRST, WHAT, READY, RIGHT, YES, NOTHING, LEFT, PRESS, OKAY, NO, MIDDLE", | |
"BLANK" : "WAIT, RIGHT, OKAY, MIDDLE, BLANK, PRESS, READY, NOTHING, NO, WHAT, LEFT, UHHH, YES, FIRST", | |
"NOTHING": "UHHH, RIGHT, OKAY, MIDDLE, YES, BLANK, NO, PRESS, LEFT, WHAT, WAIT, FIRST, NOTHING, READY", | |
"YES" : "OKAY, RIGHT, UHHH, MIDDLE, FIRST, WHAT, PRESS, READY, NOTHING, YES, LEFT, BLANK, NO, WAIT", | |
"WHAT" : "UHHH, WHAT, LEFT, NOTHING, READY, BLANK, MIDDLE, NO, OKAY, FIRST, WAIT, YES, PRESS, RIGHT", | |
"UHHH" : "READY, NOTHING, LEFT, WHAT, OKAY, YES, RIGHT, NO, PRESS, BLANK, UHHH, MIDDLE, WAIT, FIRST", | |
"LEFT" : "RIGHT, LEFT, FIRST, NO, MIDDLE, YES, BLANK, WHAT, UHHH, WAIT, PRESS, READY, OKAY, NOTHING", | |
"RIGHT" : "YES, NOTHING, READY, PRESS, NO, WAIT, WHAT, RIGHT, MIDDLE, LEFT, UHHH, BLANK, OKAY, FIRST", | |
"MIDDLE" : "BLANK, READY, OKAY, WHAT, NOTHING, PRESS, NO, WAIT, LEFT, MIDDLE, RIGHT, FIRST, UHHH, YES", | |
"OKAY" : "MIDDLE, NO, FIRST, YES, UHHH, NOTHING, WAIT, OKAY, LEFT, READY, BLANK, PRESS, WHAT, RIGHT", | |
"WAIT" : "UHHH, NO, BLANK, OKAY, YES, LEFT, FIRST, PRESS, WHAT, WAIT, NOTHING, READY, RIGHT, MIDDLE", | |
"PRESS" : "RIGHT, MIDDLE, YES, READY, PRESS, OKAY, NOTHING, UHHH, BLANK, LEFT, FIRST, WHAT, NO, WAIT", | |
"YOU" : "SURE, YOU ARE, YOUR, YOU'RE, NEXT, UH HUH, UR, HOLD, WHAT?, YOU, UH UH, LIKE, DONE, U", | |
"YOU ARE": "YOUR, NEXT, LIKE, UH HUH, WHAT?, DONE, UH UH, HOLD, YOU, U, YOU'RE, SURE, UR, YOU ARE", | |
"YOUR" : "UH UH, YOU ARE, UH HUH, YOUR, NEXT, UR, SURE, U, YOU'RE, YOU, WHAT?, HOLD, LIKE, DONE", | |
"YOU'RE" : "YOU, YOU'RE, UR, NEXT, UH UH, YOU ARE, U, YOUR, WHAT?, UH HUH, SURE, DONE, LIKE, HOLD", | |
"UR" : "DONE, U, UR, UH HUH, WHAT?, SURE, YOUR, HOLD, YOU'RE, LIKE, NEXT, UH UH, YOU ARE, YOU", | |
"U" : "UH HUH, SURE, NEXT, WHAT?, YOU'RE, UR, UH UH, DONE, U, YOU, LIKE, HOLD, YOU ARE, YOUR", | |
"UH HUH" : "UH HUH, YOUR, YOU ARE, YOU, DONE, HOLD, UH UH, NEXT, SURE, LIKE, YOU'RE, UR, U, WHAT?", | |
"UH UH" : "UR, U, YOU ARE, YOU'RE, NEXT, UH UH, DONE, YOU, UH HUH, LIKE, YOUR, SURE, HOLD, WHAT?", | |
"WHAT?" : "YOU, HOLD, YOU'RE, YOUR, U, DONE, UH UH, LIKE, YOU ARE, UH HUH, UR, NEXT, WHAT?, SURE", | |
"DONE" : "SURE, UH HUH, NEXT, WHAT?, YOUR, UR, YOU'RE, HOLD, LIKE, YOU, U, YOU ARE, UH UH, DONE", | |
"NEXT" : "WHAT?, UH HUH, UH UH, YOUR, HOLD, SURE, NEXT, LIKE, DONE, YOU ARE, UR, YOU'RE, U, YOU", | |
"HOLD" : "YOU ARE, U, DONE, UH UH, YOU, UR, SURE, WHAT?, YOU'RE, NEXT, HOLD, UH HUH, YOUR, LIKE", | |
"SURE" : "YOU ARE, DONE, LIKE, YOU'RE, YOU, HOLD, UH HUH, UR, SURE, U, WHAT?, NEXT, YOUR, UH UH", | |
"LIKE" : "YOU'RE, NEXT, U, UR, HOLD, DONE, UH UH, WHAT?, UH HUH, YOU, LIKE, SURE, YOU ARE, YOUR", | |
} | |
complicated_wires = { | |
"W" : 'CUT', | |
'R' : 'CUT IF THE LAST DIGIT OF SERIAL IS EVEN', | |
'R*' : 'CUT', | |
'W*' : 'CUT', | |
'WL' : 'DO NOT CUT', | |
'B' : 'CUT IF THE LAST DIGIT OF SERIAL IS EVEN', | |
'BL' : 'CUT IF HAS PARALLEL PORT', | |
'RB' : 'CUT IF THE LAST DIGIT OF SERIAL IS EVEN', | |
'WL*' : 'CUT IF HAS TWO OR MORE BATTERIES', | |
'B*' : 'DO NOT CUT', | |
'RL' : 'CUT IF HAS TWO OR MORE BATTERIES', | |
'RBL' : 'CUT IF THE LAST DIGIT OF SERIAL IS EVEN', | |
'RB*' : 'CUT IF HAS PARALLEL PORT', | |
'BL*' : 'CUT IF HAS PARALLEL PORT', | |
'RBL*' : 'DO NOT CUT', | |
'RL*' : 'CUT IF HAS TWO OR MORE BATTERIES', | |
} | |
def comp(): | |
""" | |
Brief: | |
Used for the 'On the Subject of Complicated Wires' challenge. | |
User will be prompted for characteristics of each wire. | |
Argument(s): | |
None to the function | |
When input-ing a wire, input a string using the following qualifiers: | |
W: White wire | |
B: Blue wire | |
R: Red wire | |
*: Has a star | |
L: Has an LED | |
Q: Exit this challenge | |
""" | |
while True: | |
combo = input('Wire input: ').upper() | |
combo = itertools.permutations(combo) | |
for i in combo: | |
found = False | |
i = ''.join(i) | |
if i in complicated_wires: | |
print (complicated_wires[i]) | |
found = True | |
break | |
if 'Q' in i: | |
return | |
if not found: | |
print ("Wire sequence not found!") | |
def whos(): | |
""" | |
Brief: | |
Used for the 'On the Subject of Who's on First' challenge | |
User will be prompted for the initial word. Then the user will be given a location. | |
After, give the word in that location to receive the list of possible words for the defuser. | |
Argument(s): | |
None | |
While completing the challenge: | |
Strings | |
Q to exit challenge | |
""" | |
while True: | |
step1 = input("Word in display: ").upper() | |
if step1 == 'Q': | |
break | |
elif step1 in whos_on_first_step_1: | |
step2 = input(whos_on_first_step_1[step1] + ": ").upper() | |
if step2 in whos_on_first_step_2: | |
print(whos_on_first_step_2[step2]) | |
else: | |
print("Word (%s) not found!" % step2) | |
else: | |
print("Word (%s) not found!" % step1) | |
def passwords(a, b=None, c=None, d=None, e=None): | |
""" | |
Brief: | |
Used for the 'On the Subject of Passwords' challenge. | |
Pass the possible characters for each letter of the challenge as an argument. | |
Argument(s): | |
a - (Required) - String of characters possible for the first letter | |
b - (Optional: Defaults to None) - String of characters possible for the second letter | |
c - (Optional: Defaults to None) - String of characters possible for the third letter | |
d - (Optional: Defaults to None) - String of characters possible for the fourth letter | |
e - (Optional: Defaults to None) - String of characters possible for the fifth letter | |
""" | |
iterlist = [] | |
numchar = 0 | |
for i in [a, b, c, d, e]: | |
if i is not None: | |
iterlist.append(list(i)) | |
numchar += 1 | |
else: | |
break | |
possible = map(lambda x: ''.join(x), list(itertools.product(*iterlist))) | |
final = set() | |
for i in possible: | |
for index, item in enumerate((map(lambda x: x[:numchar], words))): | |
if item == i: | |
final.add(words[index]) | |
return list(final) | |
def morse(*seq): | |
""" | |
Brief: | |
Used for the 'On the Subject of Morse Code' challenge | |
Give as much of the morse code sequence in order as gotten as an argument. | |
Argument(s): | |
Variable, each parameter should be a string using using '-' for dashes and '.' for dots | |
""" | |
out = "" | |
for i in seq: | |
if i in morse_seqs: | |
out += morse_seqs[i].lower() | |
else: | |
print("No morse code definition for: \'%s\', skipping" % i) | |
print("Sequence: \'%s\'" % out) | |
final_out = [] | |
for i in morse_words: | |
if i[:len(out)] == out: | |
final_out.append(i) | |
if not final_out: | |
print("No definitive word, could be:") | |
for i in morse_words: | |
possible = True | |
for j in out: | |
if j not in i: | |
possible = False | |
if possible: | |
final_out.append(i) | |
if not final_out: | |
print ("no possible solutions") | |
return list(map(lambda x: (x, morse_words[x]), final_out)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment