Skip to main content
Commonmark migration
Source Link

Golfscript, 22 21 bytes

#Golfscript, 22 21 bytes Try it online!

-1 byte thanks to careful final redefining of the n built-in.

{.n>{}{'
'\}if:n}%:n;

Explanation (with a slightly different version):

{.n>{}{"\n"\}if:n}%:n; # Full program
{                }%    # Go through every character in the string
 .n>         if        # If ASCII code is greater than previous...
                       # (n means newline by default, so 1st char guaranteed to fit)
    {}                 # Do nothing
      {"\n"\}          # Else, put newline before character
               :n      # Redefine n as the last used character
                   :n; # The stack contents are printed at end of execution
                       # Literally followed by the variable n, usually newline
                       # So because n is by now an ASCII code...
                       # ...redefine n as the new string, and empty the stack

#Golfscript, 22 21 bytes Try it online!

-1 byte thanks to careful final redefining of the n built-in.

{.n>{}{'
'\}if:n}%:n;

Explanation (with a slightly different version):

{.n>{}{"\n"\}if:n}%:n; # Full program
{                }%    # Go through every character in the string
 .n>         if        # If ASCII code is greater than previous...
                       # (n means newline by default, so 1st char guaranteed to fit)
    {}                 # Do nothing
      {"\n"\}          # Else, put newline before character
               :n      # Redefine n as the last used character
                   :n; # The stack contents are printed at end of execution
                       # Literally followed by the variable n, usually newline
                       # So because n is by now an ASCII code...
                       # ...redefine n as the new string, and empty the stack

Golfscript, 22 21 bytes

Try it online!

-1 byte thanks to careful final redefining of the n built-in.

{.n>{}{'
'\}if:n}%:n;

Explanation (with a slightly different version):

{.n>{}{"\n"\}if:n}%:n; # Full program
{                }%    # Go through every character in the string
 .n>         if        # If ASCII code is greater than previous...
                       # (n means newline by default, so 1st char guaranteed to fit)
    {}                 # Do nothing
      {"\n"\}          # Else, put newline before character
               :n      # Redefine n as the last used character
                   :n; # The stack contents are printed at end of execution
                       # Literally followed by the variable n, usually newline
                       # So because n is by now an ASCII code...
                       # ...redefine n as the new string, and empty the stack
Found improvement
Source Link

#Golfscript, 2222 21 bytes Try it online!Try it online!

Note that, because this redefines n (the "newline" built-in), the newline here is necessary.-1 byte thanks to careful final redefining of the n built-in.

1/{.n>{}{'
'\}if:n}%);:n;

Being a little bit more lax on the outputExplanation (i.e. the ASCII code of the last letter is output after the letterswith a slightly different version) allows 4 bytes to be saved. However, I'm not sure if this is allowed output.:

{.n>{}{'
'\"\n"\}if:n}%:n; # Full program
{                }%    # Go through every character in the string
 .n>         if        # If ASCII code is greater than previous...
                       # (n means newline by default, so 1st char guaranteed to fit)
    {}                 # Do nothing
      {"\n"\}          # Else, put newline before character
               :n      # Redefine n as the last used character
                   :n; # The stack contents are printed at end of execution
                       # Literally followed by the variable n, usually newline
                       # So because n is by now an ASCII code...
                       # ...redefine n as the new string, and empty the stack

#Golfscript, 22 bytes Try it online!

Note that, because this redefines n (the "newline" built-in), the newline here is necessary.

1/{.n>{}{'
'\}if:n}%);

Being a little bit more lax on the output (i.e. the ASCII code of the last letter is output after the letters) allows 4 bytes to be saved. However, I'm not sure if this is allowed output.

{.n>{}{'
'\}if:n}%

#Golfscript, 22 21 bytes Try it online!

-1 byte thanks to careful final redefining of the n built-in.

{.n>{}{'
'\}if:n}%:n;

Explanation (with a slightly different version):

{.n>{}{"\n"\}if:n}%:n; # Full program
{                }%    # Go through every character in the string
 .n>         if        # If ASCII code is greater than previous...
                       # (n means newline by default, so 1st char guaranteed to fit)
    {}                 # Do nothing
      {"\n"\}          # Else, put newline before character
               :n      # Redefine n as the last used character
                   :n; # The stack contents are printed at end of execution
                       # Literally followed by the variable n, usually newline
                       # So because n is by now an ASCII code...
                       # ...redefine n as the new string, and empty the stack
Source Link

#Golfscript, 22 bytes Try it online!

Note that, because this redefines n (the "newline" built-in), the newline here is necessary.

1/{.n>{}{'
'\}if:n}%);

Being a little bit more lax on the output (i.e. the ASCII code of the last letter is output after the letters) allows 4 bytes to be saved. However, I'm not sure if this is allowed output.

{.n>{}{'
'\}if:n}%