Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Riddler_Express_Flag_Scramble

Riddler Express

https://fivethirtyeight.com/features/can-you-solve-the-vexing-vexillology/

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

This comment has been minimized.

Copy link
Owner Author

@StewSchrieff StewSchrieff commented Jan 7, 2020

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
You can’t perform that action at this time.