Polyglot Anagrams Robbers' Thread

23

2

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

Post Rock Garf Hunter

Posted 2016-11-09T14:38:20.293

Reputation: 55 382

Not sure I understand the "anagram" part, could you elaborate a bit? – Buffer Over Read – 2016-11-11T17:37:49.223

@TheBitByte The other solution has to use all of the same characters as the original but rearranged in a different order. – Post Rock Garf Hunter – 2016-11-11T17:39:26.253

Without any additional characters? – Buffer Over Read – 2016-11-11T17:59:53.790

@TheBitByte yes and without removing any characters – Post Rock Garf Hunter – 2016-11-11T18:12:41.383

Answers

9

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)

Emigna

Posted 2016-11-09T14:38:20.293

Reputation: 50 798

11.0 is not a number? Could you please elaborate? – ETHproductions – 2016-11-09T16:41:45.257

1@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 :) – Emigna – 2016-11-09T16:45:22.093

8

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.

Conor O'Brien

Posted 2016-11-09T14:38:20.293

Reputation: 36 228

7

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!

Adnan

Posted 2016-11-09T14:38:20.293

Reputation: 41 965

1Not the solution I was looking for but +1 anyway – Post Rock Garf Hunter – 2016-11-09T16:01:37.933

7

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

Emigna

Posted 2016-11-09T14:38:20.293

Reputation: 50 798

6

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!

Adnan

Posted 2016-11-09T14:38:20.293

Reputation: 41 965

It's wonderful how the actual code is only 2 bytes! – user41805 – 2016-11-10T07:44:41.433

6

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.

Martin Ender

Posted 2016-11-09T14:38:20.293

Reputation: 184 808

5

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

Post Rock Garf Hunter

Posted 2016-11-09T14:38:20.293

Reputation: 55 382

Perhaps you should let DJMcMayhem know you cracked it? ;) – ETHproductions – 2016-11-10T01:07:40.053

@ETHproductions I told him in chat I will probably tell him again in comments. – Post Rock Garf Hunter – 2016-11-10T01:12:15.337

1This might be the first solution in the language the author intended. Spot on. :) – James – 2016-11-10T01:15:28.210

5

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 

Steven H.

Posted 2016-11-09T14:38:20.293

Reputation: 2 841

5

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.

alleks

Posted 2016-11-09T14:38:20.293

Reputation: 61

2Intended solution! (minus the scrambling, of course.) – Steven H. – 2016-11-11T06:14:10.790

1That's awesome! Nice idea. Sorry about not letting you know directly... Too little rep. – alleks – 2016-11-11T06:23:42.030

No problem! Congrats. – Steven H. – 2016-11-11T06:55:48.103

5

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.

Dennis

Posted 2016-11-09T14:38:20.293

Reputation: 196 637

Dang, nice... maybe I should've spent a little more time writing a comment-less version. I'll post my intended solution. – ETHproductions – 2016-11-11T13:49:02.077

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? – ETHproductions – 2016-11-11T14:51:24.153

If it works in both Python 2 and 3, it's not a valid solution. The crack cannot work in the original language. – Dennis – 2016-11-11T14:52:36.647

I don't understand. The intended crack isn't in Python. – ETHproductions – 2016-11-11T15:01:26.520

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. – Dennis – 2016-11-11T15:02:27.873

Yeah, sorry for the misunderstanding. – ETHproductions – 2016-11-11T15:03:09.857

4

CJam, 39 bytes, milk, A000007

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

Try it here.

jimmy23013

Posted 2016-11-09T14:38:20.293

Reputation: 34 042

4

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!

Steven H.

Posted 2016-11-09T14:38:20.293

Reputation: 2 841

3

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

Emigna

Posted 2016-11-09T14:38:20.293

Reputation: 50 798

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! – tuskiomi – 2017-07-24T16:36:50.693

3

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

Post Rock Garf Hunter

Posted 2016-11-09T14:38:20.293

Reputation: 55 382

I've edited my answer with the intended solution. nice job! I'll have to rethink my approach... – Conor O'Brien – 2016-11-10T00:46:56.390

3

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

milk

Posted 2016-11-09T14:38:20.293

Reputation: 3 043

2

CJam, 70 bytes, Shebang, A000217

ri),:+








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

Try it here.

jimmy23013

Posted 2016-11-09T14:38:20.293

Reputation: 34 042

I was afraid of the CJam solution ;) – Kade – 2016-11-09T20:54:16.660

2

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;

milk

Posted 2016-11-09T14:38:20.293

Reputation: 3 043

2

Dip, 9 bytes, Kritixi Lithos

Definitely not the intended answer.

1^,-$)×1*

Explanation:

1$^,-)×   # Basically does nothing
       1* # Repeat "1" n times

Oliver Ni

Posted 2016-11-09T14:38:20.293

Reputation: 9 650

Now all that's left for me is to crack your A000042 answer too! – user41805 – 2016-11-10T17:41:01.310

2

Pip, 6 bytes, DLosc, A000012

.()49o

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

Try it online.

ETHproductions

Posted 2016-11-09T14:38:20.293

Reputation: 47 880

I was actually curious to see if there were a different one where it would work. :) But good job. – DLosc – 2016-11-11T19:25:58.677

1

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!

Adnan

Posted 2016-11-09T14:38:20.293

Reputation: 41 965

Oh come on, You beat me by 12 seconds :) – Emigna – 2016-11-10T11:41:16.527

@Emigna The time between the answers is uncanny :p. – Adnan – 2016-11-10T11:43:24.133

1It didn't register the first time I pressed post either, so they would have been almost instantaneous :) – Emigna – 2016-11-10T11:45:08.280

1

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

user41805

Posted 2016-11-09T14:38:20.293

Reputation: 16 320

1

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.

user41805

Posted 2016-11-09T14:38:20.293

Reputation: 16 320

1

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
            .&

milk

Posted 2016-11-09T14:38:20.293

Reputation: 3 043

1

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

user41805

Posted 2016-11-09T14:38:20.293

Reputation: 16 320

1Alternate crack in Convex: WW¸`/ – milk – 2016-11-11T17:37:15.767

@milk Thanks! I added it in my latest edit – user41805 – 2016-11-11T17:40:28.340

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. – GamrCorps – 2016-11-13T13:23:12.313

@GamrCorps How's it now? – user41805 – 2016-11-13T13:36:23.837