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

76 Answers 76

3
\$\begingroup\$

Golang, 53 27 bytes

print("L");for{print("ol")}

Try it online!

EDIT: Apparently package main and func main() don't necessarily count towards the byte count for Go e.g. https://codegolf.stackexchange.com/a/107159/95793.

Previous version:

package main
func main(){print("L");for{print("ol")}}
\$\endgroup\$
3
\$\begingroup\$

PHP, 24 bytes

L<?php for(;;)echo'ol';
\$\endgroup\$
2
  • 1
    \$\begingroup\$ -1 byte using a for loop. \$\endgroup\$
    – Razetime
    Sep 28 '20 at 6:51
  • \$\begingroup\$ -2 by using ol instead of 'ol' and a for loop. \$\endgroup\$
    – Makonede
    May 10 at 17:45
3
\$\begingroup\$

Batch, 42 40 bytes

@set/p=L<nul
:g
@set/p=ol<nul
@goto g

set/p outputs the string after the = as the prompt, and then expects to read from the console, which ends the line when you hit enter. But we redirect the input, so no enter happens, and we simply end up with a infinite series of "prompts" all on one line. Edit: Saved 2 bytes thanks to @T3RROR.

\$\endgroup\$
1
  • \$\begingroup\$ -2 bytes by changing each @set/ps= to @set/p= \$\endgroup\$
    – T3RR0R
    May 11 at 14:43
3
\$\begingroup\$

Hexagony, 11 6 bytes

-5 thanks to @Bubbler

L;o;l;

Try it online!

  L ;   Executed once: Set memory to 'L' (76) and print
 o ; l  Executed repeatedly: Set memory to 'o' (111), print, set memory to 'l' (108)
  ; .   Executed repeatedly: Print

After the first row is executed once, the second and third rows are repeatedly executed, infinitely printing ol.

\$\endgroup\$
1
  • \$\begingroup\$ Simply L;o;l; works. Not sure if it can be reduced to 5 bytes, but it might be possible. \$\endgroup\$
    – Bubbler
    May 16 at 3:46
3
\$\begingroup\$

FALSE, 13 bytes

'L,[1]["ol"]#

Try it online!

Explanation

'L, // outputs "L" character
[1] // pushes lambda which evaluates to 1 onto the stack
["ol"] // pushes lambda which prints "ol" onto the stack
#   // Executes lambda on top of stack while the lambda below it
    // does not evaluate to zero

Note: This is my first post on this site, so let me know in the comments if I did something wrong.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to Code Golf! Nice first answer! Doesn't look like you did anything wrong, the formatting and explanation are better than most of my answers :p \$\endgroup\$ Jul 26 at 19:02
  • \$\begingroup\$ @Redwolf Programs Thanks for your feedback! Have a nice day! \$\endgroup\$ Jul 26 at 19:09
3
\$\begingroup\$

WedgeScript, 9 bytes

'Lo|"ol"o

Explanation:

'L         Pushes the character literal L to the stack
o          Output 
|          Loop the rest of the code infinitely
"ol"       Push the string "ol" to the stack
o          Output

Yes, Wedgescript is a custom language made by me, here is the repo with interpreter install instructions: github.com/WedgeScript/WedgeScript

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to Code Golf! I've cleaned up the formatting of your answer a bit to make it easier to read the explanation. This language looks really cool! I think I might have to check it out! \$\endgroup\$ Aug 5 at 20:55
3
\$\begingroup\$

BitCycle, 30 bytes

v001000<   ~010!

~1011000110^

Try it online!

Outputs as a stream of bits.

\$\endgroup\$
1
  • \$\begingroup\$ 30 bytes while still avoiding the undefined behaviour of outputting two bits at the same time \$\endgroup\$
    – Jo King
    Aug 18 at 16:19
3
\$\begingroup\$

Minim, 41 39 Bytes

New solution prepends 3 to the string, saving 2 bytes:

[]=3&"loL".$<[[0]--].[0]=[0]?[0]:2.C=0.

With whitespace and comments:

[] = 3 & "loL".      ; Inserts the value 3, and the string "Lol" backwards, into \
                       memory from index 0
$< [[0]--].          ; Prints the value at the index stored at index 0 as unicode, \
                       and decrements index 0
[0] = [0] ? [0] : 2. ; Sets index 0 back to 2 if it equals 0
C = 0.               ; Sets the program counter to 0, which advances to 1 afterwards

Old solution used ASCII escape character 0x3 (ETX) in the string:

[]="\x03loL".$<[[0]--].[0]=[0]?[0]:2.C=0.

GitHub Repository

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

Python 3, 44 bytes

