sed -r
, 72 69 66 59 bytes
s/(.*) (.*)/dc -e2o{\1..\2}p/e #converts two numbers into a binary range
s/.*1//gm #keep only the last 0s of each line
s/.*/wc -L<<<"&"/e #num of chars in longest line
Try it online!
I feel like if I were smarter about it there should be a way to entierly remove that second line, but this is as good as I'll be able to get it today.
more detailed explanation:
the first swap converts two numbers seperated by a space (eg, '4 9
') into
dc -e2o{4..9}p
. the e
flag means we e
xecute, so bash then expands that into
dc -e2o4p -e2o5p -e2o6p -e2o7p -e2o8p -e2o9p
. numbers get put on the stack, o
pops one number for the output base and then p
prints the top of the stack in that base.
now we have binary numbers seperated by newlines. this next swap is g
lobal and m
ultiline. we delete everything up to and including the last 1
of each line.
now we have 0s seperated by newlines. we take the full input and send it to wc
(word count). -L
gives the longest line, which is our output
equivalently,
sed -r
, 66 59 bytes
s/$/}p/ #append }p
s/(.*) /dc -e2o{\1../e #swaps 'N ' for 'dc -e2o{N..' & executes full line
s/.*1//gm #keep only the last 0s of each line
s/.*/wc -L<<<"&"/e #num chars in longest line
Try it online!
basically the same, but gets rid of an expensive regex grouping.
a
andb
always be low-high in that order? \$\endgroup\$