63
\$\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\$
  • 10
    \$\begingroup\$ Consider the sandbox first next time. \$\endgroup\$ – cat Oct 29 '16 at 18:44
  • 9
    \$\begingroup\$ When you post a new question, you are asked to first post it in the sandbox. \$\endgroup\$ – flawr Oct 29 '16 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 '16 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\$ – dorukayhan Oct 29 '16 at 23:47
  • 3
    \$\begingroup\$ TIL Googol-1 in Roman numerals \$\endgroup\$ – mbomb007 Oct 31 '16 at 18:36

58 Answers 58

34
\$\begingroup\$

Jelly, 6 4 bytes

³Ȯ*¡

This is a niladic link (function w/o arguments) that prints 10200 copies of the string 100, meaning that it prints 10100 copies of the string that consists of 10100 copies of the string 100.

Try it online!

Note that the online interpreter cuts the output at 100 KB for practical reasons. The code also works as a full program, but due to implicit output, that program prints one copy too many.

How it works

³Ȯ*¡  Niladic link. No arguments.

³     Set the left argument and initial return value to 100.
 Ȯ    Print the current return value.
  *   Compute 100 ** 100 = 1e200.
   ¡  Call Ȯ 1e200 times. 
\$\endgroup\$
  • 3
    \$\begingroup\$ Well... Wow... Printing 10^100 copies of the original output (10^100 copies of a string) is taking it a little far, even for two whole bytes. Have you submitted this to the "score is output / program-length, highest wins" challenge yet? \$\endgroup\$ – wizzwizz4 Oct 31 '16 at 17:30
  • 1
    \$\begingroup\$ Not sure which challenge you're referring to (we had a few of this type), but 3e200 probably isn't competitive anyway. \$\endgroup\$ – Dennis Oct 31 '16 at 18:26
  • 2
    \$\begingroup\$ @wizzwizz4 If you can express your number in standard notation it's probably waaay too small. \$\endgroup\$ – orlp Oct 31 '16 at 21:46
  • 1
    \$\begingroup\$ "Fall over" = fail/crash \$\endgroup\$ – Loren Pechtel Nov 1 '16 at 3:25
  • 4
    \$\begingroup\$ @LorenPechtel Jelly is implemented in Python, which handles 665-bit integers with ease. \$\endgroup\$ – Dennis Nov 1 '16 at 3:44
60
\$\begingroup\$

Fuzzy Octo Guacamole, 13 12 11 10 bytes

9+ddpp![g] 

Explanation:

9+ddpp![g]
9+           # push 9 and increment, giving 10
  dd         # duplicate, twice. now you have [10,10,10]
    pp       # raise a 10 to the 10th power, then raise that to the 10th again. That ends up being 10^100.
      ![ ]   # for loop, `!` sets the counter to the top of stack
        g    # prints an ASCII art goat. 

Sample of the goat printed:

                  ___.
                 //  \\
                ((   ""
                 \\__,
                /6 (%)\,
               (__/:";,;\--____----_
                ;; :";,:";`;,";,;";`,`_
                  ;:,;;";";,;":,";";,-Y\
                   ;,;,;";";,;":;";"; Z/
                   / ;,";";,;";,;";;"
                  / / |";/~~~~~\";;"
                 ( K  | |      || |
                  \_\ | |      || |
                   \Z | |      || |
                      L_|      LL_|
                      LW/      LLW/
\$\endgroup\$
  • 2
    \$\begingroup\$ It took me a while to understand the head of the goat. It's not easily recognizable. \$\endgroup\$ – mbomb007 Oct 31 '16 at 17:14
  • \$\begingroup\$ The gaot gave me the ASCII art, ask him about it. \$\endgroup\$ – Rɪᴋᴇʀ Oct 31 '16 at 17:14
  • 9
    \$\begingroup\$ I have no idea what you are talking about. +1. \$\endgroup\$ – djechlin Oct 31 '16 at 21:56
  • 15
    \$\begingroup\$ @djechlin Downgoat asked me to add a builtin for printing a goat. I obliged. \$\endgroup\$ – Rɪᴋᴇʀ Nov 1 '16 at 0:24
21
\$\begingroup\$

Python, 28 bytes

-1 byte thanks to Jonathan Allan!

Python 2:

i=10**100
while i:print;i-=1

Python 3 (30 bytes):

i=10**100
while i:print();i-=1
\$\endgroup\$
  • 2
    \$\begingroup\$ i=10**100 newline while i:print();i-=1 saves a byte. Save two more by using Python 2 with while i:print;i-=1 \$\endgroup\$ – Jonathan Allan Oct 29 '16 at 19:40
  • \$\begingroup\$ @JonathanAllan thanks for the -1 byte. As for the Python 2 solution, I'll leave that for you to post :) \$\endgroup\$ – FlipTack Oct 29 '16 at 19:55
  • \$\begingroup\$ Nice first answer! :) \$\endgroup\$ – Daniel Oct 30 '16 at 14:27
  • \$\begingroup\$ Can Python actually store 10 to the 100 in an integer? \$\endgroup\$ – Arturo Torres Sánchez Oct 31 '16 at 6:42
  • 7
    \$\begingroup\$ @ArturoTorresSánchez yep, there's no upper limit on int size in python :) \$\endgroup\$ – FlipTack Oct 31 '16 at 6:47
18
\$\begingroup\$

Haskell, 28 bytes

main=putStr$[1..10^100]>>"1"

Concatenates 10^100 copies of the string "1" and prints it.

\$\endgroup\$
  • \$\begingroup\$ Is the string concatenation done before the printing starts? If so I would think this breaks the rule about "no more than 4 GB of memory"... \$\endgroup\$ – daniero Oct 30 '16 at 12:39
  • 8
    \$\begingroup\$ @daniero: thanks to Haskell's laziness printing starts immediately. On my computer the program needs less than 2MB memory (including the run time system RTS). \$\endgroup\$ – nimi Oct 30 '16 at 16:17
  • \$\begingroup\$ Is s=[1..10^100]>>"1" an allowed answer format? \$\endgroup\$ – immibis Oct 31 '16 at 23:46
  • \$\begingroup\$ Infinite integers? Otherwise it falls over on 10^100 \$\endgroup\$ – Loren Pechtel Nov 1 '16 at 0:15
  • \$\begingroup\$ @immibis: the challenge says "print", which usually means "print to stdout". s from your example doesn't print - or if you use the REPL surrounds the 1 with ". I guess just putStr$[1..10^100]>>"1" without the main= would be fine, but I wanted to submit a full program. \$\endgroup\$ – nimi Nov 1 '16 at 0:20
17
\$\begingroup\$

Brainfuck, 480 188 114 106 98 bytes

Just because it needs to be done.

Assumes 8-bit cells with wrapping. Prints 250255 NUL bytes, which is 10100 times 10155 times 25255 NUL bytes.

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

Explanation:

>>>>>> is needed to leave a bit of working space.

- produces 255.

[[->>>+<<<]------>>>-] turns this into 255 copies of the value 250, giving a tape that looks like:

0 0 0 0 0 0 250 0 0 250 0 0 ... 250 0 0 [0]

<<<[<<<]+ moves the data pointer back and finishes up the initial data:

0 0 0 [1] 0 0 250 0 0 250 0 0 ...

Then comes the loop: [+...-] initially sets the 1 to a 2, which gets set back to 1 at the end of the loop. The loop terminates when the loop body already set 2 to 1.

Now, the numbers 2 250 250 250 ... 250 represent a counter, in base 250, with each number one greater than the digit it represents.

  • [>>>]<<< moves all the way to the right. Since each digit is represented by a non-zero number, this is trivial.

  • ->+[<[+>-]>[-<<<<->+>>------>>]<<<<]>>- decreases the counter by 1. Starting with the last digit: the digit gets decremented. If it remains positive, we're done. If it turns to zero, set it to 250, and continue with the digit before.

  • [<<<].>>> moves the pointer back before the left-most digit, and this is a nice moment to print a NUL byte. Then re-position to exactly the left-most digit, to see if we're done.

To verify correctness, change the initial - to + to print 2501 NUL bytes, ++ for 2502, etc.

\$\endgroup\$
16
\$\begingroup\$

C, 51 bytes

Function g() calls recursive function f() to depth 99.

Excludes unnecessary newline added between f() and g() for clarity.

f(n,i){for(i=10;i--;)n?f(n-1):puts("");}
g(){f(99);}

//call like this
main(){g();}

Prints 1E100 newlines.

Declaration of i as second parameter of f() not guaranteed to work in all versions of C. Tested on my own machine (GCC on CygWin) and on ideone.com (I believe they also run GCC), but not up to f(99) for obvious reasons!

\$\endgroup\$
  • 1
    \$\begingroup\$ Does that comply with the 4 GiB memory limit? \$\endgroup\$ – Dennis Oct 29 '16 at 20:36
  • 3
    \$\begingroup\$ @Dennis It should do, it only stores a depth 99 recursion of f,n and i on the stack, getting around the fact that C can´t handle a 100 digit number decimal number. I would estimate a max of about 20 bytes for each instance of f() so about 1980 bytes. The puts dumps the newlines to the API and the API should output and flush the buffer as necessary. \$\endgroup\$ – Level River St Oct 29 '16 at 20:45
  • 3
    \$\begingroup\$ Tested it locally and memory usage doesn't even surpass 1 MiB. \$\endgroup\$ – Dennis Oct 29 '16 at 22:31
  • \$\begingroup\$ Declaration of i as second parameter of f() not guaranteed to work in all versions of C.: It could break with a stack-args calling convention where the callee pops args from the stack (or if f writes to stack space that the caller wasn't expecting it to). clang does warn about "too few arguments in call to 'f'", in -std=c89 and -std=c99, so the definition does act as a declaration with a specific number of args. But I forget; I think that might mean the compiler knows the function expects 2 args, and will always leave space for a 2nd arg. \$\endgroup\$ – Peter Cordes Oct 31 '16 at 7:30
  • 1
    \$\begingroup\$ @FelixDombek the community decided a while back that "program" means you can write a program or function unless "full program" is explicitly specified. meta.codegolf.stackexchange.com/a/6912/15599 . Therefore my submission comprises g and its helper function f. main would be longer. There are a few other function submissions here, if you look through. \$\endgroup\$ – Level River St Jan 23 '17 at 23:23
14
\$\begingroup\$

Commodore VIC 20 machine code (40 bytes)

... here shown as hexadecimal:

1040   A9[64]A2 00 9D 68 10 E8  E0[32]D0 F8 A9 00 9D 68
1050   10 A9[31]20 D2 FF A2 00  A9[64]DE 68 10 30 08 D0
1060   F0 9D 68 10 E8 D0 F3 60

(Started using: SYS 4160)

Meaning of the bytes in brackets

  • 0x64 (occurs twice) is the base (100); (values from 2 to 127 should work)
  • 0x32 is the exponent (50) (any non-zero value (1-255) should work)
  • Note that 100^50 = 10^100; running the program 100^50 times is more RAM efficient than doing it 10^100 times
  • 0x31 is the ASCII character to be printed

and at no point no more than 4 GB of memory must be needed.

Is this a typing mistake?

We have the year 1981.

A typical home computer has 1 to 16 KB of RAM! And you will hardly find professional models that have 1 MB or more.

(Ok. Just a joke.)

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.

The program has been tested with other bases and exponents. I have no doubt it will also work with 100 and 50.

At least it does not crash with these numbers (but does not terminate in measurable time either).

The memory size is sufficient for an exponent of 50 and 100 is less than 127 so a base of 100 should not be a problem.

The the basic idea

There is a 50-digit counter that counts in the 100-system. Bytes 0x01-0x64 represent the digits 0-99. The first byte in the counter is the lowest digit. The last byte in the counter (highest digit) is followed by a byte with the value 0x00.

The counter has the initial value 100^50.

An outer loop is writing a byte to the "current channel" ("standard output" on modern systems; typically the screen) and then decrements the counter.

Decrementing is done by an inner loop: It decrements a digit and in the case of an underflow from 1 to 99 it advances to the next digit. If the byte 0x00 at the end of the counter is decremented the program stops.

The assembly code is

    ; Some constants
    base=10
    exponent=100
    character=0x32

    ; Initialize the content of the counter to 100^50
    ; (Fill the first 50 bytes with the value 100)
    lda  #base
    ldx  #0
initLoop:
    sta  counter,x
    inx
    cpx  #exponent
    bne  initLoop
    ; (The terminating 0 at the end of the counter)
    lda  #0
    sta  counter,x

    ; Now do the actual job
outerLoop:
    ; Output a character
    lda  #character
    jsr  (0xFFD2)
    ; Prepare for the inner loop
    ldx  #0
    lda  #base
innerLoop:
    ; Decrement one digit
    dec  counter,x
    ; Result is negative -> must have been the terminating
    ; NUL byte -> Exit
    bmi  progEnd
    ; Result is not zero -> Print the next byte
    bne  outerLoop
    ; Result is zero -> Was 0x01 before -> As 0x01 represents
    ; digit 0 this is an underflow -> set the digit to
    ; "exponent" (100) again (which represents digit 99)
    sta  counter,x
    ; Go to the next digit and...
    inx
    ; ... repeat the inner loop (decrement next digit)
    ; (Note that this conditional branch is ALWAYS taken)
    bne  innerLoop

progEnd:
    rts

counter:
    ; The memory used by the counter is here...

EDIT

The program runs on Commodore C64, too!

\$\endgroup\$
  • \$\begingroup\$ I borrowed @LevelRiverSt's recursion idea for my x86-64 machine-code implementation, coming in at 30B (using putchar from libc for printing). I considered an extended-precision loop counter, and it would work in x86, too. (And can similarly be pretty cheaply initialized). Maybe I'll try it sometime... \$\endgroup\$ – Peter Cordes Oct 31 '16 at 11:38
  • 1
    \$\begingroup\$ LOL wow, I .... <golf clap> ... I haven't seen 6502 assembly in ... well, a long time. \$\endgroup\$ – Alex Howansky Nov 1 '16 at 20:49
12
\$\begingroup\$

Node, 89 bytes

for(i="0".repeat(100)+1;+i;i=i.replace(/0*./,x=>"9".repeat(x.length-1)+~-x))console.log()

Outputs 10100 newlines. (Theoretically, that is; test by replacing 100 with 1 to output 101 newlines instead.)

This works by setting i to the string

00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001

(100 zeroes and a 1; a googol reversed), then repeatedly "subtracting 1" with a regex replace and outputting a newline until the string is all zeroes.

A port of the C++ answer would be 49 bytes:

(f=n=>{for(i=10;i--;)n?f(n-1):console.log()})(99)
\$\endgroup\$
  • 1
    \$\begingroup\$ This is genius! Either that or you're an expert at Retina, which doesn't necessarily rule out "genius"... \$\endgroup\$ – Patrick Roberts Jan 12 '17 at 13:45
7
\$\begingroup\$

05AB1E, 6 bytes

Tn°F1?

Explanation

Tn°    # push 10^100
   F   # 10^100 times do
    1? # print 1
\$\endgroup\$
  • 5
    \$\begingroup\$ @MartinRosenau: Fortunately 05AB1E uses python 3 integers which doesn't have a limit. \$\endgroup\$ – Emigna Oct 29 '16 at 19:24
  • 1
    \$\begingroup\$ @JanDvorak: According to the Python 3 docs there is no longer a limit to the value of integers. \$\endgroup\$ – Emigna Oct 30 '16 at 9:57
  • 1
    \$\begingroup\$ @JanDvorak: Indeed. I have used some pretty big numbers without issues (not that big though). We only need to handle 1e100 here though and python can definitely handle that :) \$\endgroup\$ – Emigna Oct 30 '16 at 10:02
  • 1
    \$\begingroup\$ @JanDvorak The maximum size of Python integers is solely dependent on the amount of available memory. \$\endgroup\$ – Mego Oct 30 '16 at 19:23
  • 4
    \$\begingroup\$ I have gotten to the limit before while trying to obfuscate a long number. The machine I was using was able to handle numbers bigger than 10^3000 before an integer overflow. \$\endgroup\$ – Esolanging Fruit Oct 31 '16 at 4:04
6
\$\begingroup\$

Ruby, 20 bytes

(10**100).times{p 1}

Prints 1 followed by a newline 1E100 times.

1E100 does not work as it evaluates to a float, not an arbitrary precision integer.

\$\endgroup\$
  • \$\begingroup\$ Can you remove the parentheses? \$\endgroup\$ – OldBunny2800 Oct 30 '16 at 20:11
  • 1
    \$\begingroup\$ @OldBunny2800 No. methods take priority over operators, so it would be interpreted as 10**(100.times{p 1}) \$\endgroup\$ – Level River St Oct 30 '16 at 21:31
  • 1
    \$\begingroup\$ For those curious, 1E100.to_i evaluated to 10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104 on my computer. \$\endgroup\$ – Andrew Grimm Oct 31 '16 at 9:43
6
\$\begingroup\$

///, 36 ASCII characters (4 distinct)

/t./.ttttt//.t/t\..........//t//t...

Outputs the . character 3*10^125 times, meaning that it outputs the string consisting of 3*10^25 repetitions of the . character, 10^100 times.

Explanation:

  1. /t./.ttttt/: Replace t. with .ttttt throughout the rest of the program, repeating until no instances of t. remain. This replaces t... with ... followed by 125 ts.
  2. /.t/t\........../: Replace .t with t.......... throughout the rest of the program, repeating until no instances of .t remain. This takes the ... followed by 125 ts, and turns it into 125 ts followed by 10^125 occurrences of ....
  3. /t//: Remove all remaining ts.
  4. t...: This gets replaced with 3*10^125 .s. Output them.

Now, outputting 10^100 repetitions of 3*10^25 repetitions of something kind of feels like cheating. This program outputs the . character exactly 10^100 times, using 45 ASCII characters:

/T/tttttttttt//.t/t..........//t//.TTTTTTTTTT

Explanation of this one:

  1. /T/tttttttttt/: Replace T with tttttttttt throughout the rest of the program. This replaces TTTTTTTTTT with 100 repetitions of t.
  2. /.t/t........../: Replace .t with t.......... throughout the rest of the program. This takes the . followed by 100 ts, and turns it into 100 ts followed by 10^100 .s.
  3. /t//: Remove all remaining ts.
  4. .TTTTTTTTTT: This gets replaced with 10^100 .s. Output them.

Finally, here's a compromise program, which outputs the . character 2*10^100 times, using 40 characters:

/t./.tttttttttt//.t/t\..........//t//t..
\$\endgroup\$
6
\$\begingroup\$

Befunge 93, 33 bytes

1>01g0`#@!# _01v
d^.1 **52p10-1g<

Unfortunately, Befunge does not have a power function, so almost all of that code is my implementation of a power function. I'm still working on this.

Explanation:

1 > 01g 0` #@!# _ 01g 1- 01p 25** 1. v
d ^                                  <

1: Start off with 1 in the top left so that when we multiply, we don't get 0 every time.

01g: get the character at position (0, 1), which is d, whose ASCII code is 100.

0`: see if the value stored in (0, 1) is greater than 0; this value will change.

#@!# _: Logical not ! to the value we get from the last step (0 or 1), so that if it was 1, now we have 0, and we Note that # means that you skip the next character in the code.

01g 1- 01p: Take the value stored in (0, 1) again, subtract 1 from it, and store this new value at (0, 1)

25**: multiply the top value of the stack by 10

1.: print 1 every time this loops

1 is printed (in theory) googol times, but that quickly runs off of the page that I tested this on.

You can run Befunge 93 code here. For some reason, the top value of the stack is 1.0000000000000006e+100 when it should be 1.0e+100. I don't know where that 6 came from, but I don't think it should be there and that it may be some rounding error or something like that.

\$\endgroup\$
4
\$\begingroup\$

ABCR, 56 bytes

++++++++++AAAAAAAAAA7a*A!(x4bBBBBBBBBBB7b+B@(xa(Ax5b(Box

Turing tarpits are fun, especially when they don't have easy multiplication or exponents. On the other hand, I only needed to use two of the three queues!

Explanation:

++++++++++                                             Set register to 10
          AAAAAAAAAA                                   Queue 10 to queue A 10 times
                    7a*A!(x                            Sum up all of queue A by:
                    7     x                             While the register is truthy:
                     a*                                 Dequeue two elements of A, sum them...
                       A                                ...and queue the result back to A.
                        !(                              If there's only one element left,
                                                        i.e. !(A.len - 1),
                                                        break from the loop.  A now has 100, our exponent.

                             4                        While A's front is truthy:
                              bBBBBBBBBBB              Clone the front of B 10 (our base) times.  (The first iteration fills it up with ten 1s)
                                         7b+B@(x       Sum up all of queue B like we did with A
                                                a(A    Decrement a (so that the loop actually ends. Runs 101 times like it should) x   

                                                       B now contains 10^100 only.

                                                   5b(B x   10^100 times:
                                                       o     print the front of queue A (0)
\$\endgroup\$
4
\$\begingroup\$

Batch, 574 242 bytes

@echo off
set t=for /l %%a in (2,1,33554432)do call:
set f=for /l %%a in (2,1,9765625)do call:
%t%a
:a
%t%b
:b
%t%c
:c
%t%d
:d
%f%e
:e
%f%f
:f
%f%g
:g
%f%h
:h
%f%i
:i
%f%j
:j
%f%k
:k
%f%l
:l
%f%m
:m
%f%n
:n
echo

Each loop falls through therefore executing an additional iteration. Loops are limited to ~2³² due to the 32-bit integer limit. The first four loops each count 2²⁵ for a total of 2¹⁰⁰ while the remaining ten loops each count 5¹⁰ for a total of 5¹⁰⁰.

Edit: Saved an unimaginable 58% thanks to @ConorO'Brien.

\$\endgroup\$
4
\$\begingroup\$

TI-Basic, 20 bytes

Straightforward. Only eight lines are displayed at once, and previous lines do not stay in memory. Because ᴇ100 is unsupported, we must loop from -ᴇ99 to 9ᴇ99. Then, if I!=0, display the string (which, by the way, is 3). This way, we print it exactly ᴇ100 times.

For(I,-ᴇ99,9ᴇ99:If I:Disp 3:End
\$\endgroup\$
  • \$\begingroup\$ Are you sure the variable "I" is precise enough to store 99 digits? \$\endgroup\$ – Martin Rosenau Oct 30 '16 at 11:33
  • \$\begingroup\$ Alright, yes, I should be enough to hold that, although it would only display up to 14 if using "Disp", but we don't actually output it, only check if it does not equal zero. Also, you're right about the symbol, but I figured you would understand what I mean. I'll copy that into my post now. \$\endgroup\$ – Timtech Oct 30 '16 at 21:42
  • \$\begingroup\$ I have never encountered a version of BASIC with infinite integers but that doesn't even matter as your loop doesn't execute nearly enough times. \$\endgroup\$ – Loren Pechtel Nov 1 '16 at 0:20
  • 1
    \$\begingroup\$ Umm yea, there's no infinite integers here. Integers must be within +-10^100 \$\endgroup\$ – Timtech Nov 1 '16 at 23:18
4
\$\begingroup\$

x86-64 machine code function, 30 bytes.

Uses the same recursion logic as the C answer by @Level River St. (Max recursion depth = 100)

Uses the puts(3) function from libc, which normal executables are linked against anyway. It's callable using the x86-64 System V ABI, i.e. from C on Linux or OS X, and doesn't clobber any registers it's not supposed to.


objdump -drwC -Mintel output, commented with explanation

0000000000400340 <g>:  ## wrapper function
  400340:       6a 64                   push   0x64
  400342:       5f                      pop    rdi       ; mov edi, 100  in 3 bytes instead of 5
  ; tailcall f by falling into it.

0000000000400343 <f>:  ## the recursive function
  400343:       ff cf                   dec    edi
  400345:       97                      xchg   edi,eax
  400346:       6a 0a                   push   0xa
  400348:       5f                      pop    rdi       ; mov edi, 10
  400349:       0f 8c d1 ff ff ff       jl     400320 <putchar>   # conditional tailcall
; if we don't tailcall, then eax=--n = arg for next recursion depth, and edi = 10 = '\n'

  40034f:       89 f9                   mov    ecx,edi   ; loop count = the ASCII code for newline; saves us one byte


0000000000400351 <f.loop>:
  400351:       50                      push   rax       ; save local state
  400352:       51                      push   rcx
  400353:       97                      xchg   edi,eax   ; arg goes in rdi
  400354:       e8 ea ff ff ff          call   400343 <f>
  400359:       59                      pop    rcx       ; and restore it after recursing
  40035a:       58                      pop    rax
  40035b:       e2 f4                   loop   400351 <f.loop>
  40035d:       c3                      ret    
# the function ends here

000000000040035e <_start>:

0x040035e - 0x0400340 = 30 bytes

# not counted: a caller that passes argc-1 to f() instead of calling g
000000000040035e <_start>:
  40035e:       8b 3c 24                mov    edi,DWORD PTR [rsp]
  400361:       ff cf                   dec    edi
  400363:       e8 db ff ff ff          call   400343 <f>
  400368:       e8 c3 ff ff ff          call   400330 <exit@plt>    # flush I/O buffers, which the _exit system call (eax=60) doesn't do.

Built with yasm -felf64 -Worphan-labels -gdwarf2 golf-googol.asm && gcc -nostartfiles -o golf-googol golf-googol.o. I can post the original NASM source, but that seemed like clutter since the asm instructions are right there in the disassembly.

putchar@plt is less than 128 bytes away from the jl, so I could have used a 2-byte short jump instead of a 6-byte near jump, but that's only true in a tiny executable, not as part of a larger program. So I don't think I can justify not counting the size of libc's puts implementation if I also take advantage of a short jcc encoding to reach it.

Each level of recursion uses 24B of stack space (2 pushes and the return address pushed by CALL). Every other depth will call putchar with the stack only aligned by 8, not 16, so this does violate the ABI. A stdio implementation that used aligned stores to spill xmm registers to the stack would fault. But glibc's putchar doesn't do that, writing to a pipe with full buffering or writing to a terminal with line buffering. Tested on Ubuntu 15.10. This could be fixed with a dummy push/pop in the .loop, to offset the stack by another 8 before the recursive call.


Proof that it prints the right number of newlines:

   # with a version that uses argc-1  (i.e. the shell's $i)  instead of a fixed 100
$ for i in {0..8}; do echo -n "$i: "; ./golf-googol $(seq $i) |wc -c; done
0: 1
1: 10
2: 100
3: 1000
4: 10000
5: 100000
6: 1000000
7: 10000000
8: 100000000
... output = 10^n newlines every time.

My first version of this was 43B, and used puts() on a buffer of 9 newlines (and a terminating 0 byte), so puts would append the 10th. That recursion base-case was even closer to the C inspiration.

Factoring 10^100 a different way could maybe have shortened the buffer, maybe down to 4 newlines, saving 5 bytes, but using putchar is better by far. It only needs an integer arg, not a pointer, and no buffer at all. The C standard allows implementations where it's a macro for putc(val, stdout), but in glibc it exists as a real function that you can call from asm.

Printing only one newline per call instead of 10 just means we need to increase the recursion max depth by 1, to get another factor of 10 newlines. Since 99 and 100 can both be represented by a sign-extended 8-bit immediate, push 100 is still only 2 bytes.

Even better, having 10 in a register works as both a newline and a loop counter, saving a byte.

Ideas for saving bytes

A 32-bit version could save a byte for the dec edi, but the stack-args calling convention (for library functions like putchar) makes tail-call work less easily, and would probably require more bytes in more places. I could use a register-arg convention for the private f(), only called by g(), but then I couldn't tail-call putchar (because f() and putchar() would take a different number of stack-args).

It would be possible to have f() preserve the caller's state, instead of doing the save/restore in the caller. That probably sucks, though, because it would probably need to get separately in each side of the branch, and isn't compatible with tailcalling. I tried it but didn't find any savings.

Keeping a loop counter on the stack (instead of push/popping rcx in the loop) didn't help either. It was 1B worse with the version that used puts, and probably even more of a loss with this version that sets up rcx more cheaply.

\$\endgroup\$
  • 2
    \$\begingroup\$ Hooray for assembly answers! :) \$\endgroup\$ – user9206 Oct 31 '16 at 13:35
4
\$\begingroup\$

PHP, 44 bytes

for($i=bcpow(10,1e2);$i=bcsub($i,print 1););

This snippet will output 1 googol times. It will not run out of memory, but it is terribly slow. I'm using BCMath to be able to handle long integers.

A bit better performing, but not as small (74 bytes):

for($m=bcpow(10,100);$m;$m=bcsub($m,$a))echo str_repeat(a,$a=min(4e9,$m));

Will output the letter a googol times. It will consume almost 4GB of memory, outputting about 4e9 characters at a time.

\$\endgroup\$
  • \$\begingroup\$ if just an 'a' takes almost 4GB, what would 'aaa' do? It will take more code, but with ob_flush(); you might go a lot further \$\endgroup\$ – Martijn Oct 31 '16 at 10:45
  • \$\begingroup\$ Uhm, it's not one a, it's a string of 4*10^9 as. There no way not go over the 4GB if you're going to put 3 times as many as in there. Ob_flush has nothing to do with it, the point of the second example is to output large strings at once instead of outputting small amounts of characters each time, which results in the program running quite a bit faster, at the cost of more memory usage. \$\endgroup\$ – chocochaos Oct 31 '16 at 11:25
  • \$\begingroup\$ As far as I know ">=" is not able to handle big integers, you should use bccomp \$\endgroup\$ – Crypto Oct 31 '16 at 12:48
  • \$\begingroup\$ You are correct, it doesn't give the correct results when comparing strings. I will fix it in a minute. \$\endgroup\$ – chocochaos Oct 31 '16 at 13:07
  • \$\begingroup\$ Edit with a somewhat different but working solution :) \$\endgroup\$ – chocochaos Oct 31 '16 at 13:23
3
\$\begingroup\$

Haskell, 45 43 bytes

r 0=[]
r i='1':r(i-1)
main=putStr.r$10^100
\$\endgroup\$
3
\$\begingroup\$

Pyke, 6 5 bytes

TTX^V

Try it here!

Untested as it crashes my browser. The first 4 chars generate 10^100 and V prints out that many newlines. Test with 100V.

\$\endgroup\$
3
\$\begingroup\$

Racket 36 bytes

(for((i(expt 10 100)))(display "1"))

Output:

1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
\$\endgroup\$
3
\$\begingroup\$

JAISBaL, 4 bytes

˖Q

Chrome can't read all the symbols, and I'm not sure about other browsers, so here's a picture:

Explanation:

# \# enable verbose parsing #\
10^100       \# [0] push 10^100 onto the stack #\
for          \# [1] start for loop #\
    space    \# [2] print a space #\

Pretty simple.... just prints a googol spaces. Three instructions, but the googol constant is two bytes.

(Written in version 3.0.5)

\$\endgroup\$
  • \$\begingroup\$ This is 6 UTF-8 bytes. Which encoding are you using? \$\endgroup\$ – Conor O'Brien Oct 30 '16 at 2:11
  • \$\begingroup\$ "bytes" does link to it... \$\endgroup\$ – Socratic Phoenix Oct 30 '16 at 2:57
  • \$\begingroup\$ Gah, sorry. I have a userscript that makes links look like regular text. \$\endgroup\$ – Conor O'Brien Oct 30 '16 at 2:58
  • \$\begingroup\$ Oh, I didn't know that was possible, okay :) \$\endgroup\$ – Socratic Phoenix Oct 30 '16 at 2:58
  • \$\begingroup\$ @ConorO'Brien umm, why? \$\endgroup\$ – Cyoce Oct 30 '16 at 16:57
3
\$\begingroup\$

JavaScript ES6, 85 83 bytes

Saved 2 bytes thanks to ETHproductions!

eval([...Array(i=100)].map(_=>`for($${--i}=0;$${i}++<10;)`).join``+"console.log()")

This prints 1e100 newlines.

The inner part generates this program, which is thereafter evaluated.

for($0=0;$0++<10;)for($1=0;$1++<10;)for($2=0;$2++<10;)for($3=0;$3++<10;)for($4=0;$4++<10;)for($5=0;$5++<10;)for($6=0;$6++<10;)for($7=0;$7++<10;)for($8=0;$8++<10;)for($9=0;$9++<10;)for($10=0;$10++<10;)for($11=0;$11++<10;)for($12=0;$12++<10;)for($13=0;$13++<10;)for($14=0;$14++<10;)for($15=0;$15++<10;)for($16=0;$16++<10;)for($17=0;$17++<10;)for($18=0;$18++<10;)for($19=0;$19++<10;)for($20=0;$20++<10;)for($21=0;$21++<10;)for($22=0;$22++<10;)for($23=0;$23++<10;)for($24=0;$24++<10;)for($25=0;$25++<10;)for($26=0;$26++<10;)for($27=0;$27++<10;)for($28=0;$28++<10;)for($29=0;$29++<10;)for($30=0;$30++<10;)for($31=0;$31++<10;)for($32=0;$32++<10;)for($33=0;$33++<10;)for($34=0;$34++<10;)for($35=0;$35++<10;)for($36=0;$36++<10;)for($37=0;$37++<10;)for($38=0;$38++<10;)for($39=0;$39++<10;)for($40=0;$40++<10;)for($41=0;$41++<10;)for($42=0;$42++<10;)for($43=0;$43++<10;)for($44=0;$44++<10;)for($45=0;$45++<10;)for($46=0;$46++<10;)for($47=0;$47++<10;)for($48=0;$48++<10;)for($49=0;$49++<10;)for($50=0;$50++<10;)for($51=0;$51++<10;)for($52=0;$52++<10;)for($53=0;$53++<10;)for($54=0;$54++<10;)for($55=0;$55++<10;)for($56=0;$56++<10;)for($57=0;$57++<10;)for($58=0;$58++<10;)for($59=0;$59++<10;)for($60=0;$60++<10;)for($61=0;$61++<10;)for($62=0;$62++<10;)for($63=0;$63++<10;)for($64=0;$64++<10;)for($65=0;$65++<10;)for($66=0;$66++<10;)for($67=0;$67++<10;)for($68=0;$68++<10;)for($69=0;$69++<10;)for($70=0;$70++<10;)for($71=0;$71++<10;)for($72=0;$72++<10;)for($73=0;$73++<10;)for($74=0;$74++<10;)for($75=0;$75++<10;)for($76=0;$76++<10;)for($77=0;$77++<10;)for($78=0;$78++<10;)for($79=0;$79++<10;)for($80=0;$80++<10;)for($81=0;$81++<10;)for($82=0;$82++<10;)for($83=0;$83++<10;)for($84=0;$84++<10;)for($85=0;$85++<10;)for($86=0;$86++<10;)for($87=0;$87++<10;)for($88=0;$88++<10;)for($89=0;$89++<10;)for($90=0;$90++<10;)for($91=0;$91++<10;)for($92=0;$92++<10;)for($93=0;$93++<10;)for($94=0;$94++<10;)for($95=0;$95++<10;)for($96=0;$96++<10;)for($97=0;$97++<10;)for($98=0;$98++<10;)for($99=0;$99++<10;)console.log()

Now, for a proof of correctness, we'll use some induction. Let's substitute the initial 100 for other values, generically N. I claim that inserting N will yield 10N newlines. Let's pipe the result of this to wc -l, which counts the number of newlines in the input. We'll use this modified but equivalent script that takes input N:

eval([...Array(+process.argv[2])].map(_=>`for($${i}=0;$${i++}++<10;)`,i=0).join``+"console.log()")

Now, here's some output:

C:\Users\Conor O'Brien\Documents\Programming
λ node googol.es6 1 | wc -l
10

C:\Users\Conor O'Brien\Documents\Programming
λ node googol.es6 2 | wc -l
100

C:\Users\Conor O'Brien\Documents\Programming
λ node googol.es6 3 | wc -l
1000

C:\Users\Conor O'Brien\Documents\Programming
λ node googol.es6 4 | wc -l
10000

We can see that this transforms the input N for small values to 10N newlines.

Here is an example output for N = 1:

C:\Users\Conor O'Brien\Documents\Programming
λ node googol.es6 1











C:\Users\Conor O'Brien\Documents\Programming
λ
\$\endgroup\$
  • \$\begingroup\$ Nice. Save a couple bytes with eval([...Array(i=100)].map(_=>`for($${--i}=0;$${i}++<10;)`).join``+"console.log()") \$\endgroup\$ – ETHproductions Oct 30 '16 at 14:16
  • \$\begingroup\$ @ETHproductions thanks! :D \$\endgroup\$ – Conor O'Brien Oct 30 '16 at 14:51
  • \$\begingroup\$ P.S. I count 83 bytes ;) \$\endgroup\$ – ETHproductions Oct 30 '16 at 17:34
  • \$\begingroup\$ Another example here. Not sure if it's useful to anyone else, but I wasn't quite sure how this worked and wrote a wrapper function for the eval'd function to play with. You can clearly see the program counting to 10^n, where n is the number of loops evaluated. I set a return condition so it breaks well before googol; change the variable used in that condition to count through different loop levels. Also, a nitpick: your second code sample shows the outer loop being $0, going down to $99; it should be reversed, with $99 being the outer loop. \$\endgroup\$ – MichaelS Oct 31 '16 at 0:04
  • \$\begingroup\$ @MichaelS true. I will change it the next chance I get. \$\endgroup\$ – Conor O'Brien Oct 31 '16 at 0:47
3
\$\begingroup\$

Mathematica, 48 30 25 bytes

For[n=1,n++<Echo@1*^100,]

Output:

>> 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
>> 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
>> 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
>> 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
>> 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
etc.
\$\endgroup\$
  • \$\begingroup\$ Can't test right now, but how about For[n=0,n++<10^100,Echo[]]? \$\endgroup\$ – Martin Ender Oct 31 '16 at 17:31
  • \$\begingroup\$ I'd consider the leading >> part of the output. They're printed if you use Echo on the console. \$\endgroup\$ – Martin Ender Nov 1 '16 at 1:23
  • \$\begingroup\$ @MartinEnder Whoops, fixed \$\endgroup\$ – LegionMammal978 Nov 1 '16 at 1:25
  • \$\begingroup\$ How about Echo@0&~Array~10^100; for 21 bytes? \$\endgroup\$ – Greg Martin Jan 8 '17 at 19:06
3
\$\begingroup\$

Fortran 95, Free-form, Recursive, 117 bytes

Program M
Call R(99)
END
Recursive Subroutine R(L)
IF(L)3,1,1
1 DO 2 I=1,10
2 Call R(L-1)
RETURN
3 PRINT*,0
END

Prints a googol of lines containing

          0

Fortran 90, Recursive, 149 bytes

     CallR(99)
     END
     RecursiveSubroutineR(L)
     IF(L)3,1,1
   1 DO2I=1,10
   2 CallR(L-1)
     RETURN
   3 PRINT*,0
     END     

Recursively calling 100 nested loops, each 10 iterations, makes exactly one googol. N, L, and the loop counters all fit in byte-sized integers.

Tested by replacing 99 with 1, 2, 3, 4, 5 and noting that in each case the resulting line count from "wc" has n+1 zeros.

Fortran II, IV, 66, or 77, 231 bytes:

      N=2*10**9
      DO1I0=1,5**10
      DO1I=1,N
      DO1J=1,N
      DO1K=1,N
      DO1L=1,N
      DO1M=1,N
      DO1I1=1,N
      DO1J1=1,N
      DO1K1=1,N
      DO1L1=1,N
      DO1M1=1,N
1     PRINT2
2     FORMAT(X)
      END

Prints a googol of newlines.

All of these programs will run on 32-bit machines; in fact, the recursive versions would work just fine on a 16-bit machine. One could use fewer loops in the brute-force version by running on an old Cray with its 60-bit integers. Here, ten nested loops of 2*10^9 inside one loop of 5^10 (9765625) equals 10 ^ 100 total iterations.

None of the versions uses any memory to speak of other than the object code itself, the counters, one copy of the output string, and, in the recursive version, a 100-level return stack.

Check the factors by comparing

bc<<<2000000000\^10*5\^10
bc<<<10\^100
\$\endgroup\$
3
\$\begingroup\$

Turing machine simulator, 1082 bytes

0 * 6 r 1
1 * E r 2
2 * C r 3
3 * 1 r 4
4 * B r 5
5 * C r 6
6 * F r 7
7 * 4 r 8
8 * 6 r 9
9 * 8 r A
A * 8 r B
B * 3 r C
C * 0 r D
D * 9 r E
E * G r F
F * H r G
G * 8 r H
H * 0 r I
I * 6 r J
J * H r K
K * 9 r L
L * 3 r M
M * 2 r N
N * A r O
O * D r P
P * C r Q
Q * C r R
R * 4 r S
S * 4 r T
T * E r U
U * E r V
V * G r W
W * 6 r X
X * D r Y
Y * E r Z
Z * 0 r a
a * F r b
b * E r c
c * 9 r d
d * F r e
e * A r f
f * H r g
g * D r h
h * E r i
i * 6 r j
j * 6 r k
k * D r l
l * G r m
m * H r n
n * 1 r o
o * 0 r p
p * 8 r q
q * C r r
r * 9 r s
s * G r t
t * 3 r u
u * 6 r v
v * 2 r w
w * 3 r x
x * E r y
y * 0 r z
z * 4 r +
+ * 5 r /
/ * A r =
= * 0 r -
- * H r \
\ * 7 r !
! * A r @
@ * 9 r #
# * 5 r $
$ * A r %
% * B r ^
^ * 5 r &
& * 9 r ?
? * 4 r (
( * C r )
) * E r `
` * 9 r ~
~ * 9 r _
_ * A * .
. 0 I l *
. 1 0 r <
. 2 1 r <
. 3 2 r <
. 4 3 r <
. 5 4 r <
. 6 5 r <
. 7 6 r <
. 8 7 r <
. 9 8 r <
. A 9 r <
. B A r <
. C B r <
. D C r <
. E D r <
. F E r <
. G F r <
. H G r <
. I H r <
. _ * r ]
< _ * r >
< * * r *
> _ = l [
> * * r *
[ _ * l .
[ * * l *
] _ * * halt
] * _ r *

Turing machine simulator

I do not know if this counts as the correct output, since it has 82 leading spaces.

I do not know if this respects the 4 GB limit, so, if it doesn't, then it's non-competitive and just for showcase. The output is 1e100 bytes, so that should be deducted from the memory byte count. The final byte count is 82 bytes.

Here is an explanation:

The first 80 lines of code are 80 different states that generate the base-191 loop count 6EC1BCF4688309GH806H932ADCC44EEG6DE0FE9FAHDE66DGH108C9G3623E045A0H7A95AB594CE99A.

The next 19 lines of code are the counter state, which decrements the count every time a character is printed.

The next 6 lines are the printer state, which appends an =.

Finally, the last 2 lines are the cleaner state, which are needed to make sure the only output is =====...=====. Leading/trailing spaces do not count as output, since they are unavoidable side-effects.

The program then halts.

1I did the math for that.

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

Pyth, 7 Bytes

New (Competing)

V^T*TTG

Explanation

G=The alphabet
Repeat 10^(10*10) times
    print(G)

Old (Non Competing) 7 Bytes

*G^T*TT

Explanation

G=The alphabet
G*(10^(10*10))==G*10^100
\$\endgroup\$
  • 1
    \$\begingroup\$ This doesn't comply with the 4 GiB remory limit. \$\endgroup\$ – Dennis Oct 29 '16 at 20:38
  • \$\begingroup\$ @Dennis I fixed it \$\endgroup\$ – Spammy23 Oct 29 '16 at 20:49
  • \$\begingroup\$ Not a golfing advice, but I don't think *TT is any shorter than a plain 100. \$\endgroup\$ – Erik the Outgolfer Jan 26 '17 at 12:06
2
\$\begingroup\$

Python 3, 32 bytes

for i in range(10**100):print()

Alternate solution, 33 bytes:

[print()for i in range(10**100)]
\$\endgroup\$
  • \$\begingroup\$ In Python 2 this is a particularly great answer. \$\endgroup\$ – user9206 Oct 31 '16 at 13:35
  • 1
    \$\begingroup\$ Not so much, @Lembik. In Python 2, range(10**100) creates a list of numbers [1, 2, 3, 4, ...], which results in OverflowError: range() result has too many items. This would work in Python 2 with a call to xrange() instead, and works in Python 3 since xrange() was renamed to range(), and the original range() that generated a list was deprecated. \$\endgroup\$ – James Murphy Nov 1 '16 at 0:16
  • 2
    \$\begingroup\$ @JamesMurphyb Yes I know that. I was trying to be funny about the impractability of codegolf answers. \$\endgroup\$ – user9206 Nov 1 '16 at 7:51
  • 1
    \$\begingroup\$ Sorry. I have trouble reading humor in a lot of SE comments. \$\endgroup\$ – James Murphy Nov 2 '16 at 2:51
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\$
  • 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\$ – Kevin Cruijssen Oct 31 '16 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\$ – Olivier Grégoire Oct 31 '16 at 13:41
  • \$\begingroup\$ @OlivierGrégoire That gives me a NullReferenceException, possibly because b is null. \$\endgroup\$ – Xanderhall Dec 7 '16 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\$ – Olivier Grégoire Dec 9 '16 at 12:00
  • \$\begingroup\$ @OlivierGrégoire I tried it in Java. I don't code in C#. \$\endgroup\$ – Xanderhall Dec 9 '16 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\$
  • \$\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 '16 at 9:21
  • \$\begingroup\$ @BasicallyAlanTuring Actually my javac won't let me compile this. \$\endgroup\$ – Niclas M Nov 2 '16 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 '16 at 9:05
  • \$\begingroup\$ @BasicallyAlanTuring Got Java 8. I guess functions are not allowed by the OP. \$\endgroup\$ – Niclas M Nov 3 '16 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 '16 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\$
  • \$\begingroup\$ Why is the p needed? \$\endgroup\$ – Maltysen Oct 30 '16 at 3:26
  • \$\begingroup\$ @Maltysen I think because of the 4 GB limit. \$\endgroup\$ – Erik the Outgolfer Oct 30 '16 at 6:18
  • \$\begingroup\$ Why? Cuz of the buffer? Doesn't that automatically flush? \$\endgroup\$ – Maltysen Oct 30 '16 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\$ – Erik the Outgolfer Oct 30 '16 at 16:08
  • \$\begingroup\$ Its working locally without the p \$\endgroup\$ – Maltysen Nov 1 '16 at 23:03

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.