title: Output a googol copies of a string

text:
# Question
Title: Output a googol copies of a string
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;
}

```

# Answer
# 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.

```
> 39 votes

# Answer
# 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/

```
> 62 votes

# Answer
# 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

```
> 23 votes

# Answer
## Haskell, 28 bytes

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

```

Concatenates 10^100 copies of the string `"1"` and prints it.
> 18 votes

# Answer
# 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.
> 17 votes

# Answer
# 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!
> 16 votes

# Answer
## 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 **G**B of memory must be needed.

Is this a typing mistake?

We have the year 1981.

A typical home computer has 1 to 16 **K**B of RAM! And you will hardly find professional models that have 1 **M**B 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!
> 15 votes

# Answer
# 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)

```
> 12 votes

# Answer
# 05AB1E, 6 bytes

```
Tn°F1?

```

**Explanation**

```
Tn°    # push 10^100
   F   # 10^100 times do
    1? # print 1

```
> 7 votes

# Answer
# Slashalash, 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 `t`s.
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 `t`s, and turns it into 125 `t`s followed by 10^125 occurrences of `...`.
3. `/t//`: Remove all remaining `t`s.
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 `t`s, and turns it into 100 `t`s followed by 10^100 `.`s.
3. `/t//`: Remove all remaining `t`s.
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..

```
> 7 votes

# Answer
# 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.
> 6 votes

# Answer
## 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.
> 6 votes

# Answer
# 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)

```
> 4 votes

# Answer
## 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.
> 4 votes

# Answer
# 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.
> 4 votes

# Answer
# 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.
> 4 votes

# Answer
# 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.
> 4 votes

# Answer
# Whispers v3, ~~48..40~~ 35 bytes

*\+ more oomph thanks to Leo!*

```
> 100
>> 1*1
>> Output 2
>> For 2 3

```

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

~~Don't~~ try it online!

**Explanation:**

In Whispers, the last line is executed first. The other lines are executed when they are referenced in an executing line.

1 `> 100` Integer \\$100\\$.

2 `>> 1*1` Result of *line 1* multiplied with itself.

3 `>> Output 2` Prints *line 2*.

4 `>> For 2 3` Executes *line 3* \\$n\\$ times, where \\$n\\$ is the result of *line 2*.
> 4 votes

# Answer
# Piet \+ ascii-piet, 112 70 bytes (5×14=70 codels)

```
vnfjlvudabknrTvn           Fv c ijjbrlk  Ev c?sj????d  Cv c ciqdlttdui

```

Try Piet online!

**Changes**

* -42 codels - thanks to @emanresu-a for getting me a different idea to set-up the stack.

**Explanation**

1. Outer path

Setting up the stack by pushing 5 and 2, then multiplying and duplicating until we have 10⁴, 10³² and 10⁶⁴. Lastly multiplying those to 10¹⁰⁰.
2. Loop

Looping a googol times and printing a 1 on each repetition. (same as before, just flipped)

```
command  -> stack after
push 1      [n, 1]
push 2      [n, 1, 2]
push 1      [n, 1, 2, 1]
roll        [1, n]
push 1      [1, n, 1]
out(Number) [1, n]
push 1      [1, n, 1]
subtract    [1, n-1]
duplicate   [1, n-1, n-1]
push 3      [1, n-1, n-1, 3]
push 1      [1, n-1, n-1, 3, 1]
roll        [n-1, 1, n-1]
greater     [n-1, 0 || 1]
pointer     [n-1]

```

**Simple Version for proving that it works**

Setting up stack with 10 and looping exactly the same for getting 10 1s as output.

Try simple loop online!

**Findings (by a 1st time user of Piet)**

* It's a refreshing exercise working with a stack-based 2D language and getting a picture out in the end.
* It's fun to try and squeeze it as small as possible, but probably there is a lot more to get :D
* I will most likely use this again on other golfing challenges
> 4 votes

# Answer
# Haskell, ~~45~~ 43 bytes

```
r 0=[]
r i='1':r(i-1)
main=putStr.r$10^100

```
> 3 votes

# Answer
## 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`.
> 3 votes

# Answer
## Racket 36 bytes

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

```

Output:

```
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

```
> 3 votes

# Answer
# 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)
> 3 votes

# Answer
# 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

```
> 3 votes

# Answer
# 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 10*N* 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 10*N* 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
λ

```
> 3 votes

# Answer
# Mathematica, ~~48~~ ~~30~~ 25 bytes

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

```

Output:

```
>> 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
>> 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
>> 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
>> 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
>> 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
etc.

```
> 3 votes

# Answer
# 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

```
> 3 votes

# Answer
# Vyxal `H`, ~~4~~ 3 bytes

*Crossed out 4 is still regular 4*

```
↵(,

```

Try it Online! Prints \\$10^{100}\\$ newlines.

```
↵   # 10 **...
    # 100 (Stack preset by flag)
 (, # Times print nothing (with a newline)

```
> 3 votes

# Answer
# 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.
> 2 votes

# Answer
# 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

```
> 2 votes

# Answer
# 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.
> 2 votes

# Answer
# Python 3, 32 bytes

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

```

Alternate solution, 33 bytes:

```
[print()for i in range(10**100)]

```
> 2 votes

# Answer
# 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.
> 2 votes

# Answer
# 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
> 2 votes

# Answer
# 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.
> 2 votes

# Answer
# 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.
> 2 votes

# Answer
# 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<
`@'|
,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<
`@'|
,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<
`@'`.
,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~<
`@','
,xZ<
`@'|
,xZ<
`@'`.
,xZ~<
`@'*|
 K aK
,xZ~<
`@','
,xZ<
`@'`.
,xZ~<
`@','
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'`.
,xZ~<
`@'*|
 K eK
,xZ~<
`@','
,xZ<
`@'`.
,xZ~<
`@','
,xZ<
`@'`.
,xZ~<
`@' |
,xZ~<
`@' |
,xZ~<
`@','
,xZ<
`@'|
 K K
,xZ<
`@'`.
,xZ~<
`@' |
,xZ~<
`@' |
,xZ~<
`@' |
,xZ~<
`@' |
,xZ~<
`@','
,xZ<
`@'`.
,xZ~<
`@'*|
 K fK
,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~<
`@'*}T
,xZ~<
`@','
 K K
,xZ<
`@'|
,xZ<
`@'`.
,xZ~<
`@','
,xZ<
`@'|
,xZ<
`@'`.
,xZ~<
`@','
,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 `Z`s. 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.
> 2 votes

# Answer
# 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.
> 2 votes

# Answer
# 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 `@`
* `eval`uate 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
> 2 votes

# Answer
# 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

```
> 2 votes

# Answer
# 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!
> 2 votes

# Answer
# Stax, 6 bytes

```
╡¢xYΓU

```

Uncompressed and explained:

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

```

Run and debug it
> 2 votes

# Answer
# 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

```
> 2 votes

# Answer
# Factor, 20 bytes

```
100 10^ [ bl ] times

```

Try it online!

* `100 10^ [ ... ] times` Call `[ ... ]` a googol times.
* `bl` Output a space.
> 2 votes

# Answer
# 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`.
> 1 votes

# Answer
## Common Lisp, 33

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

```

Print newlines.
> 1 votes

# Answer
# 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
> 1 votes

# Answer
# 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: []

```
> 1 votes

# Answer
## 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).
> 1 votes

# Answer
## Common Lisp, 37 bytes

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

```

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

# Answer
# 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.
> 1 votes

# Answer
# 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.
> 1 votes

# Answer
# 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 `10<sup>100</sup>`, 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.
> 1 votes

# Answer
# 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

```
> 1 votes

# Answer
# 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.
> 1 votes

# Answer
# 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
> 1 votes

# Answer
# SmileBASIC, 20 bytes

```
FOR I=1TO 1E100?NEXT

```
> 1 votes

# Answer
# .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

```
> 1 votes

# Answer
# 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

```
> 1 votes

# Answer
# 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.)
> 1 votes

# Answer
# Arturo, 32 bytes

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

```

Prints the number 0 with a newline a googol times.
> 1 votes

# Answer
# 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

```
> 1 votes

# Answer
# 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

```
> 1 votes

# Answer
# 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!
> 1 votes

# Answer
# ForceLang, 58 bytes

```
set k 10.pow 100
label a
set k k+-1
io.write 1
if k
goto a

```
> 0 votes

# Answer
# 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

```
> 0 votes

# Answer
# Charcoal, 9 bytes

Note that Charcoal uses a custom codepage.

```
ＦＸ¹⁰¦¹⁰⁰Ｄ

```

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

### Explanation

```
Ｆ        For
 Ｘ       Exponentiate
  ¹⁰¦¹⁰⁰  10, 100
Ｄ        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.
> 0 votes

# Answer
# 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: []

```
> 0 votes

# Answer
# 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
> 0 votes

# Answer
# 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".
> 0 votes

# Answer
# Groovy, 31 bytes

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

# Answer
# 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!
> 0 votes

# Answer
# 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

```
> 0 votes

# Answer
# 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() }

```
> 0 votes

# Answer
# 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 `bigint`s. 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.
> 0 votes

# Answer
## JavaScript, 35 bytes

BigInts ftw

```
i=10n**100n;while(i--)console.log()

```
> 0 votes

# Answer
# Julia 1.0, 30 bytes

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

```

Try it online!

with `BigInt`s, no problem calculating \\$10^{100}\\$
> 0 votes

# Answer
# 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 `10`s 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
> 0 votes

# Answer
# Pyt, 5 bytes

```
2ᴇᴇɬ*

```

Try it online!

```
2ᴇᴇ     pushes 10^100
   ɬ*   pushes "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", and repeats it a
        total of 10^100 times; implicit print

```
> 0 votes

# Answer
# 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

```
> 0 votes

# Answer
# Thunno, \\$ 9 \log\_{256}(96) \approx \\$ 7.41 bytes

```
10aS^{1ZL

```

Attempt This Online! Prints a googol `1`s.

#### 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

```
> 0 votes

# Answer
# Itr, 9 bytes

`10ä²^Må1£`

prints googol `1`s

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

```
> 0 votes

# Answer
# , 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.
> 0 votes

# Answer
# 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)
> 0 votes

# Answer
# 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.
> 0 votes

---
Tags: code-golf, string
---


title: Calculate Power Series Coefficients

text:
# Question
Title: Calculate Power Series Coefficients
Given a polynomial \\$p(x)\\$ with integral coefficients and a constant term of \\$p(0) = \pm 1\\$, and a non-negative integer \\$N\\$, return the \\$N\\$-th coefficient of the power series (sometimes called "Taylor series") of \\$f(x) = \frac{1}{p(x)}\\$ developed at \\$x\_0 = 0\\$, i.e., the coefficient of the monomial of degree \\$N\\$.

The given conditions ensure that the power series exist and that the its coefficients are integers.

### Details

As always the polynomial can be accepted in any convenient format, e.g. a list of coefficients, for instance \\$p(x) = x^3-2x+5\\$ could be represented as `[1,0,-2,5]`.

The power series of a function \\$f(x)\\$ developed at \\$0\\$ is given by

$$f(x) = \sum\_{k=0}^\infty{\frac{f^{(n)}(0)}{n!}x^n}$$

and the \\$N\\$-th coefficient (the coefficient of \\$x^N\\$) is given by

$$\frac{f^{(N)}}{N!}$$

where \\$f^{(n)}\\$ denotes the \\$n\\$-th derivative of \\$f\\$

### Examples

* The polynomial \\$p(x) = 1-x\\$ results in the geometric series \\$f(x) = 1 + x + x^2 + ...\\$ so the output should be \\$1\\$ for all \\$N\\$.
* \\$p(x) = (1-x)^2 = x^2 - 2x + 1\\$ results in the derivative of the geometric series \\$f(x) = 1 + 2x + 3x^2 + 4x^3 + ...\\$, so the output for \\$N\\$ is \\$N+1\\$.
* \\$p(x) = 1 - x - x^2\\$ results in the generating function of the Fibonacci sequence \\$f(x) = 1 + x + 2x^2 + 3x^3 + 5x^4 + 8x^5 + 13x^6 + ...\\$
* \\$p(x) = 1 - x^2\\$ results in the generating function of \\$1,0,1,0,...\\$ i.e. \\$f(x) = 1 + x^2 + x^4 + x^6 + ...\\$
* \\$p(x) = (1 - x)^3 = 1 -3x + 3x^2 - x^3\\$ results in the generating function of the triangular numbers \\$f(x) = 1 + 3x + 6x^6 + 10x^3 + 15x^4 + 21x^5 + ...\\$ that means the \\$N\\$-th coefficient is the binomial coefficient \\$\binom{N+2}{N}\\$
* \\$p(x) = (x - 3)^2 + (x - 2)^3 = 1 + 6x - 5x^2 + x^3\\$ results in \\$f(x) = 1 - 6x + 41x^2 - 277x^3 + 1873x4 - 12664x^5 + 85626x^6 - 57849x^7 + \dots\\$

# Answer
## Mathematica, 24 23 bytes

*Saved 1 byte thanks to Greg Martin*

```
D[1/#2,{x,#}]/#!/.x->0&

```

Pure function with two arguments `#` and `#2`. Assumes the polynomial `#2` satisfies `PolynomialQ[#2,x]`. Of course there's a built-in for this:

```
SeriesCoefficient[1/#2,{x,0,#}]&

```
> 9 votes

# Answer
# Matlab, ~~81 79~~ 75 bytes

Unlike the previous two answers this doesn't make use of symbolic calculations. The idea is that you can iteratively calculate the coefficients:

```
function C=f(p,N);s=p(end);for k=1:N;q=conv(p,s);s=[-q(end-k),s];end;C=s(1)

```

Try it online!

### Explanation

```
function C=f(p,N);
s=p(end);            % get the first (constant coefficient)
for k=1:N;
    q=conv(p,s);     % multiply the known coefficients with the polynomial
    s=[-q(end-k),s]; % determine the new coefficient to make the the product get "closer"
end;
C=s(1)           % output the N-th coefficient

```
> 6 votes

# Answer
# GeoGebra, 28 bytes

```
Derivative[1/A1,B1]/B1!
f(0)

```

Input is taken from the spreadsheet cells A1 and B1 of a polynomial and an integer respectively, and each line is entered separately into the input bar. Output is via assignment to the variable `a`.

Here is a gif showing the execution:

Using builtins is much longer, at 48 bytes:

```
First[Coefficients[TaylorPolynomial[1/A1,0,B1]]]

```
> 4 votes

# Answer
## Haskell, 44 bytes

```
p%n=(0^n-sum[p!!i*p%(n-i)|i<-[1..n]])/head p

```

A direct computation without algebraic built-ins. Takes input as an infinite list of power series coefficients, like `p = [1,-2,3,0,0,0,0...]` (i.e. `p = [1,-2,3] ++ repeat 0`) for `1-2*x+x^2`. Call it like `p%3`, which gives `-4.0`.

The idea is if **p** is a polynomial and **q=1/p** is it inverse, then we can express the equality **p·q=1** term-by-term. The coefficient of **xn** in **p·q** is given by the convolution of the coefficients in **p** and **q**:

**p0· qn \+ p1· qn-1 \+ ... + pn· q0**

For **p·q=1** to hold, the above must equal zero for all **n\>0**. For here, we can express **qn** recursively in terms of **q0, ..., qn-1** and the coefficients of **p**.

**qn = - 1/p0 · (p1· qn-1 \+ ... + pn· q0)**

This is exactly what's calculated in the expression `sum[p!!i*p%(n-i)|i<-[1..n]]/head p`, with `head p` the leading coefficient **p0**. The initial coefficient **q0 = 1/p0** is handled arithmetically in the same expression using `0^n` as an indicator for `n==0`.
> 4 votes

# Answer
# J, 12 bytes

```
1 :'(1%u)t.'

```

Uses the adverb `t.` which takes a polynomial `p` in the form of a verb on the LHS and a nonnegative integer `k` on the RHS and computes the `k`th coefficient of the Taylor series of `p` at `x = 0`. In order to get the power series, the reciprocal of `p` is taken before applying it.

Try it online!
> 3 votes

# Answer
# Maple, ~~58~~ 26 bytes

This is an unnamed function that accepts a polynomial in `x` and an integer `N`.

EDIT: I just noticed that there is a builtin:

```
(p,N)->coeftayl(1/p,x=0,N)

```
> 2 votes

# Answer
# MATL, 19 bytes

```
0)i:"1GY+@_)_8Mh]1)

```

Translation of @flawr's great Matlab answer.

Try it online!

### How it works

```
0)      % Implicitly input vector of polynomial coefficients and get last entry
i       % Input N
:"      % For k in [1 2 ... N]
  1G    %   Push vector of polynomial coefficients
  Y+    %   Convolution, full size
  @     %   Push k
  _     %   Negate
  )     %   Index. This produces the end-k coefficient
  _     %   Negate
  8M    %   Push first input of the latest convolution
  h     %   Concatenate horizontally
]       % End
1)      % Get first entry. Implicitly display

```
> 1 votes

# Answer
## JavaScript (ES6), 57 bytes

```
(a,n)=>a.reduce((s,p,i)=>!i|i>n?s:s-p*f(a,n-i),!n)/a[0]

```

Port of @xnor's Haskell answer. I originally tried an iterative version but it turned out to be 98 bytes, however it will be much faster for large N, as I'm effectively memoising the recursive calls:

```
(a,n)=>[...Array(n+1)].fill(0).map((_,i,r)=>r[i]=r.reduce((s,p,j)=>s-p*(a[i-j]||0),!i)/a[0]).pop()

```

`n+1` terms are required, which are saved in the array `r`. It is initially zeros which allows reducing over the entire array `r` at once, as the zeros will not affect the result. The last calculated coefficient is the final result.
> 1 votes

# Answer
# PARI/GP, ~~31~~ 27 bytes

```
f->n->Pol(Ser(1/f,,n+1))\x^n

```
> 1 votes

# Answer
# Maxima, ~~31~~ 25 bytes

Saved 6 bytes thanks to the comment of @alephalpha

```
f(e,R):=taylor(1/e,x,0,R)

```

Try it online!
> 1 votes

---
Tags: code-golf, math, polynomials
---


# Question
Title: CGAC2022 Day 10: Help Santa sort presents!
Part of **Code Golf Advent Calendar 2022** event. See the linked meta post for details.

---

Santa likes to sort his presents in a special way. He keeps "uninterleaving" the pile of presents into smaller sub-piles until each sub-pile is either full of toys or full of coal.
Your job is to, given a pile of presents, determine the maximum number of uninterleavings.

Uninterleaving a pile of presents, (eg. \\$1011011\\$), means separating every `second` item and every `second + 1` item into its own sub-pile (\\$1101\\$, \\$011\\$).

Sorting \\$010011100101\\$ would be (implies that \\$1\\$ is a present full of toys and \\$0\\$ is a present full of coal):

```
- 010011100101
 - 001100
     - 010
         - 00
         - 1
     - 010
         - 00
         - 1
 - 101011
     - 111
     - 001
         - 01
             - 0
             - 1
         - 0

```

The answer would be the maximum number of times Santa has to uninterleave the presents (from \\$010011100101\\$ to \\$0\\$ or \\$1\\$), \\$4\\$.

The shortest code wins.

## Test cases

<pre><code>[In]:  1
[Out]: 0

[In]: 1010101
[Out]: 1

[In]: 101011
[Out]: 3

[In]: 1011001101110001101011100
[Out]: 5
```
</code></pre>

# Answer
> 8 votes
# , 34 bytes

```
1 i.~]*/@(1=#@=/.~)"1(|/~2^])@i.@#

```

Try it online!

Assuming my comments for test case corrections on the OP are correct, this answer should be right.

This generates "power of 2" masks for grouping the input like:

```
0 0 0 0 0 0 0 0
0 1 0 1 0 1 0 1
0 1 2 3 0 1 2 3
0 1 2 3 4 5 6 7

```

It uses each candidate to group the input, and then checks if, using that grouping, we have "pure" coal or present groups. Then it returns the index of the first grouping that works.

# Answer
> 6 votes
# Python, 41 bytes (@dingledooper)

```
f=lambda e,j=1:e[j:]!=e[:-j]and-~f(e,j*2)

```

Attempt This Online!

### Python, 49 bytes

```
lambda e,j=1:sum(e[j:]!=e[:j-(j:=2*j)]for _ in e)

```

Attempt This Online!

Brazenly stole @jezza\_99's test harness.

### How?

Based on the observation that the required split depth equals the number of powers of two `j=1,2,4,8,...` such that `e[j:] != e[:-j]`.

For example, if `j=4` then `e[j:] == e[:-j]` means precisely that any two characters 4 positions apart must be equal. And the four full chains of such element are exactly the uninterleaved piles after two splits.

# Answer
> 4 votes
# Charcoal, ~~29~~ 21 bytes

```
Ｗ⊙Ｅθ✂θλＬθＸ²ⅈ‹⌊κ⌈κＭ→Ｉⅈ

```

Try it online! Link is to verbose version of code. Explanation: Now uses @Jonah's observation that the problem is equivalent to finding the smallest power of two count of groups where all of the groups are pure.

```
Ｗ⊙Ｅθ✂θλＬθＸ²ⅈ‹⌊κ⌈κ

```

While at least one slice of step 2 to the power the number of iterations contains both toys and coal...

```
Ｍ→

```

Increment the number of iterations. (The previous version didn't need the  because the block meant that it wasn't ambiguous.) Moving the cursor horizontally doesn't change the output since the canvas trims automatically in this case.

```
Ｉⅈ

```

Output the number of iterations. Using the X position as the iteration count saves 3 bytes over pushing dummy values to the predefined empty list and 4 bytes over using a counter variable.

# Answer
> 4 votes
# Python, ~~69~~ 58 bytes

```
f=lambda e:0if len({*e})<2else max(f(e[::2]),f(e[1::2]))+1

```

Attempt This Online!

A recursive function that splits into two branches at each indentation if the pile is not all `0` or `1`, and returns the maximum number of indentations from all of the branches.

-11 bytes thanks to @GandhiGandhi

# Answer
> 4 votes
# Jelly, 15 bytes

```
WŒœ€ẎQƊƬE€Ạ$€¬S

```

A monadic Link that accepts a list and yields the maximal number of uninterleavings required to separate the items (works for more than just two categories).

**Try it online!**

### How?

```
WŒœ€ẎQƊƬE€Ạ$€¬S - Link: list, A
W               - wrap (A)
       Ƭ        - collect up (starting with that) while distinct applying:
      Ɗ         -   last three links as a monad:
   €            -     for each:
 Œœ             -       odd-even (e.g. [1,0,1,0,0] -> [[1,1,0],[0,0]])
    Ẏ           -     tighten
     Q          -     deduplicate
            €   - for each:
           $    -   last two links as a monad:
         €      -     for each:
        E       -       all equal?
          Ạ     -     all?
             ¬  - logical NOT
              S - sum

```

# Answer
> 4 votes
# Vyxal, ~~12~~ 9 bytes

```
E?ẇ∩v≈A)Ṅ

```

Try it online!

### Explanation

Based upon Jonah's observation.

```
       )  # a lambda taking N:
E         #   2 ** N
 ?        #   push input
  ẇ       #   wrapped in chunks of length 2 ** N
   ∩      #   transposed
    v≈    #   is every element the same? (vectorise)
      A   #   all?
        Ṅ # first non-negative integer where it is true

```

# Answer
> 3 votes
# JavaScript (ES6), 71 bytes

```
f=(a,g=q=>v=new Set(a).size>1&&1+f(a.filter(_=>++q&1)))=>g``<g(1)?v:g``

```

Try it online!

Or:

```
f=(a,g=q=>v=/0,1|1,0/.test(a)&&1+f(a.filter(_=>++q&1)))=>g``<g(1)?v:g``

```

Try it online!

# Answer
> 3 votes
# Nibbles, ~~12.5~~ 10.5 bytes (21 nibbles)

```
,|`,,$+.`'`/^2$@>>=~

```

Inspired by Jonah's answer.

```
,|`,,$+.`'`/^2$@>>=~
 |                          # filter each n in
  `,                        # 0..
    ,$                      #    length of input
          `/                #   get chunks of
               @            #   input
            ^2$             #   of size 2^n,
        `'                  #   transpose,
       .                    #   and map over each group
                  =~        #     collect identical elements into groups
                >>          #     and remove the first group
,                           # finally, get the length

```

# Answer
> 3 votes
# Nekomata, 9 bytes

```
ˡ{ᵗ≡ĭ?}aṀ

```

Attempt This Online!

```
ˡ{ᵗ≡ĭ?}aṀ
ˡ{    }     Loop until failure, and count the number of iterations:
  ᵗ≡            Check that elements in the list are not all equal
    ĭ           Uninterleave
     ?          Choose any of the two lists
       a    All possible values
        Ṁ   Maximum

```

# Answer
> 2 votes
# Japt, ~~13~~ 12 bytes

```
èø2¤á)©ÒßUcó

```

Try it

```
èø2¤á)©ÒßUcó     :Implicit input of (initially singleton) array U
è                :Count the element that
 ø               :  Contain any element of
  2¤             :    2 converted to a binary string
    á            :    Permutations
     )           :End count
      ©          :Logical AND with
       Ò         :Negate the bitwise NOT of
        ß        :A recursive call with argument
         Uc      :  Flat map U
           ó     :    Uninterleave

```

# Answer
> 2 votes
# PARI/GP, 51 bytes

```
f(a,i=1)=if(i<#a&&a[1+i..-1]-a[1..-i-1],1+f(a,2*i))

```

Attempt This Online!

A port of @loopy walt's Python answer.

# Answer
> 2 votes
# 05AB1E, ~~12~~ 10 bytes

```
∞<.Δoι0KSP

```

`o` is inspired by *@Jonah*'s J answer.

Try it online or verify all test cases.

`∞<.Δ` could alternatively be `ÅΔIN` for the same byte-count:
Try it online or verify all test cases.

**Explanation:**

```
∞           # Push an infinite positive list: [1,2,3,...]
 <          # Decrease each by 1 to an infinite non-negative list: [0,1,2,...]
  .Δ        # Pop and find the first which is truthy for:
    o       #  Push 2 to the power this value
     ι      #  Uninterleave the (implicit) input into that many parts
      0KSP  #  Check if each item consists of unique digits (or is empty):
      0K    #   Remove all 0s from the list (including "00","000",etc.)
        S   #   Convert it to a flattened list of digits (also removes empty items)
         P  #   Check if all are 1s by taking the product (only 1 is truthy in 05AB1E)
            # (after which the found result is output implicitly)

```

# Answer
> 1 votes
# JavaScript (Node.js), 46 bytes

```
a=>(g=i=>a.some((v,j)=>v^a[j%i])&&1+g(2*i))(1)

```

Try it online!

Bit magic

# Answer
> 1 votes
# Scala 3, 120 bytes

A port of @loopy walt's Python answer.

---

```
def f(a:Seq[Int],i:Int=1):Int=if(i<a.length&& !a.slice(i,a.length).sameElements(a.slice(0,a.length-i)))1+f(a, 2*i)else 0

```

Attempt This Online!

---
Tags: code-golf, string, binary, sorting
---


title: Ryley's Theorem

text:
# Question
Title: Ryley's Theorem
S. Ryley proved following theorem in 1825:

> Every rational number can be expressed as a sum of three rational cubes.

### Challenge

Given some rational number \\$r \in \mathbb Q \\$ find three rational numbers \\$a,b,c \in \mathbb Q\\$ such that $$r= a^3+b^3+c^3.$$

### Details

Your submission should be able to compute a solution for every input given enough time and memory, that means having for instance two 32-bit `int` representing a fraction is not sufficient.

### Examples

$$ \begin{align} 30 &= 3982933876681^3 - 636600549515^3 - 3977505554546^3 \\ 52 &= 60702901317^3 + 23961292454^3 - 61922712865^3 \\ \frac{307}{1728} &= \left(\frac12\right)^3 + \left(\frac13\right)^3 + \left(\frac14\right)^3 \\ 0 &= 0^3 + 0^3 + 0^3 \\ 1 &= \left(\frac12\right)^3 + \left(\frac23\right)^3 + \left(\frac56\right)^3\\ 42 &= \left(\frac{1810423}{509232}\right)^3 + \left(\frac{-14952}{10609}\right)^3 + \left(\frac{-2545}{4944}\right)^3 \end{align}$$

# Answer
> 13 votes
# PARI/GP, 35 bytes

```
r->[x=r+1/3,-x+r/3/d=x^2-r,1/9/d-1]

```

Attempt This Online!

---

# PARI/GP, 40 bytes

```
r->[x=27*r^3+1,9*r-x,z=9*r-27*r^2]/(3-z)

```

Attempt This Online!

---

This formula is given in: Richmond, H. (1930). On Rational Solutions of \\$x^3+y^3+z^3=R\\$. *Proceedings of the Edinburgh Mathematical Society, 2*(2), 92-100.

$$r=\left(\frac{27r^3+1}{27r^2-9r+3}\right)^3+\left(\frac{-27r^3+9r-1}{27r^2-9r+3}\right)^3+\left(\frac{-27r^2+9r}{27r^2-9r+3}\right)^3$$

Check it online!

# Answer
> 8 votes
# Haskell, ~~95~~ ~~89~~ ~~76~~ ~~69~~ 68 bytes

```
f x=[w|n<-[1..],w<-mapM(\_->[-n,1/n-n..n])"IOU",x==sum((^3)<$>w)]!!0

```

Try it online!

Simple bruteforce solution. It tests all triples of rational numbers of the form $$ \left(\frac{a\_1}{n},\frac{a\_2}{n},\frac{a\_3}{n}\right)\qquad\text{with }-n\le\frac{a\_i}{n}\le n. $$

* We can always assume that the three rational numbers have the same denominator, since $$ \left(\frac{a\_1}{n\_1},\frac{a\_2}{n\_2},\frac{a\_3}{n\_3}\right)=\left(\frac{a\_1n\_2n\_3}{n\_1n\_2n\_3},\frac{a\_2n\_1n\_3}{n\_1n\_2n\_3},\frac{a\_3n\_1n\_2}{n\_1n\_2n\_3}\right). $$
* We can always assume that \\$-n\le\frac{a\_i}{n}\le n\\$, since $$ \frac{a\_i}{n}=\frac{a\_iN}{nN} $$ for any arbitrarily large integer \\$N\\$.

# Answer
> 7 votes
# Husk, 14 bytes

```
ḟo=⁰ṁ^3π3×/NİZ

```

Simple brute force solution. Try it online!

## Explanation

Division in Husk uses rational numbers by default and Cartesian products work correctly for infinite lists, making this a very straightforward program.

```
ḟo=⁰ṁ^3π3×/NİZ
            İZ  Integers: [0,1,-1,2,-2,3,-3...
           N    Natural numbers: [1,2,3,4,5...
         ×/     Mix by division: [0,1,0,-1,1/2,0,2,-1/2,1/3...
                This list contains n/m for every integer n and natural m.
       π3       All triples: [[0,0,0],[0,0,1],[1,0,0]...
ḟ               Find the first one
    ṁ^3         whose sum of cubes
 o=⁰            equals the input.

```

# Answer
> 2 votes
# JavaScript (Node.js), 73 bytes

Takes input as `(p)(q)`, where \\$p\\$ and \\$q\\$ are BigInt literals.

Returns `[[p1,q1],[p2,q2],[p3,q3]]` such that \\$\frac{p}{q}=\left(\frac{p\_1}{q\_1}\right)^3+\left(\frac{p\_2}{q\_2}\right)^3+\left(\frac{p\_3}{q\_3}\right)^3\\$.

```
p=>q=>[x=p*(y=p*(p*=9n*q*q)*3n/q)/q+(q*=q*q),p-x,p-=y].map(x=>[x,3n*q-p])

```

Try it online!

Derived from H. W. Richmond (1930), On Rational Solutions of x3 \+ y3 +z3 = R.

# Answer
> 2 votes
# Haskell, 70 bytes

In *An introduction to the Theory of Numbers* (by Hardy and Wright) there is an construction that even includes a rational parameter. For golfing purposes I just set this parameter to 1, and tried reducing as much as possible. This results in the formula

$$r \mapsto \left\[ {{r^3-648\\,r^2+77760\\,r+373248}\over{72\\,\left(r+72\right)^2 }} , {{12\\,\left(r-72\right)\\,r}\over{\left(r+72\right)^2}} , -{{r^2 -720\\,r+5184}\over{72\\,\left(r+72\right)}} \right\] $$

```
f r|t<-r/72,c<-t+1,v<-24*t/c^3,a<-(v*t-1)*c=((a+v*c+c)/2-)<$>[a,v*c,c]

```

Try it online!

# Answer
> 1 votes
# perl -Mbigrat -nE, 85 bytes

```
$_=eval;($a,$b)=($_*9,$_**2*27);$c=$b*$_;say for map$_/($b-$a+3),$c+1,-$c+$a-1,-$b+$a

```

You can save 8 bytes (the leading `$_=eval;`) if you know the input is an integer; this part is needed to have the program grok an input of the form `308/1728`. Input is read from STDIN. I'm using the formula given by @alephalpha.

# Answer
> 1 votes
# Maxima, 62 bytes

A port of @alephalpha's Pari/GP code in Maxima.

---

Try it online!

```
lambda([r],block([x:27*r^3+1,z:9*r-27*r^2],[x,9*r-x,z]/(3-z)))

```

---
Tags: code-golf, math, number-theory, rational-numbers, polynomials
---


# Question
Title: Minimal number of jumps to reach a square
*A Knight in chess moves two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of a capital L)*

---

Given a Knight current square in a chess board and an array of unavailable squares, calculate the minimum number of **valid** jumps required to reach a target square. If no route is available to reach the required target return 0.

A **valid** jump is a move that:

* Does not go out of the board (8x8 square board)
* Does not overlap with another piece
* Follows the Knight L shape move pattern

---

**Input**

Knight square, array of occupied squares, target square. Input might look like:

```
f("b3", ["c4", "h7", "g5", "a8"], "b7")

```
* You can use a set of coordinates instead of chess algebraic notation. It can be 0 or 1-index. Example: `b3 -> (2,3)` or `b3 -> (1,2)`
* You can assume that `Knight Square != Target Square` for every input.
* You can assume every input square is valid and non overlapping
* Input values can be taken in any order you'd like

**Output**

Minimal number of **valid** jumps to reach a square, or 0 in case no route can be found

---

**Test Cases**

```
"e3", [], "f5" -> 1
"e3", [], "f6" -> 2
"c4", [], "f6" -> 3
"g1", ["f3", "g3"], "h4" -> 4
"c4", ["d6", "b6", "e5", "e3", "e4"], "f6" -> 5
"a1", [], "h8" -> 6
"g1", ["h3","h5","g2","g3","g6","f3", "e5", "e6", "d4", "d5", "c1", "c3", "c5", "b2"], "b7" -> 7
"h1", ["f2", "g3"], "h3" -> 0
"d4", ["b3", "b5", "c2", "c6", "e2", "e6", "f3", "f5"], "a8" -> 0

```

# Answer
# Python, 154 bytes

*-17 bytes, thanks to The Thonnu*

```
def f(s,b,t,k=0):
 p=s,
 while(t in p)*64<64>k:p=[[u,v]for i in range(64)if([u:=i//8,v:=i%8]in b)<any((x-u)**2+(y-v)**2==5for x,y in p)];k+=1
 return k%64

```

Attempt This Online!

Goes through all reachable fields until target is reached, aborts after 64 steps and returns 0
> 5 votes

# Answer
# JavaScript (Node.js), 143 bytes

Expects `[source, target, occupied_0, occupied_1, ...]` where each square is a pair of 0-indexed coordinates.

```
f=(a,n)=>(g=(n,s)=>(i=b.indexOf(s))>1|s&136?0:i>0|Buffer(' "/3OS`b').some(v=>n&&g(n-1,s+v-65)))(n,...b=a.map(([x,y])=>x|y<<4))?n:n>9?0:f(a,-~n)

```

Try it online!

### How?

This is internally using the 0x88 encoding. Converting the input to this format is a bit costly, but it makes basically everything else easier and shorter (moves, square comparisons and out-of-board detections).
> 4 votes

# Answer
# Excel, 236 bytes

Define `z` as:

```
=LAMBDA(p,q,
    LET(
        a,OFFSET(
            INDIRECT(p),
            {-2,-2,-1,-1,1,1,2,2},
            {-1,1,-2,2,-2,2,-1,1}
        ),
        b,ROW(a),
        c,COLUMN(a),
        d,TOCOL(IF((b<9)*(c<9),ADDRESS(b,c,4),NA()),2),
        e,FILTER(d,ISNA(XMATCH(d,$B1#))),
        IF(SUM(N(e=$C1))>0,q+1,z(e,q+1))
    )
)

```

Within the worksheet:

```
=IFERROR(z($A1,),)

```

Knight square in cell `A1`, target square in cell `C1` and occupied squares in spilled, vertical range `B1#`.
> 3 votes

# Answer
# Charcoal, 59 bytes

```
Ｆ…β⁸Ｆ⁸⊞υ⁺ι⊕κ≔⟦θ⟧θＷ∧¬№θζΦ⁻υ⁺θη⊙θ⁼⁵ΣＸＥμ⁻℅ξ℅§κπ²«→≔⁺θιθ»Ｉ∧№θζⅈ

```

Try it online! Link is to verbose version of code. Explanation:

```
Ｆ…β⁸Ｆ⁸⊞υ⁺ι⊕κ

```

Create a list of all valid chess board squares.

```
≔⟦θ⟧θ

```

Start with one reachable square.

```
Ｗ∧¬№θζΦ⁻υ⁺θη⊙θ⁼⁵ΣＸＥμ⁻℅ξ℅§κπ²«

```

While the target has not been reached and there are still more squares that can be reached...

... increment the count of jumps, and...

```
≔⁺θιθ

```

... append the newly reachable squares to the list of reachable squares.

```
»Ｉ∧№θζⅈ

```

Output the count of jumps or `0` if the target was not reached.

51 bytes by taking input as Gaussian integers:

```
≔⟦θ⟧θＷ∧¬№θζΦ⁻ΣＥ⁸Ｅ⁸⁺κ×μＩ1j⁺θη⊙θ⁼₂⁵↔⁻μκ«→≔⁺θιθ»Ｉ∧№θζⅈ

```

Attempt This Online! Link is to verbose version of code.
> 2 votes

# Answer
# Scala, ~~378~~ 336 bytes

Port of @bsoelch's Python answer in Scala.

Saved 42 bytes thanks to the comment of @Kjetil S

---

Golfed version. Try it online!

```
def f(s:(Int,Int),b:Seq[(Int,Int)],t:(Int,Int),K:Int=0)={var p=Seq(s);var k=K;while(!p.contains(t)&&k<64){p=(for(i<-0 until 64;u=i/8;v=i%8;if !b.contains((u,v))&&p.exists{case(x,y)=>(x-u)*(x-u)+(y-v)*(y-v)==5})yield(u,v)).toList;k+=1};k%64}
def C(s:String)=(s(0)-97,s(1)-49)
def h(a:String,b:List[String],c:String)=f(C(a),b.map(C),C(c))

```

Ungolfed version. Try it online!

```
object Main {
  def f(s: (Int, Int), b: List[(Int, Int)], t: (Int, Int), k: Int = 0): Int = {
    var p = List(s)
    var kVar = k
    while (!p.contains(t) && kVar < 64) {
      p = (for (i <- 0 until 64;
                u = i / 8;
                v = i % 8;
                if !b.contains((u, v)) && p.exists { case (x, y) => (x - u) * (x - u) + (y - v) * (y - v) == 5 })
            yield (u, v)).toList
      kVar += 1
    }
    kVar % 64
  }

  def coord(s: String): (Int, Int) = {
    ("abcdefgh".indexOf(s.charAt(0)), s.charAt(1).asDigit - 1)
  }

  def helper(a: String, b: List[String], c: String): Int = {
    f(coord(a), b.map(coord), coord(c))
  }

  def main(args: Array[String]): Unit = {
    println(helper("e3", List(), "f5")) //-> 1
    println(helper("e3", List(), "f6")) //-> 2
    println(helper("c4", List(), "f6")) //-> 3
    println(helper("g1", List("f3", "g3"), "h4")) //-> 4
    println(helper("c4", List("d6", "b6", "e5", "e3", "e4"), "f6")) //-> 5
    println(helper("a1", List(), "h8")) //-> 6
    println(helper("g1", List("h3","h5","g2","g3","g6","f3", "e5", "e6", "d4", "d5", "c1", "c3", "c5", "b2"), "b7")) //-> 7
    println(helper("h1", List("f2", "g3"), "h3")) //-> 0
    println(helper("d4", List("b3", "b5", "c2", "c6", "e2", "e6", "f3", "f5"), "a8")) //-> 0
  }
}

```
> 2 votes

# Answer
# K (ngn/k), 62 bytes

```
{0^*&~^?[;z]'64{?,/x@y}[i!i@&'(4=*/4#)''i-\:/:i:(+!8 8)^y]\,x}

```

Try it online!
> 2 votes

# Answer
# , 59 bytes

```
1 :'1{.[:I.[e."1(u-.~,j./~i.8)(]~.@,&;[<@#~2j1=&|-/~)^:a:]'

```

Attempt This Online!

Takes input as complex numbers.

To handle all 3 args, we use a J adverb which modifies the list of illegal positions, and takes the target and start positions as the left and right args, respectively.

* `(u-.~,j./~i.8)` Generate the full board minus the illegal spaces
* `(]~.@,&;[<@#~2j1=&|-/~)^:a:]` Collecting each step's results until you reach a fixed point, starting the initial square, find all legal spaces that are \\$\sqrt{5}\\$ away from the current positions. In this way, we spider out stepwise to every reachable position
* `[e."1` For each steps results, is the target position in that list? Now our list of lists (the step results) will become a single 0-1 list, with the first `1` representing the index we seek
* `[:I.` All `1` indexes. Returns empty list for no matches.
* `1{.` Take the first. Exactly what we need, and since taking 1 from the empty list returns 0, it also handles the no match case.
> 1 votes

# Answer
# Haskell, 192 bytes

```
n=99
q=[-1,1]
(#)=elem
g a b p c=last$last(1+g[w|s<-a,x<-[1,2],y<-q,z<-q,w<-[zipWith(+)s[y*x,z*(3-x)]],all(`elem`[0..7])w&&not(w#b)]b(p++a)c:[n|all(#p)a]):[0|c#a]
f a b c= min(g[a]b[]c)n`mod`n

```

Attempt This Online!
> 1 votes

# Answer
# Perl 5, 166 bytes

```
sub{($s,$e,%o)=@_;@w=(0,$s);while(($n,$s,@w)=@w){$s-$e||last,push@w,map{$n+1,$_}grep{($a,$b,$c,$d)=map{$_>>3,$_%8}$s,$_;!(($a-$c)**2+($b-$d)**2-5||$o{$_}++)}0..63}$n}

```

Try it online!

```
sub steps {
  ($s,$e,%o)=@_;        #start, end, occupied set as hash from input args in @_
  @w=(0,$s);            #initial work (steps,square)
  while(($n,$s,@w)=@w){ #while work left to be done
    $s-$e||last,        #bail if current square $s equals $e end square
    push@w,             #register new work/new squares to be checked
      map{$n+1,$_}      # (new steps, new square)
      grep{                       #filter
        ($a,$b,$c,$d)             #coords of current square ($a,$b)
          =map{$_>>3,$_%8}$s,$_;  #...and potential new square ($c,$d)
        !(($a-$c)**2+($b-$d)**2-5 #pythagorean horsyness check of new vs current
          ||$o{$_}++)             #...non-occupied new squares
                                  #...and register new square as occupied
                                  #...with ++ to not enter it again
      }
      0..63                       #loop through potential new squares
  }
  $n                              #return n steps from last work
}

```
> 0 votes

---
Tags: code-golf, chess
---