ReRegex, 294 275 bytes
Saved 19 bytes by using better 'function' definitions
I'd say this is pretty good for a Regex only language.
The base lib does allow for conversion between Unary and Decimal (Which is needed as the challenge spec explicitly states decimal), but does not support Binary; So I had to write that as part of the script adding 120 bytes to it.
#import base
b(\d*):(_*)\2_b/b1$1:$2b/b(\d*):(_+)\2b/b0$1:$2b/b(\d+):b/$1/b:b/0/B(_*):1/B$1$1_:/B(_*):0/B$1$1:/B(_*):B/$1/j(\d*),\1(\d)(\d{7})(\d*):/j$1$2,$1$2$3$4:,B:$1$4B/j(\d*),\1\d{0,7}:,?(.*)/,$2,/,((_+)_+),(\2),/,$1,/,(_+),(\1_*),/,$2,/^,(_*),$/d<$1>/j,b:u<(?#input)>b:
Try it online!
By Individual Regexes.
#import base
b(\d*):(_*)\2_b/b1$1:$2b/
b(\d*):(_+)\2b/b0$1:$2b/
b(\d+):b/$1/
b:b/0/
B(_*):1/B$1$1_:/
B(_*):0/B$1$1:/
B(_*):B/$1/
j(\d*),\1(\d)(\d{7})(\d*):/j$1$2,$1$2$3$4:,B:$1$4B/
j(\d*),\1\d{0,7}:,?(.*)/,$2,/
,((_+)_+),(\2),/,$1,/
,(_+),(\1_*),/,$2,/
^,(_*),$/d<$1>/
j,b:u<(?#input)>b:
Steps
Firstly, we import the 'base' library, which gives two regexes. One which converts u<numbers>
into unary. And one which converts d<unary_underlines>
back into decimal. This is because the challenge requires IO in base10.
Then we define a handful of regexes which convert unary into binary.
b(\d*):(_*)\2_b/b1$1:$2b/
b(\d*):(_+)\2b/b0$1:$2b/
b(\d+):b/$1/
b:b/0/
The first of these, b(\d*):(_*)\2_b/b1$1:$2b/
searches for b
, optionally followed by some binary digits, then a :
, Then any amount of underlines, followed by the exact same amount of underlines plus one, and finally another b
.
We then replace that with b1
followed by the binary digits from before, :
, and just the first half of the underscores, and finally the last b
.
So this checks if the unary is not divisible by two, and if so, prepends 1 to it's binary digits, then divides it minus one by two.
The second one, b(\d*):(_+)\2b/b0$1:$2b/
is almost idendical, however does not check for an extra _
, meaning it only matches if it is divisible by two, and in this case prepends a 0
instead.
The third one checks if we're out of unary digits, and if so, strips away the padding to just leave the binary digits.
The last one checks if there never was any binary digits supplied, and in that case just leaves 0
.
The next group of Regexes we define are to convert binary back into unary, and are slightly more simple.
B(_*):1/B$1$1_:/
B(_*):0/B$1$1:/
B(_*):B/$1/
The first of this group, B(_*):1/B$1$1_:/
, much like its antithesis, detects a B
, followed by any amount of Unary digits, then :1
. It doesn't check for the matching B
in this case, as it is only searching for one digit at a time. If this is matched, it doubles the previously matched amount of unary digits and adds one, then removes the one.
The second, B(_*):0/B$1$1:/
, is almost idendical to the first, except matches a 0
rather than a 1
, and does not add an additional unary digit.
The last of these, B(_*):B/$1/
, checks if there are no more binary digits, and if so unwraps the unary. Unlike its antithesis, this does not need a special 0 case.
Next we define the j
regexes, which act as a splitting function.
j(\d*),\1(\d)(\d{7})(\d*):/j$1$2,$1$2$3$4:,B:$1$4B/
j(\d*),\1\d{0,7}:,?(.*)/,$2,/
The first, j(\d*),\1(\d)(\d{7})(\d*):/j$1$2,$1$2$3$4:,B:$1$4B/
does most of the heavy lifting. It searches for j
, optionally followed by binary digits which are the "incrementer", then a comma followed by the incrementer then exactly 8 binary digits followed by the rest of the binary number, then a :
. The first of the 8 digits is appended to the incrementer, thus incrementing it, then everything but those 8 digits from the binary input is appended after the :
following a ,
. So (If we were using 2 digits instead of 8) j,1001:
would become j1:1001:,01
then j10:1001,01,11
. Additionally, the appended array elements are wrapped in B
s, to convert them back to unary.
The other, j(\d*),\1\d{0,7}:,?(.*)/,$2,/
checks if there are less than 8 binary digits left to check after the incrementer, and if so, removes everything other than the array wrapped in ,
s. Eg. ,_,___,
During and after the creation of the array we define the comparison regexes.
,((_+)_+),(\2),/,$1,/
,(_+),(\1_*),/,$2,/
The first of these, ,((_+)_+),(\2),/,$1,/
checks a comma followed by some amount of underscores, then some more, followed by a comma, then the first amount of underscores, than a comma. It then replaces it with the total amount of underscores in the first element surrounded by ,
s.
The latter, ,(_+),(\1_*),/,$2,/
, checks for a comma followed by some amount of underscores followed by another comma, then the same amount or more underscores, and a last comma. This will instead leave the right element.
Finally, when there is on element left thus matching ^,(_*),$
, we remove the surrounding commas and convert back to decimal via d<>
. Then no-more regexes can fire and the output is presented.
The input is initially placed into the template j,b:u<(?#input)>b:
, which first converts the decimal input to unary, eg 5
-> j,b:_____b:
, then the resulting unary to binary, j,101:
Then splits the binary (which doesn't work for the example), gets the largest element, converts back to decimal, and done.
1I don't understand why people put exclamation points in challenge titles! I think it might be a character limit thing! Might be just so people notice the challenge though! – dkudriavtsev – 2017-11-15T09:06:36.233
1@Mendeleev It's an imperative sentence. Those are usually terminated with exclamation points. It's only correct punctuation, why does it upset you so? – Arthur – 2017-11-15T12:58:13.793
1
@Mendeleev People often use an exclamation mark to indicate a joke. The OP is highlighting the fact that he's making a pun. F. Scott Fitzgerald didn't like it, but in this context, it seems fine to me. If it wasn't there, you'd probably get people complaining about his spelling.
– bornfromanegg – 2017-11-15T13:50:57.983@Mendeleev because it's a bad pun... – FlipTack – 2017-11-15T15:15:14.570
@bornfromanegg I feel like people would notice the pun – dkudriavtsev – 2017-11-15T18:19:49.120
@FlipTack Yeah, worse than mine – dkudriavtsev – 2017-11-15T18:20:02.527