36
\$\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\$
11
  • 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\$ Sep 12, 2020 at 13:21
  • 5
    \$\begingroup\$ Possible duplicate of Scream very loudly \$\endgroup\$ Sep 12, 2020 at 14:38
  • 4
    \$\begingroup\$ I don't understand why this was closed. The other challenge is much simpler. \$\endgroup\$ Sep 12, 2020 at 19:28
  • 6
    \$\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\$
    – null
    Sep 13, 2020 at 11:56
  • 14
    \$\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\$ Sep 24, 2020 at 8:27

99 Answers 99

2
\$\begingroup\$

Kotlin(script), 23 32 31 bytes

print("L")while(0<1)print("ol")

In Kotlin you need a top level declaration(main function) in order to compile code but Kotlin compiler also allows compiling Kotlin scripts using kotlinc -script lol.kts so yes you can compile one liners without top level direction using a file. this cannot be verified using TIO the only online compiler that I found for Kotlin scripting or Kotlin REPL is this site. In order to test this use command line in right side of the given site and and run the code in these steps:

First create a file:

echo "print(\"L\")while(0<1)print(\"ol\")" > lol.kts"

Then run it like this:

kotlinc -script lol.kts

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to CGCC! Unfortunately, I'm not sure how to verify this on TIO; are you sure this works? The output is supposed to start with a capital L and print "olololol..."; this seems like it'd print "lollollollol..." (edit: testing with this shows the behavior I expected) \$\endgroup\$
    – hyper-neutrino
    May 16, 2021 at 2:34
  • 1
    \$\begingroup\$ @hyper-neutrino You're right this cannot be fully verified on TIO because it doesn't support Kotlin scripts. I missed the first capital L that, I'll fix it. \$\endgroup\$
    – YaMiN
    May 16, 2021 at 2:46
2
\$\begingroup\$

Javascript, 23 22 bytes

(-1 from Jo King)

f=a=>(a?"ol":"L")+f(1)

Try it online!

\$\endgroup\$
7
  • \$\begingroup\$ @joking yes. Actually, it even fits better to the requirement. Thanks \$\endgroup\$
    – SomoKRoceS
    Sep 24, 2020 at 21:52
  • 2
    \$\begingroup\$ I think this (20 bytes including f=) should work. \$\endgroup\$
    – Bubbler
    Sep 24, 2020 at 22:55
  • \$\begingroup\$ @JoKing legit :) I'll edit my answer wiith 2+ \$\endgroup\$
    – SomoKRoceS
    Sep 25, 2020 at 14:38
  • 1
    \$\begingroup\$ I'm new to code golf, but it seems to me that task requires text to be printed. So shouldn't console.log() be included in script and increase byte count? \$\endgroup\$
    – NoOorZ24
    Sep 28, 2020 at 6:07
  • 3
    \$\begingroup\$ What's the result of f()? (It's not "an infinite string" — those don't exist in JavaScript.) \$\endgroup\$
    – Lynn
    Oct 5, 2020 at 21:34
2
\$\begingroup\$

><> and Gol><>, 10 bytes

"volL
:>o$

Try it online! (><>)

Try it online! (Gol><>)

How it works

"volL    Push charcodes of v, o, l, L in that order (L is at the top)
"v       End string mode
 >       and move to the second row
  o      Pop and print one char (initially L)
: o$     Infinite loop: Swap, dup, pop and print one char
\$\endgroup\$
2
\$\begingroup\$

Flipbit, 24 bytes

<<^>>>^>^>>.^<^<^<^<<,^]

Try it online!

or, using a bit less odd behavior:

^[>>>^>^>>.^<^<^<^<<,^<]

Try it online!

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

Bash (pure bash), 43 34 31 bytes

printf L;for((;;)){ printf ol;}

Thanks manatwork

\$\endgroup\$
3
  • 2
    \$\begingroup\$ printf is shorter than echo -n. : is shorter than true. No need for the single quotes. \$\endgroup\$
    – manatwork
    Aug 5, 2021 at 20:34
  • 2
    \$\begingroup\$ If not done yet, take a look at Tips for golfing in Bash. Using those advices you may reduce this to printf L;for((;;)){ printf ol;}. \$\endgroup\$
    – manatwork
    Aug 5, 2021 at 20:43
  • \$\begingroup\$ Thanks @manatwork \$\endgroup\$
    – svin83
    Aug 5, 2021 at 21:12
2
\$\begingroup\$

C# (50, 45, 42 bytes)

for(var a="L";;)Console.Write(a+(a="ol"));

It works by setting a variable to L, printing that variable, then setting its value to ol; infinitely repeating steps 2 and 3.

Note: Thanks to @ceilingcat and @Browncat Programs for pointing out a shorter alternatives in the comments.

\$\endgroup\$
0
2
\$\begingroup\$

Pxem, filename only: 11 bytes.

Uses reference implementation feature: doesn't break the loop of .w and .a when stack is empty.

L.o.wol.p.a

OR

L.z.p12ol.a

Try it online!

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

Vyxal, 8 bytes