print('L',end='')
while 1:print('ol',end='')

How it works: The program first prints 'L' and then infinitely prints 'ol' on a single line using the end=''.

Try it online!

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

Japt, 14 11 bytes

-3 bytes thanks to @Shaggy

OoUª'L
ß"ol

Try it online!

Explanation

OoUª'L    // Output input if it exists else 'L'
ß"ol      // Run program with input being "ol"
\$\endgroup\$
2
  • \$\begingroup\$ 11 bytes \$\endgroup\$
    – Shaggy
    Sep 12 '20 at 22:31
  • \$\begingroup\$ Or 12 bytes if you want to avoid the overflow. \$\endgroup\$
    – Shaggy
    Sep 12 '20 at 23:44
2
\$\begingroup\$

Powershell v5 32 Byte

while(1-ne2){Write-Host -n 'lo'}

Has someone an idea how to shorten Write-Host? Is there an alias?

New One 52 Byte

for(1){Write-Host -n 'L'
for(1){Write-Host -n 'ol'}}
\$\endgroup\$
7
  • \$\begingroup\$ The first character printed must be a capital L, the rest must be in lower-case. You can maybe answer Scream verly loudly like this. \$\endgroup\$ Sep 24 '20 at 11:47
  • \$\begingroup\$ ...although actually there already a terser Powershell program there. \$\endgroup\$ Sep 24 '20 at 11:49
  • \$\begingroup\$ Thanks for the hint. \$\endgroup\$ Sep 24 '20 at 11:53
  • 1
    \$\begingroup\$ You can shorten your answer by 4 characters by removing the not equal expression: while(1){Write-Host -n 'lo'} \$\endgroup\$
    – DBADon
    Sep 24 '20 at 14:45
  • 1
    \$\begingroup\$ 38 bytes with set-alias. 39 bytes with raw powershell \$\endgroup\$
    – mazzy
    Sep 24 '20 at 19:37
2
\$\begingroup\$

Wolfram Language (Mathematica), 31 bytes

#0[ol,$Output~WriteString~#]&@L

Try it online!

Stops when the program hits the $IterationLimit, which defaults to 4096.

34 bytes does the job without worrying about that:

Do[$Output~WriteString~L;L=ol,∞]

Try it online!

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

MAWP, 10 bytes

76;["ol":]

Try it!

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

R, 26 25 bytes

cat('L');repeat cat('ol')

Try it online!

Well, this one is pretty straightforward.

−1 byte thanks to Steffan

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

Stax, 7 6 bytes

║►yü[c

Run and debug it

Explanation

.Lo{cpvW
.Lo      push two letter string "Lo"
   {   W loop forever
    c    duplicate           → ["Lo", "Lo"]
     p   print and pop       → ["Lo"]
      v  lowercase           → ["lo"]
         begin next iteration
\$\endgroup\$
2
\$\begingroup\$

Scala, 35 34 32 bytes

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

Try it online!

  • -1 thanks to ovs!
\$\endgroup\$
1
  • \$\begingroup\$ 1>0 is one byte shorter than true. \$\endgroup\$
    – ovs
    Oct 20 '20 at 13:11
2
\$\begingroup\$

SABDT, 23 bytes

pr"L";wh(0=0){pr"ol";}

Exspanded:

pr "L";
wh(0 = 0){
   pr "ol";
}

the 1st line prints "L".

the 2nd line is a while loop. 0 is a variable reference, since it has not been declared yet it starts as "", an empty string. essentially it is a while true loop.

the 3rd line prints "ol".

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to the site! Would you mind providing a link to this language, so that others can check/verify your solution? \$\endgroup\$ Oct 27 '20 at 11:17
  • \$\begingroup\$ @caird-coinheringaahing sure thing \$\endgroup\$ Oct 27 '20 at 22:54
2
\$\begingroup\$

BRASCA, 14 12 11 bytes

-1 bytes from RezNesX

`loL`o[:mo]

Try it online!

Explanation

`loL`         - Push 'Lol' to the stack
     o        - Output the 'L'
      [:mo]   - Output the next character of ['o', 'l']
\$\endgroup\$
1
  • \$\begingroup\$ 11 bytes: `loL`o[:mo] \$\endgroup\$
    – RezNesX
    May 12 at 11:52
2
\$\begingroup\$

Fueue, 14 bytes

76):[111)108:]

Try it online!

Explanation

76 is the character code for L, 111 is the code for o, and 108 is the character code for l. This code first prints an L and then goes into an infinite loop that keeps printing out ol.

76):[111)108:]

76              Print 'L'.
  ):[        ]  Turn the stuff in the brackets into 111)108:[111)108:]
     111 108    Print 'ol'.
        )   :   Loop infinitely.
