I can count to 1023
Anthony Shaw
1
2
4
8
16
32
64
128
256
512
1
4
16
32
64
128
256
512
21
>>> ord('a')
97
>>> ord('あ')
12354
>>> o = ord('あ')
>>> f'{o:08b}'
'11000001000010'
Oh No! We need 14 fingers for
this encoding
0 1 2 3 4 5 6 7 8 9 A B C D E F
U+304
x
ぁ あ ぃ い ぅ う ぇ え ぉ お か が き ぎ く
U+305
x
ぐ け げ こ ご さ ざ し じ す ず せ ぜ そ ぞ た
U+306
x
だ ち ぢ っ つ づ て で と ど な に ぬ ね の は
U+307
x
ば ぱ ひ び ぴ ふ ぶ ぷ へ べ ぺ ほ ぼ ぽ ま み
U+308
x
む め も ゃ や ゅ ゆ ょ よ ら り る れ ろ ゎ わ
ゟ = 12447
ぁ = 12354
Hiragana Unicode Block
Unicode UCS code blocks for Japanese
Characters
0x3000-0x303F
Japanese-style
punctuation
0x3040-0x309F Hiragana
0x30A0-0x30FF Katakana
Therefore we can subtract 0x3000 from the
value to fit it within a single byte
1
2
4
8
16
32
64
128
Flag 1
Flag 2?
import codecs
class Fingers(codecs.Codec):
def encode(self, input: str, errors='strict'):
buffer = bytearray()
for c in input:
if ord(c) & 0x3000:
flag = 1
v = ord(c) - 0x3000
else:
flag = 0
v = ord(c)
buffer.extend([flag, v]) # Add 2 byte to buffer
return bytes(buffer)
class Fingers(codecs.Codec):
def decode(self, input: bytes, errors: str = "strict"):
buffer = bytearray(input)
result = ''
while buffer:
flag = buffer.pop(0) # First Byte
v = buffer.pop(0) # Second Byte
if flag:
v += 0x3000
result += chr(v)
return result, len(input)
codec = Fingers()
output = codec.encode("Hello とうきょう")
print(f"Output is {output}")
print(codec.decode(output))

I can count to 1023

  • 1.
    I can countto 1023 Anthony Shaw
  • 2.
  • 3.
  • 5.
    >>> ord('a') 97 >>> ord('あ') 12354 >>>o = ord('あ') >>> f'{o:08b}' '11000001000010' Oh No! We need 14 fingers for this encoding
  • 6.
    0 1 23 4 5 6 7 8 9 A B C D E F U+304 x ぁ あ ぃ い ぅ う ぇ え ぉ お か が き ぎ く U+305 x ぐ け げ こ ご さ ざ し じ す ず せ ぜ そ ぞ た U+306 x だ ち ぢ っ つ づ て で と ど な に ぬ ね の は U+307 x ば ぱ ひ び ぴ ふ ぶ ぷ へ べ ぺ ほ ぼ ぽ ま み U+308 x む め も ゃ や ゅ ゆ ょ よ ら り る れ ろ ゎ わ ゟ = 12447 ぁ = 12354 Hiragana Unicode Block
  • 7.
    Unicode UCS codeblocks for Japanese Characters 0x3000-0x303F Japanese-style punctuation 0x3040-0x309F Hiragana 0x30A0-0x30FF Katakana Therefore we can subtract 0x3000 from the value to fit it within a single byte
  • 8.
  • 9.
    import codecs class Fingers(codecs.Codec): defencode(self, input: str, errors='strict'): buffer = bytearray() for c in input: if ord(c) & 0x3000: flag = 1 v = ord(c) - 0x3000 else: flag = 0 v = ord(c) buffer.extend([flag, v]) # Add 2 byte to buffer return bytes(buffer)
  • 10.
    class Fingers(codecs.Codec): def decode(self,input: bytes, errors: str = "strict"): buffer = bytearray(input) result = '' while buffer: flag = buffer.pop(0) # First Byte v = buffer.pop(0) # Second Byte if flag: v += 0x3000 result += chr(v) return result, len(input) codec = Fingers() output = codec.encode("Hello とうきょう") print(f"Output is {output}") print(codec.decode(output))