Revision 5ef66cc9-5459-4063-a75f-71af6989763f - Code Golf Stack Exchange

## [Retina], <s>317</s> <s>139</s> <s>134</s> <s>132</s> <s>70</s> <s>63</s> <s>60</s> 55 bytes

 .100{`^
 _
 *\(a`(___)+
 Fi;$&
 \b(_{5})+$
 Bu;
 ;_*
 zz
 '_&`.

[Try it online!][TIO-jchr24ti]

[Retina]: https://github.com/m-ender/retina/wiki/The-Language
[TIO-jchr24ti]: https://tio.run/##K0otycxLNPz/X8/QwKA6IY4rnksrRiMxQSM@Pl5Tm8st01pFjSsmSSO@2rRWU1uFy6nUmss6XourqopLPV4tQe//fwA "Retina – Try It Online"

## Explanation

 .100{`^
 _

The `.` is the global silent flag which turns off implicit output at the end of the program. `100{` wraps the rest of the program in a loop which is executed for 100 iterations. Finally, the stage itself just inserts a `_` at the beginning of the string, which effectively increments a unary loop counter.

 *\(a`(___)+
 Fi;$&

More configuration. `*\(` wraps the remainder of the program in a group, prints its result with a trailing linefeed, but also puts the entire group in a dry run, which means that its result will be discarded after printing, so that our loop counter isn't actually modified. `a` is a custom regex modifier which anchors the regex to the entire string (which saves a byte on using `^` and `$` explicitly).

The atomic stage itself takes care of `Fizz`. Divisibility by `3` can easily be checked in unary: just test if the number can be written as a repetition of `___`. If this is the case, we prepend `Fi;` to the string. The semicolon is so that there is still a word boundary in front of the number for the next stage. If we turned the line into `Fizz___...` the position between `z` and `_` would not be considered a boundary, because regex treats both letters and underscores as word characters. However, the semicolon also allows us to remove the `zz` duplication from `Fizz` and `Buzz`.

 \b(_{5})+$
 Bu;

We do the exact same for divisibility by `5` and `Bu;`, although we don't need to keep the `_`s around this time. So we would get a results like

 _
 __
 Fi;___
 ____
 Bu;
 Fi;______
 ...
 Fi;Bu;
 ...

This makes it very easy to get rid of the underscores only in those lines which contain `Fizz`, while also filling in the `zz`s:

 ;_*
 zz

That is, we turn each semicolon into `zz` but we also consume all the `_`s right after it. At this point we're done with FizzBuzz in unary. But the challenge wants decimal output.

 '_&`.

`&` indicates a conditional: this stage is only executed if the string contains an underscore. Therefore, `Fizz`, `Buzz` and `FizzBuzz` iterations are left untouched. In all other iterations (i.e. those which are neither divisible by 3 nor 5), we just count the number of characters, converting the result to decimal.

 [1]: http://retina.tryitonline.net/#code=CjEwMCQqClxCCsK2JGAKXGIoMTExKStcYgpGaTskMApcYigxezV9KStcYgpCdTsKOzEqCnp6CjErCiQuJg&input=

AltStyle によって変換されたページ (->オリジナル) /