Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

5 languages, 18 bytes / 5^3 = 0.144

Ouroboros, Pip, QBasic, Foo, and Pyth

5'"4"()" 1?3'@n()2 

###1. Ouroboros

Each line of the program represents a snake eating its tail.

Snake 1

Push 5, ' is a no-op, push 52 (ASCII code of "4"). ( causes the snake to pop a number and eat that many characters of its tail. Since this results in swallowing the instruction pointer (and the entire snake), execution halts.

Snake 2

Push 1, push a random number (?), push 3, ' is a no-op. @ rotates the 1 to the top of the stack and n outputs it as a number, leaving the 3 on top of the stack. Then ( eats this many characters from the end of the snake, swallowing the instruction pointer and halting.

You can run this program online in the Stack Snippet interpreter herehere.

###2. Pip

Most of the program consists of expressions which are evaluated and discarded:

  • 5
  • '" (character literal)
  • 4
  • "()"
  • 1?3'@ (ternary expression)
  • n (variable, = newline)
  • () (nil)

Finally, the last expression, 2, is printed.

###3. QBasic

Everything after ' is a comment. The first line thus boils down to 5, a line number. On the second line, 1 is a line number and ?3 is a shortcut for PRINT 3.

(Apparently having line numbers out of order isn't a problem, though it would be easy to fix if it were.)

###4. Foo

Almost everything is no-ops. "4" prints 4. The parentheses (x2) are a loop that runs until the current array cell is zero, which is true immediately and the loop exits. @, when not followed by a number, takes the value of the current array cell (initialized to 0) and pushes it to the stack.

I'm not entirely sure how the second, unmatched " is supposed to be handled. The online version seems to add a newline to the output, which the rules of the challenge allow.

###5. Pyth

5 is output. Then the program encounters '"4", which tries to read from a file named 4. As long as no such file exists, I think this should terminate the program with an error. (The online version says name 'open' is not defined--I assume because opening files isn't allowed online.)

The stray " at the end of line 1 ensures that line 2 doesn't cause a syntax error before execution.

5 languages, 18 bytes / 5^3 = 0.144

Ouroboros, Pip, QBasic, Foo, and Pyth

5'"4"()" 1?3'@n()2 

###1. Ouroboros

Each line of the program represents a snake eating its tail.

Snake 1

Push 5, ' is a no-op, push 52 (ASCII code of "4"). ( causes the snake to pop a number and eat that many characters of its tail. Since this results in swallowing the instruction pointer (and the entire snake), execution halts.

Snake 2

Push 1, push a random number (?), push 3, ' is a no-op. @ rotates the 1 to the top of the stack and n outputs it as a number, leaving the 3 on top of the stack. Then ( eats this many characters from the end of the snake, swallowing the instruction pointer and halting.

You can run this program online in the Stack Snippet interpreter here.

###2. Pip

Most of the program consists of expressions which are evaluated and discarded:

  • 5
  • '" (character literal)
  • 4
  • "()"
  • 1?3'@ (ternary expression)
  • n (variable, = newline)
  • () (nil)

Finally, the last expression, 2, is printed.

###3. QBasic

Everything after ' is a comment. The first line thus boils down to 5, a line number. On the second line, 1 is a line number and ?3 is a shortcut for PRINT 3.

(Apparently having line numbers out of order isn't a problem, though it would be easy to fix if it were.)

###4. Foo

Almost everything is no-ops. "4" prints 4. The parentheses (x2) are a loop that runs until the current array cell is zero, which is true immediately and the loop exits. @, when not followed by a number, takes the value of the current array cell (initialized to 0) and pushes it to the stack.

I'm not entirely sure how the second, unmatched " is supposed to be handled. The online version seems to add a newline to the output, which the rules of the challenge allow.

###5. Pyth

5 is output. Then the program encounters '"4", which tries to read from a file named 4. As long as no such file exists, I think this should terminate the program with an error. (The online version says name 'open' is not defined--I assume because opening files isn't allowed online.)

The stray " at the end of line 1 ensures that line 2 doesn't cause a syntax error before execution.

5 languages, 18 bytes / 5^3 = 0.144

Ouroboros, Pip, QBasic, Foo, and Pyth

5'"4"()" 1?3'@n()2 

###1. Ouroboros

Each line of the program represents a snake eating its tail.

Snake 1

Push 5, ' is a no-op, push 52 (ASCII code of "4"). ( causes the snake to pop a number and eat that many characters of its tail. Since this results in swallowing the instruction pointer (and the entire snake), execution halts.

Snake 2

Push 1, push a random number (?), push 3, ' is a no-op. @ rotates the 1 to the top of the stack and n outputs it as a number, leaving the 3 on top of the stack. Then ( eats this many characters from the end of the snake, swallowing the instruction pointer and halting.

You can run this program online in the Stack Snippet interpreter here.

###2. Pip

Most of the program consists of expressions which are evaluated and discarded:

  • 5
  • '" (character literal)
  • 4
  • "()"
  • 1?3'@ (ternary expression)
  • n (variable, = newline)
  • () (nil)

Finally, the last expression, 2, is printed.

###3. QBasic

Everything after ' is a comment. The first line thus boils down to 5, a line number. On the second line, 1 is a line number and ?3 is a shortcut for PRINT 3.

(Apparently having line numbers out of order isn't a problem, though it would be easy to fix if it were.)

###4. Foo

Almost everything is no-ops. "4" prints 4. The parentheses (x2) are a loop that runs until the current array cell is zero, which is true immediately and the loop exits. @, when not followed by a number, takes the value of the current array cell (initialized to 0) and pushes it to the stack.

I'm not entirely sure how the second, unmatched " is supposed to be handled. The online version seems to add a newline to the output, which the rules of the challenge allow.

###5. Pyth

5 is output. Then the program encounters '"4", which tries to read from a file named 4. As long as no such file exists, I think this should terminate the program with an error. (The online version says name 'open' is not defined--I assume because opening files isn't allowed online.)

The stray " at the end of line 1 ensures that line 2 doesn't cause a syntax error before execution.

Added Pyth
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

45 languages, 1218 bytes / 4^35^3 = 0.1875144

Ouroboros, Pip, QBasic, and Foo, and Pyth

5'"4"()" 1?3'@n"4"3'@n()2 

TheEach line of the program pushesrepresents a snake eating its tail.

Snake 1

Push 5, ' is a no-op, push 52 (ASCII code of "4"). ( causes the snake to pop a number and eat that many characters of its tail. Since this results in swallowing the instruction pointer (and the entire snake), execution halts.

Snake 2

Push 1, push a random number (?), andpush 3., ' is a no-op. @ rotates the 1 to the top of the stack and n outputs it as a number., leaving the "4"3 pusheson top of the corresponding ASCII code, 52stack. Then ( eats this many characters from the end of the snake. Since this results in, swallowing the instruction pointer (and the entire snake), the program haltsand halting.

1?3'@ is a ternary expression, Most of the program consists of expressions which evaluates to 3 and is discarded. n evaluates to newline and is discarded. "4" evaluates and is discarded. () evaluates to nilare evaluated and is discarded.:

  • 5
  • '" (character literal)
  • 4
  • "()"
  • 1?3'@ (ternary expression)
  • n (variable, = newline)
  • () (nil)

Finally, the last expression, 2 evaluates and, is printed.

Everything after ' is a comment, so the code executed is. The first line thus boils down to 1?35, a line number. On the second line, 1 is a line number and ?3 is a shortcut for PRINT 3.

(Apparently having line numbers out of order isn't a problem, though it would be easy to fix if it were.)

Everything up to @Almost everything is no-ops. "4" prints 4. The parentheses (x2) are a loop that runs until the current array cell is zero, which is true immediately and the loop exits. @, when not followed by a number, takes the value of the current array cell (initialized to 0) and pushes it to the stack.

I'm not entirely sure how the second, unmatched n" is a no-op. "4" prints 4supposed to be handled. The parentheses areonline version seems to add a loop that runs untilnewline to the current array cell is zerooutput, which is true immediately and the loop exitsrules of the challenge allow.  

###5. Pyth

25 is output. Then the program encounters '"4", which tries to read from a file named 4. As long as no such file exists, I think this should terminate the program with an error. (The online version says name 'open' is not defined-op-I assume because opening files isn't allowed online.)

