40
\$\begingroup\$

Let us take a break from the brain-wrecking questions and answer some of the simpler ones

You have recently read something extremely funny, and want to express your laughter to the world! But how can you?

Task

You have to display the string: Lolololololololololololololololololololololololololololololololololololololololololololololololololololololololol...

...to STDOUT.

The string should be of infinite length, or will constantly be printed until the end of time.

It is just as simple!

But remember, this is code-golf, so the source code must be as short as possible!

Note: Some languages may throw errors since excecution can be timed out, or for other reasons. That is okay! It can be weird when you laugh forever!


Good luck!

\$\endgroup\$
12
  • 2
    \$\begingroup\$ By the way, standard site rules will allow functions which return the result (e.g. in an infinite generator) making the print to STDOUT part redundant unless you specify that this must be a full program (which I'd advise against, but is allowed). \$\endgroup\$ Commented Sep 12, 2020 at 13:21
  • 5
    \$\begingroup\$ Possible duplicate of Scream very loudly \$\endgroup\$ Commented Sep 12, 2020 at 14:38
  • 5
    \$\begingroup\$ I don't understand why this was closed. The other challenge is much simpler. \$\endgroup\$ Commented Sep 12, 2020 at 19:28
  • 7
    \$\begingroup\$ @thedefault. I don't understand your comment. The difference (requires an extra character to be outputted before the program, and outputs two characters instead of one) is fairly trivial. As you can see, if we remove the print L part and change ol to A, we get an SVL answer! \$\endgroup\$ Commented Sep 13, 2020 at 11:56
  • 15
    \$\begingroup\$ I have reopened this question. I believe the small difference presents interesting golfing opportunities in some languages and, furthermore, that simply porting a solution might well not be competitive. One only needs to look at a few of the answers to see some interesting differences. If people disagree then by all means vote to close again. \$\endgroup\$ Commented Sep 24, 2020 at 8:27

132 Answers 132

2
\$\begingroup\$

Befalse (quirkster), 14 bytes

"loL".^^.4{1{;

Try it! (Usage: copy-paste into the code box, click Show above it, and use Step to run it step-by-step. Warning: Run will lock your browser.)

In order to avoid using two lines, this program commits a "return address forgery":

On : (Call) instruction, some data are pushed onto the return stack (like the one in Forth) so that ; (Ret) can return to the call position. In quirkster's interpreter, the position in the code box (rectangularized and flattened) and the IP direction (movement in 1D; right is 1 and down is code width) are pushed in the order. ; advances one step after returning before running the next instruction, so (4, 1) continues running at the first ..

"loL"    Push l, o, L in order
.        Print L
^^.      Copy l and o; print o
4{1{;    "Return" to the first .
.        Print l
         Repeat indefinitely

15 bytes

"L" !/.!
"lo"./

This exploits a bug in the interpreter, where the IP can "jump over" a newline to continue running at the start of the next line. This is because the code is stored as a newline-joined 1D string during execution. So you can get away with two mirrors to form a loop.

"L"    Push L
!/     Jump over a mirror to enter the loop
.      Print L
!      "Jump over" the newline
"lo"   Push l and o
.      Print o
       Infinite loop, printing l and o in order afterwards
\$\endgroup\$
1
\$\begingroup\$

Splinter, 11 bytes

A{\o\lA}\LA

Try it online!

Interpreter breaking version. Would run forever otherwise.

\$\endgroup\$
1
\$\begingroup\$

Barrel, 8 bytes

L#∞(ol

Implicitly prints L, then infinitely loops over implicitly printing ol. The parenthesis makes o and l into one statement, since a loop can only execute one statement. (In barrel, parentheses are self-closing.)

\$\endgroup\$
1
\$\begingroup\$

Lua, 31 bytes

u=io.write u"L"::x::u"ol"goto x

Try it online!

\$\endgroup\$
2
1
\$\begingroup\$

GForth 30 bytes

: A ." L" 0 1 do ." ol" loop ;
\$\endgroup\$
0
1
\$\begingroup\$

Batch (30 Bytes)

@ECHO OFF
ECHO L
:a
ECHO ol
GOTO :a

If you're willing to ignore @ECHO OFF, then it's 25 bytes instead.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You could get rid of @echo off without printing echo stuff by prefixing each line (except :a) with @s. Plus, as an alternative solution, you can output without newline by doing set/p=Text to output<nul \$\endgroup\$
    – FZs
    Commented Aug 19, 2021 at 12:04
1
\$\begingroup\$

Haskell, 25 bytes

main=putStr$'L':cycle"ol"

To return an infinite string, only 13 bytes required:

'L':cycle"ol"
\$\endgroup\$
1
\$\begingroup\$

Z80Golf, 9 bytes

00000000: 3E 4C FF 3B 3B F6 20 EE
00000008: 03

Try it online!

Explanation

  ld a, $4C ; Load the ASCII code of "L" into a
  rst $38   ; Jump past the end of the program (print "L") and push the next address (loop) to the stack

loop:
  dec sp    ; \
  dec sp    ; _} Push the last value (the address of loop) back to the stack by moving the stack pointer by 2 downwards
  or $20    ; Switch from uppercase to lowercase (idempotent). $4C ("L") -> $6C ("l"), $6C ("l") -> $6C ("l")
  xor $03   ; Toggle A between $6C ("l") and $6F ("o")

; ... the program runs (executes NOPs) until PC = $8000 where it prints A, then returns to the address on the stack (which is always loop)
\$\endgroup\$
1
\$\begingroup\$

BrainCrash, 43 22 bytes.

^^+++++++++++.>>[.<.>]

I'll golf off later.

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Gaia, 9 bytes

:p⌋
Lo”↑∞

Try it online!

The first line is a helper function which prints a copy of its input and returns its input converted to lowercase.

Lo” pushes the string "Lo" to the stack, and ↑∞ calls the above function infinitely. Leading quotation marks can be omitted at the start of a line.

The same could be done in a single line with Lo”⟨:p⌋⟩∞.

\$\endgroup\$
1
\$\begingroup\$

JavaScript (Node.js), 49 bytes

for(i=0;++i;){process.stdout.write(i<2?"L":"ol")}

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Pyth, 8 bytes

p\LWp"ol

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Etch, 23 bytes

do
:outnnl"lo";
forever
\$\endgroup\$
1
  • \$\begingroup\$ This looks like it outputs "lololololol", you need a capital L. \$\endgroup\$
    – emanresu A
    Commented Aug 6, 2022 at 7:35
1
\$\begingroup\$

Befunge-98 (PyFunge), 15 12 11 bytes

'Lv
'l>,'o,

Try it online!
-3 bytes thanks to @emanresuA
-1 byte thanks to @WheatWizard

Befunge-93 compatible version (1 byte more):

L"v
, <,"ol"

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ Welcome to Code Golf, and nice first answer! Be sure to check out our Tips for golfing in Befunge page for ways you can golf your program! I think this can be 12 bytes with some rearranging. \$\endgroup\$
    – emanresu A
    Commented Mar 17, 2022 at 19:26
  • \$\begingroup\$ @emanresuA thanks! However I can't get over the fact that your code produces Llolo... instead of Lolol... \$\endgroup\$ Commented Mar 17, 2022 at 20:12
  • \$\begingroup\$ Oops. I was close... \$\endgroup\$
    – emanresu A
    Commented Mar 17, 2022 at 20:17
  • \$\begingroup\$ @WheatWizard thank you too! \$\endgroup\$ Commented Mar 18, 2022 at 0:28
1
\$\begingroup\$

Rust, 41 bytes

I know I'm a little late to the party, but I'd though I'd make a Rust contribution. Here's the code:

fn main(){print!("L");loop{print!("ol")}}

Try it online! Note that it will panic on TIO after the output exceeds 128 KiB. But it doesn't panic in my terminal!

\$\endgroup\$
1
  • \$\begingroup\$ You can trim this to 30 bytes by using the header and footer sections in TIO to cover the fn main(){ and }. \$\endgroup\$ Commented Apr 15 at 16:37
1
\$\begingroup\$

PHP (25 chars)

echo'L';for(;;print'ol');
\$\endgroup\$
1
\$\begingroup\$

Clojure, 24 bytes

This is my first answer in Clojure; I only started learning it recently.

(pr 'L)(while 1(pr 'ol))

To be honest I'm not quite sure myself why (pr 'ol) works, but it does.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ while 1 can be loop[] \$\endgroup\$
    – naffetS
    Commented Mar 26, 2023 at 21:52
  • \$\begingroup\$ @naffetS That doesn't work for me. (loop[](pr 'ol)) only prints ol once before returning. \$\endgroup\$
    – Bbrk24
    Commented Mar 26, 2023 at 22:41
  • \$\begingroup\$ Nevermind sorry, you would need (recur) \$\endgroup\$
    – naffetS
    Commented Mar 26, 2023 at 23:41
