Created
July 16, 2014 22:06
-
-
Save gvx/98d81fd0e3ae883636fe to your computer and use it in GitHub Desktop.
Daily Programmer #171 Easy/Intermediate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xxxxxxxx | |
x x | |
x xxxx x | |
x x x x | |
x x x x | |
x xxxx x | |
x x | |
xxxxxxxx | |
--- | |
x x x x | |
x x x x | |
x x x x | |
x x x x | |
x x x x | |
x x x x | |
x x x x | |
x x x x | |
--- | |
xxxxx | |
xxxxxxx | |
xxxxxx | |
xxxxx | |
xxxxx | |
xxxxxx | |
xxxxxxx | |
xxxxx | |
--- | |
x x xx | |
x x xx | |
x x xx | |
xxxx xx | |
xxxx xx | |
x x xx | |
x x xx | |
x x xx | |
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xxxxxxxxxxxx | |
xxxxxxxxxxxx | |
xx xx | |
xx xx | |
xx xxxx xx | |
xx xxxx xx | |
xx xxxx xx | |
xx xxxx xx | |
xx xx | |
xx xx | |
xxxxxxxxxxxx | |
xxxxxxxxxxxx | |
--- | |
xx xx xx xx | |
xx xx xx xx | |
xx xx xx xx | |
xx xx xx xx | |
xx xx xx xx | |
xx xx xx xx | |
xx xx xx xx | |
xx xx xx xx | |
xx xx xx xx | |
xx xx xx xx | |
xx xx xx xx | |
xx xx xx xx | |
xx xx xx xx | |
xx xx xx xx | |
xx xx xx xx | |
xx xx xx xx | |
--- | |
xxxx xxxx | |
xxxx xxxx | |
xx xx | |
xx xx | |
xxxx | |
xxxx | |
xxxxxxxx | |
xxxxxxxx | |
xx xxxxxxxx xx | |
xx xxxxxxxx xx | |
--- | |
xxxxxx xxxxxx | |
xxxxxx xxxxxx | |
xxxxxx xxxxxx | |
xxxxxx xxxxxx | |
xxxxxxxxxxxxxxxx | |
xxxxxxxxxxxxxxxx | |
xxxxxxxxxxxxxxxx | |
xxxxxxxxxxxxxxxx | |
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
_format = np.vectorize('{:08b}'.format) | |
_getitem = np.vectorize(str.__getitem__) | |
def make_image(data): | |
numbers = np.frombuffer(data.replace(' ', '').decode('hex'), dtype=np.uint8) | |
binary_digits = _format(numbers) | |
replicated_digits = np.fromfunction(lambda x, y: binary_digits[x], binary_digits.shape * 2, dtype=int) | |
selected_digits = _getitem(replicated_digits, range(8)) | |
return selected_digits == '1' | |
def display_image(image): | |
cols, rows = image.shape | |
return '\n'.join(''.join('x' if image[row, col] else ' ' for col in range(cols)) for row in range(rows)) | |
if __name__ == '__main__': | |
for img in ['FF 81 BD A5 A5 BD 81 FF', 'AA 55 AA 55 AA 55 AA 55', '3E 7F FC F8 F8 FC 7F 3E', '93 93 93 F3 F3 93 93 93']: | |
print display_image(make_image(img)) | |
print '---' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from read import * | |
def rotate_clockwise(image): | |
return np.rot90(image, -1) | |
def rotate_counterclockwise(image): | |
return np.rot90(image) | |
def zoom_in(image): | |
return np.repeat(np.repeat(image, 2, 0), 2, 1) | |
def zoom_out(image): | |
return image[::2,::2] | |
def invert(image): | |
return ~image | |
if __name__ == '__main__': | |
for img in ['FF 81 BD A5 A5 BD 81 FF', 'AA 55 AA 55 AA 55 AA 55', '3E 7F FC F8 F8 FC 7F 3E', '93 93 93 F3 F3 93 93 93']: | |
print display_image(zoom_out(invert(zoom_in(rotate_clockwise(zoom_in(make_image(img))))))) | |
print '---' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment