• + 1 comment

    Solution checker not working, but even if it did I still have no idea how it could do the decoding, given that it is esplicitely asked to provide only 17-bit codes for words and avoid 8-bit codes for single alpha-nuemeric and special characters....

    strings = []
    start = None
    end = None
    
    for _ in range(1000000):
        try:
            line = input()
            for i,c in enumerate(line):
                if c.isalnum() and start is None:
                    start = i
                if not c.isalnum():
                    strings.append(c)
                    if start is not None:
                        end = i
                        strings.append(line[start:end])
                        start = None
        except EOFError:
            break
    
    d = {}
    ix = 2**9
    for i,s in enumerate(set(strings)):
        if len(s) == 1:
            b = bin(ord(s))[2:]
            b = ''.join(['0']*(8-len(b))) + b
            d[s] = b
        if len(s) > 1:
            b = bin(ix)[2:]
            b = '1' + ''.join(['0']*(16-len(b))) + b
            ix += 1
            d[s] = b    
    
    print(str(ix-2**9))
    
    for k,v in d.items():
        if len(k)>1:
            print(k + '\t' + v)
            
    encoded = ''
    for s in strings:
        if len(s)>0:
            encoded += d[s]
    print(encoded)