1
\$\begingroup\$

Rust, 41 bytes

fn main(){print!("L");loop{print!("ol")}}

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Alice, 10 bytes

"olL"wo~.K

Try it online!

Explanation

"olL"wo~.K
"olL"       Puts `olL` in the stack, `L` on the top
     w   K  Never ending loop
      o     Print the first element of the stack
       ~    Swap the stack
        .   Duplicate the first element of the stack
\$\endgroup\$
1
\$\begingroup\$

Thunno, \$ 8 \log_{256}(96) \approx \$ 6.58 bytes

'L[ZL"ol

Attempt This Online!

Explanation

'L        # Push the character "L"
  [       # Forever:
   ZL     #  Print top of stack with no trailing newline
     "ol  #  Push "ol" for the next iteration
\$\endgroup\$
1
\$\begingroup\$

Binary-encoded Golifcal, 13 bytes

Hexdump of binary encoding:

00 70 01 00 4c 18 1b 00 6c 18 00 6f 1d

This binary version can be convered back to a runnable program image using the Encoder included in the github repository for the language, or run directly by adding the -x flag.

Original program image:

enter image description here

Magnified 70x with RGB colors labeled: enter image description here

\$\endgroup\$
1
\$\begingroup\$

Fortran (GFortran) --cpp, 57 bytes

#define p(s)call fput(s)
p('L')
1 p('o');p('l');goto1;end

Try it online!.

I #define a macro p() to save typing call fput('x') for every letter. And good old goto is mostly harmless.

\$\endgroup\$
1
\$\begingroup\$

Nibbles, 5 bytes (10 nibbles)

"L"^~"ol"

Attempt This Online!

\$\endgroup\$
1
\$\begingroup\$

Python, 45 Bytes

print('Lo',end='')
while 1:print('lo',end='')

Try it online!
Seems ungolfable.

\$\endgroup\$
1
\$\begingroup\$

SAS, 42 bytes

SAS gives "the ultimate" answer in 42 bytes ;-)

