title: Javascript left-pad golf

text:
# Question
Title: Javascript left-pad golf
### Introduction

In the wake of the left-pad npm package fallout, let's have a code golf for implementing left-pad.

The *left-pad* function consists of 2 default arguments and 1 additional argument, in the form **string**, **length**, (**padchar**). If the padchar is not given, this is **standardized** to a *space character*. Let's take an example with two arguments:

```
left_pad("abc", 6)

```

First, we observe the length of the string, which is **3**. After this, we need to pad this string in the left until the length of the full string has reached the length given in the function. In this case **6**. Since the padchar is *not given*, we need to pad this with spaces:

```
   abc

```

This is a string with 3 spaces and the initial string, resulting into a string with length 6. Here is an example with the padchar given:

```
left_pad("abc", 6, "-")

```

We just do the same as the example above, but replace the spaces with the padchar. In this case, the hyphen:

```
---abc

```

### The Task

Given the **string**, **length**, and *maybe* the additional argument **padchar**, output the left-padded string. You can assume that the length number is equal or greater than the length of the string. The padchar will always consist of 1 character.

### Test cases

```
left_pad("string", length, ("padchar")) === "left-padded string"

left_pad("foo", 5) === "  foo"
left_pad("foobar", 6) === "foobar"
left_pad("1", 2, "0") === "01"
left_pad("1", 2, "-") === "-1"

```

This is , so the submission with the smallest number of bytes wins!

# Answer
## Pyth, ~~13~~ 11 bytes

```
+*.xwd-Qlzz

```

Try it here.

Takes input from STDIN as the string on the first line, length on the second line, and padding char optionally on a third line.
> 21 votes

# Answer
## JavaScript (ES6), 43 bytes

```
f=(s,n,p=" ",r=p)=>(r+=s+="")[n]?s:f(r,n,p)

```
> 14 votes

# Answer
# Javascript ES6, 35 bytes

```
(s,l,c=' ')=>c.repeat(l-s.length)+s

```

Try it. I believe this is the shortest possible implimentation currently possible in Javascript.
> 9 votes

# Answer
# JavaScript (ES6), 37 43 44 bytes

```
(a,n,c=' ')=>((c+'').repeat(n)+a).substr(-n)

```

Test:

```
> f=(a,n,c)=>((c?c:" ").repeat(n)+a).substr(-n)
< function (a,n,c)=>((c?c:" ").repeat(n)+a).substr(-n)
> f('foo', 5) === '  foo';
< true
> f('foobar', 6) === 'foobar';
< true
> f(1, 2, 0) === '01';
< true
> f(1, 2, '-') === '-1';
< true

```

Not sure if you want to count the function declaration, I'd inline this.
> 8 votes

# Answer
# Python 3, ~~33~~ ~~31~~ 29 bytes

```
lambda a,b,x=" ":a.rjust(b,x)

```

~~Fairly straightforward.~~ Thanks to @xnor for reminding me `str.rjust` is a thing. :P

For the same length (also thanks to xnor):

```
lambda a,b,x=" ":(x*b+a)[-b:]

```

Previous solution:

```
lambda a,b,x=" ":x*(b-len(a))+a

```
> 6 votes

# Answer
# 05AB1E, ~~11~~ 9 bytes

Code:

```
g-ð³0@×¹«

```

Explanation:

```
g          # Implicit first input, take the length.
 -         # Substract the length with the second input.
  ð³       # Push a space and if the third input exists, also the third input.
    0@     # Reposition the first element of the stack to the top (zero-indexed).
      ×    # Multiply the character with the difference in length.
       ¹«  # Concatenate the first input to the string.

```

Uses **CP-1252** encoding. Try it online.
> 6 votes

# Answer
## JavaScript (ES5), 70 bytes

Using recursion...

```
function f(s,c,p,u){return(s+'').length<c?f((p==u?' ':p+'')+s,c,p):s}

```

My initial go was only 57 bytes:

```
function f(s,c,p){return s.length<c?f((p||" ")+s,c,p):s}

```

But only passed the first 2 tests:

```
> f('foo', 5) === '  foo';
true
> f('foobar', 6) === 'foobar';
true
> f(1, 2, 0) === '01';
false
> f(1, 2, '-') === '-1';
false

```

I still like the shorter one, because in practise, passing numbers to a string manipulation function isn't a feature I would need.
> 6 votes

# Answer
# Mathematica, 13 bytes

```
StringPadLeft

```

Builtin-only answer #3 (first was `Range`, second was `Surd`) Or less builtin: (35 bytes)

```
##2~StringRepeat~(#3-Length@#2)<>#&

```
> 6 votes

# Answer
# JavaScript ES7, 16 bytes

```
''.padStart.bind

```

built-ins ftw! Only works on Firefox 48 and above. Valid as this feature was added March 12.

This takes input like:

```
(''.padStart.bind)(arg1)(arg2,arg3)

```
> 5 votes

# Answer
# Javascript (ES6), 55 bytes

```
(a,n,c=' ',s=a+'')=>(new Array(++n-s.length).join(c)+s)

```

Create an empty array of values and join version.

```
(a,n,c=' ')=>{a+=''; return new Array(++n-a.length).join(c)+a}

```

Is more readable but the `return` adds a few more characters.
> 4 votes

# Answer
# Julia, 4 bytes

```
lpad

```

Passes all the test cases:

```
julia> lpad("foo", 5)
"  foo"

julia> lpad("foobar", 6)
"foobar"

julia> lpad(1, 2, 0)
"01"

julia> lpad(1, 2, '-')
"-1"

```
> 4 votes

# Answer
# Bash, 57 Bytes

Parameters: *string width padchar*

```
printf -vX %$2s;Y="${X// /${3- }}$1";echo -n "${Y:${#1}}"

```

Make a string of *width* spaces.

Convert each space character into *padchar*.

Write padding then *string*.
> 4 votes

# Answer
# Python, 41 bytes

```
lambda a,b,x=' ':str(a).rjust(b,str(x))

```

Without the builtin rjust, 43 bytes:

```
lambda a,b,x=' ':str(x)*int(b/2%3)+str(a)

```

(not what one expects it to do, but it passes the test suite)
> 3 votes

# Answer
# Jelly, 12 bytes

```
L⁴_ẋ@⁵⁵⁶<?¤³

```

<sup>*So* many variable references. Wasn't Jelly supposed to be a *tacit* language?</sup>

Try it online!

### How it works

```
L⁴_ẋ@⁵⁵⁶<?¤³  Main link
              Arguments: string (³), length (⁴), padchar (⁵, defaults to 10)

L             Compute the length of ³.
 ⁴_           Subtract the length from ⁴.
          ¤   Combine the two links to the left into a niladic chain:
     ⁵          Yield ⁵.
      ⁵⁶<?      Yield ⁵ if ⁵ < ⁵, else ⁶.
              Comparing a number with itself gives 0 (falsy), but comparing a
              string / character list with itself gives [0] (truthy).
   ẋ@         Repeat the result to the right as many times as specified in the
              result to the left.
           ³  Print the previous return value and return ³.

```
> 3 votes

# Answer
# JavaScript (ES6), 34 bytes

I used a recursive solution.

```
f=(s,l,c=' ')=>s[l-1]?s:f(c+s,l,c)

```
> 3 votes

# Answer
# Powershell, ~~87~~ ~~67~~  ~~incorrect counted 54~~, 46 Bytes

```
function f($s,$l,$c=' '){$c*($l-$s.length)+$s}

```

Try it online!
> 3 votes

# Answer
# C (gcc), ~~91~~ 86 bytes

Takes 2 or 3 arguments on the command line. Also uses the rare "--\>" operator!

*-5 bytes from ceilingcat and c--*

```
l;main(c,v)int**v;{for(l=atoi(v++[2]);l-->strlen(*v);)putchar(c-3?*v[2]:32);puts(*v);}

```

Try it online!
> 3 votes

# Answer
# Lua, 39 38 bytes

```
s,n,c=...print((c or" "):rep(n-#s)..s)

```

Try it online!

Thanks to c-- for saving a byte.
> 3 votes

# Answer
# Japt, 5 bytes

```
ùVWªS

```

Try it

```
ù      # left-pad the input string with:
 V     #   second input (length)
  WªS  #   third input, or space if not specified

```

Or, for 1 byte:

```
ù

```

But this isn't a full program, so I don't think it counts. It can be called `AùBC` where A is the string, B is the length, and C is (optionally) the padding character.
> 3 votes

# Answer
# Pike, 67 bytes

```
mixed n(mixed a,int b,mixed x){return x!=""?x:" "*(b-strlen(a))+a;}

```

*sigh*. The empty string `""` evaluates to `true`. *Why!?*

mixed mixed mixed mixed mixed Pike soup...
> 2 votes

# Answer
## Pyke, 12 bytes (noncompeting)

added input node, bugfix on len node, change default results on assign node after the challenge was posted.

```
\ =zzjl-z*j+

```

Explanation:

```
\ =z         - assign default input for `z` to be " " (Will still prompt but no input will return a space instead)
    zj       -     j = input()
      l      -    len(j)
       -     -   eval_or_not_input() - ^
        z*   -  ^*input()
          j+ - ^+j

```
> 2 votes

# Answer
# JavaScript ES6, 38 bytes

```
(s,l,c=" ")=>(c.repeat(l)+s).slice(-l)

```

An alternate solution.
> 2 votes

# Answer
# Arturo, 34 bytes

```
$=>[++repeat ??attr""" "&-size<=&]

```

Try it

Arturo has `pad` but here's a non-builtin.
> 2 votes

# Answer
# Vyxal, 8 bytes

```
□ðJ3Ẏ÷ø↳

```

Try it Online!

Link is to test suite. Somehow, vyncode also gives 8 bytes.

## Explained

```
□ðJ3Ẏ÷ø↳
□ðJ      # append a space to all input arguments
   3Ẏ     # take the first 3 items of that
     ÷    # dump everything to the stack
      ø↳  # call the built-in left pad function.

```
> 2 votes

# Answer
# Ruby, 42 bytes

```
def left_pad(s,t,p=" ");p*(t-s.size)+s;end

```

Parameters: string, size, padchar.

Test suite below; should print all "true"s, just put everything in the same file.

```
puts left_pad("foo", 5) == "  foo"
puts left_pad("foobar", 6) == "foobar"
puts left_pad("1", 2, "0") == "01"
puts left_pad("1", 2, "-") == "-1"

```
> 1 votes

# Answer
# Java 8, ~~86~~ 88 bytes

This is a function. The third argument is a `varargs` to allow the optional pad char (defaults to `' '`)

```
String p(String s,int l,char...p){return s.length()<l?p((p.length>0?p[0]:' ')+s,l,p):s;}

```

Recursion! +2 bytes (added brackets because of incompatible type error)
> 1 votes

# Answer
# PHP, ~~54~~ 48 bytes

Uses Windows-1252 encoding.

```
function(&$s,$l,$p=~ß){$s=str_pad($s,$l,$p,0);};

```

Run like this (`-d` added for easthetics only):

```
php -r '$f = function(&$s,$l,$p=~ß){$s=str_pad($s,$l,$p,0);}; $s="foo";$f($s,5);echo"$s\n";' 2>/dev/null

```

Old version (without the builtin):

```
function(&$s,$l,$p=~ß){for(;strlen($s)<$l;)$s=$p.$s;};

```

# Tweaks

* Saved 6 bytes by using `str_pad` instead of a loop. Leaving the old one for reference, as builtins are frowned upon
> 1 votes

# Answer
## R, 50 bytes

Late to the party again but here it goes:

```
function(s,n,p=" ")cat(rep(p,n-nchar(s)),s,sep="")

```