\L₴{‛ol₴

Try it Online!

Will add an explanation soon.

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

Pari/GP, 22 bytes

until(!L=ol,print1(L))

Try it online!


Pari/GP, 22 bytes

while(!print1(L),L=ol)

Try it online!

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

Lexurgy, 33 bytes

a propagate:
*=>ol/_ $
*=>L/$ _ o

Explanation:

a propagate: # while the input changed last iteration...
*=>ol/_ $    # append "lo" to the end of the input
*=>L/$ _ o   # prepend "L" exactly once
\$\endgroup\$
2
\$\begingroup\$

Underload, 18 15 bytes

(L)S((ol)S:^):^

Try it online!

Prints out L, then ololololololololol...

\$\endgroup\$
1
  • \$\begingroup\$ It's Underload!!!! \$\endgroup\$
    – null
    Mar 15 at 14:30
1
\$\begingroup\$

Splinter, 11 bytes

A{\o\lA}\LA

Try it online!

Interpreter breaking version. Would run forever otherwise.

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

Turbo Assembler, 136 119 bytes

.model small
.code
start:
mov dl,'L'
mov ah,2
int 21h
i:
mov dl,'o'
mov ah,2
int 21h
mov dl,'l'
int 21h
jmp i
end start

Ungolfed version:

.model small
.code
start:
    mov dl, 'L'         ; move "L" character to DL register
    mov ah, 02h         ; print "L" character
    int 21h             ; interrupt
infinity_loop:
    mov dl, 'o'         ; move "o" character to DL register
    mov ah, 02h         ; print characters
    int 21h             ; interrupt
    mov dl, 'l'         ; move "l" character to DL register
    int 21h             ; interrupt
    jmp infinity_loop   ; go to "infinity_loop" label
end start

-17 bytes thanks to @Kamila Szewczyk

Lololololo[...] in action:

Lololololo[...]

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

><>, 12 bytes

"L"v
l"o<o"o

Explanation

"L"v     // pushes the character 'L' onto the stack and moves to the second line
l"o<o"o  // after outputting the L character, enters an infinite loop of pushing "lo" and outputting both
\$\endgroup\$
1
\$\begingroup\$

Perl 5 (ppencode-cpmpatible), 87 bytes

print q pop xor print chr ord q else while length or print uc chr ord q else and s qq q

Try it online!

How it works

# NOTE: q x STR x eq ' STR '
# chr ord STR to obtain first character
   print q pop xor
   print chr ord q else
while
# default variable is initially empty string
   length or
      # print first L
      print uc chr ord q else and
      # make sure not to come here
      s qq q
\$\endgroup\$
1
\$\begingroup\$

Factor, 29 bytes

"L"write [ "ol"write t ] loop

Try it online!

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

COMET II ("CASLシミュレータ (CASL II 対応)" by Daytime), 28 bytes.

The leftmost column shows an address, and one word is two bytes.

0000: 7001 0000 7002 0000
0004: 1210 0012 1220 0014
0008: F000 0002 7120 7110
000C: 1210 006C 1110 0012
0010: 6400 0000 004C 006F
0014: 0002

The simulator seems to output an LF automatically every time OUT is executed, and it requires you to set a break point to see how it works by step by step.

Original CASL II assembly program (63 bytes)

A START
 OUT Z,=2
 LAD GR1,108
 ST GR1,Z
 JUMP A
Z DC 'Lo'
 END

Usage example

Run just for a few steps, as I have no ideas how to scroll back the console.

Run just for a few steps, as I have no ideas how to scroll back the console.

\$\endgroup\$
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\$

APL (Dyalog Unicode), 14 bytes

{∇⍞←'ol'}⍞←'L'

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
    Aug 6 at 7:35
1
\$\begingroup\$

Thue, 35 bytes

L::=~L
()::=(ol)
ol::=~ol
::=
(oLl)

Here is a Thue interpreter that works for this challenge. Paste the code into the box, click Update, and then click Step repeatedly (note that clicking the Run button will lock up your web browser).

Try It Online has a Thue interpreter, but it adds a newline after each print and therefore doesn't match the output format of this challenge.

Explanation

The program consists of an initial string (oLl) and three rules for transforming it. The rules are applied non-deterministically: any time a rule can be applied to the current string, it may be applied. To achieve predictable behavior, we need to design the string and the rules such that only one of them can be applied at any given point.

Thus, when the string is in its initial state (oLl), the only rule that applies is the first one:

L::=~L

This means "delete L from the string and output L."

Now the string looks like (ol), and the third rule applies:

ol::=~ol

This means "delete ol from the string and output ol."

The string is now (), at which point the second rule applies:

()::=(ol)

This means "replace () in the string with (ol)." Now the string is (ol) again, rule 3 applies again, and we continue ad infinitum.

\$\endgroup\$
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
    Mar 17 at 19:26
  • \$\begingroup\$ @emanresuA thanks! However I can't get over the fact that your code produces Llolo... instead of Lolol... \$\endgroup\$ Mar 17 at 20:12
  • \$\begingroup\$ Oops. I was close... \$\endgroup\$
    – emanresu A
    Mar 17 at 20:17
  • \$\begingroup\$ @WheatWizard thank you too! \$\endgroup\$ Mar 18 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\$

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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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