73
\$\begingroup\$

I am interested in seeing programs which don't ask for any input, print a googol copies of some nonempty string, no less, no more, and then stop. A googol is defined as \$10^{100}\$, i.e., 1 followed by a hundred 0's in decimal.

Example output:

111111111111111111111111111111111111111111111111111111111111111111111111...

or

Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
...

The string can also be entirely composed of white space or special symbols. The only exception to identical copies of a fixed string is if your language decorates the output in some way that can not be prevented, but could be trivially undone in a wrapper script, like prepending a line number to each line. The wrapper script in such cases need not be provided.

You can assume your computer will never run out of time, but other than that, your program must have a reasonable demand of resources. Also, you must respect any restrictions that the programming language of your choice poses, for example, you can not exceed a maximum value allowed for its integer types, and at no point more than 4 GB of memory must be needed.

In other words, the program should in principle be testable by running it on your computer. But because of the extent of this number you will be expected to prove that the number of copies of the string it outputs is exactly 10^100 and that the program stops afterwards. Stopping can be exiting or halting or even terminating due to an error, but if so, the error must not produce any output that could not easily be separated from the program's output.

This is , so the solution with the fewest bytes wins.

Example solution (C, ungolfed, 3768 bytes)

#include <stdio.h>

int main() {
  int a00, a01, a02, a03, ..., a99;
  for(a00 = 0; a00 < 10; a00++)
  for(a01 = 0; a01 < 10; a01++)
  for(a02 = 0; a02 < 10; a02++)
  for(a03 = 0; a03 < 10; a03++)
  ...
  for(a99 = 0; a99 < 10; a99++)
    puts("1");
  return 0;
}
\$\endgroup\$
21
  • 11
    \$\begingroup\$ Consider the sandbox first next time. \$\endgroup\$
    – cat
    Oct 29, 2016 at 18:44
  • 10
    \$\begingroup\$ When you post a new question, you are asked to first post it in the sandbox. \$\endgroup\$
    – flawr
    Oct 29, 2016 at 18:48
  • 1
    \$\begingroup\$ @KritixiLithos It was toying with that idea but I could not quickly come up with a sample solution. Feel free to make a sequel :-) \$\endgroup\$
    – The Vee
    Oct 29, 2016 at 19:16
  • 3
    \$\begingroup\$ @closevoter Are you sure this is too broad? Common sense automatically narrows this down from "print a nonempty string 10^100 times" to "print a character 10^100 times". \$\endgroup\$
    – SE is dead
    Oct 29, 2016 at 23:47
  • 4
    \$\begingroup\$ TIL Googol-1 in Roman numerals \$\endgroup\$
    – mbomb007
    Oct 31, 2016 at 18:36

85 Answers 85

1 2
3
1
\$\begingroup\$

Arturo, 32 bytes

