Skip to main content
deleted 106 characters in body
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

Outdated, will fix later...


100$*99$* bottles of beer

We start by replacing the empty input with 100 1s (the actual syntax for repetition is count$*character but if the latter is omitted, it is assumed to be 1).

.
$.' bottles of beer¶

Now we replace each of those99 1s with the number of characters after that match (that's $.'), which goes from 99 down to 0, and appendfollowed by bottles of beer as well as a linefeed. So now we have:

99 bottles of beer
98 bottles of beer
...
1 bottles of beer
0 bottles of beer
%`$
W1$'W, $_1$'.¶Take one down and pass it around, $_W$'W.¶¶

This uses theNow we replace each of those %1 option which means that the stage is applied to each line individually (treating it as a separate string, so there's no way to accesss with the other lines). We matchsubstitution pattern on the end of eachsecond line with. Here $$' and append the rest ofstands for the versestring after each match, whereand we use $_W (entire input, i.eas a placeholder for later. in this caseNote that the entireoccurrences of $' on the first line) so we don't have to repeat are "incremented" by prepending a N bottles of beer1. We've got most of the work done already, except that the numbers are in unary instead of decimal, and we usewe've got W as a placeholder for the repeateds instead of on the walls and the last verse is off.

1+
$.&

This does the unary-to-decimal conversion by matching each run of 1s and replacing it with its length.

G-8`3`

This is a "grep" stage. The regex is empty, so it always matches, but the -83 limit means that only lines up to the 8ththird from the end are kept, so the last 7two are discarded. This gets rid of a few extraneous lines like the one with 0 and some empty lines that we don't wanttwo extraneous linefeeds at the end.

T`s``¶1T`s``\b1 .+

This fixes the pluralisation by removing all ss from the a match of the regex at the end, which matches anything after a 1 (on the same line).

Note that begins with athe last line doesn't have 10 since the unary representation of it is an empty string it wasn't matched by the conversion stage. Instead there will be two spaces in a row.

T.+ 1 \B
Go to the store and buy some more, 99 

And finallyThis is the only case where there is no word boundary after a space, so we replace the wrong part ofdetect the very last line like this and replace it with the correct lyrics.

Outdated, will fix later...


100$*

We start by replacing the empty input with 100 1s (the actual syntax for repetition is count$*character but if the latter is omitted, it is assumed to be 1).

.
$.' bottles of beer¶

Now we replace each of those 1s with the number of characters after that match (that's $.'), which goes from 99 down to 0, and append bottles of beer as well as a linefeed. So now we have:

99 bottles of beer
98 bottles of beer
...
1 bottles of beer
0 bottles of beer
%`$
W, $_.¶Take one down and pass it around, $_W.

