s/^/0000a/ :l s/1001a/1100a/g s/1000a/1011a/g s/0111a/1010a/g s/0110a/1001a/g s/0101a/1000a/g s/a\(.\)/\1a/g s/0\([01]\{4\}a\)/\1/ s/1\([01]\{4\}a\)/0001a\1/ /[^a]$/b l s/^0+a// s/0000a/0/g s/0001a/1/g s/0010a/2/g s/0011a/3/g s/0100a/4/g s/0101a/5/g s/0110a/6/g s/0111a/7/g s/1000a/8/g s/1001a/9/g