Skip to content

Instantly share code, notes, and snippets.

Created January 7, 2020 03:54
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?

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
all_colors[name] += 1
print(max(all_colors, key=all_colors.get))
output = []
for col in all_colors:
for x in range(all_colors[col]):
final_output = []
for pixel in output:
for x in pixel.split('_')[:-1]:
r = np.array(final_output)
r.shape = img.shape
if __name__ == '__main__':
Copy link

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