\$\endgroup\$
2
\$\begingroup\$

Canvas, 6 bytes

LWol+]

Try it here!

Constructs an infinite length string.

Explanation:
LWol+] | Full program (characters replaced for clean spacing)
-------+------------------------------------------------------
L      | Push the string "L"
 W   ] | While ToS is truthy (without popping),
  ol   |  Push the string "ol"
    +  |  Add the two strings (i.e. append "ol" to the string)
       | Print ToS (implicit) (will not ever actually occur)

Non-empty strings are always truthy in Canvas.

\$\endgroup\$
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 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 at 2:46
2
\$\begingroup\$

C# 9, 55 47 bytes

for(var x="L";;x="ol")System.Console.Write(x);

Thanks, @ceilingcat!

Previously on Code Golf

var x="L";while(true){System.Console.Write(x);x="ol";}

Using top-level statements.

Microsoft's online compiler that doesn't like this infinite loop idea...

\$\endgroup\$
3
  • \$\begingroup\$ Welcome to the site! Would it be possible for you to add in a link to an online interpreter, such as TryItOnline, so others can run your code? \$\endgroup\$ Oct 27 '20 at 23:37
  • \$\begingroup\$ Unfortunately, the only .NET 5.0 online interpreter is on Microsoft's site. This doesn't allow for injecting code. Plus, it locks up on this infinite loop. I'll add the link, but best of luck getting it to run. \$\endgroup\$ Oct 27 '20 at 23:42
  • \$\begingroup\$ @ceilingcat ooo... I didn't think of that... \$\endgroup\$ Oct 28 '20 at 15:18
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 '20 at 21:52
  • 2
    \$\begingroup\$ I think this (20 bytes including f=) should work. \$\endgroup\$
    – Bubbler
    Sep 24 '20 at 22:55
  • \$\begingroup\$ @JoKing legit :) I'll edit my answer wiith 2+ \$\endgroup\$
    – SomoKRoceS
    Sep 25 '20 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 '20 at 6:07
  • 2
    \$\begingroup\$ What's the result of f()? (It's not "an infinite string" — those don't exist in JavaScript.) \$\endgroup\$
    – Lynn
    Oct 5 '20 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\$

C (gcc), 27 bytes

f(i){f(!printf("Lol"+!i));}

Try it online!

enter image description here

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

Bash (pure bash), 43 34 31 bytes

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

Thanks manatwork

\$\endgroup\$
3
  • 1
    \$\begingroup\$ printf is shorter than echo -n. : is shorter than true. No need for the single quotes. \$\endgroup\$
    – manatwork
    Aug 5 at 20:34
  • 1
    \$\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 at 20:43
  • \$\begingroup\$ Thanks @manatwork \$\endgroup\$
    – svin83
    Aug 5 at 21:12
2
\$\begingroup\$

JavaScript (Node.js), 60 50 49 bytes

-10 bytes thanks to @user

-1 byte by replacing while(1) with for(;;)

(p=x=>process.stdout.write(...x))`L`;for(;;)p`ol`

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 50 bytes \$\endgroup\$
    – user
    Jul 27 at 21:25
  • \$\begingroup\$ 48 bytes \$\endgroup\$
    – ovs
    Aug 6 at 21:59
2
\$\begingroup\$

Vim +startinsert, 14 11 bytes

ol<C-v><C-r>"<C-o>ddL<C-r>"

Try it online!

In TIO, when the recursive register expansion (RRE) times out, nothing is outputted since it didn't finish expanding. In Vim, you may not see anything right away since the console might freeze during the RRE, but if you Ctrl+C, you can stop the expansion and see that it does work.

Explanation:

                              # '+startinsert' flag - start vim in insert mode; TIO equivalent is 'i' in the header
ol<C-v><C-r>"                 # Insert 'ol<C-r>"'
              <C-o>           # Run normal mode command, then return to insert mode:
                   dd         #   Delete 'ol<C-r>"' into unnamed register
                     L        # Insert 'L'
                      <C-r>"  # Insert unnamed register, which recursively expands to 'ol' + unnamed register
\$\endgroup\$
1
\$\begingroup\$

Raku, 14 chars, 16 bytes

Per standard rules, an infinite generator is acceptable.

{|<L ol>,~*…*}

Try it online!

Since this can be directly assigned or passed into other functions, the brackets aren't per se necessary but not sure if I can do that (if so, -2 chars/bytes). Enforcing the standard out bit is as simple as add a >>.print adds an extra 8 chars (22 chars, 24 bytes total).

(|<L ol>,~*…*)>>.print

Try it online!

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