The code:

data;put'L'@;do while(1);put'ol'@;end;run;

Human readable:

data;
  put 'L' @;
  do while(1);
    put 'ol' @;
  end;
run;
\$\endgroup\$
1
\$\begingroup\$

Byte-based instruction jumping, 8 bytes

↑L↑o↑l,L

How it works: When executed, the instructions stored in moves the instruction pointer to the right, prints the value stored there (L) and moves to the right again, making it point to the second . the second does the same again, except o is printed instead of L, and the third prints l and makes the instruction pointer point to ,.

, also makes the instruction pointer move to the right (to the second L), but then it jumps back to the last byte with the same value as the current one (the first L), and moves right once more (to the second ). Now it ends up in an infinite loop where it moves forward, prints o, moves forward, prints l, moves forward, jumps to the first L, moves forward, prints o et cetera.

\$\endgroup\$
1
\$\begingroup\$

Basic, 20 bytes

?"L";:DO:?"ol";:LOOP

Try it online!

\$\endgroup\$
1
\$\begingroup\$

JavaScript (Node.js), 41 bytes

for(x='L';process.stdout.write(x);)x='ol'

Try it online!

-2 from Dom Hastings

\$\endgroup\$
1
  • \$\begingroup\$ I think the initial value of x could just be 'L' for -2! \$\endgroup\$ Commented Nov 20, 2023 at 14:16
1
\$\begingroup\$

Vyxal 3, 7 bytes

'L{§ᶴol

Try it Online!

Lolololololol

\$\endgroup\$
1
\$\begingroup\$

Hussy.Net, 17 bytes

A("L");R(A,"ol");
  • A is an append function that simply writes the specified input to the output stream.
  • R is a repeater function that repeats the specified action with the specified input until an optionally specified escape condition is met.
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.