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

2
\$\begingroup\$

Java, 198 179 155 bytes

import java.math.*;class a{void A(a[]x){for(BigInteger b=BigInteger.ZERO;!(b=b.add(BigInteger.ONE)).equals(BigInteger.TEN.pow(100));)System.out.print(x);}}

Prints (x == null ? null : a string that starts with [La;@ or something like that) 10100 times in O(forever) time.

\$\endgroup\$
8
  • 3
    \$\begingroup\$ You have a class, but no public static void main(String[]a) method. As for golfing tips: you can replace the new BigInteger("0"), new BigInteger("1") and new BigInteger("10") with BigInteger.ZERO, BigInteger.ONE and BigInteger.TEN; you can replace import java.math.BigInteger; with import java.math.*;. \$\endgroup\$ Oct 31, 2016 at 9:35
  • 1
    \$\begingroup\$ No need for imports: something similar to this should work: java.math.BigInteger b=null;for(b=b.ZERO;!(b=b.add(b.ONE)).equals(b.TEN.pow(100);)System.out.print(x); \$\endgroup\$ Oct 31, 2016 at 13:41
  • \$\begingroup\$ @OlivierGrégoire That gives me a NullReferenceException, possibly because b is null. \$\endgroup\$
    – Xanderhall
    Dec 7, 2016 at 13:23
  • \$\begingroup\$ @Xanderhall you probably tried this in C# (because you said NRE, not NPE). I can't test the Java version right now so I can't tell what's wrong. In any case, I said "should work", not "will work". The idea to take is that you can have static method calls on instance references, even null ones. \$\endgroup\$ Dec 9, 2016 at 12:00
  • \$\begingroup\$ @OlivierGrégoire I tried it in Java. I don't code in C#. \$\endgroup\$
    – Xanderhall
    Dec 9, 2016 at 13:05
2
\$\begingroup\$

Java, 153 bytes

import java.math.*;interface M{static void main(String[]a){for(BigInteger i=BigInteger.ZERO;!i.add(i.ONE).equals(i.TEN.pow(100));)System.out.print(1);}}

Output: 1e100 1s

I know there is another Java answer which is also pretty close. Mine's got a main and is still shorter though.

This is my first code-golf entry. Tips appreciated.

\$\endgroup\$
10
  • \$\begingroup\$ This can be golfed to 117 bytes by using lambda. You still need to include the import, however. import java.math.*;()->{for(BigInteger i=BigInteger.ZERO;!i.add(i.ONE).equals(i.TEN.pow(100));)System.out.print(1);}; \$\endgroup\$
    – Shaun Wild
    Nov 2, 2016 at 9:21
  • \$\begingroup\$ @BasicallyAlanTuring Actually my javac won't let me compile this. \$\endgroup\$
    – Niclas M
    Nov 2, 2016 at 19:48
  • \$\begingroup\$ Update your Java then. Also, this is not complete compilable code. Just the bare minimum allowed for an entry. \$\endgroup\$
    – Shaun Wild
    Nov 3, 2016 at 9:05
  • \$\begingroup\$ @BasicallyAlanTuring Got Java 8. I guess functions are not allowed by the OP. \$\endgroup\$
    – Niclas M
    Nov 3, 2016 at 9:25
  • \$\begingroup\$ The code I have given you is not a complete program.. It's just what's required to be a valid CG answer. \$\endgroup\$
    – Shaun Wild
    Nov 3, 2016 at 11:06
2
\$\begingroup\$

Pyth, 8 7 bytes

V^T100G

Link

Solution is tested with small output, but it should print abcdefghijklmnopqrstuvwxyz 1e100 times.

For some reason, the p was unneeded, as 31343 (Maltysen) said.

\$\endgroup\$
6
  • \$\begingroup\$ Why is the p needed? \$\endgroup\$
    – Maltysen
    Oct 30, 2016 at 3:26
  • \$\begingroup\$ @Maltysen I think because of the 4 GB limit. \$\endgroup\$ Oct 30, 2016 at 6:18
  • \$\begingroup\$ Why? Cuz of the buffer? Doesn't that automatically flush? \$\endgroup\$
    – Maltysen
    Oct 30, 2016 at 16:04
  • \$\begingroup\$ @Maltysen I don't know, the online interpreter does not have immediate output functionality. It might flush, it might not... \$\endgroup\$ Oct 30, 2016 at 16:08
  • \$\begingroup\$ Its working locally without the p \$\endgroup\$
    – Maltysen
    Nov 1, 2016 at 23:03
2
\$\begingroup\$

PHP, 39 38 bytes

for($a=str_pad(e,99,0);T^$a++;)echo!0;

Run like this:

php -r 'for($a=str_pad(e,99,0);T^$a++;)echo!0;' 2>/dev/null

STDERR (34 bytes)

If a variant with output to STDERR is valid, then this outputs PHP Notice: Use of undefined constant T - assumed 'T' in Command line code on line 1 a googol times.

php -r 'for($a=str_pad(@e,99,0);T^++$a;);'

Explanation

for (
    $a = str_pad("e", 99, "0"); // Creates a string "e000" (98 zeroes).
    "T" ^ $a++;                 // Increment the string, binary XOR with
                                // "T": when the alphabetic part of the 
                                // string becomes "da" this results in 
                                // falsy "0", ending the loop.
)
    echo!0;                     // Print a single "1".

Note that the alphabetic part iterates from e..z (22), aa..az (26), ba..bz (26), ca..cz (26) for a total of 100, or a 1 with 2 zeroes. So only 98 zeroes need to be added to arrive at 1E100. The loop stops only when the alphabetic part is 2 digits and the second digit becomes d. The d is conveniently skipped when it's only 1 digit (since it starts at e).

Perf

This doesn't consume a ridiculous amount of resources (in fact very little) and runs fast.

Tweaks

  • Saved a byte by using 2 alphabetic chars so less padding characters (99 vs 101)
  • Added a variant using STDERR, saving 5 bytes
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Your code must be within <?php tags, even if it is a pure .php file. However, in a PHP file, you can omit the closing ?> tag. Just saying. \$\endgroup\$
    – ckjbgames
    Jan 23, 2017 at 22:27
  • \$\begingroup\$ @ckjbgames wrong. Ever tried running code with php -r? In any case, here's the relevant discussion about that. \$\endgroup\$
    – aross
    Jan 24, 2017 at 8:49
  • \$\begingroup\$ You would need to if it was meant to be on a webpage. \$\endgroup\$
    – ckjbgames
    Jan 24, 2017 at 14:15
2
\$\begingroup\$

Perl 6, 18 bytes

say 1 for ^10**100

Notes:

  • Perl 6 integers have no upper limit, so 10**100 calculates the googol just fine.
  • The ^n syntax is short for 0 ..^ n, which constructs a range from 0 (inclusive) to n (not inclusive), which conceptually contains n integers but is stored as a memory-efficient Range object.
  • The for loop iterates over it without keeping already iterated elements in memory, so the program's RAM usage will remain pretty stable - and far below 4 GB - throughout its runtime.
\$\endgroup\$
0
2
\$\begingroup\$

Bash, 72 71 bytes

Prints 10^100 at signs.
Saved 1 byte thanks to @FlipTack.

printf '@%.0s' $(eval echo $(seq 1 $(echo 10^100 | bc | tr "\n" "\0"))) 

WARNING: This is probably extremely slow.


This is my first code golf, so I hope I did well.

\$\endgroup\$
2
  • \$\begingroup\$ I think you've misunderstood the question. You don't take the string to print as input, you can print any string you want a googol times, whatever string is shortest for you to print \$\endgroup\$
    – FlipTack
    Jan 23, 2017 at 22:54
  • \$\begingroup\$ @FlipTack Thanks! One byte saved. \$\endgroup\$
    – ckjbgames
    Jan 23, 2017 at 22:55
2
\$\begingroup\$

Chip, 3815+3 = 3818 bytes

+3 bytes for flag -w

 *
,xZ.
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
 K K
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
 K K
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
 K K
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
 K K
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
 K K
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
 K K
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
 K K
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
 K K
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<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
`@','
,xZ<
`@'|
,xZ<
`@'|
 K `K
,xZ~<
`@','
,xZ<
`@'|
,xZ<
`@'`.
,xZ~'
`@'

Try it online!

Oof.

It's a beeping massive binary counter: 333 bits are needed to express 1 googol, so there are 333 half-adders @ and 333 registers Z. (Actually only 100/log10(2) = ~332.2 bits are required, but this solution can't take advantage of those massive savings). There are also a few periodic caches K, which are required for this to even run correctly.

Note about the TIO: instead of using -w (which is a fake stdin consisting of infinite null bytes), it uses regular input. The result is that it terminates at the end of input, rather than attempting to outlive the universe by a factor of 1080.

The termination condition is encoded by the presence or absence of ~ near the Zs. If you worked from the bottom up, writing a '1' when you see a ~, and '0' when you don't, you'll have the binary representation for 1 googol.

Here is a TIO that only prints 100 times. This one does use -w, showing off the termination condition.

Also scattered around are *a, *e, and *f. These work together to produce an ASCII '1' for the output. If they were absent, null characters would be printed instead.

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

Brainfuck, 45 bytes

->-[[->+<]+>-]<[[>-<-[>[----->]]>[<]<].<[+]<]

It outputs 254×250255 null bytes and exits with an error.

Brainfuck, 50 48 bytes, without errors

>>>->-[[->+<]+>-]<[[>-<-[>[----->]]>[<]<]<[.+]<]

It outputs 254×250255 times \xfa\xfb\xfc\xfd\xfe\xff, and 1524×250255 bytes in total.

\$\endgroup\$
2
  • \$\begingroup\$ How the error, pointer <0? \$\endgroup\$
    – l4m2
    Dec 18, 2022 at 16:22
  • \$\begingroup\$ @l4m2 Yes. I think that's the only way to error in a controlled manner in Brainfuck. \$\endgroup\$
    – jimmy23013
    Jan 1, 2023 at 3:26
2
\$\begingroup\$

Zsh, 26 bytes

eval repeat\ a{0..99}+10 @

Try it online!

-2 thanks to @GammaFunction

  • repeat\ a{0..99}+10: construct the string repeat a0+10 repeat a1+10 ... repeat a99+10
    • a0 through a99 are undefined and are treated as 0, so a0+10 always evaluates to 10
  • append @
  • evaluate that string, which is 100 nested loops and then on each iteration we execute the command @, which doesn't exist, so it prints (eval):1: command not found: @

To be perfectly honest, I'm surprised the existing shell answers are so bad

\$\endgroup\$
1
  • \$\begingroup\$ You can remove the last escaped space for 26 bytes. \$\endgroup\$ Feb 7, 2021 at 3:33
2
\$\begingroup\$

Japt, 5 bytes

QpLpL

I used a similar approach found here. This program prints 10200 copies of the string ", or 10100 copies of the string containing 10100 copies of the string ". The output of the program would look something like this:

"""""""""""""""""""""""""""......about 1e200 copies later......"""""""""""""""""""""""""""

Try it online!

Explanation

QpLpL
Q     - The string consisting of " (quotation mark)
 p    - That string gets repeated some amount of times, specified on next line
  LpL - L is the number 100, and LpL does 100 to the power of 100, which is 1e200
\$\endgroup\$
2
\$\begingroup\$

Bash, 25 bytes

bc<<<'for(;i++<10^100;)9'

Try it online!

bc, 18 bytes

for(;++i<10^100;)9

Why is TIO broken so it won't work unless coding in header?

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ it's because bc expects a newline at the end of the file, add a newline in the footer to put the code in the Code section, also the bc version is one iteration short of a googol, here's a fix \$\endgroup\$
    – c--
    Jul 18, 2022 at 19:56
2
\$\begingroup\$

Stax, 6 bytes

╡¢xYΓU

Uncompressed and explained:

AJ|A          10^100
    D         For that many iterations
     1p       print 1

Run and debug it

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

MUMPS, 20 bytes

 f %=1:1:"1E100" w 1

Try it online!

  • There is a leading space so that f is interpreted as a command rather than a line label.
  • f %=1:1:"1E100" assigns 1 to the variable % and increments it by 1 on each loop until it reaches a googol. f is short for the for command. Numbers in scientific notation have to be written as strings in standard M, hence the quotes.
  • w 1 prints 1 and is executed once per loop. w is short for the write command.

This can be reduced to 18 bytes in GT.M where the quotes aren't necessary for 1E100 to be interpreted as a number.

 f %=1:1:1E100 w 1
\$\endgroup\$
2
\$\begingroup\$

Factor, 20 bytes

100 10^ [ bl ] times

Try it online!

  • 100 10^ [ ... ] times Call [ ... ] a googol times.
  • bl Output a space.
\$\endgroup\$
1
\$\begingroup\$

Common Lisp, 33

(dotimes(i(expt 10 100))(terpri))

Print newlines.

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

Swift 3, 55 bytes

Dependency: Foundation for pow(73 bytes if you count import statement)

stride(from:0,to:pow(10,100),by:1).map{_ in print(1)}

I know there is another answer above. However, pow(10,100.0) generates error message: fatal error: Double value cannot be converted to Int because the result would be greater than Int.max, and it also requires Foundation as well

\$\endgroup\$
1
  • 3
    \$\begingroup\$ Yes, necessary imports are always counted. \$\endgroup\$
    – cat
    Oct 30, 2016 at 21:08
1
\$\begingroup\$

Clojure, 36 bytes

(doseq[i(range(.pow 100M 50))](prn))

Using java interlop cuts it down from original (reduce *'(repeat 10 100)) since clojure core does not have exponent. dotimes can only work with longs as was pointed out in comment, sadly; I had to resort to lazy seq (+5 bytes).

\$\endgroup\$
4
  • \$\begingroup\$ dotimes requires long as a parameter doesn't it? \$\endgroup\$
    – cliffroot
    Oct 31, 2016 at 10:12
  • \$\begingroup\$ It works with any N that returns TRUE for (number? N), rounding or dropping fractions when needed. \$\endgroup\$
    – Michael M
    Oct 31, 2016 at 11:33
  • \$\begingroup\$ goo.gl/xjwj0e it casts it to long. it agrees with the results that I get when I try to run your code, it fails with IllegalArgumentException trying to cast that number to long \$\endgroup\$
    – cliffroot
    Oct 31, 2016 at 11:41
  • 1
    \$\begingroup\$ You are right, I had an overwritten core dotimes with some math package. I will edit with something that works in a moment. \$\endgroup\$
    – Michael M
    Oct 31, 2016 at 11:54
1
\$\begingroup\$

Common Lisp, 37 bytes

(loop repeat(expt 10 100)do(print'x))

Nothing fancy. Print X followed by newline 10^100 times.

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

Dip, 8 bytes

TT*T^(¹p

Prints googol newlines.

Explanation:

TT       # Pushes 10 twice
             # Stack: [10, 10]
  *      # Multiply 10 by 10
             # Stack: [100]
   T     # Push 10
             # Stack: [100, 10]
    ^    # Raise 10 to 100
             # Stack: [Googol]
     (   # Do Googol times
             # Stack: []
      ¹  # Push ""
             # Stack: [""]
       p # Print
             # Stack: []

Better version that puts to use some features released after this challenge: (4 bytes)

UX(q

Explanation:

U    # Push 100
         # Stack: [100]
 X   # Raise 10 to 100
         # Stack: [Googol]
  (  # Repeat Googol times
         # Stack: []
   q # Print a newline
         # Stack: []
\$\endgroup\$
1
\$\begingroup\$

LiveCode, 83 bytes

on g c
   if c=100 then
      put 1 after fld 1
   else
      repeat 10
         g c+1
      end repeat
   end if
end g

Logically pretty straightforward, but validated by changing the test value for c. Set it to 1, you get ten 1's. Set it to 2, you get 100. Set it to 3 you get 1,000, etc.

LiveCode automatically formats with leading spaces, but it's not required for the code to work.

The argument c will default to empty, and in LiveCode it's perfectly fine to add 1 to empty (and results in 1).

LiveCode can write to stdout, but it's a visual environment and putting text into a field is more common.

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

C# - 127 123 98 bytes

using System;using b=Numerics.BigInteger;void f(){for(b n=b.Pow(10,100);n-->0;)Console.Write(0);}}

Prints 10^100 copies of 0.

\$\endgroup\$
5
  • \$\begingroup\$ You can golf it by 1 byte by changing n>0;n-- to n-->0;. +1 for the rest. :) \$\endgroup\$ Oct 31, 2016 at 14:53
  • \$\begingroup\$ @KevinCruijssen I can also save bytes by turning this into a shorter function, since OP didn't mention "full program". Thanks! :) \$\endgroup\$
    – Yytsi
    Oct 31, 2016 at 17:07
  • \$\begingroup\$ Also you can change your using to using b= System.Numerics.BigInteger and use the alias in the rest of the code \$\endgroup\$
    – user19547
    Nov 3, 2016 at 22:13
  • \$\begingroup\$ This should work using System;using b=Numerics.BigInteger;void f(){for(b n=b.Pow(10,100);n-->0;)Console.Write(0);}} for 98 bytes. :) \$\endgroup\$
    – user19547
    Nov 3, 2016 at 22:23
  • \$\begingroup\$ @Phaeze Thanks! Haven't even edited the previous edit in yet, but will do today :) \$\endgroup\$
    – Yytsi
    Nov 4, 2016 at 4:46
1
\$\begingroup\$

Sed + bash, 107 bytes

sed "s/Z/\;done/g;s/\([A-L]\)/\1=n\;while((\1--))\;do /g"<<<"n=10;An=10**9;BCDEFGHIJKLpwdZZZZZZZZZZZZ"|bash

By removing the "|bash" at the end, you can see that the bash script generated (with newlines added for readability) is

n=10;A=n;while((A--));do n=10**9;B=n;while((B--));do C=n;while((C--));do
D=n;while((D--));do E=n;while((E--));do F=n;while((F--));do G=n;while((G--));do
H=n;while((H--));do I=n;while((I--));do J=n;while((J--));do K=n;while((K--));do
L=n;while((L--));do pwd;done;done;done;done;done;done;done;done;done;done;done;
done

which is similar to my original bash solution, below, except that it runs 11 loops of 10^9 nested in one loop of 10, for a total of 10^100 iterations. It never uses a value greater than 10^9, which fits in 32 bits. Each output line is generated with the shell builtin "pwd" instead of "echo", to save a byte.

Tested by changing 10**9 to "2" or "3" and verifying that the script generates 10 * N^11 lines.

Bash, 312 bytes

n=2*10**9
a=9765625;while((a--));do
b=n;while((b--));do c=n;while((c--));do d=n;while((d--));do e=n;while((e--));do
f=n;while((f--));do g=n;while((g--));do h=n;while((h--));do i=n;while((i--));do
j=n;while((j--));do k=n;while((k--));do echo "Hello, World!"
done;done;done;done;done;done;done;done;done;done;done

(2*10^9)^10 * 9765725 is exactly one googol.

This needs no memory because it doesn't store anything other than the 11 counters and one copy of the "Hello, World!" string. The counters are integers that never exceed 32 bits.

Unfortunately I couldn't find a way to do this with a recursive function.

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

LOLCODE, 224 bytes

HAI 1.2
I HAS A n ITZ A NUMBR
n R 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
IM IN YR loop UPPIN YR v TIL BOTH SAEM v AN n
BTW THIS WHERE I PRINT
VISIBLE "HAI!!1"
IM OUTTA YR loop
KTHXBYE

I had absolutely no idea how to calculate 10100, so why not just write it out? Apparently, there's no ^ operator or power function in LOLCODE.

I didn't count the bytes for the BTW part, since it's a comment for explaining the code. "explain"

Also, my ressource didn't quite explain how datatypes work in-depth, so we can only assume that NUMBR can store this much.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Try I HAS A b ITZ A NUMBR b R 10 I HAS A n ITZ A NUMBR n R PRODUKT OF b AN PRODUKT OF b AN n instead of using n R 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000. \$\endgroup\$
    – ckjbgames
    Jan 23, 2017 at 22:23
1
\$\begingroup\$

Pushy, 5 bytes

Non-competing as the language postdates the challenge.

THe:"

Prints 10100 newlines. You can Try it online, but output is truncated at 100KB, and the site becomes very unresponsive when you run it.

T      \ Push 10
 H     \ Push 100
  e    \ Exponentiate - pops both and computes 10 ^ 100
   :   \ Pop the googol and that many times do:
    "  \   Print the whole stack - just a newline, as it's now empty.

You can verify this generates a googol by running THe# in the online interpreter. The reference implementation is in Python and therefore has no upper limit on integer size. The googol itself does not take too much data to store, in fact you only need 333 bits to store an integer of that size (although as Python integer this seems to take up 58 bytes) - nowhere near the memory restriction on this challenge.

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

Actually, 9 bytes

2╤╤DW;Y.D

Try it online!

This takes a really long time to run. Here is a faster version that only prints 100 zeroes.

Explanation:

2╤╤DW;Y.D
2╤╤         push 10**(10**2)
   D        subtract 1
    W       while the value on top of the stack is truthy:
     ;Y.      duplicate it, boolean negate it (0 if truthy, 1 if falsey), pop it and print it
        D     decrement the other copy
            (after the while loop finished, (10**100)-1 zeroes will have been printed, separated by newlines)
            implicitly print the only stack value (0), followed by a newline
\$\endgroup\$
4
  • \$\begingroup\$ Does this fit within the memory requirements of the challenge? sys.getsizeof(1) returns 28, and so storing a googol copies of 1 would take 2.8 × 10^89 TB, but the challenge restricts memory to 4GB. I may be wrong though, I don't know how Actually is interpreted. \$\endgroup\$
    – FlipTack
    Jan 23, 2017 at 22:57
  • \$\begingroup\$ @FlipTack In Python (the language that Actually is written in), small integers (under 256, I believe) are not unique objects - there is only ever one 1. Thus, this program just contains a googol references to 1, which are much smaller than the actual object. I don't know the memory impact of multiple references to 1, though, so it may still violate the memory limit. I'll change it to something that definitely doesn't run afoul. \$\endgroup\$
    – user45941
    Jan 23, 2017 at 23:01
  • \$\begingroup\$ I don't think storing a googol of anything is possible, whether it be integers or references. Even just storing a googol bits needs 1.25 × 1087 terabytes. So the new solution seems more sensible. \$\endgroup\$
    – FlipTack
    Jan 25, 2017 at 21:03
  • \$\begingroup\$ I meant 1.25 x 10^87 (missed the exponent) \$\endgroup\$
    – FlipTack
    Jan 26, 2017 at 10:29
1
\$\begingroup\$

TrumpScript 189 bytes

I is 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000A is,I -I;We is 1000001 -1000000as long as,I >A;:say,A;I is,I -We;!America is great

Try it online!

Unfortunately 100 bytes taken up by the number as TrumpScript has no exponentials

Explanation

I is googol (using googol for clarity) sets the variable I to 10^100

A is I -I sets A to 0. 0 in the code as a number is invalid as all number must be > 1000000

We is 1000001 -1000000 assigns we as 1

as long as, I > A;: starts while loop checking that I > 0

say A prints out 0

I is,I -We subtracts 1 from I

America is great ends the program

\$\endgroup\$
1
  • 2
    \$\begingroup\$ You could use multiplication. \$\endgroup\$
    – ckjbgames
    Jan 24, 2017 at 1:52
1
\$\begingroup\$

SmileBASIC, 20 bytes

FOR I=1TO 1E100?NEXT
\$\endgroup\$
1
\$\begingroup\$

.COM, 21 bytes

0000h: 83 FC 9A 74 0B B9 10 27 51 E8 F4 FF 59 E2 F9 C3
0010h: B4 02 CD 21 C3                                 

    org 100h
f:  cmp sp, -2-4*25
    jz g
    mov cx, 10000
r:  push cx
    call f
    pop cx
    loop r
    ret
g:  mov ah, 2
    int 33
    ret       
\$\endgroup\$
1
\$\begingroup\$

HadesLang, 3153 bytes

I know this is really bad...but at least I tried, right?

for[num a in range:[0,99]]
for[num b in range:[0,99]]
for[num c in range:[0,99]]
for[num d in range:[0,99]]
for[num e in range:[0,99]]
for[num f in range:[0,99]]
for[num g in range:[0,99]]
for[num h in range:[0,99]]
for[num i in range:[0,99]]
for[num j in range:[0,99]]
for[num k in range:[0,99]]
for[num l in range:[0,99]]
for[num m in range:[0,99]]
for[num n in range:[0,99]]
for[num o in range:[0,99]]
for[num p in range:[0,99]]
for[num q in range:[0,99]]
for[num r in range:[0,99]]
for[num s in range:[0,99]]
for[num t in range:[0,99]]
for[num u in range:[0,99]]
for[num v in range:[0,99]]
for[num w in range:[0,99]]
for[num x in range:[0,99]]
for[num y in range:[0,99]]
for[num z in range:[0,99]]
for[num A in range:[0,99]]
for[num B in range:[0,99]]
for[num C in range:[0,99]]
for[num D in range:[0,99]]
for[num E in range:[0,99]]
for[num F in range:[0,99]]
for[num G in range:[0,99]]
for[num H in range:[0,99]]
for[num I in range:[0,99]]
for[num J in range:[0,99]]
for[num K in range:[0,99]]
for[num L in range:[0,99]]
for[num M in range:[0,99]]
for[num N in range:[0,99]]
for[num O in range:[0,99]]
for[num P in range:[0,99]]
for[num Q in range:[0,99]]
for[num R in range:[0,99]]
for[num S in range:[0,99]]
for[num T in range:[0,99]]
for[num U in range:[0,99]]
for[num V in range:[0,99]]
for[num W in range:[0,99]]
for[num X in range:[0,99]]
for[num Y in range:[0,99]]
for[num Z in range:[0,99]]
for[num aa in range:[0,99]]
for[num ba in range:[0,99]]
for[num ca in range:[0,99]]
for[num da in range:[0,99]]
for[num ea in range:[0,99]]
for[num fa in range:[0,99]]
for[num ga in range:[0,99]]
for[num ha in range:[0,99]]
for[num ia in range:[0,99]]
for[num ja in range:[0,99]]
for[num ka in range:[0,99]]
for[num la in range:[0,99]]
for[num ma in range:[0,99]]
for[num na in range:[0,99]]
for[num oa in range:[0,99]]
for[num pa in range:[0,99]]
for[num qa in range:[0,99]]
for[num ra in range:[0,99]]
for[num sa in range:[0,99]]
for[num ta in range:[0,99]]
for[num ua in range:[0,99]]
for[num va in range:[0,99]]
for[num wa in range:[0,99]]
for[num xa in range:[0,99]]
for[num ya in range:[0,99]]
for[num za in range:[0,99]]
for[num Aa in range:[0,99]]
for[num Ba in range:[0,99]]
for[num Ca in range:[0,99]]
for[num Da in range:[0,99]]
for[num Ea in range:[0,99]]
for[num Fa in range:[0,99]]
for[num Ga in range:[0,99]]
for[num Ha in range:[0,99]]
for[num Ia in range:[0,99]]
for[num Ja in range:[0,99]]
for[num Ka in range:[0,99]]
for[num La in range:[0,99]]
for[num Ma in range:[0,99]]
for[num Na in range:[0,99]]
for[num Oa in range:[0,99]]
for[num Pa in range:[0,99]]
for[num Qa in range:[0,99]]
for[num Ra in range:[0,99]]
for[num Sa in range:[0,99]]
for[num Ta in range:[0,99]]
for[num Ua in range:[0,99]]
for[num Va in range:[0,99]]
out:1
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
\$\endgroup\$
3
  • \$\begingroup\$ What is that supposed to be. Do you really need so many for loops. Also if possible provide a link so this can be tested / \$\endgroup\$ Jun 1, 2018 at 13:59
  • \$\begingroup\$ @Muhammad Salman Because Hades doesn't have a datatype for BigInts yet. Unfortunatly I can't provide a link to test this :/ \$\endgroup\$
    – Azeros
    Jun 1, 2018 at 14:02
  • \$\begingroup\$ Is the language stable and has it been released ? If it is you should probably have it added to TIO. Will make it a lot easier for link providing. \$\endgroup\$ Jun 1, 2018 at 14:10
1
\$\begingroup\$

05AB1E, 4 bytes

т°F,

Prints \$10^{100}\$ copies of 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n.

(Don't) try it online.

Explanation:

т     # Push 100
 °    # Pop and push 10^100
  F   # Loop that many times:
   ,  #  And print the top of the stack with trailing newline;
      #  (because the stack and input are both empty, it uses the previous value, which
      #   was the 10^100)

Note: the existing 05AB1E answer uses the legacy version of 05AB1E. In that answer, the Tn could be т to push 100 now as well, but the , won't use the previous value implicitly. (The old version of 05AB1E was built in Python 3, the new version in Elixir.)

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