(I'm pretty sure this is correct based on The stray " at the Esolangs page, but if someone who has Foo wants to verify, that'd be goodend of line 1 ensures that line 2 doesn't cause a syntax error before execution.)

4 languages, 12 bytes / 4^3 = 0.1875

Ouroboros, Pip, QBasic, and Foo

1?3'@n"4"()2 

The program pushes 1, a random number (?), and 3. ' is a no-op. @ rotates the 1 to the top of the stack and n outputs it as a number. "4" pushes the corresponding ASCII code, 52. Then ( eats this many characters from the end of the snake. Since this results in swallowing the instruction pointer (and the entire snake), the program halts.

1?3'@ is a ternary expression, which evaluates to 3 and is discarded. n evaluates to newline and is discarded. "4" evaluates and is discarded. () evaluates to nil and is discarded. Finally, 2 evaluates and is printed.

Everything after ' is a comment, so the code executed is 1?3. 1 is a line number and ? is a shortcut for PRINT.

Everything up to @ is no-ops. @, when not followed by a number, takes the value of the current array cell (initialized to 0) and pushes it to the stack. n is a no-op. "4" prints 4. The parentheses are a loop that runs until the current array cell is zero, which is true immediately and the loop exits.  2 is a no-op.

(I'm pretty sure this is correct based on the Esolangs page, but if someone who has Foo wants to verify, that'd be good.)

5 languages, 18 bytes / 5^3 = 0.144

Ouroboros, Pip, QBasic, Foo, and Pyth

5'"4"()" 1?3'@n()2 

Each line of the program represents a snake eating its tail.

Snake 1

Push 5, ' is a no-op, push 52 (ASCII code of "4"). ( causes the snake to pop a number and eat that many characters of its tail. Since this results in swallowing the instruction pointer (and the entire snake), execution halts.

Snake 2

Push 1, push a random number (?), push 3, ' is a no-op. @ rotates the 1 to the top of the stack and n outputs it as a number, leaving the 3 on top of the stack. Then ( eats this many characters from the end of the snake, swallowing the instruction pointer and halting.

Most of the program consists of expressions which are evaluated and discarded:

  • 5
  • '" (character literal)
  • 4
  • "()"
  • 1?3'@ (ternary expression)
  • n (variable, = newline)
  • () (nil)

Finally, the last expression, 2, is printed.

Everything after ' is a comment. The first line thus boils down to 5, a line number. On the second line, 1 is a line number and ?3 is a shortcut for PRINT 3.

(Apparently having line numbers out of order isn't a problem, though it would be easy to fix if it were.)

Almost everything is no-ops. "4" prints 4. The parentheses (x2) are a loop that runs until the current array cell is zero, which is true immediately and the loop exits. @, when not followed by a number, takes the value of the current array cell (initialized to 0) and pushes it to the stack.

I'm not entirely sure how the second, unmatched " is supposed to be handled. The online version seems to add a newline to the output, which the rules of the challenge allow.

###5. Pyth

5 is output. Then the program encounters '"4", which tries to read from a file named 4. As long as no such file exists, I think this should terminate the program with an error. (The online version says name 'open' is not defined--I assume because opening files isn't allowed online.)

The stray " at the end of line 1 ensures that line 2 doesn't cause a syntax error before execution.

Added Foo
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

Ouroboros, Pip, & QBasic4 languages, 912 bytes / 3^34^3 = 0.333331875

Ouroboros, Pip, QBasic, and Foo

1?3'@n3'@n"4"()2 

###1. Ouroboros

The program pushes 1, a random number (?), and 3. ' is a no-op. @ rotates the 1 to the top of the stack and n outputs it as a number, leaving. 3"4" on the top ofpushes the stackcorresponding ASCII code, 52. Then ( eats this many characters from the end of the snake. Since this results in swallowing the instruction pointer (and the entire snake), the program halts.

You can run this program online in the Stack Snippet interpreter here.

###2. Pip

1?3'@ is a ternary expression, which evaluates to 3 and is discarded. n evaluates to newline and is discarded. "4" evaluates and is discarded. () evaluates to nil and is discarded. Finally, 2 evaluates and is printed.

###3. QBasic

Everything after ' is a comment, so the code executed is 1?3. 1 is a line number and ? is a shortcut for PRINT.

###4. Foo

Everything up to @ is no-ops. @, when not followed by a number, takes the value of the current array cell (initialized to 0) and pushes it to the stack. n is a no-op. "4" prints 4. The parentheses are a loop that runs until the current array cell is zero, which is true immediately and the loop exits. 2 is a no-op.

(I'm pretty sure this is correct based on the Esolangs page, but if someone who has Foo wants to verify, that'd be good.)

Ouroboros, Pip, & QBasic, 9 bytes / 3^3 = 0.33333

1?3'@n()2 

###1. Ouroboros

The program pushes 1, a random number (?), and 3. ' is a no-op. @ rotates the 1 to the top of the stack and n outputs it as a number, leaving 3 on the top of the stack. Then ( eats this many characters from the end of the snake. Since this results in swallowing the instruction pointer, the program halts.

You can run this program online in the Stack Snippet interpreter here.

###2. Pip

1?3'@ is a ternary expression, which evaluates to 3 and is discarded. n evaluates to newline and is discarded. () evaluates to nil and is discarded. Finally, 2 is printed.

###3. QBasic

Everything after ' is a comment, so the code executed is 1?3. 1 is a line number and ? is a shortcut for PRINT.

4 languages, 12 bytes / 4^3 = 0.1875

Ouroboros, Pip, QBasic, and Foo

1?3'@n"4"()2 

###1. Ouroboros

The program pushes 1, a random number (?), and 3. ' is a no-op. @ rotates the 1 to the top of the stack and n outputs it as a number. "4" pushes the corresponding ASCII code, 52. Then ( eats this many characters from the end of the snake. Since this results in swallowing the instruction pointer (and the entire snake), the program halts.

You can run this program online in the Stack Snippet interpreter here.

###2. Pip

1?3'@ is a ternary expression, which evaluates to 3 and is discarded. n evaluates to newline and is discarded. "4" evaluates and is discarded. () evaluates to nil and is discarded. Finally, 2 evaluates and is printed.

###3. QBasic

Everything after ' is a comment, so the code executed is 1?3. 1 is a line number and ? is a shortcut for PRINT.

###4. Foo

Everything up to @ is no-ops. @, when not followed by a number, takes the value of the current array cell (initialized to 0) and pushes it to the stack. n is a no-op. "4" prints 4. The parentheses are a loop that runs until the current array cell is zero, which is true immediately and the loop exits. 2 is a no-op.

(I'm pretty sure this is correct based on the Esolangs page, but if someone who has Foo wants to verify, that'd be good.)

Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142
Loading