i:10^100while[i>0][dec'i 0print]

Prints the number 0 with a newline a googol times.

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

Rust, 114 bytes

||{let i=0..10u128.pow(25);let f=|_|i.clone();for _ in i.clone().flat_map(f).flat_map(f).flat_map(f){print!("h")}}

Try it online!

Not bad for a language without built-in arbitrary precision integers. The code creates a lazily evaluated iterator 10^100 elements long and then prints h for every element in it.

||{                         // Anonymous function block
  let i=0..10u128.pow(25);  // declare i as the exclusive range from 0 to 10^25
  let f=|_|i.clone();       // anonymous function that ignores input and ouptputs i
  for _ in i.clone()        // for every value in i
            .flat_map(f)    // map every element with the function f, then flatten
            .flat_map(f)    // map again
            .flat_map(f){   // map one more time
    print!("h")             // print h
  }                         // end for loop
}                           // end fn
\$\endgroup\$
1
\$\begingroup\$

Fig, \$11\log_{256}(96)\approx\$ 9.054 bytes

Rt@100mC',1

Try it online!

This is really impractical in Fig, as it has no explicit for loops (only an infinite while loop). I had to use a reduce as a map would eventually calculate the entire list and will make the computer run out of memory.

Rt@100mC',1
      mC    # The list of numbers
 t          # (Lazily) take
  @100      # 10^100 of them
R       '   # Reduce the list of a googol items
         ,1 # Ignore the reducing and print a 1
\$\endgroup\$
2
  • 1
    \$\begingroup\$ you really need a two-byte constant for 100. \$\endgroup\$
    – naffetS
    Oct 18, 2022 at 17:48
  • \$\begingroup\$ @Sʨɠɠan there is :P Except @@2 doesnt really parse \$\endgroup\$
    – Seggan
    Oct 18, 2022 at 19:48
1
\$\begingroup\$

C (gcc), 44 bytes

f(n){n?f(--n),f(n-n%9):puts(f);}g(){f(900);}

Try it online!

C (gcc), 45 bytes

f(n){n?f(--n),f(n/9*9):puts("");}g(){f(900);}

Try it online!

tio showed f call for 10, 100 and 1000

JavaScript (V8), 36 bytes

f=(n=900)=>n?f(--n)|f(n-n%9):print()

Try it online!

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

ForceLang, 58 bytes

set k 10.pow 100
label a
set k k+-1
io.write 1
if k
goto a
\$\endgroup\$
0
\$\begingroup\$

Python 2, 35 bytes

Under more realistic programming circumstances, Python allows you to multiply strings by a number, as with 'x' * 100, which would produce a string that's a hundred characters long and composed of nothing but the letter x.

However, it appears that Python string objects don't appreciate having indices whose values exceed the maximum of int. Python is content to re-cast large int values to a special bignum sort of thing, but the longest string that Python can handle is on the order of several gigabytes, and assuming each character in Python is 1 byte, it would take much, much more memory to contain the string that would unfold from 'x'*10**100.

As such, Python's built-in arbitrary arithmetic and the humble while loop allow us to produce a more practical program, which spits out one x per line for a googol lines. Thankfully, this proves to be shorter than the admittedly more readable for x in xrange(10**100):, as range() and xrange() are both limited to the largest possible value for a C long type, which is Python's native non-bignum int.

i=0
while i<10**100:
    print'x';i+=1
\$\endgroup\$
3
  • 1
    \$\begingroup\$ i=10**100 newline while i:print;i-=1 prints googol newlines and is 7 bytes shorter \$\endgroup\$
    – FlipTack
    Oct 30, 2016 at 11:03
  • \$\begingroup\$ It's also am exact copy of someone else's solution, so I'll leave it as is. \$\endgroup\$ Oct 30, 2016 at 12:32
  • \$\begingroup\$ If I'm right, it's an exact copy of @FlipTack program. \$\endgroup\$
    – user63571
    Jan 23, 2017 at 23:39
0
\$\begingroup\$

Charcoal, 9 bytes

Note that Charcoal uses a custom codepage.

FX¹⁰¦¹⁰⁰D

Prints one googol newlines. Takes around 3.16887646×10⁹⁰ years to finish running.

Explanation

F        For
 X       Exponentiate
  ¹⁰¦¹⁰⁰  10, 100
D        Print (Dump) contents of canvas ("") plus newline

This will not freeze your computer (luckily!) because Charcoal has a 10ms minimum delay between prints by default. Charcoal used range as of this challenge's posting, therefore using more than 4GB of memory, but this has been fixed.

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

PHP7 (64-bit), 36 bytes

<?=bcsub(bcpow(10,bcpow(10,100)),1);

Should output 10^(10^100)-1 so 10^100 times the digit 9.

As of PHP 7.0.0, there are no particular restrictions regarding the length of a string on 64-bit builds. Source

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I don't think there's enough RAM in the entire universe to complete this operation. I tried with only 1e10 and it stopped after it had allocated 5 GB and then tried to allocate 18.4 exabytes. I gave it 10GB, so I was a bit short :) \$\endgroup\$
    – aross
    Nov 1, 2016 at 10:15
0
\$\begingroup\$

05AB1E, 8 bytes

TTT*mFõ,

Prints googol newlines.

Try it online! (Not recommended)

Explanation:

