convert unary to binary, rules below are buggy and don't work on all inputs rules $|[A]->$an|[A] [A]n|[B]->[A]u[B] [A]g|[B]->[A]u[B] [A]u|[B]->[A]|g[B] $a[A]g$->$0n[A]$ $0[A]g$->$00n[A]$ $1[A]g$->$01n[A]$ $a[A]u$->$0|n[A]$ $0[A]u$->$10n[A]$ $1[A]u$->$11[A]n$ [A]n$->[A]$ input $||||||$