title: Golf a mutual quine

text:
# Question
Title: Golf a mutual quine
Using *two* languages of your choice, write the smallest “mutual quine” you can.

That is, write a program P in language A that outputs the source code for a program Q in language B, such that the output of program Q is identical to the source code for P.

Empty files don't count, nor do "read the source file and print it"-style programs.

**Edit:** Answers with P=Q no longer count.

# Answer
> 3 votes
# Gol\>\<\> and APL, 10 bytes and 13 bytes

```
'r3d*:::}H

```

Try it online! Which outputs:

```
'''r3d*:::}H'

```

Try APL online!

Which simple prints the code as a string (with the `'` escaped with another `'`)

# Answer
> 34 votes
## Python and Ruby, 39 characters

This Python snippet

```
s='puts %%q{s=%r;print s%%s}';print s%s

```

generates this Ruby snippet

```
puts %q{s='puts %%q{s=%r;print s%%s}';print s%s}

```

which then generates the inital Python snippet again:

```
$ diff -s mutualquine.py <(ruby <(python mutualquine.py))
Files mutualquine.py and /dev/fd/63 are identical

```

Note that this is similar to J B's answer.

# Answer
> 24 votes
## C and Perl, 73

This C:

```
main(s){printf(s="print q<main(s){printf(s=%c%s%c,34,s,34);}>",34,s,34);}

```

...outputs the following Perl:

```
print q<main(s){printf(s="print q<main(s){printf(s=%c%s%c,34,s,34);}>",34,s,34);}>

```

...that outputs the C back.

# Answer
> 16 votes
# C and C++, 123 chars

This C (compilable with gcc v4.3.4):

```
#include <stdio.h>
main(){char *c="#include <stdio.h>%cmain(){char *c=%c%s%c;printf(c,10,34,c,34);}";printf(c,10,34,c,34);}

```

outputs this (identical) C++ (compilable with g++ 4.3.4, one warning):

```
#include <stdio.h>
main(){char *c="#include <stdio.h>%cmain(){char *c=%c%s%c;printf(c,10,34,c,34);}";printf(c,10,34,c,34);}

```

*This is within the rules as posted.* :P And, like Ventero's, this is based on J B's answer.

# Answer
> 16 votes
# \>\<\> (Fish) and Python - 26 characters

```
"00gr00g:a9*2+$' tnirp'>o<

```

Generates this Python

```
print "\"00gr00g:a9*2+$' tnirp'>o<"

```

# Answer
> 10 votes
**Python + Piet one-liners: 417 chars + 7391 7107 executing codels**

This Python script produces a 7393 x 2 image; the rightmost 2x2 block of which is a "sentinel" which terminates the program; so I'm not counting those; and the second row is otherwise white. I can probably golf the piet code down further by using addition/subtraction/multiplication chains instead of the naive binary algorithm... but I don't want to give away a solution to a future puzzle.

I'm not going to post the image here, because of its ridiculous dimensions. If you want to see it, run the python code, and pipe the output to a .ppm file. Then, convert the .ppm to a .gif, and run the output at Rapapaing. (alternately, use a non-web Piet interpreter that groks .ppm)

```
A='P=lambda A:reduce(lambda(D,H,B),P:(D[P/3:]+D[:P/3],H[P%3*2:]+H[:P%3*2],B+"".join("%i "%H[(D[0]/P)%2]for P in[1,2,4])),map(" A !        @    B".find,A),([1,3,2,6,4,5],[0,192,192,255,0,255],"P3 %i 2 255 "%(len(A)+2)))[2]+"255 "*4+"0 0 "+"255 "*len(A)*3+"255 0 0 "*2;B=lambda D:["@!%s","@@!%s!"][D%2]%B(D/2)if 1<D else"";print P("".join("A%sB"%B(ord(D))for D in"A=%s;exec A[:-13]"%`A`)+" ");exec A[:-13]';exec A[:-13]

```

*edit: golfed the piet a bit by reducing Hamming weight of variable names.*

**less golfed pre-quine**:

This is a previous version, before I realized I could make it a one-liner. It's marginally easier to understand. The function P translates a special instruction set into Piet; and the function p takes an integer and produces a sequence of instructions to create that integer on the stack. I'm only using the instructions `=,+,:,|`, so this could probably be made more efficient... but I kinda like having a fullblown Piet compiler (of sorts) in the source.

```
s="""def P(s):
 l=len(s)+1;R="P3 %i 2 255 "%(l+2);C=[1,3,2,6,4,5];V=[0,192,192,255,0,255]
 for x in map("=|^+-*/%~>.,:@$?#!".find,"="+s):
  C=C[x//3:]+C[:x//3];V=V[x%3*2:]+V[:x%3*2]
  for i in [1,2,4]:R+="%i "%V[(C[0]//i)%2]
 return R+"255 "*4+"0 0 "+"255 "*l*3+"255 0 0 "*2
p=lambda x:[":+%s","::+%s+"][x%2]%p(x/2)if x/2 else""
print P("".join("|%s!"%k(ord(c))for c in "s="+`s`+";exec s[:-13]"))
exec s[:-13]"""
exec s[:-13]

```

# Answer
> 10 votes
# Java to Python - 219

Java:

```
class Q{public static void main(String[]a){char q=34,c=39;String s="print%sclass Q{public static void main(String[]a){char q=34,c=39;String s=%s%s%s;System.out.printf(s,c,q,s,q,c);}}%s";System.out.printf(s,c,q,s,q,c);}}

```

Python:

```
print'class Q{public static void main(String[]a){char q=34,c=39;String s="print%sclass Q{public static void main(String[]a){char q=34,c=39;String s=%s%s%s;System.out.printf(s,c,q,s,q,c);}}%s";System.out.printf(s,c,q,s,q,c);}}'

```

Makes use of the fact that python allows `'` for strings; this makes it much easier to write the java program's source in the python program.

# Answer
> 8 votes
# /Brainf..k/, 6988 bytes

## Brainfuck

```
++++++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>++>>>++++++>>>+++++++>>>+++++++++++>>>++++++>>>+++++++>>>++++++++++>>>+>>>++++++++>>>+>>>++++++++++>>>+++++++++++>>>++>>>+++++++++>>>+>>>++>>>++++++>>>+>>>+>>>+>>>+>>>+>>>++>>>+>>>++>>>+>>>++>>>+>>>++>>>+>>>++>>>++>>>++++++++++>>>+++++++++++>>>++>>>++++++++++>>>+++++++++++>>>++>>>++++++++++>>>+++++++++++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>+>>>++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>+>>>++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>+>>>+>>>++>>>+>>>++>>>+>>>++>>>++>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>++++++++++>>>+++++++++++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>+>>>++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>+>>>+>>>+>>>++>>>+>>>++>>>+>>>++>>>++>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>++++++++++>>>+++++++++++>>>++>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>+>>>++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>+>>>+>>>+>>>++>>>+>>>++>>>+>>>++>>>+>>>++>>>+>>>++>>>++>>>++>>>++++++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>++>>>++++++++++>>>+++++++++++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++>>>++++++++++>>>+++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>+>>>++>>>++>>>+++++++>>>++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+>>>++++++>>>+++++++>>>++>>>++++++>>>+++++++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>++>>>++++++>>>+++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>+++++++>>>++>>>+>>>++++++>>>+++++++>>>++++++>>>+++++++>>>++>>>++++++>>>+++++++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>++>>>++++++>>>+++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++++>>>+>>>++>>>+++++++++>>>++>>>++++++>>>+++++++>>>+>>>+>>>+>>>+>>>+>>>+>>>++>>>+>>>++>>>+>>>++>>>++>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>++>>>++++++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>++>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>++++++>>>+++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>+>>>+>>>+>>>+>>>++++++++++>>>+++++++++++>>>++>>>+>>>+>>>+>>>+>>>++>>>+>>>++>>>+>>>++>>>++>>>++>>>++++++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>++>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>++>>>++>>>++++++>>>+++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>+>>>++++++++>>>+++++++++>>>++>>>++++++++++>>>+>>>+>>>+>>>++++++++++>>>+++++++++++>>>++++++++>>>+>>>++>>>+++++++++>>>++>>>++++++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++++>>>+>>>++>>>+++++++++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>++>>>++++++>>>+++++++>>>+++++++>>>++>>>+++++++>>>++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>+++++++>>>++>>>++++++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++++>>>+>>>++>>>+++++++++>>>++++++>>>++++++>>>+++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>++>>>+++++++>>>++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>+++++++>>>++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>++++++++++>>>++++++>>>+++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>+>>>++++++>>>+++++++>>>++>>>++++++++++>>>++++++>>>++++++>>>++++++>>>++++++++>>>++++++>>>++++++>>>++++++>>>+++++++++>>>+++++++>>>+++++++>>>+++++++>>>++++++++>>>+++++++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++++>>>++++++>>>++++++++>>>++++>>>+++++++>>>+++++>>>+++>>>+++++>>>++++>>>+++++++>>>+++>>>++++++>>>++++++>>>+++++++++>>>+++++++>>>+++>>>+++++>>>++++++++>>>++++>>>+++++++++>>>+++++++>>>+++++++>>>+++++++++>>>++++++>>>++++++++>>>++++++>>>++++++>>>++++++>>>+++++++++>>>+++++++>>>+++++++>>>+++++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++++++>>>++++>>>+++++++++>>>+++++++++>>>+++++++++>>>+++++++++>>>+++++++++>>>+++++++++>>>+++++++++>>>+++++++++>>>+++++++++>>>+++++++++>>>++++++>>>+++++>>>+++++++>>>+++++++>>>+++++++>>>+++++++>>>+++++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>{({}<>)<>}<>{([({})]()<((((()()()()()){}){}){})>){({}()<({}())>){({}()<({}()())>){({}()<({}()())>){({}()<({}())>){({}()<({}((()()()){}()){})>){({}()<({}()())>){({}()<({}(((()()()){}()){}){}())>){({}()<({}()())>){({}()<({}(((()()()()())){}{}){})>){(<{}({}()())>)}}}}}}}}}}{}({}<(<>)<>{({}<>)<>}{}>)(<><>)<>{({}<>)<>}{}<>{({}[()])<>(((((()()()){}())){}{}){}())<>}{}<>(((({})(((()()())){}{}){}())))<>}{}([]){((({}[()])<{({}[()]<({}<({}<>)<>>)>)}{}>)<{({}[()]<<>({}<>)>)}{}>)}{}{<>({}<>)}{}(<>){<<<[<<<]>>>[>++++++++++++++++++++++++++++++++++++++++.<[->.+.->+<<]>+.[-]>>]<[<<<]>>>[<++++++++++++++++++++++++++++++++++++++++>-[<+>-[<++>-[<++>-[<+>-[<++++++++++++++>-[<++>-[<+++++++++++++++++++++++++++++>-[<++>-[<++++++++++++++++++++++++++++++>-[<++>-]]]]]]]]]]<.>>>>]}{}<>

```

Try it online!

## Brain-Flak

```
(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()())(()()()()()())(()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()()()()()()()()()())(())(()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()()()())(())(()())(()()()()()())(())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(())(())(()())(())(()())(())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(())(())(())(()())(())(()())(())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(())(()()()()()())(()()()()()()())(()())(()()()()()())(()()()()()()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()())(()()()()()())(()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()())(()())(())(()()()()()())(()()()()()()())(()()()()()())(()()()()()()())(()())(()()()()()())(()()()()()()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()())(()()()()()())(()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()())(())(()())(()()()()()()()()())(()())(()()()()()())(()()()()()()())(())(())(())(())(())(())(()())(())(()())(())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()()()()()())(()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(())(())(())(())(()()()()()()()()()())(()()()()()()()()()()())(()())(())(())(())(())(()())(())(()())(())(()())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()())(()())(()()()()()())(()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(())(()()()()()()()())(()()()()()()()()())(()())(()()()()()()()()()())(())(())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()())(())(()())(()()()()()()()()())(()())(()()()()()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()())(())(()())(()()()()()()()()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()())(()()()()()())(()()()()()()())(()()()()()()())(()())(()()()()()()())(()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()())(()())(()()()()()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()())(())(()())(()()()()()()()()())(()()()()()())(()()()()()())(()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()())(()()()()()()())(()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()())(()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()())(()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(())(()()()()()())(()()()()()()())(()())(()()()()()()()()()())(()()()()()())(()()()()()())(()()()()()())(()()()()()()()())(()()()()()())(()()()()()())(()()()()()())(()()()()()()()()())(()()()()()()())(()()()()()()())(()()()()()()())(()()()()()()()())(()()()()()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()()()())(()()()()()())(()()()()()()()())(()()()())(()()()()()()())(()()()()())(()()())(()()()()())(()()()())(()()()()()()())(()()())(()()()()()())(()()()()()())(()()()()()()()()())(()()()()()()())(()()())(()()()()())(()()()()()()()())(()()()())(()()()()()()()()())(()()()()()()())(()()()()()()())(()()()()()()()()())(()()()()()())(()()()()()()()())(()()()()()())(()()()()()())(()()()()()())(()()()()()()()()())(()()()()()()())(()()()()()()())(()()()()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()())(()()()()())(()()()()()()())(()()()()()()())(()()()()()()())(()()()()()()())(()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()()){({}<>)<>}<>{([({})]()<((((()()()()()){}){}){})>){({}()<({}())>){({}()<({}()())>){({}()<({}()())>){({}()<({}())>){({}()<({}((()()()){}()){})>){({}()<({}()())>){({}()<({}(((()()()){}()){}){}())>){({}()<({}()())>){({}()<({}(((()()()()())){}{}){})>){(<{}({}()())>)}}}}}}}}}}{}({}<(<>)<>{({}<>)<>}{}>)(<><>)<>{({}<>)<>}{}<>{({}[()])<>(((((()()()){}())){}{}){}())<>}{}<>(((({})(((()()())){}{}){}())))<>}{}([]){((({}[()])<{({}[()]<({}<({}<>)<>>)>)}{}>)<{({}[()]<<>({}<>)>)}{}>)}{}{<>({}<>)}{}(<>){<<<[<<<]>>>[>++++++++++++++++++++++++++++++++++++++++.<[->.+.->+<<]>+.[-]>>]<[<<<]>>>[<++++++++++++++++++++++++++++++++++++++++>-[<+>-[<++>-[<++>-[<+>-[<++++++++++++++>-[<++>-[<+++++++++++++++++++++++++++++>-[<++>-[<++++++++++++++++++++++++++++++>-[<++>-]]]]]]]]]]<.>>>>]}{}<>

```

Try it online!

The Brain-Flak might time out on TIO.

## Explanation

Coming soon.

# Answer
> 4 votes
## Ruby and Python (393 + 413 = 806 chars)

Slight change of this answer of mine. Could definitely be reduced since I just hard-coded the input without any optimisation.

### Ruby (393 chars)

```
require 'json';s=%q[{"ruby":[" %q[","require 'json';s=##;j=JSON.load s;puts j[l='python'][1].sub('##',j[l][0].delete(' ')+s+j[l][2].delete(' '))"," ]"],"python":["' ''","import json,re;s=##;j=json.loads(s);l='ruby';print(re.sub('##',j[l][0].replace(' ','')+s+j[l][2].replace(' ',''),j[l][1],1))","' ''"]}];j=JSON.load s;puts j[l='python'][1].sub('##',j[l][0].delete(' ')+s+j[l][2].delete(' '))

```

### Python (413 chars)

```
import json,re;s='''{"ruby":[" %q[","require 'json';s=##;j=JSON.load s;puts j[l='python'][1].sub('##',j[l][0].delete(' ')+s+j[l][2].delete(' '))"," ]"],"python":["' ''","import json,re;s=##;j=json.loads(s);l='ruby';print(re.sub('##',j[l][0].replace(' ','')+s+j[l][2].replace(' ',''),j[l][1],1))","' ''"]}''';j=json.loads(s);l='ruby';print(re.sub('##',j[l][0].replace(' ','')+s+j[l][2].replace(' ',''),j[l][1],1))

```

# Answer
> 3 votes
# Python 2 to Befunge 98, ~~94~~ 78

Again, making use of Python's two ways of making strings:

Python:

```
s='<@,kM%c%cs=%c%s%c;print s%%(39,34,39,s,39,34)%c';print s%(39,34,39,s,39,34)

```

Befunge 98:

```
<@,kM'"s='<@,kM%c%cs=%c%s%c;print s%%(39,34,39,s,39,34)%c';print s%(39,34,39,s,39,34)"

```

The python program formats the string to include itself and the characters for the single and double quote.

The Befunge program works like this:

* `<`: move to the left, and wrap around. So now we execute the commands from right to left
* `"`: make it so that every char we encounter is pushed to the stack until we encounter another `"`, so we push:

```
)43,93,s,93,43,93(%s tnirp;'c%)43,93,s,93,43,93(%%s tnirp;c%s%c%=sc%c%Mk,@<'=s

```

Which is actually just the python program, reversed because of the way Befunge prints (which is a pop+print loop)
* `'M`: push `M` to the stack. `M` is also the number 77, which is one less than the number of chars pushed to the stack by the `"`s.
* `k`: pop the top value off the stack (`M`) and do the next operation that many times, plus one.
* `,`: pop the top value off the stack and print the char.
* `@`: end the program.

# Answer
> 2 votes
## Clipper and C (111 + 108 = 219 chars)

### Clipper (111)

```
?'char*f="%c%cchar*f=%c%s%c;main(){printf(f,63,39,34,f,34,39,10);}%c%c";main(){printf(f,63,39,34,f,34,39,10);}'

```

### C (108)

```
char*f="%c%cchar*f=%c%s%c;main(){printf(f,63,39,34,f,34,39,10);}%c%c";main(){printf(f,63,39,34,f,34,39,10);}

```

This is a bit of a cop-out because:

1. the "print" command in Clipper is really simple: `?'foo'` :-)
2. I based it on the "classic C" quine from http://www.nyx.net/~gthompso/quine.htm, with some modification to squeeze in the `?` and `'`s.
3. I didn't `#include <stdio.h>`, so it gives a compiler warning
4. The C code output by the Clipper version had to be prodded to remove a line break that had been introduced by an 80-character column limit in either my terminal or the Harbour printing routine or something.

# Answer
> 2 votes
## Underload and Betaload, 16 bytes

Underload:

```
(a(:^)*a(S)*S):^

```

Betaload:

```
((a(:^)*a(S)*S):^)S

```

Betaload is a superset of Underload, so this could be two Underload answers.

# Answer
> 2 votes
# Jelly, 13 bytes

```
“Ṿ;⁾v`+/ŒṘ”v`

```

Try it online!

# RAD

```
'“Ṿ;⁾v`+/ŒṘ”v`'

```

Try it online!

A Jelly quine that wraps itself in single quotes, such that the resultant RAD program simply prints the original Jelly program back out.

# Answer
> 2 votes
# Vyxal, 10 bytes

```
`:qpq`:qpq

```

Try it Online!

# Vyxal `V`

```
`\`:qpq\`:qpq`

```

Try it Online!

The `V` flag does nothing, the first is a quine that unevaluates itself, and the second is a string.

Or...

# Vyxal `DrV`, 16 bytes

```
`q\`:Ė\`p1→ip`:Ė

```

Try it Online!

# Vyxal `Dr`

```
0`q\`:Ė\`p1→ip`:Ė

```

Try it Online!

The 0 at the start is a NOP - Vyxal pads the stack with 0s anyway, so the two programs are functionally identical.

```
`q\`:Ė\`p    `:Ė # Standard eval quine
         1→ip    # If `V` (single-char variable names) is off, this stores 1 to the variable ip.
                 # If it's on, this stores 1 to the variable i and prepends a 0 to the current program.

```

# Answer
> 1 votes
# Guile, 114 bytes

```
((lambda(v)(format #t".\\~s"(format #f" (~a~s)"v v)))"(lambda(v)(format #t\".\\\\~s\"(format #f\" (~a~s)\"v v)))")

```

Try it online!

# Forth (gforth), 139 bytes

```
.\" ((lambda(v)(format #t\".\\\\~s\"(format #f\" (~a~s)\"v v)))\"(lambda(v)(format #t\\\".\\\\\\\\~s\\\"(format #f\\\" (~a~s)\\\"v v)))\")"

```

Try it online!

# Answer
> 0 votes
# Python and ~-~! - 77 and 81 = 158

This Python code:

```
q=chr(124);s='@%sq=chr(124);s=%s;print(s%%repr(s))%s:';print(s%(q,repr(s),q))

```

outputs this ~-~! code:

```
@|q=chr(124);s='@%sq=chr(124);s=%s;print(s%%repr(s))%s:';print(s%(q,repr(s),q))|:

```

Can definitely be improved a lot, and adopts a whole bunch from the other answers.

# Answer
> 0 votes
# Javascript and Windows .bat, 71 bytes and 81 bytes

```
f=()=>{console.log('echo f='+(f+';f()').replace(/(?=[>^\\])/g,'^'))};f()

```

and

```
echo f=()=^>{console.log('echo f='+(f+';f()').replace(/(?=[^>^^^\^\])/g,'^^'))};f()

```

---
Tags: code-golf, quine, polyglot
---


title: Cheating Cyclic Quine

text:
# Question
Title: Cheating Cyclic Quine
## Concept

Write a program that outputs code in its programming language. That code, when executed, must output the original program.

## Rules

* Since this is a cheating quine, you can read the original source code.
* First output program must be in the same language as the original program.
* You may not output a regular quine. The two programs must be different.
* Standard loopholes apply.
* This is so shortest answer wins, however it will not be selected.

# Answer
# Bash \+ coreutils, 11 bytes

```
tr xy yx<$0

```

This prints

```
tr yx xy<$0

```

Try it online!

In turn, that prints

```
tr xy yx<$0

```
> 28 votes

# Answer
# , 2 bytes

7 uses a 3-bit character set, but takes input packed into bytes (and according to meta, languages with sub-byte character sets are counted using bytes for the file on disk). Here's an `xxd` dump of the program:

```
00000000: 4cf4                                     L.

```

When giving this file to the 7 interpreter, it will output the following program:

```
00000000: 4fa6 7f                                  O..

```

which will then in turn output the original program again.

So what's happening here? There's no source reading involved (actually, I don't think it's possible to read the source in 7), although arguably the program is cheating in another way; let me know what you think. Here's how the program works. (Note that each 7 command has two variants, some of which don't have names and can't appear in the original program. There are twelve commands total, in six pairs. I'm using bold for active commands, nonbold for passive commands, and in cases where the active command has no name, I'm giving it the same name as the corresponding passive command and relying on the bold to distinguish. In the case where both are named, e.g. `**7**` which is the active variant of `1`, each command gets its own name and the bold is just syntax highlighting.)

```
231**7**23       Original program, unpacked into octal
231          Push **237** onto the stack
    23       Push **23** onto the stack
             (implicit) append a copy of the top of stack to the program
      **2**      Duplicate top of stack (currently **23**)
       **3**     Output top of stack, pop second stack element

```

At this point, the 7 interpreter sees that the top of stack contains commands (**`2`** and **`3`**) that aren't representable, so it escapes the top of the stack, producing `**7**23` (which is). The first command output selects the output format; in this case, it's format 7, "format the output the same way as the program". So the commands get output packed into bytes. Then the program continues:

```
231**7**23**23**
             (implicit) append a copy of the top of stack to the program
        **2**    Duplicate top of stack (currently **237**)
         **3**   Output top of stack, pop second stack element
          **7**  Push an empty element onto the stack

```

At this point, there's nothing but empty stack elements on the stack, so the program exits. We output `23` earlier. If we escape **`237`** (and we have to, because it contains unrepresentable commands), we get `**7**231`. That gets output directly, making the final output of the program `237231` (formatted the same way as the program, i.e. packed into bytes). That's `4fa67f`. (It can be noted that the `1` was entirely pointless in terms of affecting the output; the only reason it's there is to make the two programs different.)

Running `237231` proceeds almost exactly the same way; the difference is that the useless `1` runs just after the first print (and the empty element gets implicitly deleted the second time the current end of the program is reached). Again, the `231` ends up outputting itself, the `23` ends up outputting itself preceded by a `7`, and we get `231723`, the original program.

The observant might note that the two programs, despite being the same length in the language's "native" octal, are different lengths on disk. That's because a 7 program can be padded with an arbitrary number of 1 bits, and the packed format discards the trailing padding. Here's how the encoding happens:

```
2  3  1  7  2  3
010011001111010011(1...)
4   c   f   4   padding

```

In other words, two bytes, `4C` `F4`, are enough to represent the program, so that's all I used.
> 21 votes

# Answer
# Snails, 0 bytes

The second program is

```
1
```

The first program counts the number of matches of the empty pattern on the empty input (which really has area 0, but the pattern is always run at least once as a hack to allow programs to decide what they want to print on empty input). The second program begins with a quantifier (like `{1}` in regex), which causes a parse error. Since the program does not parse successfully, STDOUT is the empty string.
> 21 votes

# Answer
# Python 3, ~~297~~ ~~279~~ ~~251~~ ~~243~~ ~~225~~ ~~218~~ ~~208~~ ~~180~~ ~~126~~ 111 bytes

Non-cheating:

```
A=''';print(("A="+("'"*3+A)*2).translate({65:66,66:65}))''';print(("A="+("'"*3+A)*2).translate({65:66,66:65}))

```

This prints:

```
B=''';print(("B="+("'"*3+B)*2).translate({65:66,66:65}))''';print(("B="+("'"*3+B)*2).translate({65:66,66:65}))

```

which, when executed, prints the original program.
> 11 votes

# Answer
# RProgN, 4 Bytes.

The community seems to consider this sort of thing as a cheating quine, which thus satisfies the criteria.

```
1
2

```

With a trailing newline.

This prints

```
2
1

```

With a trailing newline, which prints the first code.

RProgN prints the stack popping, so from top to bottom.

Try it online!
> 8 votes

# Answer
## Batch, 14 bytes

```
@echo @type %0

```

Which when run as `cyclicquine.bat` outputs

```
@type cyclicquine.bat

```

Which when run outputs the original batch file.
> 8 votes

# Answer
# Jolf, 6 bytes

```
1q_a_q

```

When run, this outputs:

```
q_a_q1

```

Which in turn outputs `1q_a_q`.

Try it here!

# Explanation

```
1q_a_q
1       the digit one (ignored)
 q      the source code (ignored)
     q  the source code
    _   reversed
   a    and outputted
 _      and reversed (ignored)

q_a_q1
q       the source code (ignored)
     1  the digit one (ignored)
    q   the source code
   _    reversed
  a     and outputted
 _      and reversed (ignored)

```
> 6 votes

# Answer
# JavaScript (ES6), ~~69~~ ~~60~~ 59 bytes

```
(_0=_=>console.log(`(_0=${_0})()`.replace(/0/g,n=>+!+n)))()

```

Outputs:

```
(_1=_=>console.log(`(_1=${_1})()`.replace(/1/g,n=>+!+n)))()

```

---

-1 byte (@ETHProductions): use 0 in regex instead of \d
> 5 votes

# Answer
# Bash + Sed, 15 bytes

Same idea as Dennis's Answer.

```
sed y/xz/zx/ $0

```
> 3 votes

# Answer
# Bash, ~~Cat,~~ and Rev, ~~19~~ 16 bytes

```
rev $0 # 0$  ver

```

*-3 thanks to @izabera*
> 3 votes

# Answer
## \>\<\>, 16 bytes

```
"$r00gol?!;50.01

```

Try it here!

**Outputs**

```
"$r00gol?!;50.10

```

This is a modification of the one provided here. I'm not sure if it's cheating, it reads the codebox and outputs it.
> 1 votes

# Answer
# C (gcc), 55 bytes

```
N,s[];main(){*s^=read(open(__FILE__,0),s,54);puts(s);}

```

Note the trailing newline.

First run:

```
x,s[];main(){*s^=read(open(__FILE__,0),s,54);puts(s);}

```

Try it online!

Second run:

```
N,s[];main(){*s^=read(open(__FILE__,0),s,54);puts(s);}

```

Try it online!

This one is rather simple. It reads the file, and XORs the first byte (technically first `int`, but it is effectively the same) with `54`. Since it is an unused variable, it doesn't affect anything.

Note that this abuses the empty array cheat where GCC will let you write up to one page in an array with empty brackets. It also expects the page to be zero filled, which is the default.

A version which does not write out of bounds is this:

```
y,s[15];main(){*s^=read(open(__FILE__,0),s,56);puts(s);}

```

Try it online!

Which will turn into this

```
A,s[15];main(){*s^=read(open(__FILE__,0),s,56);puts(s);}

```

Try it online!

I xor against `read()` because it returns the number of bytes read, and it is shorter than XORing against a constant.
> 1 votes

# Answer
# Self-modifying Brainfuck, ~~22~~ 20 bytes

Note that SMBF stores the program itself to the left of the initial pointer.

```
~<[<]>[-<->]<.>>[.>]

```

Try it online!

It will output this (replace `\x82` with a `0x82` byte)

```
\x82<[<]>[-<->]<.>>[.>]

```

Which in turn will print this:

```
~<[<]>[-<->]<.>>[.>]

```

Explanation:

```
~      Dummy byte to be negated to 0x82 (or on second, 0x7e or ~)
<[<]   Scan backwards to the start of the program
>      Go forwards to the first byte
[-<->] Negate cell 0 into cell minus 1
<.     Print the negated byte
>>     Skip to the second byte of the program
[.>]   Print the rest of the program

```

Because I can't directly do it with TIO because it treats inputs as UTF-8, here is a Bash script version which prints outputs with `xxd`:

Try it online!

# Self-modifying Brainfuck (infinite loop, theoretical), 15 bytes

This version is shorter, but instead of exiting normally, it hangs in an infinite loop. Note that you won't see this in the console as the console is line buffered.

```
<[.<]-[][+]<.[<

```

Try it online!

This will print this:

```
<[.<]+[][-]<.[<

```

which, when run, will print this

```
<[.<]-[][+]<.[<

```

Try it online!

**Note that in both cases, the code will get stuck in an infinite loop after printing, so you have to manually stop TIO or wait for the timeout**

Explanation:

```
<[.<]    Print the program backwards
-[]      Enter an infinite loop to avoid executing the backwards code
[+]<.[<  The same code backwards (minus the last bracket) which uses a minus
         instead of a plus before the infinite loop.

```

My previous 11 byte infinite loop solution:

```
<[.<]]<.[<+

```

Try it online!

I *thought* this was an infinite loop which just sat there spinning, but the instruction pointer will eventually underflow and the program will *very slowly* print endless `0x00` as it tries to traverse a 4 GB loop.
> 1 votes

# Answer
# Vyxal, 10 bytes

```
`:qpq`:qpq

```

Try it Online!

This outputs

```
`\`:qpq\`:qpq`

```

Which outputs the original code.

The first is a quine that unevaluates itself, and the second is a string.
> 1 votes

---
Tags: code-golf, quine, code-generation
---


title: Can you outgolf me? (Cops section)

text:
# Question
Title: Can you outgolf me? (Cops section)
# Cops section

The robbers section can be found here.

Thanks to **FryAmTheEggman**, **Peter Taylor**, **Nathan Merrill**, **xnor**, **Dennis**, **Laikoni** and **Mego** for their contributions.

---

### Challenge

Your task is to write 2 different programs (full programs/functions/etc.) in the **same** language and the **same** version (e.g. Python 3.5 ≠ Python 3.4, so that is not allowed), and when given **n** (using STDIN/function arguments/etc.), compute **a(n)** where **a** is an OEIS sequence of your choice. One of those programs is shorter than the other. You only need to submit the *longer* program of the two. The other one needs to be saved in case of not being cracked after 7 days. Your submission is cracked when your program has been outgolfed (whether it is by 1 byte or more).

For example, if the task you chose was to perform **2 × *n***, this could be a valid submission (in Python 2):

> ## Python 2, 16 bytes, score = 15 / 16 = 0.9375
>
> ```
> print(2*input())
>
> ```
>
> Computes A005843, (offset = 0).

If your submission has been cracked, then you need to state that in your header like so:

> ## Python 2, 16 bytes, score = 15 / 16 = 0.9375, \[cracked\] + link
>
> ```
> print(2*input())
>
> ```
>
> Computes A005843, (offset = 0).

---

### Offset

This can be found on every OEIS page. For example, for A005843, the offset is `0,2`. We only need to use the first one, which is `0`. This means that the function is defined for all numbers ≥ 0.

In other words, the function OEIS(n) starts with **n = 0**. Your program needs to work for all cases given by OEIS.

More information can be found here.

---

### Scoring

The score you get for your submission is equal to the following formula:

**Score** = **Length (in bytes) of secret code** ÷ **Length (in bytes) of public code**

The example above has the score 15 ÷ 16 = 0.9375.

The submission with the **lowest** score wins. Only submissions that have posted their solution will be eligible for winning.

---

### Rules

* The task you need to do is an OEIS sequence of your choice.
* Given **n**, output **OEIS(n)**. Deviation is **not** allowed, so you need to produce the exact same sequence (when given n, you need to output OEIS(n)).
* Submissions that are not cracked within a period of 7 days are considered **safe** after the **solution has been posted** (submissions older than 7 days that do not have their solution posted are still vulnerable in being cracked).
* In your submission, you need to post the following things: **language name**, **byte count**, **full code**, so no pastebin links etc. (to prevent answers like Unary), **OEIS sequence**, **score with lengths of both programs** and additionally, the encoding that is used.
* Note: the same sequence **cannot** be posted twice in the *same* language. (For example, if the sequence A005843 has been done in Pyth, you cannot use Pyth again for that same sequence.)
* Input and output are both in decimal (base 10)

### Leaderboard

```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><style>table th,table td{padding: 5px;}th{text-align: left;}.score{text-align: right;}table a{display: block;}.main{float: left;margin-right: 30px;}.main h3,.main div{margin: 5px;}.message{font-style: italic;}#api_error{color: red;font-weight: bold;margin: 5px;}</style> <script>QUESTION_ID=88979;var safe_list=[];var uncracked_list=[];var n=0;var bycreation=function(x,y){return (x[0][0]<y[0][0])-(x[0][0]>y[0][0]);};var byscore=function(x,y){return (x[0][1]>y[0][1])-(x[0][1]<y[0][1]);};function u(l,o){jQuery(l[1]).empty();l[0].sort(o);for(var i=0;i<l[0].length;i++) l[0][i][1].appendTo(l[1]);if(l[0].length==0) jQuery('<tr><td colspan="3" class="message">none yet.</td></tr>').appendTo(l[1]);}function m(s){if('error_message' in s) jQuery('#api_error').text('API Error: '+s.error_message);}function g(p){jQuery.getJSON('//api.stackexchange.com/2.2/questions/' + QUESTION_ID + '/answers?page=' + p + '&pagesize=100&order=desc&sort=creation&site=codegolf&filter=!.Fjs-H6J36w0DtV5A_ZMzR7bRqt1e', function(s){m(s);s.items.map(function(a){var he = jQuery('<div/>').html(a.body).children().first();he.find('strike').text('');var h = he.text();if (!/cracked/i.test(h) && (typeof a.comments == 'undefined' || a.comments.filter(function(b){var c = jQuery('<div/>').html(b.body);return /^cracked/i.test(c.text()) || c.find('a').filter(function(){return /cracked/i.test(jQuery(this).text())}).length > 0}).length == 0)){var m = /^\s*((?:[^,;(\s]|\s+[^-,;(\s])+).*(0.\d+)/.exec(h);var e = [[n++, m ? m[2]-0 : null], jQuery('<tr/>').append( jQuery('<td/>').append( jQuery('<a/>').text(m ? m[1] : h).attr('href', a.link)), jQuery('<td class="score"/>').text(m ? m[2] : '?'), jQuery('<td/>').append( jQuery('<a/>').text(a.owner.display_name).attr('href', a.owner.link)) )];if(/safe/i.test(h)) safe_list.push(e);else uncracked_list.push(e);}});if (s.items.length == 100) g(p + 1);else{var s=[[uncracked_list, '#uncracked'], [safe_list, '#safe']];for(var i=0;i<2;i++) u(s[i],byscore);jQuery('#uncracked_by_score').bind('click',function(){u(s[0],byscore);return false});jQuery('#uncracked_by_creation').bind('click',function(){u(s[0],bycreation);return false});}}).error(function(e){m(e.responseJSON);});}g(1);</script><link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/Sites/codegolf/all.css?v=7509797c03ea"><div id="api_error"></div><div class="main"><h3>Uncracked submissions</h3><table> <tr> <th>Language</th> <th class="score">Score</th> <th>User</th> </tr> <tbody id="uncracked"></tbody></table><div>Sort by: <a href="#" id="uncracked_by_score">score</a> <a href="#" id="uncracked_by_creation">creation</a></div></div><div class="main"><h3>Safe submissions</h3><table> <tr> <th>Language</th> <th class="score">Score</th> <th>User</th> </tr> <tbody id="safe"></tbody></table></div>
```

> **Note**
>
> This challenge is finished. The final winner is **feersum** with his *Seed answer*. Congratulations! :).
>
> You can still submit new cops, but be aware that they are no longer competing.

# Answer
> 37 votes
# Seed, 5861 bytes, score = 5012 / 5861 = 0.85

The sequence is primes (A000040) with offset 1. a(1) = 2, a(2) = 3, a(3) = 5 etc.

```
106 [encoded data, 5857 characters]

```

The Befunge-98 programs were tested with this interpreter.

Solution:

```
62 [encoded data, 5009 characters]

```

# Answer
> 27 votes
# Jelly, 5 bytes, score 0.8 (4 / 5) \[cracked!\]

```
R²SÆ½

```

Computes A127721.

Try it online!

---

Here's the solution:

```
RÆḊḞ

```
* implicitly take input `n`
* `R`: list from `[1, 2, ..., n]`
* `ÆḊ`: In our case, this will actually return the square root of the sum of squares (which may be useful in future golfing)!
* : floor the result.

The documentation for `ÆḊ` reads:

> `ÆḊ`: Determinant, extended to non-square matrices.

The key is *extended to non-square matrices*. The "determinant" of a non-square matrix is usually undefined, but one reasonable definition is `sqrt(det(A A^T))` (which for a square matrix reduces to `|det(A)|`). In our case, `A A^T` is a 1 x 1 matrix containing the sum of squares. The square root of the determinant of that gives us exactly what we need to shave off the last byte!

# Answer
> 12 votes
## Retina, 28 bytes, score = 0.9286... (26/28), cracked by feersum

```
.+
$*
^$|^((^|\3)(^.|\1))*.$

```

Computes A192687, (offset = 0).

Try it online! (The first line enables a linefeed-separated test suite.)

This is the difference between Hofstadter's male and female sequences. (Relevant PPCG challenge.)

This was my original code:

```
.+
$*
^((^.|\3)(\1)|){2,}$

```

This answer was a bit of a gamble anyway, because the actual solution is based on a regex I announced to be the shortest known Fibonacci-testing regex in chat a few months ago. Luckily, no one seemed to remember that. :)

# Answer
> 12 votes
## Stack Cats, 14 bytes, score = 13 / 14 = 0.929 \[cracked\]

That's 10 bytes of code, plus 4 for the arguments  `-nm`.

Computes A017053. In case OEIS is down, that's `a(n) = 7n + 6`, starting at `n = 0`.

```
![_-_:-_-_

```

The full code (usable without `-m` argument) is `![_-_:-_-_-_-:_-_]!`

The hidden solution was

```
!]|{_+:}_

```

# Answer
> 11 votes
# Hexagony, 91 bytes, Score = 0.725274725 (66/91) \[Cracked\]

Computes A000045 (Fibonacci sequence, offset 0).

I won't be too surprised if someone manages to beat this and my more golfed version~~, although it should be hard.~~

Edit: Holy cow, @MartinEnder whipped me with a 33 byte solution.

Golfed (91):

```
?\]~<~.{>'"/(@{\''1<{!1>{{1}/}{'\1</={}/_\'0"/>+(}\/}(+'+'%=<>=%"=+("\/+"(+}+<>{{}=~\.....|

```

Formatted:

```
      ? \ ] ~ < ~
     . { > ' " / (
    @ { \ ' ' 1 < {
   ! 1 > { { 1 } / }
  { ' \ 1 < / = { } /
 _ \ ' 0 " / > + ( } \
  / } ( + ' + ' % = <
   > = % " = + ( " \
    / + " ( + } + <
     > { { } = ~ \
      . . . . . |

```

Try it online!

I'm not going to post an explanation for this, it's too horrible...

Golfed (66):

```
?{1}]0@._.>\>+{./'++.!.|.*'}..\}{\=++.../'"<_}\"+<./{(/\=*"=/>{=+"

```

Formatted:

```
      ? { 1 } ] 0
     @ . _ . > \ >
    + { . / ' + + .
   ! . | . * ' } . .
  \ } { \ = + + . . .
 / ' " < _ } \ " + < .
  / { ( / \ = * " = /
   > { = + " . . . .
    . . . . . . . .
     . . . . . . .
      . . . . . .

```

Colored:

Try it online!

Explanation:

The memory layout I used looks a little like this:

```
   |
   a
   |
  / \
b+a  b
/     \
      |
    input

```

The initialization (in black) sets a=0 and b=1. Then, the main loop:

* goes from `a` to the input cell - `'"`
* decrements the input - `(`
* adds b and a - `{{=+`
* moves it "out of the way" - `"+{=*`
* sets a to b - `'+`
* moves a "out of the way" - `'+}=*`
* moves b+a back to its original position - `"=+`
* sets b to b+a - `"+`
* moves a back to its original position - `}+`

Once the input cell reaches 0, the MP moves to a, prints, and exits.

What I could have done to save more bytes is to use &, which just sets the current cell to either its left or right neighbor. I also could have had a bit better flow control, but it's okay as it stands.

# Answer
> 10 votes
# , 10 bytes, score 0.6 (6 / 10) \[cracked\]

```
R‘ạḤc’*@RP

```

A tad cheaty since M and Jelly are quite similar, but allowed by the rules. This version is based on @LeakyNun's crack to my Jelly answer.

This calculates sequence A068943. Try it online!

### Intended solution

The following code works in M/Jelly.

```
R¹¡PÐL

```

I actually had a 4-byte solution to which I added some fluff to make it seem more difficult to crack by using brute force.

```
R¡FP

```

Try it online!

This is the one I'm going to explain.

```
R¡FP  Main link. Argument: n

 ¡    Execute the left to the left n times, updating the return value.
R       Range; map each integer k to [1, ..., k].
      This does the following for the first values of n.
        1 → [1]
        2 → [1,2]   → [[1],[1,2]]
        3 → [1,2,3] → [[1],[1,2],[1,2,3]] → [[[1]],[[1],[1,2]],[[1],[1,2],[1,2,3]]]
  F   Flatten the resulting, nested array.
   P  Take the product of the reulting array of integers.

```

# Answer
> 7 votes
## Snowman, 50 bytes, score = 0.9 (45 / 50) \[cracked by Lynn\]

```
((}#NDe`nOnO|`2nMNdE0nR2aGaZ::nM;aF;aM:nS;aF,nM*))

```

This is a subroutine that takes a number as its argument and returns another number.

Computes A122649 (offset = 1).

Try it online!

# Answer
> 7 votes
## Haskell, 15 bytes, score = 13/15 (0.866) (cracked)

```
f x=1+2*div x 2

```

A109613 with offset 0. Repeats each odd number twice.

```
1, 1, 3, 3, 5, 5, 7, 7, 9, 9, 11, 11, 13, 13, ...

```

# Answer
> 6 votes
# Brachylog, 27 bytes, score = 0.666... (18/27), Cracked!

```
+ybL:L:[1]co~c[A:B]hl-?,A*.

```

Computes A010551 (offset = 0).

You can try it online here.

### Explanation

Since the vast majority of people don't know this language, and since I'm posting this answer mostly to get people looking into it (See: Brachylog's Wiki), I'll provide a short explanation of the code above:

```
+           Add 1 to the input N
ybL         L = [1, 2, ..., N+1]
:L:[1]c     Construct a list [1, 2, ..., N+1, 1, 2, ..., N+1, 1]
o           Sort the list from smallest to biggest
~c[A:B]     A concatenated to B results in that sorted list
hl-?,       The length of A is N + 1
A*.         The output is the result of the product of all elements of A

```

# Answer
> 6 votes
## Haskell, 4 bytes / 5 bytes (cracked by Leaky Nun)

Let's start simple. A000012, the sequence of all 1's (offset 0). Here's a table:

```
0 -> 1
1 -> 1
2 -> 1
3 -> 1
4 -> 1
 ...

```

**5 bytes:**

```
f n=1

```

# Answer
> 6 votes
# Java 7, 53 bytes, score = 0.9623 (51/53) Cracked

```
int f(int n){return n<1?3:n<2?0:n<3?2:f(n-2)+f(n-3);}

```

Computes the Perrin sequence, A001608

```
f(0)=3
f(1)=0
f(2)=2
f(n)=f(n-2)+f(n-3)

```

First code golf attempt, feel free to point out any mistakes.

## Explanation after cracking:

miles shortened the first three values (0,1,2) -\> (3,0,2) to

```
n<2?3-3*n:n<3?2

```

while my own solution was a slightly over-engineered

```
n<3?(n+4)%5*2%5

```

Combining the two tricks, you get

```
n<3?3-3*n%5

```

for a 47-byte

```
int k(int n){return n<3?3-3*n%5:f(n-2)+f(n-3);}

```

which looks pretty compact for Java :)

# Answer
> 5 votes
## Cheddar, 7 bytes, score = 0.8571 (6/7), \[cracked\]

```
n->2**n

```

Pretty simple, just the powers of two. OEIS A000079

Try it online!

# Answer
> 4 votes
# J, 17 bytes, score = 0.8235 (14/17) (cracked)

```
(+/@(!+:)&i.-)@>:

```

Computes A002478.

The funny thing is that this version was originally the short one to be kept secret.

# Answer
> 4 votes
## Pyke, 11 bytes, score = 0.45 (5/11) \[cracked\]

```
hZRVoeX*oe+

```

Calculates OEIS A180255

Try it here!

# Answer
> 4 votes
# Python 2, 43 bytes, score = 0.9302 (40/43), cracked

`f=lambda n:n==1or-(-sum(map(f,range(n)))/3)`

Computes A072493

Let's see if anybody can golf off all 3 bytes.

# Answer
> 4 votes
# Jelly, 9 bytes, score 0.5556 (5 / 9) \[cracked\]

```
r©0+’Ac®Ḅ

```

This calculates sequence A119259. Try it online!

# Answer
> 4 votes
# Brachylog, 11 bytes, score = 10 / 11 = 0.909, cracked!

```
ybLrb:Lrcc.

```

Computes A173426.

Try it online!

### Explanation

```
ybL      L = [1, 2, …, Input]
rb       Get [Input - 1, …, 2, 1]
:Lrc     Concatenate [1, 2, …, Input] and [Input - 1, …, 2, 1]
c.       Concatenate [1, 2, …, Input, Input - 1, …, 2, 1] into a single integer

```

# Answer
> 4 votes
# J, 20 bytes, score = 0.75 (15/20) (cracked)

```
[:*/0 1(]{:,+/)^:[~]

```

Computes A001654.

My solution for 15 bytes was

```
*&(+/@:!&i.-)>:

```

# Answer
> 3 votes
# Sesos, 14 bytes, score = 0.8571 (12/14) (cracked)

```
0000000: 16f8be 760e1e 7c5f3b 07ddc7 ce3f                  ...v..|_;....?

```

Computes A000290.

Try it online!

### Hints

This binary file has been generated by the following assembler:

```
set numin
set numout
get
jmp,sub 1,fwd 1,add 1,fwd 1,add 1,rwd 2,jnz
fwd 1
jmp
  sub 1,fwd 1
  jmp,sub 1,fwd 1,add 1,fwd 1,add 1,rwd 2,jnz
  fwd 1
  jmp,sub 1,rwd 1,add 1,fwd 1,jnz
  rwd 2
jnz
fwd 3
put

```

# Answer
> 3 votes
## MATL, 11 bytes, score = 0.8181 (9/11), cracked

```
YftdA-1bn^*

```

Computes the Möbius function, or A087811 (offset 1).

Try it online!

### Resources for robbers

I think this one should be easy, but anyway here is some help.

Code explanation:

```
Yf     % Implicit input. Push array of prime factors, with repetitions
t      % Duplicate
d      % Compute consecutive differences
A      % 1 if all those differences are nonzero, 0 otherwise
-1     % Push -1
b      % Bubble up array of prime factors to the top of the stack
n      % Number of elements
^      % -1 raised to that
*      % Multiply. Implicitly display

```

Language documentation.

MATL chatroom.

# Answer
> 3 votes
# Jelly, 11 bytes, score 0.5455 (6 / 11) \[cracked\]

```
Ḷ+’cḶ
r1*ÇP

```

This calculates sequence A068943. Try it online!

# Answer
> 3 votes
## MarioLANG, 87 bytes, score = 0.839 (73/87), cracked

```
;
)-)+(< >>
-)===" ""====
>>+([!)( >-(+(
"====#[(("== [
!-) - <!!![)<<)
#======###====:

```

Computes A000217, the triangular numbers. Offset 0.

Try it online!

### Short Solution:

Since the crack took only 1 byte off, I'll share my solution in 73 bytes, which uses a different algorithm altogether:

```
;   +)-<
-   (=="
+)-<(
(=="+
> [!>)[!(
"==#===#[
!    -  <))
#=========:

```

Try it online!

**The first program** lays out all the numbers from n to 1 along the tape, then adds up all numbers until it comes across a 0-value cell. It does this by copying each cell into the two adjacent cells, decrementing the right copy, and repeating the process on it until it reaches 0. During this process, the tape looks like this (for n=5):

```
0 0 5 0 0 0 0
0 5 0 5 0 0 0
0 5 0 4 0 0 0
0 5 4 0 4 0 0
0 5 4 0 3 0 0
0 5 4 3 0 3 0
0 5 4 3 0 2 0
0 5 4 3 2 0 2

```

... and so on. Then it moves left, summing the cells until it reaches a cell with 0.

**The second program** only works with three cells of the tape. Until the first cell reaches 0, it does the following:

* Move the value of the first cell to the second cell.
* Decrement the second cell to 0, adding its own value to the first and third cells.
* Decrement the first cell.

After the first cell reaches 0, the third cell will contain n + (n-1) + (n-2) + ... + 2 + 1.

# Answer
> 3 votes
# , 18 bytes, score 0.3889 (7 / 18) \[cracked\]

```
r0+c
‘Ḥc0r$×Ç:‘+\S

```

This approach is based on @Sp3000's golf of my Jelly answer.

The code calculates sequence A116881 (row sums of **CM(1,2)**). Try it online!

# Answer
> 3 votes
## Haskell, 28 bytes, score = 0.3571 (10/28), cracked

```
f n|odd n=1|1>0=2*f(div n 2)

```

A006519, the highest power of 2 dividing `n`, starting at `n=1`.

```
1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1, 16, 1, ...

```

While you get cracking credit for any shorter code, I consider the real puzzle to be getting down to 10 bytes.

# Answer
> 2 votes
## 05AB1E, 9 bytes, score = 0.6667 (6/9), Cracked

```
ÐnŠ·sÉO4/

```

Computes: A087811

Try it online

# Answer
> 2 votes
# Hexagony, 7 bytes, score = 0.857 (6/7), cracked

Not designed to be the winning submission, but definitely a brain cracker. It actually isn't that hard if you think about it :p. Code:

```
\!?__@(

```

Or a more readable version:

```
 \ !
? _ _
 @ (

```

Computes A052246.

Try it online!.

# Answer
> 2 votes
# J, 10 bytes, score = 0.9 (9/10) (cracked by Dennis)

```
*2%~3<:@*]

```

Computes A000326.

This one should be easy.

Online interpreter.

Quickref.

# Answer
> 2 votes
# J, 9 bytes, score = 0.6667 (6/9) (cracked by Dennis)

```
9 o.0j1^]

```

Computes A056594.

# Answer
> 2 votes
## 05AB1E, 7 bytes, score = 0.571 (4/7), Cracked

```
0s·Ì3c;

```

Computes: A006331

Try it online

After golfing 5 unique versions of this sequence before finding this public version I hope I haven't left any obvious improvement out there so it'll at least be a challenge for the robbers.

# Answer
> 2 votes
# , 9 bytes, score 0.6667 (6 / 9) \[cracked\]

```
r©0+’Ac®Ḅ

```

A tad cheaty since M and Jelly are quite similar, but allowed by the rules. @miles' crack to my Jelly answer doesn't work in M; it lacks the `œċ` atom.

This calculates sequence A119259. Try it online!

# Answer
> 2 votes
## QBasic (QB64), 30 bytes, score = 28 / 30 = 0.9333 (cracked)

```
INPUT n:p=n MOD 2:?p*n+(n+p)/2

```

Computes A014682, a version of the Collatz function (offset 0).

This works on the QB64 emulator with autoformatting turned off. It *should* work on actual QBasic as well, but I don't have a copy to test it.

---

My 28-byte version used a bitwise operator and integer division:

```
INPUT n:?(1AND n)*n+(n+.5)\2

```

# Answer
> 2 votes
## *Acc!!*, 526 bytes, score = 0.5627 (296/526) (cracked)

```
N
Count x while _%60-46 {
(_+_%60*5-288)*10+N
}
_/60
Count i while _/27^i {
_+27^i*(_/27^i*26-18)
}
_*3+93
Count i while _/27^i/27%3 {
_-i%2*2+1
Count j while _/3^(3*j+2-i%2)%3 {
_+3^(1+i%2)
Count k while _/3^(3*k+1+i%2)%3-1 {
_+3^(3*k+1+i%2)*26
}
}
}
Count i while _/27^i/3 {
_-_/27^i/3%27*27^i*3+_/3^(3*i+1+_%3)%3*3
}
_/3
Count i while _/100^i {
_+_/100^i*100^i*9
}
Count i while _/100^i/10 {
_+_/100^i/10%10
Count j while i+1-j {
_+(_%10-_/100^(j+1)%10)*(100^(j+1)-1)
}
}
_/100
Count j while _/100^j {
Write _/100^j%10+48
}

```

Computes A000204, Lucas numbers with offset 1.

A couple of notes. Due to *Acc!!*'s input limitations, the program takes input as a decimal number terminated with a period (`.`); for example:

```
> python acc.py Program.txt
5.
11

```

This program has exponential time complexity, so I wouldn't recommend running it with input greater than about 14 (takes 60 seconds on my laptop). However, *given enough time*, the algorithm will return the correct result for any positive integer *n*. Thus: **a crack attempt that places any size limits on the input value is invalid**.

Have fun!

# Answer
> 2 votes
## Python, 46 bytes, score = 0.97826 (45 / 46) \[cracked\]

```
f=lambda n,k=1:n and-~f(n-("01"in bin(k)),k+1)

```

Calculates A101082 (offset = 1), which are:

> Numbers n such that binary representation contains bit strings "10" and "01" (possibly overlapping).

---

@Dennis cracked the submission as intended, which was to replace `"01"in bin(k)` with some bit twiddling, namely `(k&-k)+k&k>0`, to check that `k`'s binary representation isn't of the form `111...111000...000`.

# Answer
> 2 votes
## *Acc!!*, 512 bytes, score = 0.5625 (288 ÷ 512) (cracked)

Fourth try. Let's see how fast Dennis cracks this one. *(Edit: 8 minutes, that's a record!)*

```
N
Count x while _%60-46 {
(_+_%60*5-288)*10+N
}
_/30
Count i while _/27^i {
_+(_/27^i*26-18)*27^i
}
_*3+93
Count i while _/27^i/27%3 {
_-i%2*2+1
Count j while _/3^(3*j+2-i%2)%3 {
_+3+i%2*6
Count k while _/3^(3*k+1+i%2)%3-1 {
_+27^k*3^(i%2)*78
}
}
}
Count i while _/27^i/3 {
_-_/27^i/3%27*27^i*3+_/3^(3*i+1+_%3)%3*3
}
_/3
Count i while _/100^i {
_*10-_%100^i*9
}
Count i while _/100^i/10 {
_+_/100^i/10%10
Count j while i+2-j {
_+(_%10-_/100^j%10)*(100^j-1)
}
}
_/100
Count j while _/100^j {
Write _/100^j%10+48
}

```

Computes A002878, Lucas(2\*n+1), offset = 0.

Due to *Acc!!*'s input limitations, the program takes input as a decimal number terminated with a period (`.`); for example:

```
> python acc.py Program.txt
3.
29

```

This program has exponential time complexity, so I wouldn't recommend running it with input greater than about 7. However, *given enough time*, the algorithm will return the correct result for any positive integer *n*. Thus: **a crack attempt that places any size limits on the input value is invalid**.

# Answer
> 2 votes
# Woefully, (noncompeting, but you still get points for cracking it), ~~520/776= ~0.67~~ Cracked by Feersum.

Computes A000042 (would compute repunits, but that one has 0 as first member)

Offset 1, zero indexed (0 outputs 1, 1 outputs 11, 2 outputs 111, etc.)

```
| |||||||| | |
|| |||||| |
||| |||| |
|||| || |
||||| || |
|||| |||| |
||| |||||| |
|| |||||||| |
| |||||||||| |
|| ||||||||| |
||| |||||||| |
|||||||||||| |
|||||||||||| |
|||||||||||| |
||||||||||| |
|||||||||| |
|||||||||| |
|||||||||| |
|||||||||| |
||||||||||| |
|||||||||||| |
||||||||||||| |
|||||||||||| |
||||||||||| |
|||||||||| |
||||||||| |
|||||||| |
||||||| |
|||||| |
||||| |
|||| |
||| |
|| |
|| |
|| |
| |
| |
| |
| |
| |
|| |
|| |
|| |
||| |
|||| |
||||| |
|||||| |
||||||| |
|||||||| |
||||||| |
|||||||| |
||||||||| |
|||||||||| |
||||||||||| |
|||||||||||| |
||||||||||||| |
|||||||||||| |
||||||||||| |
|||||||||| |
||||||||| |
|||||||| |
||||||| |
|||||| |
||||| |
|||| |
||| |
|| |
|| |
|| |
|| |
||| |
|||| |
||| |
|| |
| |
| |
| |
|| |
|| |
|| |
|| |

```

Try it online!

---

I like to think that my shorter solution was a pretty nice one.

```
| || || |
|| || |
||| || |
|||| || |
||||| || |
|||| |||| |
||| ||||| |
|| |||||| |
| ||||||| |
|| |||||| |
||| ||||| |
||| |||| |
|||| || |
||| ||| |
|| |||| |
| ||||| |
|||||||| |
||||||||| |
|||||||||| |
|||||||||| |
||||||||| |
|||||||| |
||||||| |
|||||| |
||||| |
||||| |
||||| |
|||| |
|||| |
|||| |
|||| |
|||| |
||| |
||| |
||| |
|||| |
|||| |
||||| |
||||| |
|||||| |
||||| |
|||| |
||| |
|| |
| |
| |
| |
| |
|| |
||| |
||| |
|||| |
||| |
|| |
| |
| |
| |
|| |
|| |
|| |
|| |
||| |
||| |
|||| |
||| |
|| |
| |

```

What I did was remove the push one command from the top, replace it at the bottom and at the end of the first command, which was free because I just had to replace some pipes, which then allowed me to shorten the push nine commands some more, because it didn't need to move that much anymore

# Answer
> 2 votes
# J, 12 bytes, score = 0.9167 (11/12) (cracked)

```
(#++/)@I.@#:

```

Computes A230877.

# Answer
> 2 votes
# J, 18 bytes, score = 0.7222 (13/18) (cracked)

```
0{]1&(}.],+/)2 1"_

```

Computes the Lucas numbers, A000032.

# Answer
> 1 votes
# Sesos, 14 bytes, score = 0.6429 (9/14) (cracked)

```
0000000: aed40b b47bc2 8e01be 8e9ddb b107                  ....{.........

```

Computes A130909.

Try it online!

# Answer
> 1 votes
# Python 3.5, 38 bytes, Score = 0.86842 (33/38) (Cracked):

```
G=lambda n:n<1and 1or(2*n-1)**2*G(n-1)

```

Computes A001818.

Try It Online! (Ideone)

# Answer
> 1 votes
# 05AB1E, 10 bytes, score = 5 ÷ 10 = 0.5, cracked

This one isn't too hard actually :p. Code:

```
[NNÂÊ½¾¹Q#

```

Computes the **N**th **non-palindromic number**, which is A029742.

Try it online!

# Answer
> 1 votes
# JavaScript (ES6), 77 bytes, score = 0.9481 (73 / 77) \[Cracked\]

```
n=>eval("for(i=0;n;a||n--)[...s=a=++i+''].map(d=>a-=Math.pow(d,s.length));i")

```

Computes A005188, (offset = 1).

---

Didn't end up being super interesting but I thought I'd try and submit something.

*Note: This is in **ES6** so there is no `**` operator. I just thought this would make it more cross-browser compatible and easier to test.*

# Answer
> 1 votes
# 05AB1E, 13 bytes, score = 0.769 (10 ÷ 13), cracked

This one isn't too hard either. Code:

```
µN•vÉ•vyK}g_½

```

Calculates A001742 (offset = 1).

Try it online!.

# Answer
> 1 votes
**Python (3.4.3), 77 bytes, score = 0.7272 (56/77) cracked**

```
import math;lambda x: 1 if x==0 else (0 if ((math.sqrt(1+8*x)-1)/2)%1 else 1)

```

Computes A010054, offset = 0

# Answer
> 1 votes
# Coffeescript, 83 bytes, score = 79/83 = 0.952 \[cracked!\]

```
r=(n)->return if r<0 then 0 else Array(parseInt(n/9)+2).join ((n-1)%9+1).toString()

```

Computes A010785.

(Not so) Surprisingly, @DomHastings managed to shave 33 bytes off of my solution.

Wow, I suck at , don't I? Well, here's my other code:

```
r=(n)->return if r<0 then 0 else ((n-1)%9+1).toString().repeat(parseInt(n/9)+2)

```

Here's a less messy version of the code:

```
r=(n)->
  if r<0
   return 0
  else
   ((n-1)%9+1).toString().repeat(parseInt(n/9)+2)
   # ((n-1)%9+1).toString() is the repeating digit (as a string).
   # parseInt(n/9)+2 is the times the digit is repeated.

```

# Answer
> 1 votes
## Pip, 24 bytes, score = 22 / 24 = 0.9166 (cracked)

```
Y53T++i>ay.:k.A(yi)A(ya)

```

Computes A109648 (offset = 0). Try it online!

---

My 22-byte version:

```
T++v>alPB A(lJk|5v)l@a

```

# Answer
> 1 votes
## Actually, 28 bytes, Score = 0.39285714 (11/28) (cracked)

```
2√;;4*;u@D))u(*,;)@ⁿ)1-*ⁿ@-½

```

Computes A048696 (offset = 0). Actually uses CP437 for its encoding.

Try it online!

Dennis's solution is *actually* almost identical to mine:

```
19,`;τ(+`nX (Dennis)
19(`;)τ+`nX (Mine)

```

A Levenshtein distance of 3 is pretty impressive!

Try it online!

# Answer
> 1 votes
# Jelly, 22 bytes, score 0.2727 (6 / 22) \[cracked\]

```
‘ðḤ;+;c2\×P:+’×$¥µÐ€‘S

```

This calculates sequence A116881. Try it online!

# Answer
> 1 votes
# 05AB1E, 7 bytes, score = 0.857 (6 / 7) \[cracked\]

This one shouldn't be too hard if you think about it :p. Code:

```
L!zO¹!*

```

Try it online!

Computes A002627.

# Answer
> 1 votes
## *Acc!!*, 523 bytes, score = 0.55067 (288/523) (cracked)

Second try, slightly different sequence.

```
N
Count x while _%60-46 {
(_+_%60*5-288)*10+N
}
_/60
Count i while _/27^i {
_+27^i*(_/27^i*26-18)
}
_*3+93
Count i while _/27^i/27%3 {
_-i%2*2+1
Count j while _/3^(3*j+2-i%2)%3 {
_+3^(1+i%2)
Count k while _/3^(3*k+1+i%2)%3-1 {
_+3^(3*k+1+i%2)*26
}
}
}
Count i while _/27^i/3 {
_-_/27^i/3%27*27^i*3+_/3^(3*i+1+_%3)%3*3
}
_/3
Count i while _/100^i {
_*10-_%100^i*9
}
Count i while _/100^i/10 {
_+_/100^i/10%10
Count j while i+1-j {
_+(_%10-_/100^(j+1)%10)*(100^(j+1)-1)
}
}
_/100
Count j while _/100^j {
Write _/100^j%10+48
}

```

Computes A000032, Lucas numbers with offset 0.

Due to *Acc!!*'s input limitations, the program takes input as a decimal number terminated with a period (`.`); for example:

```
> python acc.py Program.txt
5.
11

```

This program has exponential time complexity, so I wouldn't recommend running it with input greater than about 14 (takes 60 seconds on my laptop). However, *given enough time*, the algorithm will return the correct result for any positive integer *n*. Thus: **a crack attempt that places any size limits on the input value is invalid**.

# Answer
> 1 votes
## *Acc!!*, 522 bytes, score = 0.5555 (290 ÷ 522) (cracked)

Third try. Thanks to Dennis for the golfing "help" with the first two. ;^)

```
N
Count x while _%60-46 {
(_+_%60*5-288)*10+N
}
_/60*2
Count i while _/27^i {
_+(_/27^i*26-18)*27^i
}
_*3+93
Count i while _/27^i/27%3 {
_-i%2*2+1
Count j while _/3^(3*j+2-i%2)%3 {
_+3+i%2*6
Count k while _/3^(3*k+1+i%2)%3-1 {
_+27^k*3^(i%2)*78
}
}
}
Count i while _/27^i/3 {
_-_/27^i/3%27*27^i*3+_/3^(3*i+1+_%3)%3*3
}
_/3
Count i while _/100^i {
_*10-_%100^i*9
}
Count i while _/100^i/10 {
_+_/100^i/10%10
Count j while i+1-j {
_+(_%10-_/100^(j+1)%10)*(100^(j+1)-1)
}
}
_/100
Count j while _/100^j {
Write _/100^j%10+48
}

```

Computes A005248, Lucas(2\*n), offset = 0.

Due to *Acc!!*'s input limitations, the program takes input as a decimal number terminated with a period (`.`); for example:

```
> python acc.py Program.txt
3.
18

```

This program has exponential time complexity, so I wouldn't recommend running it with input greater than about 7. However, *given enough time*, the algorithm will return the correct result for any positive integer *n*. Thus: **a crack attempt that places any size limits on the input value is invalid**.

# Answer
> 1 votes
# Excel, 16 bytes, score = 0.75, \[cracked by Dennis♦\]

```
=FACTDOUBLE(2*n)

```

Computes **A000165****:** double factorial of even numbers, (offset = 0).

# Answer
> 1 votes
# INTERCAL, ~~85 bytes~~ Score: 77/85=0.90588, safe.

Input: up to `SIX FIVE FIVE THREE FIVE`, although actual calcuatable input is smaller than that.

This calculates A000217.

```
PLEASEWRITEIN.1PLEASE.2<-#1DO(1000)NEXTDO.2<-.3DO(1030)NEXTDO.3<-.3~#65534DOREADOUT.3

```

Try it online!

## The answer

77 bytes.

```
PLEASEWRITEIN.2PLEASE.1<-.2DO(1020)NEXTDO(1030)NEXTDO.3<-.3~#65534DOREADOUT.3

```

C-INTERCAL has a subroutine that just increments .1, which is (1020).

Try it online!

# Answer
> 0 votes
# Python, 39 bytes, 26/39=2/3=0.666 cont. points, cracked

```
s=lambda x:x+s(x-1)if x==1else x+s(x-1)

```

won't last long, but lets see just how long. Just doing the robbers a favour I guess (also because I don't know eso golf langs ;\_;)

umm, I accidentally bad code but someone cracked my lower score so...

computes A000217

# Answer
> 0 votes
## Python, 69 bytes, score = 0.97 (67÷69), cracked

```
f=lambda n:reduce(lambda x,y:x*y,range(1,n+1),1)
lambda n:f(n*2)/f(n)

```

Computes A001813

# Answer
> 0 votes
# 05AB1E - 1 byte - A000027

Code: `I`

# 05AB1E - 0 bytes - A000027

Code:

Explanation:

`I` means that it pushes the input to the stack.

means that nothing is changed to the stack, but the input was already added to the stack by default, so it prints out the input.

---
Tags: code-challenge, number, sequence, cops-and-robbers
---


title: Square Number Digit Density

text:
# Question
Title: Square Number Digit Density
The square number digit density (SNDD) of a number - invented by myself - is the ratio of the count of square numbers found in consecutive digits to the length of the number. For instance, 169 is a 3-digit number containing 4 square numbers - 1, 9, 16, 169 - and thus has a square number digit density of 4/3, or 1.33. The 4-digit number 1444 has 6 squares - 1, 4, 4, 4, 144, 1444 - and thus a ratio of 6/4, or 1.5. Notice in the previous example that squares are allowed to be repeated. Also, 441 is not allowed, because it cannot be found consecutively inside the number 1444.

Your task is to write a program that searches a given range A - B (inclusive) for the number with the highest square number digit density. Your program should abide by the following specifications:

* Take input A, B in the range 1 to 1,000,000,000 (1 billion). Example: `sndd 50 1000`
* Return as a result the number with the largest SNDD. In the case of a tie, return the smallest number.
* 0 does not count as a square in any form, 0, 00, 000, etc. Neither do squares starting with 0, such as 049 or 0049.
* Note that the entire number does not have to be a square number.

Examples:

```
sndd 14000 15000
Output: 14441

sndd 300 500
Output: 441

```

Bonus: What is the number with the largest SNDD between 1 and 1,000,000,000? Can you prove whether this is the largest possible, or there might be a larger one in a higher range?

**Current Scores:**

1. Ruby: 142
2. Windows PowerShell: 153
3. Scala: 222
4. Python: 245

Now that an answer has been selected, here is my (ungolfed) reference implementation in JavaScript: http://jsfiddle.net/ywc25/2/

# Answer
## Ruby 1.9, 142 characters

```
$><<($*[0]..$*[1]).map{|a|n=0.0;(1..s=a.size).map{|i|n+=a.chars.each_cons(i).count{|x|x[0]>?0&&(r=x.join.to_i**0.5)==r.to_i}};[-n/s,a]}.min[1]

```
* (139 -\> 143): Fixed output in case of a tie.
> 3 votes

# Answer
Answering the bonus: the best score for numbers \<1e9 is 5/3=1.666..., generated by 144411449 (and maybe others?).

But you can do better with larger numbers. Generally if n has a score of x, then you can concatenate two copies of n and get the same score x. If you're lucky and n has the same first and last digit, then you can drop one of those digits in the concatenation and improve your score slightly (one less than double the number of squares and one less than double the number of digits).

n=11449441 has a score of 1.625 and has the same first & last digit. Using that fact, we get the following sequence of scores:

```
1.625 for 11449441
1.666 for 114494411449441
1.682 for 1144944114494411449441
1.690 for 11449441144944114494411449441
1.694 for 114494411449441144944114494411449441

```

which gives an infinite sequence of numbers which are strictly (although decreasingly) better than previous numbers, and all but the first 2 better than the best score for numbers \< 1e9.

This sequence may not be the best overall, though. It converges to a finite score (12/7=1.714) and there may be other numbers with better scores than the limit.

**Edit**: a better sequence, converges to 1.75

```
1.600 14441
1.667 144414441
1.692 1444144414441
1.706 14441444144414441
1.714 144414441444144414441

```
> 8 votes

# Answer
## Windows PowerShell, 153 ~~154~~ ~~155~~ ~~164~~ ~~174~~

```
$a,$b=$args
@($a..$b|sort{-(0..($l=($s="$_").length)|%{($c=$_)..$l|%{-join$s[$c..$_]}}|?{$_[0]-48-and($x=[math]::sqrt($_))-eq[int]$x}).Count/$l},{$_})[0]

```

Thanks to Ventero for a one-byte reduction I was too stupid to find myself.

154-byte version explained:

```
$a,$b=$args   # get the two numbers. We expect only two arguments, so that
              # assignment will neither assign $null nor an array to $b.

@(   # @() here since we might iterate over a single number as well
    $a..$b |  # iterate over the range
        sort {   # sort
            (   # figure out all substrings of the number
                0..($l=($s="$_").length) | %{  # iterate to the length of the
                                               # string – this will run off
                                               # end, but that doesn't matter

                    ($c=$_)..$l | %{       # iterate from the current position
                                           # to the end

                        -join$s[$c..$_]    # grab a range of characters and
                                           # make them into a string again
                    }
                } | ?{                     # filter the list
                    $_[0]-48 -and          # must not begin with 0
                    ($x=[math]::sqrt($_))-eq[int]$x  # and the square root
                                                     # must be an integer
                }

            ).Count `  # we're only interested in the count of square numbers
            / $l       # divided by the length of the number
        },
        {-$_}  # tie-breaker
)[-1]  # select the last element which is the smallest number with the
       # largest SNDD

```
> 3 votes

# Answer
## Python, 245 256

```
import sys
def t(n,l):return sum(map(lambda x:int(x**0.5+0.5)**2==x,[int(n[i:j+1])for i in range(l)for j in range(i,l)if n[i]!='0']))/float(l)
print max(map(lambda x:(x,t(str(x),len(str(x)))),range(*map(int,sys.argv[1:]))),key=lambda y:y[1])[0]

```
* 256 → 245: Cleaned up the argument parsing code thanks to a tip from Keith Randall.

This could be a lot shorter if the range were read from `stdin` as opposed to the command line arguments.

**Edit:**

With respect to the bonus, my experiments suggest the following:

**Conjecture 1**. *For every n* ∈ ℕ*, the number in* *n* *with the largest SNDD must contain solely the digits 1, 4, and 9.*

**Conjecture 2.***n* ∈ ℕ ∀ i ∈ ℕ*n* : SNDD(*n*) ≥ SNDD(*i*).

**Proof sketch**. The set of squares with digits 1, 4, and 9 are likely finite. ∎
> 2 votes

# Answer
## Scala, 222

```
object O extends App{def q(i: Int)={val x=math.sqrt(i).toInt;x*x==i}
println((args(0).toInt to args(1).toInt).maxBy(n=>{val s=n+""
s.tails.flatMap(_.inits).filter(x=>x.size>0&&x(0)!='0'&&q(x.toInt)).size.toFloat/s.size}))}

```

(Scala 2.9 required.)
> 2 votes

# Answer
Considering the bonus question: Outside of the range the highest possible SNDD is infinite.

At least, if I read the question correctly, a square like 100 (10\*10) does count.

If you consider the number 275625, the score is 5/6, since 25, 625, 5625, 75625 and 275625 are all square.

Adding 2 zero's gives: 27562500, which has a score of 10/8. The limit of this sequence is 5/2=2.5

Along the same lines, you can find squares which end in any number of smaller squares desired. I can proof this, but you probably get the idea.

Admittedly, this is not a very nice solution, but it proofs there's no upper limit to the SNDD.
> 1 votes

# Answer
## Clojure - 185 chars

Probably could be optimised further but here goes:

```
(fn[A,B]((first(sort(for[r[range]n(r A(inc B))s[(str n)]l[(count s)]][(/(count(filter #(=(int%)(max 1%))(for[b(r(inc l))a(r b)](Math/sqrt(Integer/parseInt(subs s a b))))))(- l))n])))1))

```

Used as a function with two parameters:

```
(crazy-function-as-above 14000 15000)
=> 14441

```
> 1 votes

# Answer
# Jelly, 21 bytes, language postdates challenge

```
DµẆ1ị$ÐfḌÆ²S÷L
rµÇÐṀḢ

```

Try it online!

## Explanation

Helper function (calculates digit density of its input):

```
DµẆ1ị$ÐfḌÆ²S÷L
Dµ              Default argument: the input's decimal representation
  Ẇ             All substrings of {the decimal representation}
      Ðf        Keep only those where
   1ị$          the first digit is truthy (i.e. not 0)
        Ḍ       Convert from decimal back to an integer
         Æ²     Check each of those integers to see if it's square
           S    Sum (i.e. add 1 for each square, 0 for each nonsquare)
            ÷L  Divide by the length of {the decimal representation}

```

Main program:

```
rµÇÐṀḢ
rµ              Range from the first input to the second input
  ÇÐṀ           Find values that maximize the helper function
     Ḣ          Choose the first (i.e. smallest)

```

The program's arguably more interesting without the  – that way, it returns all maximal-density numbers rather than just one – but I added it to comply with the specification.
> 1 votes

# Answer
# Japt `-h`, 18 bytes

Well, this is pretty hideous!

```
õV ñÈì ã fÎxÈì ¬v1

```

Try it

```
õV ñÈì ã fÎxÈì ¬v1     :Implicit input of integers U & V
õV                     :Range [V,U]
   ñ                   :Sort by
    È                  :Passing each through the following function
     ì                 :  Convert to digit array
       ã               :  Sub-arrays
         f             :  Filter by
          Î            :    First element (0 is falsey)
           x           :  Reduce by addition after
            È          :  Passing each through the following function
             ì         :    Convert from digit array
               ¬       :    Square root
                v1     :    Divisible by 1?
                       :Implicit output of last element

```
> 0 votes

---
Tags: code-golf, number-theory
---


title: Find out your Ghost ghost name

text:
# Question
Title: Find out your Ghost ghost name
Inspired by a tweet by Nathan W. Pyle

There is, now, a standard method of converting your boring, normal human name into a mysterious, ethereal Ghost Name™. Ably described by Mr Pyle...

```
Use your first name:

a - add “t” after it

e - add “boo” after it

h - becomes “s”

n - add “oo” after it

r - add “eee” after it

y - add “oo” after it

that’s it that’s your ghost name

```

(Note that the rule for h is a substitution, not an append)

Well, needless to say we don't want to waste too many chars of code converting your name, time for some golfing!

The task:

* Convert a single-word string of a name into a Ghost Name™
* Your code will accept a string and output a string
* Upper-case letters will still be converted. The appended strings will appear after an upper-case version of their letter, and an upper-case H will become an upper-case S.
* Spaces, punctuation, anything other than the prescribed letters will remain unchanged.

Rules:

* It's code golf, attempt to make the Ghost Name™ conversion in as few bytes as possible.
* Please include a link to an online interpreter, such as TIO.

Test Cases

```
Andrew               > Atnoodreeeeboow
Stephanie            > Steboopsatnooieboo
Harry                > Satreeereeeyoo
Tim                  > Tim
Tonleeboo            > Tonoolebooebooboo
Great Britain        > Greeeebooatt Breeeitatinoo
L33t H4x0rz          > L33t S4x0reeez
catfaceemoji       > cattfatcebooeboomoji

```

Satppyoo golfinoog!

# Answer
> 4 votes
# JavaScript (Node.js), 92 bytes

```
s=>s.replace(/[aehnry]/gi,c=>[c+'boo',c+'t',c+'eee',c>{}?'s':'S',c+'oo'][Buffer(c)[0]%16%5])

```

Try it online!

### Commented

```
s =>              // s = input string
s.replace(        // replace in s:
  /[aehnry]/gi,   //   look for all instances of these characters,
                  //   ignoring their case
  c =>            //   for each character c:
  [               //     lookup table:
    c + 'boo',    //       0: add 'boo' to 'e'
    c + 't',      //       1: add 't' to 'a'
    c + 'eee',    //       2: add 'eee' to 'r'
    c > {} ? 's'  //       3: turn 'h' into 's' and 'H' into 'S'
           : 'S', //
    c + 'oo'      //       4: add 'oo' to either 'n' or 'y'
  ]               //
  [               //     hash function:
    Buffer(c)[0]  //       ASCII code modulo 16 modulo 5
    % 16 % 5      //       (this is case insensitive)
  ]               //
)                 // end of replace()

```

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