TTT      # Push 10 three times
             # Stack: [10, 10, 10]
   *     # Multiply 10 by 10
             # Stack: [10, 100]
    m    # Raise 10 to 100
             # Stack: [Googol]
     F   # Do Googol times
             # Stack: []
      õ  # Push ""
             # Stack: [""]
       , # Print
             # Stack: []
\$\endgroup\$
1
  • \$\begingroup\$ Not recommended? More like won't run. \$\endgroup\$ Jan 23, 2017 at 17:46
0
\$\begingroup\$

VBA 117 bytes

Sub q():Dim x(100):While x(100)=0:Debug.Print:x(0)=x(0)+1:i=0:While x(i)>9:x(i)=0:i=i+1:x(i)=x(i)+1:Wend:Wend:End Sub

Invoke with q. Prints a googol newlines to immediate window. Easy to test by changing the "While x(100)" to say "While x(2)", which prints a hundred newlines.

I could use "MsgBox 0" in place of "Debug.Print" (saving 3 characters) but that would involve pressing return on the output more times than feasible, countering the whole idea of "program".

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

Groovy, 31 bytes

{Eval.me(it*"1${'0'*10**100}")}

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

cQuents, 11 bytes

"#10^100::0

Given enough time (and memory, although it times out on TIO instead of running out of output space), will print 10^100 copies of whatever is to the right of 0.

Explanation

"             No join on output
 #10^100      Set n to 10^100
        ::    Print the sequence from 1 to n
          0   Each item in the sequence is 0

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Note current version uses & instead of ::, saving 1 byte \$\endgroup\$
    – Stephen
    Feb 1, 2019 at 4:54
0
\$\begingroup\$

BRASCA, 8 bytes

lH^[ho{]

Try it online! I'm using TIO for this one instead of the JS-based online interpreter cause Python numbers. I recommend running it locally.

Explanation

lH^       - Push 10^100
   [   ]  - While not zero:
    ho{   -   Print codepoint 97 (a) and decrement the counter
\$\endgroup\$
0
\$\begingroup\$

Kotlin, 72 bytes

import kotlin.math.*;fun main()=repeat(2.0.pow(3).toInt()){_->println()}

Ungolfed

import kotlin.math.*;

fun main() =
  repeat(2.0.pow(3).toInt()) { _ -> println() }
\$\endgroup\$
0
\$\begingroup\$

Perl 5 -Mbigint, 32 bytes

$i=0;say while 10**100>($i=$i+1)

Try it online!

Perl's bigint module allows for integers to be of arbitrary size. It also overloads all of the math operators so that literal integers become bigints. Therefore, this satisfies the constraints of the challenge: it outputs one googol newlines, it does not exceed a reasonable amount of memory as it does not actually store a googol entries of any sort, and it will stop when $i reaches 1 googol.

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

JavaScript, 35 bytes

BigInts ftw

i=10n**100n;while(i--)console.log()
\$\endgroup\$
0
\$\begingroup\$

Julia 1.0, 30 bytes

for i=1:big(10)^100 show(1)end

Try it online!

with BigInts, no problem calculating \$10^{100}\$

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

TI-Basic, 72 bytes

102→dim(ʟA
Repeat ʟA(102
Disp 1
10→ʟA(1
For I,1,101
If 9<ʟA(I
1+ʟA(I+1→ʟA(I+1
End
ʟA not(ʟA>9→A
End

Explanation:

The list ʟA stores a base-10 101-digit number (from indices 2 to 102). 10 is put in ʟA(1) so that ʟA(2), the last digit of the number, is incremented. We search all 10s in the number to increment the next digit, and then remove them all with the line ʟA*not(ʟA>9)→A. We print a 1 each step, and stop when there is a non-zero in ʟA(102), meaning we reached \$10^{100}\$

there is a shorter TI-Basic answer but it won't work due to the limited precision of big numbers (which are floats)

TI-83 online emulator

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

Pyt, 5 bytes

2ᴇᴇɬ*

Try it online!

2ᴇᴇ     pushes 10^100
   ɬ*   pushes "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", and repeats it a
        total of 10^100 times; implicit print
\$\endgroup\$
0
\$\begingroup\$

GolfScript, 14 bytes

:n;10..*?{1p}*

Try it online!

Explanation

:n;10..*?{1p}*

:n;            # redefine (n)ewline as nothing (supresses the newline in 'p')
   10..*?    * # 10^100 times..
         {1p}  # print 1
\$\endgroup\$
0
\$\begingroup\$

Thunno, \$ 9 \log_{256}(96) \approx \$ 7.41 bytes

10aS^{1ZL

Attempt This Online! Prints a googol 1s.

Factoid

The 10aS can be replaced with any of the following:

  • 10Z2
  • aAaS
  • aAZ2
  • Z1aS
  • Z1Z2

Explanation

Just multiplying a googol with a string won't work because of memory limits: Attempt This Online!

So, we have to print each character separately:

10         # Push 10, or
aA         # Push 10, or
Z1         # Push 10

  aS       # Push 100, or
  Z2       # Push 100

    ^      # Push 10 ** 100

     {     # Loop that many times:

      1ZL  #  Print 1
\$\endgroup\$
0
\$\begingroup\$

Itr, 9 bytes

10ä²^Må1£

prints googol 1s

online interpreter

The online interpreter will stop after the first 10000 characters of the program output

Explantion

10ä²^Må1£
10        ; literal 10
  ä       ; duplicate
   ²      ; square -> 100
    ^     ; power: gives 10^100
     Må   ; for all elements of the 1-based range, discarding the index
       1£ ; print one
\$\endgroup\$
0
\$\begingroup\$

J, 9 bytes

echo~!!6x

Attempt (smaller version of) This Online!

Mildly surprised that no one has thought of using factorial here so far. Googol divides 405!, so n! copies of a string where n ≥ 405 is a googol copies of some much longer string. (For the sake of a 404 joke, googol does not divide 404!.)

!!6x evaluates to 720!, and then echo~ prints the value of 720! followed by newline 720! times. echo is defined to be 0 0 $ 1!:2&2, so echo~ x evaluates like this:

echo~ x
x echo x
x (0 0 $ 1!:2&2) x
0 0 $ x 1!:2&2 x
0 0 $ (iterate 1!:2&2 x times on x)

1!:2&2 prints its argument with newline and returns it unchanged, so echo~ x prints x plus newline x times.

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

Piet + ascii-piet, 40 bytes (7×13=91 codels)

tliumliusabdNt?fqasjfceqtMtL?E?Ukl?_ti ?

Try Piet online! (10 instead of googol)

The horizontal path pushes a googol, and then the vertical loop prints 3 that many times.

  • A1 .. A6: 3 dup * 1 + push 10
  • A6 .. A13 .. B13 .. B5: dup * dup * dup dup * dup * dup * dup dup * * * push the 100th power of that
  • B5 .. B3: 1 CC+ set up the IP so that when it enters the size-3 block again, it bounces off on the right side
  • C1 .. C2 .. G2 .. G1 .. F1: 3 outN 1 - dup ! DP+ print 3, decrement the counter, test if it is zero and turn right to exit (F4 .. G4)
\$\endgroup\$
0
\$\begingroup\$

Befunge-98 (PyFunge), 22 20 bytes

'cka'bk*1#;_@#:-1.0;

Explanation

# Construct googol
'c                   Push 99
  ka                 Iterate "push 10" 99 times, then pushes it again
    'b               Push 98
      k*             Iterate "multiply" 98 times, then once more (10^100)
        1#           Push 1, jump into print loop with 1 and googol as top two of stack
# Print loop (goes RTL after first encountering _ with 1 on the stack)
          ;        ; 
                 .0  Prints 0
               -1    Decrement iterator
           _@#:      Exit if iterator is 0

Try it online!

Befunge-98 (theoretical), 13 bytes

'cka'bk*1-k.@

Explanation

'cka'bk*       Construct googol as above
        1-     Subtract 1 (TOS is 10^100 - 1)
          k.@  Iterate "print TOS" (0) 10^100 - 1 times, then once more, then exit.

Unfortunately this solution doesn't work for PyFunge because the number is too big to iterate with, and I think the number is just too big to store at all for FBBI.

\$\endgroup\$
1 2
3

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.