This is a continuation of the discussion on this gist.
-
-
Save Davidebyzero/9735222 to your computer and use it in GitHub Desktop.
Thanks!
I am now down to 57 chars on the log2 regex (md5sum c58bef1340954f1bbaf02c5790f33a01, --npcg+
only, --neam
independent). I’ll gladly share it if you want.
I haven’t yet tried applying this algorithm to the base 10 or rounding down version of the task, but it should give significant improvements.
EDIT:
- 76 chars for the version that strictly rounds down (or 74 if I’m allowed to return 0 instead of no match for a 0 input).
- 97 chars for the base 10 version
Wow! 57 chars. That's incredible. I don't want you to just show it to me right away though; I'd like some time to try to figure it out. Can't work on it right away but I plan on it. I would indeed like to see them, please!
I did have an idea on how to make my floor-logarithm regexes much shorter. It did a little worse than the technique I already used, and frankly I'm very happy about that. The one I'd already used is much more interesting, and the one I just now tried would trivialize it if it did better.
And I'm also quite impressed to see that 76-57=19, a smaller difference than my 93-69=24.
This discussion has been continued in the Mathematical Regexes Stack Exchange chat room.
Hello, Grimy, and welcome!
Wow, that is awesome. My b31a12cf9a9982d7d3204d198f87ba4f is 69 bytes, so you have beaten me! Very well done. I'd like to exchange our regexes, but privately, to maintain the viability of this challenge for a little longer. I'd like to see your earlier versions too!
I recently forked the log2 regex into:
Tying up another loose end, I also wrote a regex to take a single unary number as input, and divide by sqrt(2) (rounding down) and return the result as a match, using an algorithm very similar to the one I sketched above. It uses molecular lookahead. The first fully correct version was 1159 bytes and I got it down to 849. I plan on porting it to pure ECMAScript, but I expect it will roughly double in length.