Skip to content

Instantly share code, notes, and snippets.

@mkowoods
Created June 4, 2015 21:16
Show Gist options
  • Save mkowoods/ba8b7d9fad2ed6e6d8d9 to your computer and use it in GitHub Desktop.
Save mkowoods/ba8b7d9fad2ed6e6d8d9 to your computer and use it in GitHub Desktop.
#http://www.reddit.com/r/dailyprogrammer/comments/38fjll/20150603_challenge_217_intermediate_space_code/
decoders = {
'Omicron V' : lambda coded : "".join([chr(c ^ int('0b10000', 2)) for c in coded]),
'Hoth' : lambda coded : "".join([chr(c - 10) for c in coded]),
'Ryza' : lambda coded : "".join([chr(c + 1) for c in coded]),
'Htrae' : lambda coded : "".join([chr(c) for c in coded[::-1]])
}
englishiness = lambda sentence : sum([c.isalpha() or c.isspace() for c in sentence])/float(len(sentence))
def decoder_ring(coded_message):
coded_message = map(int, coded_message.split())
return max([(k, fn(coded_message)) for k,fn in decoders.items()], key = lambda x : englishiness(x[1]))
if __name__ == "__main__":
print decoder_ring(" 115 101 108 115 115 105 77 32 101 104 116 32 101 114 105 70 ")
print decoder_ring(" 71 117 48 115 127 125 117 48 121 126 48 96 117 113 115 117 ")
print decoder_ring(" 97 111 42 109 121 119 111 42 115 120 42 122 111 107 109 111 ")
print decoder_ring(" 86 100 31 98 110 108 100 31 104 109 31 111 100 96 98 100 ")
print decoder_ring(" 101 99 97 101 112 32 110 105 32 101 109 111 99 32 101 87 ")
print decoder_ring(" 84 113 121 124 105 48 64 98 127 119 98 113 125 125 117 98 48 121 99 48 99 96 105 121 126 119 48 127 126 48 101 99 ")
print decoder_ring(" 78 107 115 118 131 42 90 124 121 113 124 107 119 119 111 124 42 115 125 42 125 122 131 115 120 113 42 121 120 42 127 125 ")
print decoder_ring(" 67 96 104 107 120 31 79 113 110 102 113 96 108 108 100 113 31 104 114 31 114 111 120 104 109 102 31 110 109 31 116 114 ")
print decoder_ring(" 115 117 32 110 111 32 103 110 105 121 112 115 32 115 105 32 114 101 109 109 97 114 103 111 114 80 32 121 108 105 97 68 ")
print decoder_ring(" 86 121 98 117 48 100 120 117 48 93 121 99 99 124 117 99 ")
print decoder_ring(" 80 115 124 111 42 126 114 111 42 87 115 125 125 118 111 125 ")
print decoder_ring(" 69 104 113 100 31 115 103 100 31 76 104 114 114 107 100 114 ")
print decoder_ring(" 115 101 108 115 115 105 77 32 101 104 116 32 101 114 105 70 ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment