23
\$\begingroup\$

This is the robbers' thread of this challenge

The cops will choose an OEIS sequence and write two full programs in two different languages that produces that nth item in the sequence when given an n via STDIN. The two programs must be anagrams of each other, meaning each can be rearranged from the other's letters.

They will present the OEIS number, the source code for and the name of one language it is in.

You must find an anagram of the original cop's submission that runs in a language other than the one used by the cop. To crack an answer you must only find any language and program which produces the sequence and is an anagram of the original, not necessarily the answer the cop was thinking about.

You may output by character code or include STDERR in your solution, but only if the cop has indicated their hidden solution does so. Decimal output to STDOUT is always a valid crack.

Thus cops are incentivized to make it as hard as possible to find any language that does the task using their list of symbols.

Scoring

The person with the most cracks will be the winner of this section. Only the first crack for each solution will count towards one's score.

Leader Board

Big thanks to every one that took place in this challenge.

Here is the leader board as it stands

Place  User             Score
-----------------------------
1      Adnan            3
1      Kritixi Lithos   3
1      Emigna           3
1      milk             3
5      Steven H.        2
5      Wheat Wizard     2
5      jimmy23013       2
8      ETH Productions  1
8      Dennis           1
8      alleks           1
8      Martin Ender     1
8      Oliver           1
8      Conor O'Brien    1
\$\endgroup\$
4
  • \$\begingroup\$ Not sure I understand the "anagram" part, could you elaborate a bit? \$\endgroup\$ Nov 11, 2016 at 17:37
  • \$\begingroup\$ @TheBitByte The other solution has to use all of the same characters as the original but rearranged in a different order. \$\endgroup\$
    – Wheat Wizard
    Nov 11, 2016 at 17:39
  • \$\begingroup\$ Without any additional characters? \$\endgroup\$ Nov 11, 2016 at 17:59
  • \$\begingroup\$ @TheBitByte yes and without removing any characters \$\endgroup\$
    – Wheat Wizard
    Nov 11, 2016 at 18:12

24 Answers 24

9
\$\begingroup\$

05AB1E, 38 bytes, Loovjo, A000290

nXtdief e():return X*X
pr e(input())##

Try it online!

Very likely not the intended solution, but it works.

Explanation

n      # square input
 X     # push 1
  t    # push sqrt(1)
   d   # push is_number(1.0)
    i  # if true do the rest of the code (1.0 is not a number so it will never execute)
\$\endgroup\$
2
  • 1
    \$\begingroup\$ 1.0 is not a number? Could you please elaborate? \$\endgroup\$ Nov 9, 2016 at 16:41
  • 1
    \$\begingroup\$ @ETHproductions: the function is_number checks that the number only consist of 0-9. As . is not a number, it becomes false. The function could use a more descriptive name :) \$\endgroup\$
    – Emigna
    Nov 9, 2016 at 16:45
8
\$\begingroup\$

Jolf, 15 bytes, Adnan, A000290

*&"?!#$|<=@\^{}

Try it here! Definitely not the intended solution, but hey, it works.

Explanation

*&"?!#$|<=@\^{}
*                multiply
 &               the two inputs to this func, x, y: x && y
                 returns y if x and y, or the falsey argument.
  "?!#$|<=@\^{}  this string is always truthy, so the second arg is used.
                 two implicit inputs are taken, both equal to the first arg
                 so, this corresponds to *xx, which is x^2.
\$\endgroup\$
7
\$\begingroup\$

05AB1E, 49 bytes, Wheat Wizard, A000290

Actually the same approach as Emigna's crack :p.

n4i<({({)({[()]){))()()()turpetne/"*"*splint>}}}}

Explanation:

n          # Square the input
 4i        # If 4 == 1, do the following...
   <({...

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Not the solution I was looking for but +1 anyway \$\endgroup\$
    – Wheat Wizard
    Nov 9, 2016 at 16:01
7
\$\begingroup\$

05AB1E, 35 bytes, Oliver, A000290

Cops should stop posting n^2 challenges in python...

n0iprt(input()**(1+1))
"'1°3¢','m'"

Try it online!

Explanation

n    # square input
 0i  # if 0 == 1 do the rest of the code
\$\endgroup\$
6
\$\begingroup\$

2sable, 7 bytes, Kritixi Lithos, A005843

Code:

r^#ei2*

Explanation:

r         # Reverse the stack, which is a no-op
 ^        # XOR the input with itself, always leading to 0
  #       # If 1, break (which stops the program)
   e      # Compute input nPr input, which always leads to 1
    i     # If equal to one, do the following..
     2*   #   Multiply the input by 2.

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ It's wonderful how the actual code is only 2 bytes! \$\endgroup\$
    – user41805
    Nov 10, 2016 at 7:44
6
\$\begingroup\$

Hexagony, 13 bytes, Adnan, A002378

?"&\>=})\*!@<

Try it online!

Unfolded:

  ? " &
 \ > = }
) \ * ! @
 < . . .
  . . .

Not 100% whether this is the original, because the top left \ is unused.

The <\> are just mirrors, so the program is actually entirely linear:

?"&)}=*!@

?          Read input.
 "         Move back and left.
  &        Copy input.
   )       Increment copy.
    }=     Move forward and right and turn around (to face the n and n+1 edges).
      *    Multiply.
       !   Print.
        @  Terminate.
\$\endgroup\$
0
5
\$\begingroup\$

V, 13 bytes, DJMcMayhem, A002275

v!:x]''"
@ai1

Try it online!

This might be the first solution in the language the author intended.


Explanation

v!:x]''"   Does nothing
@ai1       inserts 1 a times
\$\endgroup\$
3
  • \$\begingroup\$ Perhaps you should let DJMcMayhem know you cracked it? ;) \$\endgroup\$ Nov 10, 2016 at 1:07
  • \$\begingroup\$ @ETHproductions I told him in chat I will probably tell him again in comments. \$\endgroup\$
    – Wheat Wizard
    Nov 10, 2016 at 1:12
  • 1
    \$\begingroup\$ This might be the first solution in the language the author intended. Spot on. :) \$\endgroup\$
    – DJMcMayhem
    Nov 10, 2016 at 1:15
5
\$\begingroup\$

2sable, Conor O'Brien, A000290

~*

Try it online!

I don't know how it works, there's really only one program that meets the requirements and I just brute-forced to find the language it worked in.

After looking through the docs, I am able to come up with an explanation:

~         Push Input OR Input (always pushes the input)
 *        Multiply that by Input 
\$\endgroup\$
5
\$\begingroup\$

Pyth, 26 bytes, Steven H., A023443

Code:

tQ.qly 7:esau0euii s uxC !

Try online.

Fairly simple:

 Q                            Reads input
t                             Substracts 1 from it
  .q                          Quits program (implicit print)
    ly 7:esau0euii s uxC !    None of this ever plays a part...
                                I just thought it'd be fun to scramble it.
\$\endgroup\$
3
  • 2
    \$\begingroup\$ Intended solution! (minus the scrambling, of course.) \$\endgroup\$
    – Steven H.
    Nov 11, 2016 at 6:14
  • 1
    \$\begingroup\$ That's awesome! Nice idea. Sorry about not letting you know directly... Too little rep. \$\endgroup\$
    – alleks
    Nov 11, 2016 at 6:23
  • \$\begingroup\$ No problem! Congrats. \$\endgroup\$
    – Steven H.
    Nov 11, 2016 at 6:55
5
\$\begingroup\$

Python 3, 118 bytes, ETHproductions, A042545

s,a=801**.5-28,[0,0==0]
for i in range(int(input())):a+=[a[i]+a[-1]*int(1/s)];s=1/s-1//s
(print(a[-2]),) #.0fhlmop|

Test it on Ideone.

Cop submission

i=input();s=1/(801**.5-28);a=[0,1]
for p in range(i):a+=[a[-2]+a[-1]*int(s)];s=1/(s-int(s))
print a[i]#,,,.//000fhlmo|

What's different

The cop submission doesn't work in Python 3 for two reasons.

  • Python 2's input function automatically evals one line of input, while Python 3's counterpart just returns the line as a string. We can simply call int to fix this.

  • print was a statement in Python 2, but it is a function in Python 3. In particular, that means that we have to surround its argument with parentheses.

That means we need int() and (), but those characters aren't all part of the comment. That means we must make some changes.

Instead of the fraction s, we keep track of 1/s.

The initialization of ss=1/(801**.5-28) – becomes s=801**.5-28, saving the characters 1/().

The factor of a[-1] in the update of aint(s) – becomes int(1/s), costing the characters 1/.

The update of ss=1/(s-int(s)) – becomes s=1/s-1//s, costing the characters 1//, but saving the characters (int()).

The saved characters in ()(int()) cover those we needed to port the code to Python 3, but obtaining them cost us 1//. We can take // from the comment, but we'll have to save 1 elsewhere.

One way (the only one?) of saving the needed 1 is to replace the 1 in the initialization of a with 0==0. This costs those four characters, but we can take 00 from the comment.

So far, we have the following code.

i=int(input());s=801**.5-28;a=[0,0==0]
for p in range(i):a+=[a[-2]+a[-1]*int(1/s)];s=1/s-1//s
print(a[i]) #,,,.()0fhlmo|

To recover one of the = we now "owe", we can rewrite the initialization of s and a with a single assignment: s,a=801**.5-28,[0,0==0] Additionally, this saves a ; and costs a ,, which can be be added to and removed from the comment.

The second = can be saved by not storing the input in a variable, i.e., writing range(int(input())) instead, saving the characters in i=. We use i after the loop as well, but the ith element of a is just the second one from the right, so we can replace i with -2. For the same reason, a[-2] in the loop body can be replaced with i.

We now have a permutation into working Python 3 code:

s,a=801**.5-28,[0,0==0]
for i in range(int(input())):a+=[a[i]+a[-1]*int(1/s)];s=1/s-1//s
print(a[-2]) #,.()0fhlmop|

However, this code also works in Python 2! One way of fixing this is to replace print(a[-2]) with (print(a[-2]),); we have the characters we need in the comment. As mentioned before, print is a function in Python 3, so this constructs the tuple (None,). However, Python 2's print statement is a SyntaxError inside a tuple literal.

\$\endgroup\$
6
  • \$\begingroup\$ Dang, nice... maybe I should've spent a little more time writing a comment-less version. I'll post my intended solution. \$\endgroup\$ Nov 11, 2016 at 13:49
  • \$\begingroup\$ I've created a modified version of my program that works in both Python 2 and 3, uses no comments, and has a very different (intended) solution. Is it worth posting as a separate answer? \$\endgroup\$ Nov 11, 2016 at 14:51
  • \$\begingroup\$ If it works in both Python 2 and 3, it's not a valid solution. The crack cannot work in the original language. \$\endgroup\$
    – Dennis
    Nov 11, 2016 at 14:52
  • \$\begingroup\$ I don't understand. The intended crack isn't in Python. \$\endgroup\$ Nov 11, 2016 at 15:01
  • \$\begingroup\$ Oh, you mean a new cop submission. I thought we were talking about a different crack to this one... Sure, go ahead and post it. \$\endgroup\$
    – Dennis
    Nov 11, 2016 at 15:02
4
\$\begingroup\$

CJam, 39 bytes, milk, A000007

l~0{"e.bockj(>=@$t0)@$t0+(<7)??0t:"};1?

Try it here.

\$\endgroup\$
4
\$\begingroup\$

Pyth, 7 bytes, Luis Mendo, A000217

x:{ps}1

As requested, the program exits with error after printing the correct answer.

Try it online here!

\$\endgroup\$
3
\$\begingroup\$

05AB1E, 12 bytes, tuskiomi, A000012

1,(FI1=1=1,)

Try it online!

Explanation

1,            # print 1
  (           # negate input
   F          # that many times do (i.e. no times)
    I1=1=1,)  # the rest of the code
\$\endgroup\$
1
  • \$\begingroup\$ Funny. I didn't have a 2nd program for this, because I didn't understand what cops and robbers was (whoops). good job being inventive! \$\endgroup\$
    – tuskiomi
    Jul 24, 2017 at 16:36
3
\$\begingroup\$

05AB1E, 38 bytes, Conor O'Brien, A000290

n2iJ=>eval(Array(J).fill(J).jo`+`)|-2;

Try it Online!


Explanation

This is based on Emigna's crack here.

n   #Squares the number
 2i #Runs the rest of the code if 2==1
\$\endgroup\$
1
  • \$\begingroup\$ I've edited my answer with the intended solution. nice job! I'll have to rethink my approach... \$\endgroup\$ Nov 10, 2016 at 0:46
3
\$\begingroup\$

05AB1E, 27 bytes, boboquack, A000012

1 1pif:
    if :
        rint( '1' )

Try it online

How it works:

1                     # push 1
  1                   # push 1
   p                  # pop (1), push is_prime(1)
    i                 # pop (is_prime(1), false), if is false so don't execute rest
\$\endgroup\$
2
\$\begingroup\$

CJam, 70 bytes, Shebang, A000217

ri),:+








e#|  d00->1@@@++-^,[o=input(v=0i=1whil o v=i i+=1pnt v

Try it here.

\$\endgroup\$
1
  • \$\begingroup\$ I was afraid of the CJam solution ;) \$\endgroup\$
    – Kade
    Nov 9, 2016 at 20:54
2
\$\begingroup\$

Convex, 75 bytes, boboquack, A004526

2/Q2 2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2*2*2*; 2*;                 2; 2; 2;

Try it online

How it works:

2  e# push 2
 / e# pop first 2, divide, push result
   e# push a bunch of garbage but discard it all with semi-colons (;)
  Q2 2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2*2*2*; 2*;                 2; 2; 2;
\$\endgroup\$
2
\$\begingroup\$

Dip, 9 bytes, Kritixi Lithos

Definitely not the intended answer.

1^,-$)×1*

Explanation:

1$^,-)×   # Basically does nothing
       1* # Repeat "1" n times
\$\endgroup\$
1
  • \$\begingroup\$ Now all that's left for me is to crack your A000042 answer too! \$\endgroup\$
    – user41805
    Nov 10, 2016 at 17:41
2
\$\begingroup\$

Pip, 6 bytes, DLosc, A000012

.()49o

I figured I'd try the OP's esolang first ;-)

Try it online.

\$\endgroup\$
1
  • \$\begingroup\$ I was actually curious to see if there were a different one where it would work. :) But good job. \$\endgroup\$
    – DLosc
    Nov 11, 2016 at 19:25
1
\$\begingroup\$

05AB1E, 25 bytes, Mego, A000583

Code:

nnYi=put("");prit`Y**4`,X

Explanation:

n       # Square the input
 n      # Square the squared input
  Y     # Constant that pushes 2
   i    # If equal to 1, do the following:
    =put...

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Oh come on, You beat me by 12 seconds :) \$\endgroup\$
    – Emigna
    Nov 10, 2016 at 11:41
  • \$\begingroup\$ @Emigna The time between the answers is uncanny :p. \$\endgroup\$
    – Adnan
    Nov 10, 2016 at 11:43
  • 1
    \$\begingroup\$ It didn't register the first time I pressed post either, so they would have been almost instantaneous :) \$\endgroup\$
    – Emigna
    Nov 10, 2016 at 11:45
1
\$\begingroup\$

Dip, 8 bytes, Oliver, A000042

(1J&F},1

Explanation

              #Implicit Input
(             #Start range loop
 1            #Push 1 to the stack
  J           #Join all the elements in the stack
   &          #End program
    F},1      #These are ignored

The funny thing is that this was the intended language! Dip is an esolang created by Oliver.

Test Cases and Running Dip from Command-Line

$python3 dip.py
Dip v1.0.0 by Oliver Ni.
>>> (1J&F},1
> 4
1111
>>> (1J&F},1
> 7
1111111
\$\endgroup\$
1
\$\begingroup\$

2sable, 14 bytes, Dopapp, A121377

Q@5 2*%6 8*+.&

Try it online.

How it works (more or less):

Q@
  5              # Push 5
    2            # Push 2
     *           # Pop (2), pop (5), push 5*2=10
      %          # Pop (10), pop (input), push input%10
       6         # Push 6
         8       # Push 8
          *      # Pop (8), pop (6), push 8*6=48
           +     # Pop (48), pop (input), push input+48
            .&
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 4 bytes, Oliver, A000012

p¥_1

Try it online!

This is a sequence of 1s.

              # Implicit input
p¥_           # Does nothing
   1          # Pushes 1 to the stack
              # Implicit output

This outputs 1 no matter what the input is.

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

Dip, 5 bytes, Oliver, A000012

`¸WW/

The sequence just prints a 1 no matter what the input is. Oliver's answer prints a 1.0. This program also prints a 1.0. This apparently is the intended solution.

Explanation

`¸                  # push character `¸`
  W                 # pushes 1000000
   W                # pushes 1000000 also
    /               # divides the last two items in stack resulting in 1.0
                    # implicit output (1.0)

Alternative solution (courtesy of @milk)

Convex, 5 bytes

WW¸`/

Try it online!

Explanation

                  // implicit input
W                 // pushes -1
 W                // pushes -1 also
  ¸               // calculates the LCM of the two numbers (which evaluates to 1)
   `              // finds its string representation
    /             // slices the string (so that it would evaluate to "1")
                  // implicit output
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Alternate crack in Convex: WW¸`/ \$\endgroup\$
    – milk
    Nov 11, 2016 at 17:37
  • \$\begingroup\$ @milk Thanks! I added it in my latest edit \$\endgroup\$
    – user41805
    Nov 11, 2016 at 17:40
  • \$\begingroup\$ Your Convex program kinda doesn't work as you think it does. As of right now, it pushes -1 twice, LCMs them (which would be 1), finds the string representation, and finally slices the string (which would be "1") by every [input] characters (since the input is a number. \$\endgroup\$
    – GamrCorps
    Nov 13, 2016 at 13:23
  • \$\begingroup\$ @GamrCorps How's it now? \$\endgroup\$
    – user41805
    Nov 13, 2016 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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