Skip to content

Instantly share code, notes, and snippets.

@StewSchrieff
Created January 7, 2020 03:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save StewSchrieff/24769b0f28730426e65a8a68b4fe5222 to your computer and use it in GitHub Desktop.
Save StewSchrieff/24769b0f28730426e65a8a68b4fe5222 to your computer and use it in GitHub Desktop.
Riddler_Express_Flag_Scramble

Riddler Express

Late night quick coding challenge. Read in all the pixels of the scrambled images, rudimentarily sort them, and then send them back out as images. This will give you a much better idea of what colors you are actually looking at, and can eyeball what the answers might be.

Code runs on both png and gif filetypes, so you can just download the images and go!

import matplotlib.pyplot as plt
import numpy as np
def unscramble(path):
img = plt.imread(path, 3)
all_colors = {}
for x in img:
for y in x:
name = ''
for val in y:
name += str(val)
name += '_'
if name not in all_colors:
all_colors[name] = 1
else:
all_colors[name] += 1
print(all_colors)
print(max(all_colors, key=all_colors.get))
output = []
for col in all_colors:
for x in range(all_colors[col]):
output.append(col)
output.sort()
final_output = []
for pixel in output:
for x in pixel.split('_')[:-1]:
final_output.append(int(x))
r = np.array(final_output)
r.shape = img.shape
print(img.shape)
print(r.shape)
plt.imshow(r)
plt.show()
if __name__ == '__main__':
unscramble('./input/clipperton.gif')
@StewSchrieff
Copy link
Author

Here's France compared to Flag 1:
Screen Shot 2020-01-06 at 10 55 03 PM

Here's Brazil compared to Flag 2:
Screen Shot 2020-01-06 at 10 51 17 PM

Here's Namibia compared to Flag 3:
Screen Shot 2020-01-06 at 10 56 28 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment