#! /n/gnu/bin/sed -f # Translate "248" to "JXB" # to avoid confusion with dice throws: s/2/J/g s/4/X/g s/8/B/g # Insert dice throws after each character: s/^/\#\#/g s/$/\#\#\#\#\#\#\#\#/g s/\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\10\24\32\46\51\65\73\87/g # Insert spaces with right probabilities: s/\([MNGK]\)\([0-7]\)/\1\2 \2/g s/R\([0-4]\)/R\1 \1/g s/A\([0-7]\)E\([0-2]\)/A\1E\2 \1/g s/O\([0-7]\)E\([0-4]\)/O\1E\2 \1/g s/X\([0-7]\)/ \1X\1/g s/\([^XCTSDHZ][0-7]\)O\([0-3]\)/ \2\1O\2/g # Hack to fix the " "-"C" digraph count: s/ \([0-7]\)C\([0-3]\)/ \1S\2C\2/g s/ \([0-7]\)C\([4-7]\)/ \1T\2C\2/g # Hack to fix the " "-"A" digraph count: s/ \([0-7]\)A\([0-2]\)/ \1B\2A\2/g s/ \([0-7]\)A\([3-6]\)/ \1O\2D\1A\2/g s/ \([0-7]\)A\([7-7]\)/ \1O\2H\1A\2/g # Remove dice throws and padding: s/\#//g s/[0-9]//g # Remove extra spaces: s/ */ /g # Translate "JXB" to "248" s/J/2/g s/X/4/g s/B/8/g