This uses the % option which means that the stage is applied to each line individually (treating it as a separate string, so there's no way to access the other lines). We match the end of each line with $ and append the rest of the verse, where we use $_ (entire input, i.e. in this case the entire line) so we don't have to repeat N bottles of beer and we use W as a placeholder for the repeated on the wall.

G-8`

This is a "grep" stage. The regex is empty, so it always matches, but the -8 limit means that only lines up to the 8th from the end are kept, so the last 7 are discarded. This gets rid of a few extraneous lines like the one with 0 and some empty lines that we don't want at the end.

T`s``¶1 .+

This fixes the pluralisation by removing all ss from the a match of the regex at the end, which matches a line that begins with a 1.

T.+ 1 
Go to the store and buy some more, 99 

And finally, we replace the wrong part of the very last line with the correct lyrics.


99$* bottles of beer

We start by replacing the empty input with 99 1s followed by bottles of beer.

1
1$'W, 1$'.¶Take one down and pass it around, $'W.¶¶

Now we replace each of those 1s with the substitution pattern on the second line. Here $' stands for the string after each match, and we use W as a placeholder for later. Note that the occurrences of $' on the first line are "incremented" by prepending a 1. We've got most of the work done already, except that the numbers are in unary instead of decimal, and we've got Ws instead of on the walls and the last verse is off.

1+
$.&

This does the unary-to-decimal conversion by matching each run of 1s and replacing it with its length.

G-3`

This is a "grep" stage. The regex is empty, so it always matches, but the -3 limit means that only lines up to the third from the end are kept, so the last two are discarded. This gets rid of the two extraneous linefeeds at the end.

T`s``\b1 .+

This fixes the pluralisation by removing all ss from the match of the regex at the end, which matches anything after a 1 (on the same line).

Note that the last line doesn't have 0 since the unary representation of it is an empty string it wasn't matched by the conversion stage. Instead there will be two spaces in a row.

.+ \B
Go to the store and buy some more, 99

This is the only case where there is no word boundary after a space, so we detect the line like this and replace it with the correct lyrics.

Post Undeleted by Martin Ender
added 34 characters in body
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

Retina, 157159 bytes

Byte count assumes ISO 8859-1 encoding. The leading linefeed is significant.


100$*
.
$.'99$*1 bottles of beer¶beer
%`$1
W1$'W, $_1$'.¶Take one down and pass it around, $_W$'W.¶¶
1+
$.&
G-8`3`
W
 on the wall
T`s``¶1T`s``\b1 .+
T.+ 1 \B
Go to the store and buy some more, 99 

Try it online!Try it online!

I can't be believe I (or anyone else) have ever done this in Retina...

Explanation

Outdated, will fix later...


100$*

We start by replacing the empty input with 100 1s (the actual syntax for repetition is count$*character but if the latter is omitted, it is assumed to be 1).

.
$.' bottles of beer¶

Now we replace each of those 1s with the number of characters after that match (that's $.'), which goes from 99 down to 0, and append bottles of beer as well as a linefeed. So now we have:

99 bottles of beer
98 bottles of beer
...
1 bottles of beer
0 bottles of beer
%`$
W, $_.¶Take one down and pass it around, $_W.¶

This uses the % option which means that the stage is applied to each line individually (treating it as a separate string, so there's no way to access the other lines). We match the end of each line with $ and append the rest of the verse, where we use $_ (entire input, i.e. in this case the entire line) so we don't have to repeat N bottles of beer and we use W as a placeholder for the repeated on the wall.

G-8`

This is a "grep" stage. The regex is empty, so it always matches, but the -8 limit means that only lines up to the 8th from the end are kept, so the last 7 are discarded. This gets rid of a few extraneous lines like the one with 0 and some empty lines that we don't want at the end.

W
 on the wall

Now we substitute our W placeholder. At this point, we've got everything in place except that the last verse is still wrong.

T`s``¶1 .+

This fixes the pluralisation by removing all ss from the a match of the regex at the end, which matches a line that begins with a 1.

T.+ 1 
Go to the store and buy some more, 99 

And finally, we replace the wrong part of the very last line with the correct lyrics.

Retina, 157 bytes

Byte count assumes ISO 8859-1 encoding. The leading linefeed is significant.


100$*
.
$.' bottles of beer¶
%`$
W, $_.¶Take one down and pass it around, $_W.
G-8`
W
 on the wall
T`s``¶1 .+
T.+ 1 
Go to the store and buy some more, 99 

Try it online!

I can't be believe I (or anyone else) have ever done this in Retina...

Explanation


100$*

We start by replacing the empty input with 100 1s (the actual syntax for repetition is count$*character but if the latter is omitted, it is assumed to be 1).

.
$.' bottles of beer¶

Now we replace each of those 1s with the number of characters after that match (that's $.'), which goes from 99 down to 0, and append bottles of beer as well as a linefeed. So now we have:

99 bottles of beer
98 bottles of beer
...
1 bottles of beer
0 bottles of beer
%`$
W, $_.¶Take one down and pass it around, $_W.¶

This uses the % option which means that the stage is applied to each line individually (treating it as a separate string, so there's no way to access the other lines). We match the end of each line with $ and append the rest of the verse, where we use $_ (entire input, i.e. in this case the entire line) so we don't have to repeat N bottles of beer and we use W as a placeholder for the repeated on the wall.

G-8`

This is a "grep" stage. The regex is empty, so it always matches, but the -8 limit means that only lines up to the 8th from the end are kept, so the last 7 are discarded. This gets rid of a few extraneous lines like the one with 0 and some empty lines that we don't want at the end.

W
 on the wall

Now we substitute our W placeholder. At this point, we've got everything in place except that the last verse is still wrong.

T`s``¶1 .+

This fixes the pluralisation by removing all ss from the a match of the regex at the end, which matches a line that begins with a 1.

T.+ 1 
Go to the store and buy some more, 99 

And finally, we replace the wrong part of the very last line with the correct lyrics.

Retina, 159 bytes

Byte count assumes ISO 8859-1 encoding. The leading linefeed is significant.


99$*1 bottles of beer
1
1$'W, 1$'.¶Take one down and pass it around, $'W.¶¶
1+
$.&
G-3`
W
 on the wall
T`s``\b1 .+
.+ \B
Go to the store and buy some more, 99

Try it online!

I can't be believe I (or anyone else) have ever done this in Retina...

Explanation

Outdated, will fix later...


100$*

We start by replacing the empty input with 100 1s (the actual syntax for repetition is count$*character but if the latter is omitted, it is assumed to be 1).

.
$.' bottles of beer¶

Now we replace each of those 1s with the number of characters after that match (that's $.'), which goes from 99 down to 0, and append bottles of beer as well as a linefeed. So now we have:

99 bottles of beer
98 bottles of beer
...
1 bottles of beer
0 bottles of beer
%`$
W, $_.¶Take one down and pass it around, $_W.¶

This uses the % option which means that the stage is applied to each line individually (treating it as a separate string, so there's no way to access the other lines). We match the end of each line with $ and append the rest of the verse, where we use $_ (entire input, i.e. in this case the entire line) so we don't have to repeat N bottles of beer and we use W as a placeholder for the repeated on the wall.

G-8`

This is a "grep" stage. The regex is empty, so it always matches, but the -8 limit means that only lines up to the 8th from the end are kept, so the last 7 are discarded. This gets rid of a few extraneous lines like the one with 0 and some empty lines that we don't want at the end.

W
 on the wall

Now we substitute our W placeholder. At this point, we've got everything in place except that the last verse is still wrong.

T`s``¶1 .+

This fixes the pluralisation by removing all ss from the a match of the regex at the end, which matches a line that begins with a 1.

T.+ 1 
Go to the store and buy some more, 99 

And finally, we replace the wrong part of the very last line with the correct lyrics.

Post Deleted by Martin Ender
added 3 characters in body
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

Retina, 157 bytes

Byte count assumes ISO 8859-1 encoding. The leading linefeed is significant.


100$*
.
$.' bottles of beer¶
%`$
W, $_.¶Take one down and pass it around, $_W.¶
G-8`
W
 on the wall
T`s``¶1 .+
T.+ 1 
Go to the store and buy some more, 99 

Try it online!

I can't be believe I (or anyone else) have ever done this in Retina...

Explanation


100$*

We start by replacing the empty input with 100 1s (the actual syntax for repetition is count$*character but if the latter is omitted, it is assumed to be 1).

.
$.' bottles of beer¶

Now we replace each of those 1s with the number of characters after that match (that's $.'), which goes from 99 down to 0, and append bottles of beer as well as a linefeed. So now we have:

99 bottles of beer
98 bottles of beer
...
1 bottles of beer
0 bottles of beer
%`$
W, $_.¶Take one down and pass it around, $_W.¶

This uses the % option which means that the stage is applied to each line individually (treating it as a separate string, so there's no way to access the other lines). We match the end of each line with $ and append the rest of the verse, where we use $_ (entire input, i.e. in this case the entire line) so we don't have to repeat N bottles of beer and we use W as a placeholder for the repeated on the wall.

G-8`

This is a "grep" stage. The regex is empty, so it always matches, but the -8 limit means that only lines up to the 8th from the end are kept, so the last 7 are discarded. This gets rid of a few extraneous lines like the one with 0 and some empty lines that we don't want at the end.

W
 on the wall

Now we substitute our W placeholder. At this point, we've got everything in place except that the last verse is still wrong.

T`s``¶1 .+

This fixes the pluralisation by removing all ss from the a match of the regex at the end, which matches a line that begins with a 1.

T.+ 1 
Go to the store and buy some more, 99 

And finally, we replace the wrong part of the very last line with the correct lyrics.

Retina, 157 bytes

Byte count assumes ISO 8859-1 encoding. The leading linefeed is significant.


100$*
.
$.' bottles of beer¶
%`$
W, $_.¶Take one down and pass it around, $_W.¶
G-8`
W
 on the wall
T`s``¶1 .+
T.+ 1 
Go to the store and buy some more, 99 

Try it online!

I can't be believe I (or anyone else) have ever done this Retina...

Explanation


100$*

We start by replacing the empty input with 100 1s (the actual syntax for repetition is count$*character but if the latter is omitted, it is assumed to be 1).

.
$.' bottles of beer¶

Now we replace each of those 1s with the number of characters after that match (that's $.'), which goes from 99 down to 0, and append bottles of beer as well as a linefeed. So now we have:

99 bottles of beer
98 bottles of beer
...
1 bottles of beer
0 bottles of beer
%`$
W, $_.¶Take one down and pass it around, $_W.¶

This uses the % option which means that the stage is applied to each line individually (treating it as a separate string, so there's no way to access the other lines). We match the end of each line with $ and append the rest of the verse, where we use $_ (entire input, i.e. in this case the entire line) so we don't have to repeat N bottles of beer and we use W as a placeholder for the repeated on the wall.

G-8`

This is a "grep" stage. The regex is empty, so it always matches, but the -8 limit means that only lines up to the 8th from the end are kept, so the last 7 are discarded. This gets rid of a few extraneous lines like the one with 0 and some empty lines that we don't want at the end.

W
 on the wall

Now we substitute our W placeholder. At this point, we've got everything in place except that the last verse is still wrong.

T`s``¶1 .+

This fixes the pluralisation by removing all ss from the a match of the regex at the end, which matches a line that begins with a 1.

T.+ 1 
Go to the store and buy some more, 99 

And finally, we replace the wrong part of the very last line with the correct lyrics.

Retina, 157 bytes

Byte count assumes ISO 8859-1 encoding. The leading linefeed is significant.


100$*
.
$.' bottles of beer¶
%`$
W, $_.¶Take one down and pass it around, $_W.¶
G-8`
W
 on the wall
T`s``¶1 .+
T.+ 1 
Go to the store and buy some more, 99 

Try it online!

I can't be believe I (or anyone else) have ever done this in Retina...

Explanation


100$*

We start by replacing the empty input with 100 1s (the actual syntax for repetition is count$*character but if the latter is omitted, it is assumed to be 1).

.
$.' bottles of beer¶

Now we replace each of those 1s with the number of characters after that match (that's $.'), which goes from 99 down to 0, and append bottles of beer as well as a linefeed. So now we have:

99 bottles of beer
98 bottles of beer
...
1 bottles of beer
0 bottles of beer
%`$
W, $_.¶Take one down and pass it around, $_W.¶

This uses the % option which means that the stage is applied to each line individually (treating it as a separate string, so there's no way to access the other lines). We match the end of each line with $ and append the rest of the verse, where we use $_ (entire input, i.e. in this case the entire line) so we don't have to repeat N bottles of beer and we use W as a placeholder for the repeated on the wall.

G-8`

This is a "grep" stage. The regex is empty, so it always matches, but the -8 limit means that only lines up to the 8th from the end are kept, so the last 7 are discarded. This gets rid of a few extraneous lines like the one with 0 and some empty lines that we don't want at the end.

W
 on the wall

Now we substitute our W placeholder. At this point, we've got everything in place except that the last verse is still wrong.

T`s``¶1 .+

This fixes the pluralisation by removing all ss from the a match of the regex at the end, which matches a line that begins with a 1.

T.+ 1 
Go to the store and buy some more, 99 

And finally, we replace the wrong part of the very last line with the correct lyrics.

added 1817 characters in body
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975
Loading
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975
Loading