Skip to content

Instantly share code, notes, and snippets.

@jgrahamc
Created April 16, 2021 13:47
Show Gist options
  • Select an option

  • Save jgrahamc/e8fff36fbc67437e8028f3246267c7c1 to your computer and use it in GitHub Desktop.

Select an option

Save jgrahamc/e8fff36fbc67437e8028f3246267c7c1 to your computer and use it in GitHub Desktop.

Revisions

  1. jgrahamc created this gist Apr 16, 2021.
    57 changes: 57 additions & 0 deletions morseify.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    code = {
    '01': 'A',
    '1000': 'B',
    '1010': 'C',
    '100': 'D',
    '0': 'E',
    '0010': 'F',
    '110': 'G',
    '0000': 'H',
    '00': 'I',
    '0111': 'J',
    '101': 'K',
    '0100': 'L',
    '11': 'M',
    '10': 'N',
    '111': 'O',
    '0110': 'P',
    '1101': 'Q',
    '010': 'R',
    '000': 'S',
    '1': 'T',
    '001': 'U',
    '0001': 'V',
    '011': 'W',
    '1001': 'X',
    '1011': 'Y',
    '1100': 'Z',
    '01111': '1',
    '00111': '2',
    '00011': '3',
    '00001': '4',
    '00000': '5',
    '10000': '6',
    '11000': '7',
    '11100': '8',
    '11110': '9',
    '11111': '0'
    }

    def morse(b):
    r = []
    for p in code:
    if b.startswith(p):
    for i in morse(b[len(p):]):
    r.append(code[p] + i)

    if len(r) == 0:
    return [b]
    else:
    return r

    def clean(m):
    return [i for i in m if 'EE' not in i and 'TT' not in i and 'MM' not in i]

    for c in range(33, 127):
    b = format(c, '08b')
    print('\n'.join(clean(morse(b))))