Created
December 28, 2020 21:06
-
-
Save kpmiller/1fd4612c0228783ab168584b7429795b to your computer and use it in GitHub Desktop.
Good Sudoku clipboard format
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
#!/usr/bin/env python3 | |
import base64 | |
#Good Sudoku's share puzzle clipboard format | |
#given the starting puzzle: | |
#7.. 64. 2.. | |
#.6. 7.. 4.. | |
#..8 ..5 .9. | |
# | |
#... ..7 ..5 | |
#... .3. ... | |
#8.. 1.. ... | |
# | |
#.3. 4.. 8.. | |
#..6 ..3 .1. | |
#..5 .16 ..7 | |
#copy link gives this text: | |
#Check out this puzzle in GoodSudoku! playgoodsudoku.com/puzzle/$cAZAIABgcAQAAIAFCQAAAHAFAAAwAAgAEAAAAwQAgAAGADAQAFAWAHA= | |
# using the end of the URL string: | |
s = "$cAZAIABgcAQAAIAFCQAAAHAFAAAwAAgAEAAAAwQAgAAGADAQAFAWAHA=" | |
#this is data of the puzzle encoded in base64 | |
tb64 = base64.b64decode(s) | |
for i in tb64: | |
s = "0x%02x," % i | |
print("%-6s"%s, end='') | |
print("\n\n\n") | |
#output of this is | |
# 0x70, 0x06, 0x40, 0x20, 0x00, 0x60, 0x70, 0x04, 0x00, | |
# 0x00, 0x80, 0x05, 0x09, 0x00, 0x00, 0x00, 0x70, 0x05, | |
# 0x00, 0x00, 0x30, 0x00, 0x08, 0x00, 0x10, 0x00, 0x00, | |
# 0x03, 0x04, 0x00, 0x80, 0x00, 0x06, 0x00, 0x30, 0x10, | |
# 0x00, 0x50, 0x16, 0x00, 0x70, | |
# Each byte is 2 squares of the puzzle, the upper 4 bits are one number | |
# and the lower 4 bits is the next square | |
# Squares are tightly packed and there is a pad 0 at the end (since there are only 81 numbers) | |
t = [] | |
for i in tb64: | |
low = i & 0xf; | |
high = i >> 4; | |
t.append(high) | |
t.append(low) | |
print (t) | |
print("\n\n\n") | |
for i in range(0, len(t)): | |
if (t[i] == 0): | |
print('.', end='') | |
else: | |
print (t[i], end='') | |
if (i%9) == 8: | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment