{{ message }}

Instantly share code, notes, and snippets.

# StewSchrieff/1_explanation.md

Created Jan 7, 2020
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 commented Jan 7, 2020

 Here's France compared to Flag 1: Here's Brazil compared to Flag 2: Here's Namibia compared to Flag 3: