10
\$\begingroup\$

In any programming language, make a program that outputs infinite subsequent powers of two, starting at any power of two with finite integer exponent. There does not need to be a seperator between outputs.
Note: it only has to theoretically output infinite subequent powers of two given infinite integer size (so you can ignore any potential issues with floating-point).
Each power of two sufficently sized (greater than some value) must be theoretically be able to be outputted within a finite amount of time.
An example in js might look like this:

var num = 1;
while (true){
  console.log(num);
  num *= 2;
}

Remember, shortest wins

Standard Loopholes apply.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Possible duplicate \$\endgroup\$
    – Shaggy
    Commented May 29, 2023 at 20:43
  • 1
    \$\begingroup\$ @Shaggy That counts incrementally. This counts by repeated doubling. \$\endgroup\$
    – Dadsdy
    Commented May 29, 2023 at 21:12
  • 5
    \$\begingroup\$ Multiplying by 2 instead of adding 1 isn't a significant enough difference for me such that the majority of solutions for one aren't trivially modifiable to work for the the other. \$\endgroup\$
    – Shaggy
    Commented May 29, 2023 at 21:31
  • \$\begingroup\$ Given that the upvotes on my comment above would be sufficient to VTC this and that my Rockstar solution was automatically flagged as a duplicate of my solution to the dupe target, I'm afraid I'm going to have to swing my hammer here. \$\endgroup\$
    – Shaggy
    Commented May 30, 2023 at 21:42
  • \$\begingroup\$ Well, I solved this before I realized it was closed. Here's my 10 Piet-ASCII. \$\endgroup\$
    – SanguineL
    Commented Jun 27, 2023 at 20:04

40 Answers 40

1
2
1
\$\begingroup\$

Fortran (GFortran), 51 bytes

integer(kind=16)i;i=1
1 print*,2**i;i=i+1;goto1;end

Try it online!

Fortran's default integer max is 2147483647 (=2^31-1) but setting kind=16 extends the range up to 170141183460469231731687303715884105727 (=2^127-1)

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

bc, 14 bytes

while(1)2^x++

Try it online!

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

Arturo, 19 bytes

1whileø[*2print<=]

enter image description here

1         ; push 1 to the stack
whileø[   ; start infinite loop
    <=    ; duplicate
    print ; print
    *2    ; double
]         ; end infinite loop(?)
\$\endgroup\$
1
\$\begingroup\$

Nibbles, 3 bytes (6 nibbles)

`.;2*
`.;2*       # full program
`.;2*@$     # with implicit args added
`.          # repeatedly apply (while results are unique)
   2        # starting with 2
  ;         # (and save the 2 for later)
    *       #   multiply
     @      #   saved value of 2
      $     #   by result-so-far

enter image description here


Alternative approach, also 3 bytes (6 nibbles):

.,~^2
.,~^2       # full program
.,~^2$      # with implicit arg added
.           # map over
 ,          # list from 1..
  ~         # infinity:
   ^2       #   2 to the power of
     $      #   each element in the list
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 2 bytes

∞o

Try it online.

Explanation:

∞   # Infinite list of positive integers: [1,2,3,...]
 o  # Take 2 to the power each value in the list
    # (after which the infinite list is output implicitly as result)
\$\endgroup\$
1
\$\begingroup\$

MathGolf, 4 bytes

îóo∟

Try it online.

Explanation:

   ∟  # Do-while true without popping:
 ó    #  Take 2 to the power
î     #  the 1-based loop index
  o   #  Print with trailing newline without popping
\$\endgroup\$
1
\$\begingroup\$

Python, 24 bytes

-1 byte from @Sisyphus

a=1
while[print(a)]:a*=2

Attempt This Online!

Python 2, 24 bytes

a=1
while 1:print a;a*=2

Attempt This Online!

\$\endgroup\$
1
  • 3
    \$\begingroup\$ while[print(a)]:a*=2 \$\endgroup\$
    – Sisyphus
    Commented May 30, 2023 at 7:47
1
\$\begingroup\$

Go, 32 bytes, to STDERR

func f(n int){println(n);f(n*2)}

Attempt This Online!

Go, 45 bytes, to STDOUT

import."fmt"
func f(n int){Println(n);f(n*2)}

Attempt This Online!

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

Knight, 13 bytes

;=a 1W=a*2aOa

Try it online!

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

Alice, 11 bytes

.2~E/ O \h

Try it online!

The trailing newline is required

.             Duplicates the top of the stack, or two `0` if the stack is empty
 2~           Pushes two on the stack, swap the top two items
   E          Calculates `2^n`, where `n` is the current iteration minus 1
    / O \     Prints the number
         h    Increments the exponent
\$\endgroup\$
1
2

Not the answer you're looking for? Browse other questions tagged or ask your own question.