This simply prints the output to stdout but does not actually return the padded string (wasn't sure if this is a requirement for the challenge). If this is needed, the solution is slightly longer at 61 bytes:

```
function(s,n,p=" ")paste0(c(rep(p,n-nchar(s)),s),collapse="")

```
> 1 votes

# Answer
# brainfuck, 212 bytes

```
,----------[++++++++++<[<]<+>>[>],----------]<[<]<<<,----------[<[-<++++++++++>]<[->+<]>>>++++++++[-<----->]<++[-<+>],----------]>>[-<<<->>>]++++[>++++++++<-]><<+>,[<->[-<<+>>]]<[->>[-<<<+>>>]<<]<<[->.<]>>>>>[.>]

```

## Explained

```
,----------[      While it isn't a newline
    ++++++++++        Restore the character
    <[<]<+>>[>]       Increment the counter behind the array and return
,----------]      Read and repeat
<[<]<<<           navigate behind the length
,----------[                   While it isn't a newline
    <[-<++++++++++>]<[->+<]>>      x10 the stored number
    >++++++++[-<----->]<++             sub 39
    [-<+>]                         Copy into stored
,----------]                   Read and repeat
>>[-<<<->>>]        Subtract the counter from the target
++++[>++++++++<-]>  Prepare a space
<<+>,[<->[-<<+>>]]  If the next byte isnt eof then we copy it left two and zero the test byte
<[->>[-<<<+>>>]<<]  If the text bit is still high copy space in there instead
<<[->.<]            While the counter is positive write the pad char
>>>>>[.>]           Write the rest of the string

```

Arguments separated by linefeeds. If no pad char is present, a linefeed after the length must still be included.

Try it online!
> 1 votes

# Answer
# Go, 110 bytes

```
import."strings"
func l(n int,c...string)string{q,p:=c[0]," "
if len(c)>1{p=c[1]}
return Repeat(p,n-len(q))+q}

```

Attempt This Online!

Uses Go's variadic arguments feature to have an optional argument. Expects at minimum 1 string passed to the function (the string to be padded); the first string after that is the padding character.

A solution were all arguments are explicit is significantly shorter:

### Go, 76 bytes, no variadic arguments

```
import."strings"
func l(s,c string,n int)string{return Repeat(c,n-len(s))+s}

```

Attempt This Online!
> 0 votes

# Answer
# C, 64 bytes

```
f(s,n,c,p){return memset(p,c,asprintf(&p,"%*s",n,s)-strlen(s));}

```

Try it here.
> -3 votes

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


# Question
Title: Build a random number generator that passes the Diehard tests
While there are many code golf questions on here involving randomness, I haven't seen one yet that actually asks for building an algorithmic pseudorandom number generator. There's this one that asks you to generate a bit stream, but the randomness tests provided on that one were not very rigorous, and it's not code-golf.

The program you write will have a single callable function that will return a random integer from 0 to 4294967295. This function must not call upon any libraries or other functions that were not also written as part of the program, especially calls to /dev/random or a language's built-in rand() library. More specifically, you are limited to the basic operators of the language you are working in, such as arithmetic, array access, and conditional flow control statements.

The score of your program is calculated as follows:

```
Score = C / R

```

Where C is the length of the code in characters, and R is the number of Diehard tests that your generator passes (If your random number generator does not pass at least one Diehard test, its score is infinity and it is disqualified). Your generator passes a Diehard test if the file it generates provides a range of P-values that appear to be distributed uniformly along the interval \[0, 1).

To calculate R, use your random number generator with its default seed to generate a 16 MB binary data file. Each call of the function returns four bytes; if your function is too slow to return bytes, this will factor a trade-off into attaining a low score by how difficult it is to test. Then, run it through the Diehard tests and check the P-values provided. (Do not try and implement these yourself; use the ones provided here)

Lowest score wins, of course.

# Answer
# ECMAScript 6, 31 30 25 / 15 = 1.66

This is Keith Randall's solution implemented in ES6:

```
e=3;R=_=>e=e**3%(2**32-5)

```
> 4 votes

# Answer
## Perl 28 / 13 ≈ 2.15

```
sub r{$s^=~($s^=$s/7215)<<8}

```

*log file here*

## Perl 29 / 13 ≈ 2.23

```
sub r{$s^=~($s^=$s<<8)/60757}

```

*log file here*

These are something of a variation on a Xorshift, using floating point division instead of a right shift. They both pass 13 of 15 tests, failing only tests 6 and 7.

I'm not exactly sure how long the cycle is, but because the following code doesn't terminate in any short period of time, it's likely the full *232*:

```
$start = r();
$i++ while $start != r();
print $i;

```

---

## Perl 39 / 10 = 3.9

```
$s=$^T;sub r{~($s=$s*$s%4294969373)||r}

```

*Note: if you're looking for a Blum-Blum-Shub-esque PRNG, Keith Randall's solution is far better than either of these.*

As with my original solution below, this is also an implementation of the Blum Blum Shub, with one major difference. I uses a modulus slightly larger than *232* (*M = 50971 • 84263*), and whenever a value is encountered that it is not a valid 32-bit integer (that is, larger than *232*), it returns the next value in the rotation instead. In essense, these values are pruned out, leaving the rest of the rotation undisturbed, resulting in a nearly uniform distribution.

It seems to have helped. In addition to passing the same 9 tests as before, it now also convincingly passes the Minimum Distance test. A sample log file can be found here.

---

## Perl 33 / 9 ≈ 3.67 (Invalid?)

```
 $s=$^T;sub r{$s=$s*$s%4294951589}

```

*Note: this solution might be considered invalid, as the top-most 0.00037% of the range will never be observed.*

A quick and dirty implementation of the Blum Blum Shub. I claim the following results:

```
 1. passed - Birthday Spacings
 2. FAILED - Overlapping Permutations
 3. passed - Ranks of 31x31 and 32x32 Matrices
 4. passed - Ranks of 6x8 Matrices
 5. FAILED - Monkey Tests on 20-bit Words
 6. FAILED - Monkey Tests OPSO, OQSO, DNA
 7. FAILED - Count the 1s in a Stream of Bytes
 8. passed - Count the 1s for Specific Bytes
 9. passed - Parking Lot Test
10. FAILED - Minimum Distance Test
11. passed - Random Spheres Test
12. FAILED - The Squeeze Test
13. passed - Overlapping Sums Test
14. passed - Runs Test
15. passed - The Craps Test

```

A sample log file can be found here, feel free to dispute any of the results. The file for diehard can be generated in the following manner:

```
print pack('N', r()) for 1..4194304

```

and then piping the output into a file. Minimum Distance looks like it might have passed, but if you run it multiple times it's always very close to *1.0*, which indicates failure.

---

## Details

In general, the Blum Blum Shub is a terrible PRNG, but it's performance can be improved by choosing a good modulus. The *M* I've chosen is *7027 • 611207*. Both of these prime factors, *p* and *q*, have modular residue *3 (mod 4)*, and *gcd(φ(p-1), φ(q-1)) = 2*, which is as low as it can be.

Although these are the only criteria listed on the wiki page, it doesn't seem to be enough. Almost all of the modulo I tried failed every test. But there's a handful that will pass some of the tests, and the one I've chosen seems to be exceptionally good, for whatever reason.

As a final note, Test 5 on its own seems to be a fairly good indicator of how good the PRNG is. If it doesn't *almost* pass Test 5, it will fail the rest of them spectacularly.

---

## BONUS: Perl 62 / 14 ≈ 4.43

```
$t=$^T;sub r{$t|=(($s=$s/2|$t%2<<31)^($t/=2))<<31for 1..37;$t}

```

Just for geekery, this is a 32-bit version of the PRNG used in the original Tetris for NES. Amazingly, it passes 14 of the 15 tests!

```
 1. passed - Birthday Spacings
 2. passed - Overlapping Permutations
 3. passed - Ranks of 31x31 and 32x32 Matrices
 4. passed - Ranks for 6x8 Matrices
 5. passed - Monkey Tests on 20-bit Words
 6. passed - Monkey Tests OPSO, OQSO, DNA
 7. FAILED - Count the 1s in a Stream of Bytes
 8. passed - Count the 1s for Specific Bytes
 9. passed - Parking Lot Test
10. passed - Minimum Distance Test
11. passed - Random Spheres Test
12. passed - The Squeeze Test
13. passed - Overlapping Sums Test
14. passed - Runs Test
15. passed - The Craps Test

```

Sample log file can before here.

Admittedly, the `1..37` bit isn't an exact transcription. In the orginal version, the entropy routine is updated 60 times per second, and then queried at random intervals, largely dependent on user input. For anyone who cares to disassemble the ROM, the entropy routine begins at `0xAB47`.

Python-style pseudo-code:

```
carry = entropy_1 & 1
entropy_1 >>= 1
entropy_2 = (entropy_2 >> 1) | (carry << 31)
carry = (entropy_1 & 1) ^ (entropy_2 & 1)
entropy_1 |= carry << 31

```
> 23 votes

# Answer
## Python, 46 / 15 = 3.0666

```
v=3
def R():global v;v=v**3%(2**32-5);return v

```

Uses modular exponentiation to generate randomness. 2\**32-5 is the largest prime less than 2^32. (Same deal with not being able to run test #2.)
> 8 votes

# Answer
# Mathematica, 32 / 15 = 2.133

```
x=3;Mod[x=Mod[x^2,28!-67],2^32]&

```

A straightforward implementation of BBS.

Binary file generated with:

```
f = %; (* assigns anonymous function declared in the previous expression to f *)
Export["random.bin", Array[f, 2^22], "UnsignedInteger32"];

```

Summary of results:

```
 1. BIRTHDAY SPACINGS TEST           .684805
 2. OVERLAPPING 5-PERMUTATION TEST   .757608/.455899
 3. BINARY RANK TEST                 .369264/.634256
 4. BINARY RANK TEST                 .838396
 5. THE BITSTREAM TEST                (no summary p-value)
 6. OPSO, OQSO and DNA                (no summary p-value)
 7. COUNT-THE-1's TEST               .649382/.831761
 8. COUNT-THE-1's TEST                (no summary p-value)
 9. PARKING LOT TEST                 .266079
10. MINIMUM DISTANCE TEST            .493300
11. 3DSPHERES TEST                   .492809
12. SQEEZE                           .701241
13. OVERLAPPING SUMS test            .274531
14. RUNS test                        .074944/.396186/.825835/.742302
15. CRAPS TEST                       .403090/.403088/.277389

```

Full `random.bin` here.

Full log file here.
> 8 votes

# Answer
# Ruby, 32/15 = 2.1333

This is Keith Randall's solution, implemented in Ruby.

```
$v=3;def R;$v=$v**3%(2**32-5)end

```
> 5 votes

# Answer
## Python, 41 / 15 = 2.73333

```
v=0
def R():global v;v=hash(`v`);return v

```

Kinda cheating using the built-in hash function, but it *is* built-in, so no more cheating than using other builtins, like `len`. On the flip side, it pains me to have to pay for the `global v;` statement...

Passes all the Diehard tests (I had a problem with test #2, it SEGVs on my OSX machine. For my score, I'm assuming it will pass).

Here's a driver to generate the 16MB file:

```
import sys
for i in xrange(1<<22):
  r=R()
  sys.stdout.write('%c%c%c%c'%(r&255, r>>8&255, r>>16&255, r>>24&255))

```
> 3 votes

# Answer
# C# 144 / 15 = 9.6

```
uint a=15,b=26,y;uint q(int n){y=(a*1414549U+876619U)^(b*889453U+344753U);b=a;a=y>>12;return(a%256)<<n;}uint r(){return q(24)|q(16)|q(8)|q(0);}

```

This passed all of the tests.

With not too many more characters it passes TestU01.

Result: http://codepad.org/iny6usjV

```
    uint a = 15;
    uint b = 26;

    byte prng8()
    {
        uint y = ((a * 1414549U + 876619U) ^ (b * 889453U + 344753U)) >> 12;
        b = a;
        a = y;
        return (byte)y;
    }

    uint prng32()
    {
        return ((uint)prng8() << 24) | ((uint)prng8() << 16) | ((uint)prng8() << 8) | (uint)prng8();
    }

```
> 3 votes

# Answer
**C, 38/15 = 2.533**

```
long long x;f(){return(x+=x*x+9)>>32;}

```

I couldn't get the Diehard tests working on my machine, but it passes the PractRand suite for up to 8GB of output so I assume it would pass them all.
> 3 votes

# Answer
# C# - 103 / 14 = 7.36

```
double j=999;uint N(){uint i=0,n=0;for(;i++<4;n=n*256+(uint)j%256)for(j/=277;j<100000;j*=j);return n;}

```

## Results

Passes all except test #6
See results at http://codepad.org/k1NSoyQW

## Explanation

C# just can't compete with Ruby and Python for terseness, as usual, but I enjoyed trying. There are certainly other values that will work just as well (i.e., the initial value for j=999, and the divisor=277). I picked these after brief experimentation.

## With file-creation wrapper

```
class R
{
    public static void Main(string[] args)
    {
        var r = new R();
        using (var f = new System.IO.FileStream(".\\out.bin", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read))
        using (var b = new System.IO.BinaryWriter(f))
        {
            for (long i = 0; i < 12 * 1024 * 1024; i += 4)
            {

                b.Write(r.N());
            }
        }
    }

    double j = 999;

    uint N()
    {
        uint i = 0, n = 0;
        for (; i++ < 4; n = n * 256 + (uint)j % 256)
            for (j /= 277; j < 100000; j *= j) ;
        return n;
    }

}

```
> 2 votes

# Answer
# Brain-Flak, 344/(pending)

```
<>((()()){})<> push the amount of iterations to do for the PRNG
(((((((((((((((((((((((((((((((((((()()()){}()){})){}{}){()()()()({}[()])}{})){}{})){}{})()){}{})()){}{})){}{})){}{}){}())){}{})){}{})()){}{})()){}{})){}{})){}{})()){}{})()){}{}) push M (one of the values for the Blum Blum Shub PRNG
((((((((((((()()()){}){}){})){}{}){()({}[()])}{}){}())){}{})()){}{}) push s see above
<>{({}[()])<>starts the loop
(({({})({}[()])}{}) squares the current number
(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({}))mods by M
<>}{}<>loop ends

```

Try it online!

This works fine but the diehard tests links are all broken :( so until we get new ones i do not have a final score

This uses the Blum Blum Shub PRNG so it should pass most the cases. The numbers used are large enough no patterns will appear within the 16 MB of test cases
> 0 votes

# Answer
# Objective-C, 40/1 = 40

Pretty clever approach, exploiting `.hash` to somewhat cheat here, but I like it

```
for(int v=9;v=@(v).hash;printf("%i",v));

```
> 0 votes

---
Tags: code-challenge, random, test-battery
---


title: Clock (transliterate) Cipher

text:
# Question
Title: Clock (transliterate) Cipher
## Introduction:

*I have loads of different ciphers stored in a document I once compiled as a kid, I picked a few of the ones I thought were best suitable for challenges (not too trivial, and not too hard) and transformed them into challenges. Most of them are still in the sandbox, and I'm not sure yet whether I'll post all of them, or only a few. Here is the third and easiest one (after the Computer Cipher and Trifid Cipher I posted earlier).*

---

With a Clock Cipher we use the following image to encipher text:

So a sentence like `this is a clock cipher` would become:

```
t  h i s     i s     a     c l  o  c k     c i p  h e r    (without additional spaces of course, but added as clarification)
19:7:8:18:00:8:18:00:AM:00:2:11:14:2:10:00:2:8:15:7:4:17

```

## Challenge:

Given a string `sentence_to_encipher`, encipher it as described above.

## Challenge rules:

* You can assume the `sentence_to_encipher` will only contain letters and spaces.
* You can use either full lowercase or full uppercase (please state which one you've used in your answer).
* You are not allowed to add leading zeros for the single-digit enciphered letters `b` through `j`, but two zeros `00` are mandatory for spaces.
* You should use `:` as separator, and an additional leading or trailing `:` is not allowed.
* You are allowed to use lowercase `am` and `pm` instead of uppercase `AM` and `PM`, as long as it's consistent.

## General rules:

* This is , so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
* Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
* Default Loopholes are forbidden.
* If possible, please add a link with a test for your code (i.e. TIO).
* Also, adding an explanation for your answer is highly recommended.

## Test cases:

```
Input:  "this is a clock cipher"
Output: "19:7:8:18:00:8:18:00:AM:00:2:11:14:2:10:00:2:8:15:7:4:17"

Input:  "test"
Output: "19:4:18:19"

Input:  "what time is it"
Output: "22:7:AM:19:00:19:8:12:4:00:8:18:00:8:19"

Input:  "acegikmoqsuwy bdfhjlnprtvxz"
Output: "AM:2:4:6:8:10:12:14:16:18:20:22:24:00:1:3:5:7:9:11:13:15:17:19:21:23:PM"

Input:  "easy peazy"
Output: "4:AM:18:24:00:15:4:AM:PM:24"

```

# Answer
# Python 2, ~~74~~ 72 bytes

```
lambda s:':'.join(['AM','PM','00',`ord(c)-97`]['az '.find(c)]for c in s)

```

Try it online!

Takes input as all lowercase
> 7 votes

# Answer
# 05AB1E, ~~22~~ 21 bytes

```
„AM24L„PM00)˜Að«s‡':ý

```

Try it online! or as a Test Suite

Some alternate **21** byte solutions:

```
':ýAð«24L„AMš„PMª00ª‡
00„AM24L„PM)˜AIk>è':ý

```
> 6 votes

# Answer
# Perl 6, 47 bytes

```
*.ords>>.&{<<00 AM{1..24}PM>>[$_%32]}.join(":")

```

Try it online!

Anonymous Whatever lambda that takes a string of either case and returns the encrypted string.

### Explanation:

```
*.ords>>.&{                         } # Map the ordinal values to
           <<              >>[$_%32]  # The index in the list
              00 AM{1..24}PM  # 00, AM, the numbers 1 to 24 and PM
                                     .join(":")   # And join with colons

```
> 5 votes

# Answer
# Java (JDK), 86 bytes

```
s->"".join(":",s.map(c->c<33?"00":c<66?"AM":c>89?"PM":c-65+"").toArray(String[]::new))

```

Try it online!

## Credits

* -1 byte thanks to Kevin Cruijssen
> 5 votes

# Answer
# C# (Visual C# Interactive Compiler), 70 bytes

```
s=>string.Join(":",s.Select(a=>a<33?"00":a<66?"AM":a>89?"PM":a%65+""))

```

Takes input as a string of lowercase letters. First checks if the char is a space, and if it is, converts it to `00`. Next, it checks for if the char is an A, and converts it to `AM`. It checks again for Z and converts it to `PM` if it is. Lastly, if the char passes all the checks, it gets converted to its alphabetic order-1.

-2 bytes thanks to @dana

Try it online!

```
// Input taking a string
s =>
// Join the following IEnumerable<char> with a ":" character
string.Join(":",
// Map all the characters in the string
s.Select(a =>
// Is the char less than 33, aka a space?
a < 33 ?
// If so, it's a "00"
"00"
// Else, is this an 'A'?
: a < 66 ?
// If so, convert it to "AM"
"AM" :
// If it's not 'A' or a space, could it be a 'Z'?
a > 89 ?
// If it is, turn the character into "PM"
"PM" :
// If it fails all of the checks above, get the characters position in the alphabet and subtract one from that.
a % 65 + ""))

```
> 5 votes

# Answer
# Pyth, 25 bytes

```
j\:m@+++"AM"S24"PM""00"xG

```

Try it online here, or verify all the test cases at once here.

```
j\:m@+++"AM"S24"PM""00"xGdQ   Implicit: Q=eval(input()), G=lowercase alphabet
                              Trailing dQ inferred
            S24               [1-24]
       +"AM"                  Prepend "AM"
      +        "PM"           Append "PM"
     +             "00"       Append "00" - this is the dictionary
   m                      Q   Map each element of Q, as d, using:
                       xGd      Get the index of d in G, -1 if not present (i.e. space)
    @                           Get the element from the dictionary at the above index
j\:                           Join the result on ":", implicit print

```
> 4 votes

# Answer
# JavaScript (Node.js),  ~~72~~  65 bytes

Takes input in lowercase.

```
s=>[...Buffer(s)].map(c=>c<33?'00':c>121?'PM':c-97||'AM').join`:`

```

Try it online!
> 4 votes

# Answer
# Red, ~~124~~ ~~121~~ ~~110~~ 109 bytes

```
func[s][replace/all form collect[forall s[keep switch/default
c: -97 + s/1[0['AM]25['PM]-65["00"]][c]]]sp":"]

```

Try it online!
> 3 votes

# Answer
# Ruby, 49 bytes

```
->a{a.map{|c|["00",:AM,*1..24,:PM][c.ord%32]}*?:}

```

Try it online!

Port of Jo King's Perl answer. Takes input as an array of chars, returns a string with AM/PM in uppercase.
> 3 votes

# Answer
# 05AB1E, 20 bytes

```
':ýð00:A24L„AMš„PMª‡

```

Greatly inspired by *@Mr.Xcoder*'s 22-byter in the comment of the existing 05AB1E answer by *@Emigna*.

Takes the input as a list of lowercase characters (would be 21 bytes with a leading `S` if I take the input as a string).

Try it online or verify all test cases.

**Explanation:**

```
':ý            '# Join the (implicit) input list of characters by ":"
                #  i.e. ["e","a","s","y"," ","p","e","a","z","y"] → "e:a:s:y: :p:e:a:z:y"
ð00:            # Replace all spaces " " with "00"
                #  i.e. "e:a:s:y: :p:e:a:z:y" → "e:a:s:y:00:p:e:a:z:y"
A               # Push the lowercase alphabet
 24L            # Push a list in the range [1,24]
    „AMš        # Prepend "AM" at the start of this list
        „PMª    # And append "PM" at the end of the list
            ‡   # Transliterate; mapping letters to the list-items at the same indices
                # (and output the result implicitly)
                #  i.e. "e:a:s:y:00:p:e:a:z:y" → "4:AM:18:24:00:15:4:AM:PM:24"

```
> 3 votes

# Answer
# Charcoal, 26 bytes

```
ＵＢ:Ｆθ«→≡ι ×0²a¦AM¦z¦PMＩ⌕βι

```

Try it online! Link is to verbose version of code. Takes input in lower case (can trivially be changed to upper case). Explanation:

```
ＵＢ:

```

Set the background character to `:`. This fills in the gaps between the output values created by the right movement.

```
Ｆθ«→

```

Loop over each character, leaving a gap each time. (The first move has no effect as the canvas is still empty at this point.)

```
≡ι ×0²a¦AM¦z¦PM

```

Switch on the character and if it's space, `a` or `z` then output the appropriate code. I use `×0²` instead of `00` here as the latter would cost two bytes in additional separators.

```
Ｉ⌕βι

```

Otherwise output the letter's 0-indexed position in the lower case alphabet as a string.
> 3 votes

# Answer
# Perl 5 -pl, 46 bytes

```
s/./("00",AM,1..24,PM)[ord($&)%32].":"/ge;chop

```

Case doesn't matter. To run as `perl -ple '<code>'`. `-l` option passed to `perl` allows to drop the last colon with `chop`.

Try it online!
> 3 votes

# Answer
# Scala, 69 bytes

```
_.map(_.-(64)%32)map "00"+:"AM"+:1.to(24).map("".+):+"PM"mkString ":"

```

Try it in Scastie!
> 3 votes

# Answer
# PowerShell, ~~72~~ ~~69~~ 63 bytes

```
$(switch($args){a{'AM'}z{'PM'}' '{'00'}default{$_-97}})-join':'

```

Try it online!

Takes a lowercase string and does not add a leading `0`.

The string is passed to the function using splatting.

It iterates through all the characters of the string, replacing them with their encoded values.

The resulting items are then joined using ':' as separator.

-6 bytes thanks to mazzy !
> 3 votes

# Answer
# Tcl, 100 bytes

```
proc C s {join [lmap c [split $s ""] {scan $c %c v
expr $v==65?"AM":$v==90?"PM":$v==32?00:$v-65}] :}

```

Try it online!
> 2 votes

# Answer
# C# (Visual C# Interactive Compiler), 98 bytes

```
s=>string.Join(':',s.Select(c=>"az ".Contains(c)?new[]{"AM","PM","00"}["az ".IndexOf(c)]:c-97+""))

```

Takes input as a (lowercase) char array. Try it online!
> 2 votes

# Answer
# Jelly, 24 bytes

```
«"⁾PMµØAḊiȯ⁾00µe?€⁾AZj”:

```

Try it online!
> 2 votes

# Answer
# Vyxal, ~~31~~ 22 bytes

```
øA‹u025"J`00ṙ§m`2ẇĿ\:j

```

Thanks to @lyxal!
I'm not familiar with Vyncode so just classic version.
Try it Online!

Explanation:

```
øA                      # Convert letter to number (space=0 and vectorized by default)
  ‹                     # Increment (vectorized)
   u025                 # Push -1, 0 and 25
       "                # Pair top two items (0 and 25)
        J               # Join -1  (so "J shorter than 3¨ẇ)
         `00ṙ§m`        # This uncompressed to `00ampm` (how?)
                2ẇ      # Split into 2-chunks
                  Ŀ     # Transliterate: replace each item of one value in another value with the corresponding element from a third value
                   \:j  # Join by ":"

```

Old version for compare:

```
C97-⟨65N|0|25⟩⟨‛00|‛AM|‛PM⟩Ŀ\:j

```

Try it Online!
> 2 votes

# Answer
# Wolfram Language (Mathematica), ~~98~~ 95 bytes

```
StringRiffle[Switch[#,1,"AM",26,"PM",0,"00",_,ToString@(#-1)]&/@LetterNumber@Characters@#,":"]&

```

Try it online!
> 1 votes

---
Tags: code-golf, string, cipher, encoding
---


title: Tips for golfing in Pip

text:
# Question
Title: Tips for golfing in Pip
Pip is an imperative golfing language with infix operators. It also borrows some features from functional and array programming.

What general tips do you have for golfing in Pip? I'm looking for approaches and tricks that are commonly useful for code golf and are specific to Pip (e.g. "remove comments" is not an answer).

Please post one tip per answer.

# Answer
> 8 votes
# Use preinitialized variables

Pip has many global variables that are pre-initialized so you can avoid manually writing a number/string/something else out yourself.

Here are some of them (complete list):

* `_` Identity function (== `{a}`)
* `h` 100
* `i` 0
* `k` `", "`
* `l` Empty list
* `m` 1000 (mnemonic: Roman numeral M)
* `n` Newline character
* `o` 1
* `s` Space character
* `t` 10
* `v` -1
* `w` Matches whitespace `\s+`
* `x` Empty string
* `z` Lowercase alphabet a to z
* `B` Block that returns its second argument (`{b}`)
* `G` Block that returns its argument list (`{g}`)
* `AZ` Uppercase alphabet A to Z
* `CZ` Lowercase consonants b to z
* `PA` All **P**rintable **A**SCII characters, 32 through 126
* `PI` \\$\pi\\$ (3.141592653589793)
* `VW` Lowercase vowels a to u
* `VY` Lowercase vowels a to y
* `XA` Matches one Latin letter `[A-Za-z]` (there are more `X*` commands)

Link to documentation

# Answer
> 5 votes
# Use the `Y` operator

From a quick survey, it looks like I use `Y` (or one of its variants, `YP` and `YO`) in one out of every three Pip answers--more so as the answers get more complex.

### Storing a value

`Y` stands for "yank," which will be familiar to Vim users as a command that copies the current line or selection into a buffer. The unary `Y` operator in Pip does something similar: it saves a copy of its operand in the `y` global variable and returns the operand unchanged. Essentially, `Y<expr>` is equivalent to `y:<expr>`, but shorter.

This alone makes `Y` (and the `y` variable) useful in many cases. Need to store something in a variable and don't care which one you use? `Y` saves a byte from the assignment. Need to use an expression twice? Yank it and use `y` twice instead. If the expression is longer than two bytes, you'll save.

But `Y` is also useful in another way:

### Manipulating operator precedence

Suppose we want to count the number of 0s in the input and then tack the count onto the end of that input. (For example, input of `1001101` should result in `1001101 3`.) Counting the 0s is `0Na`, and so we would like to do `a.s.0Na`. But that won't work because `N` is lower precedence than `.`, and the expression would parse as `((a.s).0)Na`. To enforce precedence, we can use parentheses: `a.s.(0Na)`. This always works, and sometimes it's the only option.

But often, we can use `Y` instead. The trick is that `Y` has very low precedence--the lowest, in fact, together with `P` and `O`. So *any* expression to the right of `Y` will parse as `Y`'s operand, while the whole `Y` expression will in turn be the right operand of whatever comes to its left. And `Y` will pass its operand through unchanged (plus assign it to `y`, but we don't care about that as long as we're not using `y` for something else). If we write `a.s.Y0Na`, it parses as `(a.s).(Y(0Na))`, just as if we had parenthesized `0Na`. But it only costs one byte, while the parentheses cost two.

### Caveats

A `Y` expression can only be used on the right side of a binary operator, not the left, because `Y` will take *everything* to the right of it as its operand. For instance, if we wanted to prepend the count of 0s instead of appending it, we couldn't do `Y0Na.s.a`--that would parse as `Y(0N(a.s.a))`. Instead, we'd have to fall back on parentheses or another strategy.

There is only one `y` variable, so you can't yank two different values in the same program (unless you can structure your code so that you don't need both of them at the same time). You'll have to pick one to assign to a different variable. Try it both ways and see which one saves you more bytes.

Binary operators in Pip always evaluate their left-hand side first, which means that you generally can't use the new value of `y` in the same expression where you yanked it: If you want to calculate the square of `a+1`, you can't do `y*Ya+1` (`y` won't be `a+1` when it's evaluated, because `a+1` hasn't been yanked yet); and you can't do `Ya+1*a` (which would parse as `Y(a+(1*a))`). In situations like this, you'll probably want to yank the value first, in a separate expression: `Ya+1y*y`. If you absolutely need to do it in one expression, you can parenthesize the `Y` part: `(Ya+1)*y`. This works because the left-hand side of `*` is evaluated first, so `y` has the correct value when the right-hand side is evaluated.

# Answer
> 3 votes
# Manipulating operator precedence with `:`

The `:` meta-operator turns any regular operator into a compute-and-assign version that modifies its left-hand side (LHS) in place. For example, `x+:5` adds `5` to `x` and stores the result back into `x`. The expression evaluates to the result of the computation: if `x` was originally `2`, then `x+:5` would set `x` to `7` and also evaluate to `7`.

Besides adding the compute-and-assign semantics, the `:` meta-operator changes the operator's precedence and associativity to match the precedence and associativity of the assignment operator: very low precedence, right-associative. The main reason is so that the new compound operator behaves like an assignment operator. However, we can also take advantage of this behavior in many situations by treating `:` as a "lower the precedence" meta-operator.

### Example

Suppose we want to subtract 2 from each digit of a number. The straightforward way would be to split the argument into characters (digits) and subtract:

```
(^a)-2

```

Because `^` has lower precedence than `-`, we have to wrap it in parentheses, costing two extra bytes. Instead, we can use `:` to make the precedence of `-` lower, costing only one byte:

```
^a-:2

```

Now `-:` has lower precedence than `^`, and the expression parses as `(^a)-:(2)` without needing parentheses.

### Caveat

If the LHS of your higher-precedence operator is an lvalue (an assignable value such as a variable or an item in a list), adding the `:` meta-operator will modify its value. Sometimes this is fine (e.g. if the expression is at the top level and you just want to output it and halt). Other times, you need the value to stay unmodified; in those cases, you'll probably need to go back to parentheses.

In the above example, the LHS of `-:` is the expression `^a`, which is not an lvalue. Therefore, nothing is modified (if you use the `-w` flag, you'll see a warning: `Attempting to assign to non-lvalue`). The expression still evaluates to the result of the computation, as desired.

# Answer
> 2 votes
# Replace simple functions with lambdas

Lambdas are a generally good way to save 2 bytes(at the very least), as compared to a regular function that requires braces.

Pip's lambdas, however, do not mimic the general attributes of a lambda in say, Python. You cannot shorten all standalone functions into lambdas.

They're an extension of the identity function `_`, where `_ = {a}`. This means that you can create a lambda out of a function *only* if you are writing a function with a single expression.

Lambdas in Pip have some interesting uses other than single expressions. For example, you can reference the main function's arguments without yanking/copying them.

From Dlosc's tutorial on functions:

> The function `_+a` adds its argument to the program's first command-line argument. `a` still has its top-level value because it's not inside curly braces.

The catch is that you cannot use commands(If, Else if, Loops) and everything must come down to one statement, as it is generally with applying operators on functions.

Due to those restrictions, Pip lambdas are generally better suited for small mapping or filtering functions. Happy golfing!

If you do find an interesting use case, do tell me.

# Answer
> 2 votes
# Output in pieces rather than concatenating

Say you have two expressions that you want to concatenate together and autoprint at the end of your program. The best-case scenario is that you simply use `.`:

```
a+b.'!

```

But sometimes the precedence doesn't cooperate:

```
(aJb).'!

```

You could lower the precedence of `.` using the `:` meta-operator, but that still costs an extra byte:

```
aJb.:'!

```

*If* this expression is the last expression in your program (i.e. you want it to be autoprinted and your program doesn't do anything else afterwards), and *if* you're concatenating Scalars (i.e. you're not depending on the vectorizing behavior of the `.` operator), then you can instead simply output the first expression using `O` and autoprint the second expression:

```
OaJb'!

```

This outputs the result of `aJb` without a trailing newline, then immediately outputs an exclamation point (with a trailing newline)--which produces the same output as concatenating them.

# Answer
> 1 votes
# `M` can map a value instead of a function

Normally, you would use `M` like this:

```
UC_M"abc"

```

with the left-hand side being a function and the right-hand side being some iterable you want to map it to. If you need to swap the arguments, `"abc"MUC_` works too.

But in the case where you just want to replace every item in the iterable with a constant value, `M` can do that too--just give it a non-function as its left-hand side:

```
42M"abc"

```

This will return `[42;42;42]`: one `42` for every character in `"abc"`. If you don't mind that you're getting a list and not a string, this is one byte shorter than `42X#"abc"`, and it's two bytes shorter than the list equivalent `42RL#"abc"`.

The value can be literally anything\* that's not a function: Scalar, Pattern, List, Range, or even Nil.

This trick also works with some other map operators:

* `aMJb` joins the results into a string after mapping (may be particularly useful when `a` is not a Scalar to begin with)
* `aMMb` will give you a list of lists of `a`, the lengths of the sublists matching the lengths of the items in `b`
* `aMCb` will give you a `b`x`b` grid (nested list) of `a`

That last one is a useful alternative to `ZG` when you want a value other than 0 (for example).

---

* Technically, it'll behave differently if given a list that contains a function.

# Answer
> 1 votes
# Shortcuts for certain lists

Normally, if you need a list of constants, you just enclose the items in square brackets, with separators as necessary (`[4 8 15 16 23 42]`). But there are shorter ways to construct some commonly used lists:

* First, don't forget you can use preset variables if you haven't reassigned them. The empty list can be `l` instead of `[]`. Using `i` for `0` and `o` for `1` in a list can save a byte (or even two) if they are next to another number, since lowercase variables don't require a separator: `[0 5]``[i5]`. Using `v` for `-1`, `t` for `10`, `h` for `100`, or `m` for `1000` also saves bytes directly, since the variable names are shorter than the numbers they represent.
* Use a range if possible: `[0 1]``[io]``,2`. This still saves a byte if it's 1-based (`[o2]``\,2`) or starts at some other number (`[v0]``v,1`).
* For a list of digits, split a number: `[1]``^1`; `[3o4o5 9]``^314159`; `[oi]``^t`. This works for characters, too: `['#]``^'#`; `['h'i]``^"hi"`.

Note that the latter two methods involve operators with different precedences, which you'll need to take into account. If working around the precedence is too much trouble, you can always fall back on the standard list syntax.

# Answer
> 1 votes
# Use unary operators whenever possible

A lot of binary operators in Pip have unary versions. The concept should be familiar: many programming languages have binary `-` for subtraction and unary `-` for negation. Pip extends the idea to a lot of other operators:

* Binary `/` for division, unary `/` for reciprocal
* Binary `^` to split on a separator, unary `^` to split into a list of characters
* Binary `TB` to convert to a given base, unary `TB` to convert to binary
* Binary `||` to strip characters from a string, unary `||` to strip whitespace from a string
* Binary `Z` to zip two iterables together, unary `Z` to zip all the items of a list together

and many others.

The obvious benefit of unary operators is that they don't require two arguments. Instead of `1/x`, `/x` will do the trick for -1 byte. The less-obvious benefit comes when we start combining operators:

## Unary operators let you ignore precedence, sometimes

In an expression with two binary operators, the higher-precedence operator will be evaluated first: `vEa%2` is `(vEa)%2` because `E` has higher precedence than `%`. If we wanted `vE(a%2)` instead, we would need to use parentheses or some other trick to manipulate the precedence.

However, in an expression like `vE%a`, the only way to evaluate is `vE(%a)`: `E` is evaluated first, but its right argument can only be the subexpression `%a`; it can't "steal" an operand from the lower-precedence operator like it could from binary `%`.

In a sense, the precedence of a unary operator doesn't matter on its left, only on its right. An expression like `%vEa` is still going to parse as `%(vEa)` because `E` is higher precedence than unary `%`. But if you can set up your expression so that a unary operator is the right-hand side of a binary operator, you can drop the parentheses and save more bytes.

Here's a real-life example. We want to group (`<>`) the longer string before we weave (`WV`) it with the shorter string, but `WV` is higher precedence than `<>`.

```
"NESW"WV("NESESWNW"<>2)  Original version, 23 bytes
"NESW"WV:"NESESWNW"<>2   Using a precedence trick, 22 bytes
"NESW"WV<>"NESESWNW"     Using a unary operator, 20 bytes

```

# Answer
> 1 votes
# Use a list instead of concatenating

The default output format for Lists is to concatenate all of their items together. If you need to output more than three strings concatenated, you save bytes by throwing them all in a List instead of actually concatenating them:

```
m//60." hours, ".m%60." minutes"
[m//60" hours, "m%60" minutes"]

```

You may be able to save even more in specific cases by using one of the list-formatting flags:

```
[m//60"hours,"m%60"minutes"]   ; (with -s flag to join on spaces)

```

This trick works even better if one of your items is actually a List, or involves an operator with lower precedence than concatenation:

```
"The arguments are ".(gJk).'!
["The arguments are "gJk'!]

```

If you're doing something with the result other than just outputting it, this approach may not work for you. One context where it *does* work, however, is with the `R`eplace operator: if the second argument is a Scalar or Pattern, a third argument that is a List will be converted to a string before being substituted.

# Answer
> 0 votes
# How to crash the interpreter

Pip is designed to be pretty forgiving. Operations that cause errors in other languages, such as dividing by zero, usually just return nil (and print a warning message, but only if you enable warnings using the `-w` flag). But sometimes in golf, you *want* the program to crash. For example, it's the only way to break out of an infinite loop.

There are a couple of ways to get a fatal error, but the golfiest is to trigger a runtime parse error by evaluating a string as code. Evaluating any single character that's an operator will crash the interpreter, since the operator needs (at least one) operand. Shorter still, the variable `k` is preset to `", "`, which works just as well: `Vk`, 2 bytes.

---
Tags: code-golf, tips
---


# Question
Title: What dice do I need to display my words?
*A sequel to What dice do I need to display every integer up to X?*

Numbers are great, but let's take it to the next level. I'd like to have a set of dice that can be arranged and rotated to display any words I want. Think Boggle:

And not just that; I want to specify the number of sides those dice have. The set should contain the fewest number of dice possible.

For example—
If I want to be able to display any of the following words with 4-sided dice:

```
CODE
GOLF
IS
VERY
FUN

```

I would need 4 dice with the following letters on their sides (each line represents a die):

```
C G I V
O S R U
D L N Y
E F

```

Note that the last die only has letters on two of its sides.

## The challenge:

* Given a number of sides N, and 1 or more words, write a program that outputs the N-sided dice that are required to be able to display all of the words (one at a time).
* The first input is always an integer, 4 at minimum. This number determines the number of sides that each of the dice will have.
* All other inputs are strings of English-alphabet capital letters, at least 1 character in length. They may be provided in any format you like; delimited, a list, array, etc.
* Each side of a die must be either blank or contain a single English-alphabet capital letter.
* Unlike the number challenge, you do **not** need to ensure that every die is used for every word. If there's a two-letter word and 4 total dice required, you only need to ensure that 2 dice have the correct letters on them.
* Output must be provided so that all the letters on each die is shown, and each die is separated somehow. So `CGIVOSRUDLNYEF` is not valid output for the above example, but these are valid:

```
CGIV OSRU DLNY EF

CGIV
OSRU
DLNY
EF

["CGIV", "OSRU", "DLNY", "EF"]

[["C", "G", "I", "V"], ["O", "S", "R", "U"], ["D", "L", "N", "Y"], ["E", "F"]]

```
* The dice in the output, and the letters in each side do not need to be in any particular order.
* A correct solution outputs the fewest possible dice given the inputs.
* There may be multiple correct outputs for a given input. You need only output one.

Here are a couple more test cases:

```
Input: 4,EASY,TEST,TEASE
Output:
E
A T
S
Y T
E

Input: 5,MEDIC,FROG,WOW,ZEBRA,SCENES,ZOOM,BABOON,LOITER,XRAY,MEDIUM,GUEST,SUNDAY,ROMP
Output:
M S B L G
Z A F W E
D E B T M
M Y S O R
I N W X P
U C O A Y

```

## Bonus challenges:

* Your program must also handle the number of sides being 3, 2, or 1.
* Your program must assume that an `M` can be rotated and used as a `W`. `W` can never appear in the output. This also goes for `C` and `U`, `Z` and `N`, `H` and `I`.
* A correct solution outputs the fewest possible *letters* for a given input, not just the fewest dice.

# Answer
> 2 votes
# Charcoal, 133 bytes

```
ＮθＷＳ⊞υι≔⟦⊞ＯＥ⌈⊞ＯＥυＬιＬ⪪⪫υωθωυ⟧υ≔⟦⟧ηＦυ«≔⊟ιζ≔§ζ⁰εＦΦＥＸＬιＬε﹪÷κＸＬιＥενＬι⬤κ⁼¹№κμ«≔Ｅι⁺λ…§ε⌕κμ›№κμ№λ§ε⌕κμκ¿⬤κ¬›Ｌλθ¿⊖Ｌζ⊞υ⊞ＯκΦζμ⊞ηΦκλ»»⊟Φη⁼Ｌι⌊ＥηＬλ

```

Try it online! Link is to verbose version of code. Takes input as an integer and a list of newline-terminated strings. Explanation: Brute force, so incredibly slow; link only has two words because that's all it can solve in a reasonable amount of time.

```
ＮθＷＳ⊞υι

```

Input `N` and the words.

```
≔⟦⊞ＯＥ⌈⊞ＯＥυＬιＬ⪪⪫υωθωυ⟧υ

```

Start off with a number of blank dice equal to the minimum of the length of the longest word or the minimum number of dice needed to write each letter of each word on its own face, and all of the words needing to be placed.

```
≔⟦⟧η

```

Start collecting possible placements.

```
Ｆυ«

```

Process all of the partial placements.

```
≔⊟ιζ

```

Get the remaining words.

```
≔§ζ⁰ε

```

Get the first word.

```
ＦΦＥＸＬιＬε﹪÷κＸＬιＥενＬι⬤κ⁼¹№κμ«

```

Get all of the permutations (even on the first iteration where it makes no difference whatsoever) of placing the letters of the word onto the dice.

```
≔Ｅι⁺λ…§ε⌕κμ›№κμ№λ§ε⌕κμκ

```

Get the result of this letter placement.

```
¿⬤κ¬›Ｌλθ

```

Check that there aren't too many letters on any of the dice.

```
¿⊖Ｌζ

```

If there are more words left to place, then...

```
⊞υ⊞ＯκΦζμ

```

... create the next partial placement to be processed, otherwise...

```
⊞ηΦκλ

```

... collect the possible placement, removing any empty dice.

```
»»⊟Φη⁼Ｌι⌊ＥηＬλ

```

Output any of the placements that have the fewest dice.

Since the above version is so inefficient, I have also written a slightly less inefficient 175 byte version that can handle slightly less trivial cases:

```
ＮθＷＳ⊞υι≔⌈ＥυＬιη≔⊟Φυ⁼Ｌιηζ≔⟦⊞ＯＥ⌈⟦ηＬ⪪⪫υωθ⟧⎇‹ιη§ζιω⁻υ⟦ζ⟧⟧υ≔⟦⟧ηＦυ«≔⊟ιζ¿ζ«≔§ζ⁰ε≔Φζλζ≔ＥΦＥＸＬιＬε﹪÷κＸＬιＥενＬι⬤κ⁼¹№κμＥι⁺μ…§ε⌕κν›№κν№μ§ε⌕κνδ≔⌊ＥδＬ⪫κωεＦδ¿›⁼εＬ⪫κω⊙κ›Ｌλθ⊞υ⊞Ｏκζ»⊞ηΦικ»⊟Φη⁼Ｌι⌊ＥηＬλ

```

Try it online! Link is to verbose version of code. Explanation: Only one permutation of the longest string and only word placements that reuse the most possible dice are considered, so for the example of `TOO` and `ON`, the letters of `TOO` will be put on three dice, and then the `O` of `ON` will never be matched with the `T`.

# Answer
> 3 votes
# Python3, 1070 bytes:

```
from itertools import*
P=permutations
def U(w,c):c=[i for i in c if i];t=[''.join(j)for i in P(c,len(c))for j in product(*i)];return[i for i in w if all(i not in j for j in t)]
E=enumerate
def f(w,n):
 C=-1;G=eval(str(w))
 while 1:
  C+=1
  q,S=[(G[:i]+G[i+1:],[[j]for j in a]+[[]for _ in range(len(max(G,key=len))-len(a))]+[[]for _ in range(C)])for i,a in E(G[:1])],[]
  while q:
   a,b=q.pop(0)
   if not a:return b
   F=0
   for m in sorted([K for i in P([*E(b)],len(a[0]))if(K:=[(u,I)for(u,x),(I,y)in zip(E(a[0]),i)if x in y])],key=len)[::-1]:
    I={i for i,_ in E(b)}-{i for _,i in m};w={i for i,_ in E(a[0])}-{u for u,_ in m};W=0
    for i in P(I,len(w)):
     B=eval(str(b));T=1
     for x,y in zip(i,w):
      if len(B[x])<n:B[x]+=[a[0][y]]
      else:T=0;break
     if T and B not in S:q+=[(U(a,B),B)];S+=[B];W=1
     else:W=max(W,0)
    if W:F=1
    else:F=max(F,0)
   if F==0:
    for i in P(E(b),len(a[0])):
     B=eval(str(b));T=1
     for(x,_),y in zip(i,a[0]):
      if len(B[x])<n:B[x]+=[y]
      else:T=0
     if T and B not in S:q+=[(U(a,B),B)];S+=[B]

```

Try it online!

# Answer
> 3 votes
# Python 3, 205 bytes

```
from itertools import*
def f(n,w,k=1):
 for s in product(*[[*product(*[{*''.join(w)}]*n)]]*k):
  if all(any(all(W.count(c)<=F.count(c)for c in W)for F in product(*s))for W in w):return s
 return f(n,w,k+1)

```

A recursive function that accepts a positive integer, `n`, and a list of strings `w` and returns a tuple (collection) of tuples (dice) of characters (faces).

**Try it online!** (adding `'FFF'` requires four dice)

It's too slow for the test cases as it is checking all possibilities (hence the inputs given in the TIO links, with `n=3` and a very small set of letters). We could prune the dice being considered by only using those with `min(n, number of unique letters in inputted words)` unique faces, which most of the time would mean we only consider those with `n` different faces, and we could start our considerations with `min(word length)` dice, but doing both still won't be enough to complete the given test cases on TIO.

---
Tags: code-golf, boggle
---


title: Evolution of Powers of Two

text:
# Question
Title: Evolution of Powers of Two
*This is a repost of Evolution of “Hello World!”, originally written by user Helka Homba*

*It should not be closed as a duplicated, due to meta consensus here.*

*The original was asked over two years ago and was last active more than six months ago. I have permission from Helka Homba to post this here*

*Since the original, many languages have been invented, and many people have joined the site who have never had an opportunity to answer the original, so I feel that this repost is acceptable.*

---

The challenge is to make a program that prints `2^n` to stdout, where `n` is the number of your program. The catch is that your program must have a Levenshtein distance of 10 or less from the program in the answer submitted before yours.

# How This Will Work

Below I will submit the first answer using C#, which prints 2^(n=1)=`2`.

The next person to answer must modify the code with up to 10 single character insertions, deletions, or substitutions so that when it is run in the language of the new answer, it prints `2^n` (with `n` being the answer number). For example, the 25th answer (let's say it's in Pyth) would print 2^25, or 33554432.

This will continue on until everyone get stuck because there is no new language the last answer's program can be made to run in by only changing 10 characters. The communal goal is to see how long we can keep this up, so try not to make any obscure or unwarranted character edits (this is not a requirement however).

# Formatting

Please format your post like this:

```
#Answer N - [language]

    [code]

[notes, explanation, observations, whatever]

```

Where N is the answer number (increases incrementally, N = 1, 2, 3,...).

You do not have to tell which exact characters were changed. Just make sure the Levenshtein distance is from 0 to 10.

If you answer in some language or the resulting code is just a mess, *do please* explain what you did and why it works, though this isn't required.

# Rules

The key thing to understand about this challenge is that **only one person can answer at a time and each answer depends on the one before it**.

There should never be two answers with the same N. If two people happen to simultaneously answer for some N, the one who answered later (even if it's a few seconds difference) should graciously delete their answer.

Furthermore...

* A user may not submit two answers in a row. (e.g. since I submitted answer 1 I can't do answer 2, but I could do 3.)
* Try to avoid posting too many answers in a short time frame.
* Each answer must be in a different programming language.
    + You may use different major versions of a language, like Python 2/3
    + Languages count as distinct if they are traditionally called by two different names. (There may be some ambiguities here but don't let that ruin the contest.)
* You do not have to stick to ASCII, you can use any characters you want. Levenshtein distance will be measured in unicode **characters**.
* The output should only be `2^n` and no other characters. (Leading/trailing whitespace is fine, as is unsuppressible output like `>>>` or `ans=`)
* If your language doesn't have stdout use whatever is commonly used for quickly outputting text (e.g. `console.log` or `alert` in JavaScript).
* When the power of two you have to output gets very large, you may assume infinite memory, but not an infinite integer size. Please be wary of integer overflows.
* You may make use of scientific notation or whatever your languages most natural way of representing numbers is. (Except for unary, *DO NOT* output in unary)

**Please make sure your answer is valid.** We don't want to realize there's a break in the chain five answers up. Invalid answers should be fixed quickly or deleted before there are additional answers.

**Don't edit answers unless absolutely necessary.**

# Scoring

Once things settle down, the user who submits the most (valid) answers wins. Ties go to the user with the most cumulative up-votes.

## Edit these when you post an answer:

### Leaderboard

> ### 13 languages
>
> Okx
>
> ### 8 languages
>
> zeppelin
>
> ### 4 languages
>
> Pavel
> Jonathan Allan
> Kritixi Lithos
> Riker
>
> ### 3 languages
>
> boboquack
>
> ### 2 languages
>
> bmarks
> Conor O'Brien
> Destructible Watermelon
> ovs
> Tom Carpenter
>
> ### 1 language
>
> ATaco
> Blocks
> Dennis
> dzaima
> Erik the Outgolfer
> ETHproductions
> ghosts\_in\_the\_code
> Leo
> Lynn
> Matheus Avellar
> Nathaniel
> Qwerp-Derp
> R. Kap
> Taylor Raine
> nimi
> Mistah Figgins
> PidgeyUsedGust
> steenbergh

### Languages used so far:

> 1. C# (Pavel)
> 2. /// (boboquack)
> 3. Retina (Dennis)
> 4. Jelly (Jonathon Allan)
> 5. Pyth (boboquack)
> 6. \>\<\> (Destructible Watermelon)
> 7. Minkolang (Kritixi Lithos)
> 8. Perl (Pavel)
> 9. Python (Qwerp-Derp)
> 10. dc (R. Kap)
> 11. Charcoal (Jonathon Allan)
> 12. Self Modifying BrainFuck (Leo)
> 13. SOGL (dzaima)
> 14. ShapeScript (Jonathon Allan)
> 15. Pyke (boboquack)
> 16. Ruby (Nathaniel)
> 17. 05AB1E (ovs)
> 18. STATA (bmarks)
> 19. bc (Kritixi Lithos)
> 20. Japt (Okx)
> 21. 2sable (Kritixi Lithos)
> 22. Cheddar (Jonathon Allan)
> 23. Pylons (Okx)
> 24. Bash (zeppelin)
> 25. Pushy (Okx)
> 26. CJam (Erik the Outgolfer)
> 27. MATL (Okx)
> 28. MATLAB (Tom Carpenter)
> 29. Octave (Kritixi Lithos)
> 30. R (ovs)
> 31. JavaScript ES7 (Tom Carpenter)
> 32. Convex (Okx)
> 33. Mathematica (ghosts\_in\_the\_code)
> 34. Pip (Okx)
> 35. Stacked (Conor O'Brien)
> 36. GolfScript (Okx)
> 37. Actually (Lynn)
> 38. RProgN (Okx)
> 39. Scheme (bmarks)
> 40. Element (Okx)
> 41. J (Blocks)
> 42. Cubix (ETHproductions)
> 43. zsh (zeppelin)
> 44. VBA (Taylor Raine)
> 45. Fish (zeppelin)
> 46. Reticular (Okx)
> 47. Perl 6 (Pavel)
> 48. RProgN2 (ATaco)
> 49. PHP (Matheus Avellar)
> 50. Jolf (Conor O'Brien)
> 51. Haskell (nimi)
> 52. Befunge-98 (Mistah Figgins)
> 53. Gnuplot (zeppelin)
> 54. QBIC (steenbergh)
> 55. FOG (Riker)
> 56. Qwerty-RPN (Okx)
> 57. Korn Shell (ksh) (zeppelin)
> 58. Julia (Riker)
> 59. Python 3 (Pavel)
> 60. Vimscript (Riker)
> 61. Dash (zeppelin)
> 62. Vitsy (Okx)
> 63. csh (zeppelin)
> 64. Ohm (Okx)
> 65. Bosh (zeppelin)
> 66. es-shell (Riker)
> 67. Gol\>\<\> (PidgeyUsedGust)

This question works best when you sort by oldest.

# Answer
# Answer 64, Ohm, distance 10

```
64º,;S)1'a"bc"<<x
2^63
x
#??92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`#(expt 2 39); ^
exit
 @n.out (*2 32#e#a44******O@) //2 25)
"e
"2ej
:py print(2**60)
"%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024print(2**53)--0;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```

Added `64º,;S)1'a`

Only the `64º,` is actual code, the rest is just junk.

This program will print the correct output, but it will also ask for some `STDIN` *after* it has printed 264.
> 5 votes

# Answer
# Answer 67, Gol\>\<\>, distance 6

We van use the trampoline `#` to just append the code in reverse. By removing `S)1'a` the `;` can be reused, needing only 6 characters to be added.

```
#64º,;n*:"C"
"bc"<<x
2^66
x
#??92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`#(expt 2 39); ^
quit()
@n.out (*2 32#e#a44******O@) //2 25)
"e
"2ej
:
py
p
riker
i
n
t
(2**60)
"%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#

```

Try it online!

I think keeping the `#` allows for some other languages to use it as a commented line.
> 6 votes

# Answer
# Answer 17: 05AB1E, Distance of 3

```
#"Ａ#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.
#1024p#rint(512);
#0}}//4|
#β”6904”±r«"$2
puts 16384 8*

```

Try it online!
> 5 votes

# Answer
# Answer 24: Bash, distance 8

```
#23#2ej
printf $[2**24]
#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.
#1024p#rint(512);
#0}}//4|
#ß”6904”±r«"$2
#puts 16384 8*di 2^18o8*'

```

Try It Online !
> 5 votes

# Answer
## Answer 51, Haskell, distance 10

```
--2@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`(expt 2 39); ^ exit @n.out (*2 32#e#a44******O@)//2 25)#e#2ej#printf("% $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024
print(2^51)--;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```

Remove 2 NL, replace `^` at the beginning with `-`, prepend another `-`, delete `*` within the `print`, replace 2nd `*` with `^`, overwrite `49`with `51`, insert `--` after the print.
> 5 votes

# Answer
# Answer 3: Retina, distance 3

```
/class HelloWorld {static void Main() {
    System.Console.Write(2);
}}//4|
8

```

Appended `|\n8` (distance 3).

Try it online!
> 4 votes

# Answer
# Answer 4: Jelly distance 3

```
/class HelloWorld {static void Main() 0{
    System.Console.Write(2);
0}}//4|
8Ḥ

```

**Try it online!**

all insertions: `00Ḥ`.

`0{` and `0}` are there to suppress parsing errors (pop from empty list due to the `{` and `}` being quicks that turn monads into dyads using the left and right argument respectively).

"unhalves" 8 to make 16.
> 4 votes

# Answer
# Answer 5: Pyth

```
32 "/class HelloWorld {static void Main() 0{
    System.Console.Write(2);
0}}//4|
8Ḥ

```

Prints the numeric literal `32`, then the space between the `2` and the `"` suppresses printing of the (auto-completed) string literal.

+4 characters - `32 "`

Try it on herokuapp
> 4 votes

# Answer
# Answer 6 - \>\<\>

```
32""/class HelloWorld {static void Main() 0{;n***~
    System.Console.Write(2);
0}}//4|
8Ḥ

```

replaced a space with ", the code pushes 3, 2, 4, then reverses, pushes 4,2,3, then pops 3 off the stack, and multiplies 2, 4, 4, 2, for 64, outputs it and halts

Try it online

maybe use https://www.fishlanguage.com/playground
> 4 votes

# Answer
# Answer 8: Perl

```
#327;N.""/class HelloWorld {static void Main() 0{;n***~
#    System.Console.
print(256);
#0}}//4|
#8Ḥ

```

Exactly distance of 10: +4 `#` for comments, +1 newline after `System.Console.`, +3 for transforming `write` into `print`, +2 for turning `2` into `256`.

I wasn't going to participate, but I wanted to make sure some regular langs were added before anything got too insane.

Try it online!
> 3 votes

# Answer
# Answer 20: Japt, distance 8

```
2**20$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.
#1024p#rint(512);
#0}}//4|
#ß”6904”±r«"$2
#puts 16384 8*di 2^18*/

```

Try it online!

Modifications:

Changed `2^19` to `2**20` at the start of the program, to calculate the power (4)

Replaced `#` with `$` on the first line so that everything past it is interpreted as JS (1)

On the last line, removed the `/` and added a `*/` at the end of the program, so the comment takes up the whole program (3)
> 3 votes

# Answer
# Answer 27: MATL, distance 4

```
27W%2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß”6904”±r«"$2 #puts 16384 8*di 2^18o8*'

```

Try it online!

Added `27W%`

Explanation:

```
  W   2 to the power of
27    27
   %  Start of single line comment

```
> 3 votes

# Answer
# Answer 42: Cubix, distance 8

```
2^41 NB.`(expt 2 39); ^ exit @ⁿ.óout (*2 32#e#a44******O@)//2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß6904±r"$2 #puts 16384 8*di 2^18o8*'*

```

Try it online!

The `lert(2**31` in the middle was changed to `44******O@`.
> 3 votes

# Answer
# Answer 49: PHP, distance 6

```
<?#"#28@P2*Jp;math 2\^45#2^41 NB.`(expt 2 39); ^ exit @n.óout (*2 32#e#a44******O@)//2 25)#e#2ej#printf("% $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.#1024
print(2**49);#0}}//4|
#ß6904±r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```

Added `<?` and `?>` to open and close PHP tags, respectively.

Replaced `48` with `49`.

`#` starts a comment on PHP, so nothing is considered except for

```
<? print(2**49); ?>

```

Here's a screenshot of proper syntax highlihgting and output to help visualize:
> 3 votes

# Answer
# Answer 50: Jolf, distance 10

```
^2@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`(expt 2 39); ^ exit @n.out (*2 32#e#a44******O@)//2 25)#e#2ej#printf("% $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.#1024
print(2**49);#0}}//4|
#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```

Try it here!

Prepended `^2@2(` (+5)

Removed `±` and `ß` from `#ß6904±r` (+2)

Removed `ó` from `óout` (+1)

Removed `<?` from `<?#"#28@P2*` (+2)

Total: 10. *Remove all the non-ASCII characters!*

## Explanation

`(` stops parsing, so the code looks like:

```
^2@2
^      exponentiate
 2     two
  @2   to the 50 (char code of 2)

```
> 3 votes

# Answer
# Answer 52. Befunge-98, distance 8 + 2

Thanks to @DestructibleWatermelon for golfing a byte!

```
--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`(expt 2 39); ^ exit @n.out (*2 32#e#a44******O@)//2 25)#e#2ej#printf("%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024
print(2^51)--;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```

Try it Online!

Added `'3k` before the `2`, and `'2k*.` between the `2` and `@`.

`--` does nothing,
`'3k2` puts 52 2s onto the stack, and
`'2k*.@` multiplies them together, prints the number, and exits

Also, I added a `d"` after `printf("%` to make other people's lives easier, as I had 2 extra characters. It doesn't affect the Befunge-98 program.
> 3 votes

# Answer
# Answer 60, Vimscript, distance 10

```
"bc<<<2^57 #x??92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`#(expt 2 39); ^ exit @n.out (*2 32#e#a44******O@) //2 25)
"e
"2ej
:py print(2**60)
"%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024print(2**53)--0;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```

Changed the 2 `#` on the start of the middle two lines to `"`, added a `"` in front of the first line, and `:py<space>` in front of the last line.

For clarification:

`"` is a line comment in vimscript (at least at the start of a line), and doesn't need to be matched.

Vim can run python code, so this is really equivalent to asking python for the answer.
> 3 votes

# Answer
# Answer 2: ///

```
/class HelloWorld {static void Main() {
    System.Console.Write(2);
}}//4

```

+4 chars - `///4`

Try it online!
> 2 votes

# Answer
# Answer 7: Minkolang, Distance: 4

```
327;N.""/class HelloWorld {static void Main() 0{;n***~
    System.Console.Write(2);
0}}//4|
8Ḥ

```

Try it online!

I added `7;N.` to the program. Basically `3`, `2` and `7` are pushed to the stack and then 2 is raised to the seventh power using `;`. This is then outputted as a `N`umber and then the program stops on the `.`
> 2 votes

# Answer
# Answer 10: dc, Distance of 5

```
#327;N.""/class HelloWorld {static void Main() 0{;n***~
#    System.Console.
1024p#rint(512);
#0}}//4|
#8

```

Here is a valid `dc` program which outputs `1024`.

Try it online!
> 2 votes

# Answer
# Answer 11: Charcoal, distance 5

```
Ａ#327;N.""/class HelloWorld {static void Main() 0{;n***~
#    System.Console.
1024p#rint(512);
#0}}//4|
β2048

```

**Try It Online!**

The uppercase Greek letters  and `β` are variables which are assigned the ASCII characters following. The final value is implicitly printed.
> 2 votes

# Answer
# Answer 12: Self-modifying Brainfuck

```
Ａ#327;N<.""/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.
1024p#rint(512);
#0}}//4|
#β6904

```

Try it online!

SMBF is just like brainfuck, except the source code is available on the tape to the left of the starting position. Here we have the number to print in reverse at the end of the code, and we do `<.` four times to print all four digits.

I added a `<` before each `.` in the code (there were 3 of them), an extra `<.`, and modified the final number. Distance should be 8.
> 2 votes

# Answer
# Answer 29: Octave, Distance: 1

```
disp(2^29)%2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß”6904”±r«"$2 #puts 16384 8*di 2^18o8*'

```

Try it online!

All I had to do was to change the `28` to `29`
> 2 votes

# Answer
# Answer 31: JavaScript ES7, Distance 7

```
alert(2**31)//2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß”6904”±r«"$2 #puts 16384 8*di 2^18o8*'

```

ES7 supports the `**` operator for power.

You can try online here.
> 2 votes

# Answer
# Answer 33: Mathematica, distance 9

```
2^33 (*2 32#e#alert(2**31)//2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß”6904”±r«"$2 #puts 16384 8*di 2^18o8*'*)

```

Explanation

Puts everything inside comments and outputs 2^33

*Please verify that this answer is valid before putting your own because I am new at this and don't want to end up breaking the chain.*
> 2 votes

# Answer
# Answer 37: Actually, distance 7

```
2:37@ⁿ.óout (*2 32#e#alert(2**31)//2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß6904±r"$2 #puts 16384 8*di 2^18o8*'*

```

Replaced `36?#` with `:37@ⁿ.ó`.

Try it online!
> 2 votes

# Answer
# Answer 38: RProgN, distance 10

```
2 38 ^ exit @ⁿ.óout (*2 32#e#alert(2**31)//2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß6904±r"$2 #puts 16384 8*di 2^18o8*'*

```

Try it online!

Replaced `2:37` with `2 38 ^ exit`  (10) (note the trailing space)

Explanation:

```
2            2
     ^       to the power of
  38         38
       exit  Stop the prgram

```
> 2 votes

# Answer
# Answer 47: Perl 6, distance 10

```
#28@P2*Jp;math 2\^45#2^41 NB.`(expt 2 39); ^ exit @n.óout (*2 32#e#a44******O@)//2 25)#e#2ej#printf("% $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.#1024
print(2**47);#0}}//4|
#ß6904±r"$2 #puts 16384 8*di 2^18o8*'*

```

Perl 6 is considered distinct from Perl. I tried to set up C down the road by adding `"%` after `printf`, hopefully someone uses that.

Try it online!
> 2 votes

# Answer
# Answer 48: RProgN2, distance 9

```
"#28@P2*Jp;math 2\^45#2^41 NB.`(expt 2 39); ^ exit @n.óout (*2 32#e#a44******O@)//2 25)#e#2ej#printf("% $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.#1024
print(2**47);#0}}//4|
#ß6904±r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^

```

Added a `"` to the start which stopped everything from breaking, the `[[[` at the end clears the memory, and `268*^` calculates the new answer. Implicitly printed.

Try it online!
> 2 votes

# Answer
# Answer 66, es (shell) + `bc`, distance 8

```
#64º,;S)1'a
"bc"<<x
2^66
x
#??92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`#(expt 2 39); ^
quit()
@n.out (*2 32#e#a44******O@) //2 25)
"e
"2ej
:
py
p
riker
i
n
t
(2**60)
"%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024print(2**53)--0;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```

Changed `exit` to `quit()`, and added `iker` after the first `r`. I couldn't resist and I wanted to add 4 more characters.
> 2 votes

# Answer
# Answer 1: C#

```
class HelloWorld {static void Main() {
    System.Console.Write(2);
}}

```

Pro tip: comment out what you don't need.

Try it online!
> 1 votes

# Answer
# Answer 9: Python 2

```
#327;N.""/class HelloWorld {static void Main() 0{;n***~
#    System.Console.
print(512);
#0}}//4|
#8

```

A very simple port of Perl to Python, with a distance of 4.

Try it online!
> 1 votes

# Answer
# Answer 13: SOGL 0.8.2, distance 5

```
Ａ#327;N<.""/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.
1024p#rint(512);
#0}}//4|
#β”6904”±r«

```

A little explanation:

```
Ａ#327;N<.               do some random stuff
         "...”          push that string
              6904”     push "6904"
                   ±    reverse
                    r   convert to number
                     «  bitshift left

```

note: to run this you'll have to replace the newlines to ¶ because that's how the interpreter was made to work.
> 1 votes

# Answer
# Answer 15: Pyke

```
"Ａ#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.
1024p#rint(512);
#0}}//4|
#β”6904”±r«"$2 16384*s

```

Substitutes two `'` for two `"`, adds two `$`, substitutes `0*` for `2(space)` and adds `*s`. (8)

`"Ａ#327;N<."` String literal, put on stack `"..."$` Is it all lower? No, so put `0` on the stack instead
`"/class HelloWorld...#β”6904”±r«"` String literal, put on stack
`"..."$` Is it all lower? No, so put `0` on the stack instead
`2 16384` Numeric literals, put on stack
`*` Multiply top two numbers on stack, put `32768` on the stack instead
`s` Sum the whole stack: replace whole stack with `32768`
(implicit print stack)

Try it online!
> 1 votes

# Answer
## Answer 18: STATA, distance 10

```
/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.
#1024p#rint(512);
#0}}//4|
#ß”6904”±r«"$2
puts 16384 8*/di 2^18

```

Added `/*` and `/di 2^18`
> 1 votes

# Answer
# Answer 19: bc, 165 bytes, distance: 6

```
2^19#/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.
#1024p#rint(512);
#0}}//4|
#ß”6904”±r«"$2
#puts 16384 8*/di 2^18

```

Try it online!

Distance:

* Hashes on the first and last line (2)
* `2^19` (4)
> 1 votes

# Answer
# Answer 21: 2sable, 161 bytes, distance: 3

```
2**20$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.
#1024p#rint(512);
#0}}//4|
#ß”6904”±r«"$2
#puts 16384 8*di 2^18o8*

```

Try it online!

Distance:

* Inserted `o` (evaluates `2**a` where `a` is the value on top of stack)
* Inserted `8`
* Removed `/`
> 1 votes

# Answer
# Answer 22. Cheddar, distance 10

```
print 2**22
'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.
#1024p#rint(512);
#0}}//4|
#ß”6904”±r«"$2
#puts 16384 8*di 2^18o8*'

```

**Try it online!**

inserted `print`, changed a `0` to a `2` to print the evaluation of `2**22`; inserted a new line and a `'` and added a trailing `'` wrapping the rest into an unused string.
> 1 votes

# Answer
# Answer 23: Pylons, distance 7

```
#23#2ejprint 2**22
'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.
#1024p#rint(512);
#0}}//4|
#ß”6904”±r«"$2
#puts 16384 8*di 2^18o8*'

```

Try it online!

Added `#23#2ej` to the start of the program.

Explanation:

```
#23#     Push the number 23 to the stack
    2    Push the digit 2 to the stack
     e   Calculate 2^23
      j  Print stack as a string and terminate the program

```
> 1 votes

# Answer
# Answer 25: Pushy, distance 4

```
2 25e#2ej
printf $[2**24]
#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.
#1024p#rint(512);
#0}}//4|
#ß”6904”±r«"$2
#puts 16384 8*di 2^18o8*'

```

Try it online!

Added `2 25e#` to the start of the program, and removed `#23#`.

Explanation:

```
2       Push 2
  25    Push 25
    e   Power
     #  Print

```

I don't have a clue why this works... it just does.
> 1 votes

# Answer
# Answer 26: CJam, distance 9

```
2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß”6904”±r«"$2 #puts 16384 8*di 2^18o8*'

```

Try it online!

That `e#` at the start saved me much hassle.

Explanation before the `e#`:

```
2 25)# e# Program.
2      e# 2.
  25   e# 25.
    )  e# Increment.
     # e# Power.
```

Added: `)#`
Removed: `\n\n\n\n\n\n\n`
> 1 votes

# Answer
# Answer 28: MATLAB, distance 9

```
disp(2^28)%2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß”6904”±r«"$2 #puts 16384 8*di 2^18o8*'

```

Helpfully in the last answer, all of the extraneous code was converted into a MATLAB style comment (`%`) leaving just `27W` as code. This can be converted into code for MATLAB using the `disp` function to display 2^28 without including `ans=`.

---

I used this calculator for the Levenshtein distance because it nicely handles multi-line inputs.
> 1 votes

# Answer
# Answer 30: , Distance of 9

```
cat(2**30)#2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß”6904”±r«"$2 #puts 16384 8*di 2^18o8*'

```

Try it online!
> 1 votes

# Answer
# Answer 34: Pip, distance 5

```
2**34  (*2 32#e#alert(2**31)//2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß”6904”±r«"$2 #puts 16384 8*di 2^18o8*'*

```

Try it online!

Changed `2^33` to `2**34` (3)

Added a space (1)

Accidentally removed a trailing `)` while copying (1)

Explanation:

`2**34` is pretty obvious.

Pip counts two spaces as a comment.
> 1 votes

# Answer
# Answer 35: Stacked, distance 10

```
2  35^out (*2 32#e#alert(2**31)//2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß6904±r"$2 #puts 16384 8*di 2^18o8*'*

```

Try it online! Changelog:

```
changed (+3): 2**34 => 2  35
inserted (+4): 35 => 35^out
removed: (+3): ”6904”±r« => 6904±r

```
> 1 votes

# Answer
# Answer 36: GolfScript, distance 3

```
2  36?#out (*2 32#e#alert(2**31)//2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß6904±r"$2 #puts 16384 8*di 2^18o8*'*

```

Try it online!

Explanation:

```
Changed 35 to 36 (1)
Changed ^ to ? (1)
Added # (1)

```
> 1 votes

# Answer
## Answer 39: Scheme, distance 9

```
(expt 2 39); ^ exit @ⁿ.óout (*2 32#e#alert(2**31)//2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß6904±r"$2 #puts 16384 8*di 2^18o8*'*

```

Added `(expt` (with trailing space)

Changed 8 to 9

Added `);`
> 1 votes

# Answer
# Answer 40: Element, distance 6

```
2 40^`(expt 2 39); ^ exit @ⁿ.óout (*2 32#e#alert(2**31)//2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß6904±r"$2 #puts 16384 8*di 2^18o8*'*

```

Try it online!

Added `2 40^``

There are no comments or program terminators added, because Element will only print when it comes across a ``` character.
> 1 votes

# Answer
# Answer 41: J, distance: 6

```
2^41 NB.`(expt 2 39); ^ exit @ⁿ.óout (*2 32#e#alert(2**31)//2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß6904±r"$2 #puts 16384 8*di 2^18o8*'*

```

Changed from `2 40^` to `2^41 NB.`
> 1 votes

# Answer
# Answer, 43: Zsh, distance 10

```
#2^41 NB.`(expt 2 39); ^ exit @ⁿ.óout (*2 32#e#a44******O@)//2 25)#e#2ej#
printf $[2**43]
bye
'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n*
**~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß6904±r"$2 #puts 16384 8*di 2^18o8*'*

```

Try It Online !
> 1 votes

# Answer
# Answer 44: VBA, Distance 10

Anonymous immediate window routine that takes no input and outputs to the VBE immediate window.

```
?2^44'#2^41 NB.`(expt 2 39); ^ exit @n.óout (*2 32#e#a44******O@)//2 25)#e#2ej#printf $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß6904±r"$2 #puts 16384 8*di 2^18o8*'*

```

Added `?2^43'`and recondensed lines
> 1 votes

# Answer
# Answer 45: Fish (shell), distance 10

> Finally, a command line shell for the 90s

(c) fishshell.com

```
math 2\^45#2^41 NB.`(expt 2 39); ^ exit @n.óout (*2 32#e#a44******O@)//2 25)#e#2ej#printf $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.#1024p#rint(512);#0}}//4|
#ß6904±r"$2 #puts 16384 8*di 2^18o8*'*

```

Note that this does not work on TIO Nexus due to lack of white space in `...45#2...`, but works just nice on my `fish, version 2.0.0`.
> 1 votes

# Answer
# Answer 46: Reticular, distance 9

```
28@P2*Jp;math 2\^45#2^41 NB.`(expt 2 39); ^ exit @n.óout (*2 32#e#a44******O@)//2 25)#e#2ej#printf $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.#1024p#rint(512);#0}}//4|
#ß6904±r"$2 #puts 16384 8*di 2^18o8*'*

```

Added `28@P2*Jp;`

Explanation:

```
2         Push 2
 8@P      Push 8th prime 0-indexed (23)
    2     Push 2
     *    Multiply (46)
      J   Exponentiate
       p  Print
        ; Terminate progrma

```

Try it online!
> 1 votes

# Answer
# Answer 55: FOG, distance 8

```
?92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`#(expt 2 39); ^ exit @n.out (*2 32#e#a44******O@)//2 25)#e#2ej
#printf("%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024print(2**53)--0;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```

`?` does nothing, `92a5*` makes `55`, `2p@` powers and ends the program, auto-outputting. Also added a newline before `#printf`.

I inserted `9` before the first `2`, `5*2p@` after it.
> 1 votes

# Answer
## Answer 54, QBIC, distance 8

```
?2^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`#(expt 2 39); ^ exit @n.out (*2 32#e#a44******O@)//2 25)#e#2ej#printf("%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024print(2**53)--0;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```
* Removed newline
* Added # after the \`
* Prepended ?2^54┘
* Removed Herobrine

for a total Levenstein distance of 8.

The `#` at the start of the previous answer creates a 'silent string literal' in QBIC: it declares and fills A$, but doesn't use it right away. All the code up until the backtick is placed into that string. There is a backtick in that code, so we need to manually add another `#` to repeat this trick (with B$).
> 1 votes

# Answer
# Answer 57: Korn Shell (ksh), distance 10

```
bc<<<2^57 #x??92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`#(expt 2 39); ^ exit @n.out (*2 32#e#a44******O@) //2 25)
#e
#2ej
#printf("%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024print(2**53)--0;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```

Try It Online !
> 1 votes

# Answer
# Answer 61, Dash, distance 10

```
"bc"<<x
2^61
x
#??92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`#(expt 2 39); ^
exit
 @n.out (*2 32#e#a44******O@) //2 25)
"e
"2ej
:py print(2**60)
"%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024print(2**53)--0;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```

Changes:

* Added " after "bc +1
* Replaced \< with a newline +1
* Appended x +1
* Replaced 57 with 61 +2
* Removed # +1
* Added newline after x +1
* Added # +1
* Surrounded exit with newlines +2

Total: `1+1+1+2+1+1+1+2=10`
> 1 votes

# Answer
# Answer 62: Vitsy, distance 9

```
297*1-^N;"bc"<<x
2^61
x
#??92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`#(expt 2 39); ^
exit
 @n.out (*2 32#e#a44******O@) //2 25)
"e
"2ej
:py print(2**60)
"%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024print(2**53)--0;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```

Try it online!

Added `297*1-^N;` (9)

Explanation:

```
2           2
      ^     to the power of
 9          (9
   *        multiplied by
  7         7
     -      minus
    1       one)
       N    print as integer
        ;   terminate program

```
> 1 votes

# Answer
# Answer 63, C Shell (csh), distance 10

```
"bc"<<x
2^63
x
#??92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`#(expt 2 39); ^
exit
 @n.out (*2 32#e#a44******O@) //2 25)
"e
"2ej
:py print(2**60)
"%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024print(2**53)--0;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```

Erased answer #62 by @Okx (sorry !), changed 61 to 63.
> 1 votes

# Answer
# Answer 65, Bosh (Schily Bourne Shell), distance 10

```
#64º,;S)1'a
"bc"<<x
2^65
x
#??92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`#(expt 2 39); ^
exit
 @n.out (*2 32#e#a44******O@) //2 25)
"e
"2ej
:
py
p
r
i
n
t
(2**60)
"%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024print(2**53)--0;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```

Added `#`, newline in front of `bc`, replaced 63 with 65, the rest are dummy newlines.
> 1 votes

# Answer
# Answer 68, Jellyfish, distance 10

```
PC68º,;n*:"C"
BBc"<<x
2**66
x
#??92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`#(expt 2 39); ^
qut()
@n.out (*2 32#e#a44******O@) //2 25)
"e
"2ej
:
py
p
r1ker
s
n
t
(2**60)
"%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#

```

Try it online!
> 1 votes

# Answer
# Answer 69, Vyxal, distance 6

```
`C68º,;n*:"C"
BBc"<<x
2**66
x
#??92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.#(expt 2 39); ^
qut()
@n.out (*2 32#e#a44******O@) //2 25)
"e
"2ej
:
py
p
r1ker
s
n
t
(2**60)
"%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#`69E

```

Try it Online!

* Added a backtick att tthe start and end
* Appended `69E`
* Removed an existing backtick
> 1 votes

# Answer
# Answer 70 - Desmos, distance 8

```
`C68º,;n*:"C"
BBc"<<x
2**66
o=2^{70}
#??92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.#(expt 2 39); ^
qut()
@n.out (*2 32#e#a44******O@) //2 25)
"e
"2ej
:
py
p
r1ker
s
n
t
(2**60)
"%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#`69E

```

Try it on Desmos!

Changed line 4 from `x` to `o=2^{70}` (1 substitution + 7 insertions = distance of 8).

The entirety of this relies on the fact that Desmos treats all lines as distinct expressions/equations. That is, if lines 1 and 2 aren't defined by each other, then line 2 will still "run" even if line 1 causes an error.

Output is shown in the grey box next to a proper variable declaration, which is what happens on line 4 of the code. All others are basically junk due to various reasons. Line 4 had to be edited, though, because a stray `x` could display the line `y=x` on the graph.
> 1 votes

# Answer
# Answer 14 ShapeScript, distance 9

```
'Ａ#327;N<.""/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.
1024p#rint(512);
#0}}//4|
#β”6904”±r«'0*16384

```

**Try it online!**

Place everything in a string by enclosing between two `'`s, multiply that string by `0` with `0*` then push the integers `1`, `6`, `3`, `8`, and `4` onto the stack, which then gets implicitly printed.

...should be ripe for a change to `...2*16384`.
> 0 votes

# Answer
# Answer 16: Ruby, distance 8

```
#"Ａ#327;N<."$"/class HelloWorld {static void Main() 0{;n***~
#    System<.Console<.<.
#1024p#rint(512);
#0}}//4|
#β”6904”±r«"$2
puts 16384*4

```

added 2 `#`'s, a newline and `puts`, and changed `s` to `4`.
> 0 votes

# Answer
# Answer 32: Convex, distance 7

```
2 32#e#alert(2**31)//2 25)#e#2ej#printf $[2**24]#'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024p#rint(512);#0}}//4|#ß”6904”±r«"$2 #puts 16384 8*di 2^18o8*'

```

Try it online!

Added `2 32#e#`.

Explanation:

```
2       Push 2
  32    Push 32
    #   Power
     e# Line comment

```
> 0 votes

# Answer
# Answer 53, Gnuplot, distance 5

```
#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`(expt 2 39); ^ exit @n.out (*2 32#e#a44******O@)//2 25)#e#2ej#printf("%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024
print(2**53)--0;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```
> 0 votes

# Answer
# Answer 56: Qwerty-RPN, distance 7

```
2 56^#x??92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`#(expt 2 39); ^ exit @n.out (*2 32#e#a44******O@)//2 25)#e#2ej
#printf("%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024print(2**53)--0;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```

Added `2 56^#x` (7)

Explanation:

```
2       Push 2
 56     Push 56
   ^    Calculate exponent
    #   Print
     x  Terminate program

```

Unfortunately, there is no online interpreter for this language.
> 0 votes

# Answer
# Answer 58: Julia, distance 10

```
#bc<<<2^57 #x??92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`#(expt 2 39); ^ exit @n.out (*2 32#e#a44******O@) //2 25)
#e
#2ej
print(2^58) #"%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024print(2**53)--0;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```

Try it online!
> 0 votes

# Answer
# Answer 59, Python 3, Distance of 3

```
#bc<<<2^57 #x??92a5*2p@^54┘#--2'3k:'2k*.@2(#"#28@P2*Jp;math 2\^45#2^41 NB.`#(expt 2 39); ^ exit @n.out (*2 32#e#a44******O@) //2 25)
#e
#2ej
print(2**59) #"%d" $[2**43]bye'$/*#"A#327;N<."$"/class HelloWorld {static void Main() 0{;n***~#    System<.Console<.<.#1024print(2**53)--0;#0}}//4|#6904r"$2 #puts 16384 8*di 2^18o8*'*[[[268*^?>

```
> 0 votes

---
Tags: math, number, arithmetic, answer-chaining
---