Skip to content

Instantly share code, notes, and snippets.

@AnotherJoSmith
Forked from StewSchrieff/1_explanation.md
Created January 10, 2020 19:10
Show Gist options
  • Save AnotherJoSmith/bbf9f5046ac8e740226d0f55698b0f56 to your computer and use it in GitHub Desktop.
Save AnotherJoSmith/bbf9f5046ac8e740226d0f55698b0f56 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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment