11
\$\begingroup\$

This is the cop's thread, where one should post the scrambled code. Here is the robbers' thread where the cracked source should be posted and linked to the cop's answer.


NB: I am currently writing up the edit for who won on both the Cops and Robbers forum. Any answer that is not marked as safe on the Cops thread as of April 15 will not be counted as competing, however you are still allowed to post answers, mark them as safe and crack them.
Any answer that is still not cracked or marked as safe as of April 15 will be counted as non-competing, which I have a seperate leaderboard for. (safe non-competing and competing answers)


Task: Write the shortest safe program that given two inputs \$x,y\$, outputs \$\arg(x+iy)\$, where \$\arg(z)\$ is defined as the angle between the positive real axis and the line joining the origin and \$z\$.


This is , so the rules are:

  • In your answer, post a scrambled version of your source code, which should not work. (should be written in any order)
  • You can take input/output in any standard way.
  • Hardcoding is forbidden.
  • Standard loopholes are banned.
  • If your code is cracked by the robbers, you must mention that it has been cracked in your title and include a spoiler containing your exact code.
  • Same thing applies for safe answers. (mention in the title that it's safe and include the spoiler)
  • You must specify the programming language you used and byte count.
  • Answers are considered safe after 5 days.

  • You can assume that \$|x|,|y|\le5\$.
  • You can also assume that \$x,y\in\mathbb Z\$
  • Minimum decimal precision is 5 decimal places with any rounding mechanism of your choice.
  • You must state the rounding mechanism in your answer.
  • You are not allowed to return as fractions (numerator/denominators)

+-------------+
|Example cases|
+-------------+

+ - + - + -------------------------- +
| x | y | Output (10 decimal places) |
+ - + - + -------------------------- +
| 5 | 5 |        0.7853981633        |
+ - + - + -------------------------- +
| 1 | 4 |        1.3258176636        |
+ - + - + -------------------------- +
| 0 | 2 |        1.5707963267        |
+ - + - + -------------------------- +
| 0 | 0 |         Undefined          |
+ - + - + -------------------------- +
| -1| 0 |        3.1415926535        |
+ - + - + -------------------------- +
| 1 | 0 |              0             |
+ - + - + -------------------------- +
| -2| 1 |        2.6779450445        |
+ - + - + -------------------------- +
| -3| -4|       -2.2142973355        |
+ - + - + -------------------------- +
| 2 | -5|       -1.1902899496        |
+ - + - + -------------------------- +

The shortest safe answer by April 15 will be considered the winner.


Update Apr 15: It's April 15th! Time to see who the winners are!

Shortest safe (competing) answers (top 5):

1st: LdBeth     |J          |10 bytes|
2nd: LdBeth     |J          |12 bytes|
2nd: Luis Mendo |MATL       |12 bytes|
4th: CrSb0001   |Mathematica|18 bytes|
5th: Greg Martin|Mathematica|46 bytes|

Shortest safe (competing and non-competing) answers (top 10):

NB: For a safe non-competing answer to qualify, it must have been posted
at the latest April 10th and still not have been cracked.

1st: LdBeth      |J                  |10 bytes|
2nd: LdBeth      |J                  |12 bytes|
2nd: Luis Mendo  |MATL               |12 bytes|
4th: CrSb0001    |Mathematica        |18 bytes|
5th: math seat   |Vyxal 3            |22 bytes|
6th: Greg Martin |Mathematica        |46 bytes|
7th: Neil        |Java (JDK)         |47 bytes|
8th: att         |Mathematica        |50 bytes|
9th: M Virts     |Python             |51 bytes|
10th: Arnauld    |JavaScript (NodeJS)|55 bytes|

Most "safe" languages (top 5):

NB: Counted by number of safe answers in that language. If there
is a tie, then it is sorted by the number of bytes. (increasing)
Answers that are non-competing are not counted in the total.

1st: Mathematica        |3 answers|114 bytes|
2nd: J                  |2 answers| 22 bytes|
3rd: MATL               |1 answer | 12 bytes|
4th: JavaScript (NodeJS)|1 answer | 55 bytes|
\$\endgroup\$
17
  • 1
    \$\begingroup\$ (1,0) has argument 0 and (-1,0) has argument pi. You should also have test cases in quadrants II, III, and IV. \$\endgroup\$
    – Tbw
    Commented Mar 15 at 20:41
  • 6
    \$\begingroup\$ Is there a reason for this task along with this kind of cops and robbers? Seems kind-of random. \$\endgroup\$
    – xnor
    Commented Mar 15 at 21:10
  • 6
    \$\begingroup\$ I would also like to note that this challenge is basically just asking people to implement the atan2 function. \$\endgroup\$
    – mbomb007
    Commented Mar 15 at 21:41
  • 2
    \$\begingroup\$ Does it matter what happens when the input is 0,0? \$\endgroup\$ Commented Mar 16 at 17:10
  • 3
    \$\begingroup\$ I understand that the mathematical function is undefined; I'm asking whether it matters what the code returns in that case, as long as it doesn't return a number. \$\endgroup\$ Commented Mar 16 at 17:41

23 Answers 23

4
\$\begingroup\$

JavaScript (Node.js), 51 bytes, Cracked

""%%%%%%%%%%()+0134445566677788[]``aaaacdeeeelnpsuv

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Cracked. \$\endgroup\$
    – Neil
    Commented Mar 15 at 22:57
4
\$\begingroup\$

Wolfram Language (Mathematica), 13 bytes, cracked by @totallyhuman

*crane*@RANT@

Displays the result to 6 significant figures, hence at least 5 decimal places.

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

Uiua 0.10.0, 14 bytes, cracked

↥⍥⌵)∠.⊃±×(0∩¬÷

Does not round the answer at all beyond what Uiua does natively.

Edit: my solution as a bit different from the cracked answer:

⍥(×÷.0)¬±↥⊃∩⌵∠

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

Wolfram Language (Mathematica), 53 bytes, cracked by @att

B{[[@#&#&#&#=!=/+<+/1122900,eternal,emote,ego]]}.IIII

Hint/teaser: the 31-byte subset @##&+{[}].,,,/112aeeeegIIImnrtt is almost a solution to this challenge, but it erroneously returns an error for inputs \$(x,0)\$ when \$x<0\$.

Solution to the teaser:

Im@Integrate[1/e,{e,1.,#+#2I}]&

\$\mathop{\rm arg}(x+iy)\$ is the imaginary part of \$\log(x+iy)\$; and \$\log z\$ is the antiderivative of \$\frac1z\$ (just like in the real numbers). When \$z\$ is complex but not real, Mathematica understands that it should do a contour integral that correctly computes \$\log z\$. However, when \$z\$ is real, Mathematica interprets this as a regular integral in the real numbers, and complains (understandably) when \$z\$ is negative.

Actual solution:

Im@Integrate[1/e,{e,1.,#+#2I+Boole[#<0&&#2==0]/9!I}]&

So we spend 22 more bytes adding a tiny imaginary part to any negative real input, forcing Mathematica to do the complex contour integral without affecting the output very much.

\$\endgroup\$
1
  • \$\begingroup\$ Cracked \$\endgroup\$
    – att
    Commented Mar 20 at 1:49
4
\$\begingroup\$

JavaScript (Node.js), 55 bytes, safe

The output is not explicitly rounded.

(())*++++++,,,,-/6=====BBBBBBBMMM[[[]]]aeffhhhhhrrrrrtu

Hint 1

This computes Math[Buffer(97, 116, 97, 110) + 2], starting with B = 6 and r = 1.

Hint 2

We compute h = "1"+6 = 16, 97 = 16*6+1, 116 = "1"+16 and 110 = 116-6.

Solution

Math[Buffer([M=(B=6,h=[r=B/B]+B)*B+r,h=r+++h,M,h-B])+r]

Try it online!

\$\endgroup\$
3
  • 2
    \$\begingroup\$ For anyone else trying to solve this confused by the lack of I/O: I'm fairly certain this is of the form Math[xxx] where xxx evaluates to atan2 somehow. \$\endgroup\$
    – emanresu A
    Commented Mar 17 at 8:35
  • \$\begingroup\$ This has been safe for a while, can you reveal the solution? \$\endgroup\$
    – emanresu A
    Commented Mar 27 at 22:38
  • \$\begingroup\$ @emanresuA Done! \$\endgroup\$
    – Arnauld
    Commented Mar 27 at 22:50
3
\$\begingroup\$

Wolfram Language (Mathematica), 46 bytes, cracked by vindobona

####&,22ACLNPT[[[[[[]]]]]]aabdeiilnoooorrssstt

Sorry I don't have words like Greg Martin did. Expects [x,y].

\$\endgroup\$
10
  • 1
    \$\begingroup\$ sort[boatloads[ironies]] ;) \$\endgroup\$ Commented Mar 17 at 18:49
  • \$\begingroup\$ Just to check (I'm sure you're right): there really should be four #s? If there were three #s, I've cracked it. \$\endgroup\$ Commented Mar 17 at 19:10
  • \$\begingroup\$ @GregMartin yes, four \$\endgroup\$
    – att
    Commented Mar 18 at 0:22
  • \$\begingroup\$ I can't figure out the last # :p What's the convention here: should I post my near miss to help other robbers, or just let the cop post stand for itself? \$\endgroup\$ Commented Mar 19 at 17:04
  • \$\begingroup\$ @GregMartin I'd be interested in seeing what you have, at least \$\endgroup\$
    – att
    Commented Mar 19 at 21:24
3
\$\begingroup\$

Wolfram Language (Mathematica), 46 bytes, safe

@@####^^&&--+{[[(())]]}.,,//122255AIISbmmmmmsu

As with my other submissions, this is an unnamed function of two variables. The output is printed to the default number of decimal places, and is correct to at least 11 decimal places. Solution:

Im@Sum[-5(1-(#/Abs@#)^.2)^m/m,{m,52}]&[#+I#2]&

Try it online! Explanation:

At its heart this code is simply one of the standard ways of calculating the argument of the complex number \$x+iy\$ as the imaginary part of its logarithm: Im@Log[#+I#2]& or, more verbosely, Im@Log@#&[#+I#2]&. The new approach is to replace \$\log (1-w)\$ by its power series \$-\sum_{m=1}^\infty w^m/m\$. Applying this formula with \$w=1-(x+iy)\$ gives

Im@Sum[-(1-#)^m/m,{m,52}]&[#+I#2]&

(The 52 ensures we're summing enough terms of the power series to get the required accuracy; the number itself is pretty arbitrary.) Unfortunately, the power series only converges when \$w\$ is close to \$1\$. So we exploit two mathematical tricks: first, we use the fact that \$\log z = 5\log(z^{1/5})\$ (this is dangerous in the complex numbers generally, but it's safe if we're declaring ahead of time that \$-\pi<\arg z\le\pi\$ as this challenge does) to limit the argument of \$w\$ in this application:

Im@Sum[-5(1-#^.2)^m/m,{m,52}]&[#+I#2]&

Second, we limit the modulus of \$w\$ by just replacing the input divided by its own modulus, resulting in the final code:

Im@Sum[-5(1-(#/Abs@#)^.2)^m/m,{m,52}]&[#+I#2]&

After these two tricks, the only numbers we input into the power series are those along a circular arc through the origin, which is well inside the radius of convergence of the power series and thus allows its truncation to 52 terms to be a good enough approximation to the true value.

graph of inputs to final function

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

Wolfram Language (Mathematica), 50 bytes, safe

##&(())**+,,.////0012@@DHIMN[[[[[]]]]]^^adeinrsttu

Expects [x,y].

Hint:

The result could be exact, if not for N

Minus

Solution

Head[((1.+#*#)^I^2&//Minus/@D[r@t,t][[0,0]])[]]/*N

Try it online!

This is mostly just a convoluted way to fetch ArcTan by performing a symbolic antiderivative.

Derivative[-1] performs an antiderivative.

Derivative is too obvious if all letters are present, but we can generate it with D[r@t,t]: Try it online! r and t are red herrings.

This yields Derivative[1][r][t]. We can fetch Derivative[1] by taking part [[0,0]], and negate the 1 with Minus/@.

Apply this on \$\arctan'\$ = (1.+#*#)^I^2& to obtain ArcTan[#1]&. Try it online!

There are a number of ways to extract ArcTan from this expression, but this uses Head[(...)[]]. The last step is composition with N.

\$\endgroup\$
2
\$\begingroup\$

C (gcc), 65 bytes, cracked by @Guido

No rounding.

hey, sexy
     #(()),,.2;<>aaaaaacdfffhhillllmnnnooorrsttttttuu{}
\$\endgroup\$
1
2
\$\begingroup\$

Python, 50 bytes, Cracked by @Mukundan314

from math import*
def j(l,a):a*me.fog.magic(l+0b1)

No rounding.

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

J, 11 bytes, cracked by @LdBeth

*&_,.1:_.&^

Takes a complex number in the form of x + 1j * y. Output is not rounded. The behavior is identical to the built-in 12&o.; returns zero on zero input.

Hint 1

A page that is two links away from NuVoc might be helpful.

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

Java (JDK), 47 bytes, safe

0000000000000023344466778\\\\\\\aaaaadeuuuuuuu

Takes arguments in the order y, x and doesn't round. Solution:

\u004da\u0074\u0068\u003a\u003aa\u0074a\u006e2

Try it online! Link includes test cases. Without Unicode escapes:

Math::atan2

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 4 ASCII code +7 unicode escape code, and possibly a space \$\endgroup\$
    – LdBeth
    Commented Apr 5 at 18:26
1
\$\begingroup\$

J, 10 bytes, safe

o.&:^._1r9

Does not round the answer.

Hint

There is ^:_1

Answer

9&o.r.^:_1, It might appear a bit weird that r. accepts complex number, but r. n is defined as \$e^{\mathbb{i}n}\$ in J, and the inverse of it is \$\ln(n)/\mathbb{i}\$, 9&o. only takes the real component of the result.

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

Vyxal 3, 22 bytes

ᵇİ0daṫȦ#+>Q[\\ik|¬¿÷∆∨

Input is taken as [y,x], output is not rounded. The program quits when received [0,0].
I had fun scrambling the code :p

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

C (gcc), 68 bytes

No rounding; this one's a bit more complex, so I'm giving you all a hint ;)

#include <math.h>
     (())*+,Iaaaaacceefffgllllnnnooooprrrtttttux{}
\$\endgroup\$
1
1
\$\begingroup\$

Go, 69 bytes, cracked by @Mukundan314

   ""(())./12468;PPaaaccceeefffhhilllmmmmnnnnooooppprrrsssttttuuwxx{}

Solution

import."math/cmplx";func Powfss(n complex128)float64{return Phase(n)}

Attempt This Online!

\$\endgroup\$
2
  • \$\begingroup\$ Cracked? \$\endgroup\$ Commented Mar 22 at 13:12
  • \$\begingroup\$ @Mukundan314 it seems to work on my end, so yes, I think it is a crack. \$\endgroup\$
    – CrSb0001
    Commented Mar 22 at 13:15
1
\$\begingroup\$

MATL, 12 bytes. Safe

*LUYYZjlssty

Non-required information provided as a courtesy for the robbers:

  • Input is a row vector of two numbers.
  • Output is not rounded.
  • Input [0 0] gives output 0.

Solution

Code

tZysUL*sYlYj

Try at MATL Online!

Explanation

t % Implicit input: row vector of two numbers. Duplicate

Zy % Size: gives [1 2]

s % Sum: gives 3

U % Square: gives 9

L % Paste from the 9th level of clipboard L: gives predefined literal [1 1i]

* % Multiply by original copy of input, element-wise

s % Sum: gives the complex number represented by the input

Yl % Logarithm

Yj % Imaginary part. Implicit display

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

J, 12 bytes, safe

^.(123!&o+).

A monadic tactic function that takes a complex number. No rounding performed.

Hint 1

The behavior is identical to the built-in 12&o.

Hint 2

Try to find a combination of the subset that gives the integer 12

Hint 3

Try (^123!+.)&o.

Answer

(3^!.1+2)&o., the trick is the stope ^!.n function, 3^!.1+2 <--> 3 * 4 <--> 12. And 12&o. is the complex number angle function in J.

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

Python, 2829 bytes

Maybe not the most well golfed submission, but hey maybe that'll help it not get cracked :D

It uses the math.atan2 to do the real work.

 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))),,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,--1122:::[[]]__________aaabbbdeeeeeeeeeeeegillllllllllmmnnnnnnnnnoprrrrssssttttttttyy
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I'm going to save this answer, it's now my favorite of all time lol \$\endgroup\$
    – CrSb0001
    Commented Apr 10 at 12:14
1
\$\begingroup\$

Python, 51 bytes

''''((())),,,2:____aaaaaaaabbbdeghilmmmnoprrtttttt

A bit better than my other one, still uses math.atan2

\$\endgroup\$
0
\$\begingroup\$

Wolfram Language (Mathematica), 57 bytes, Cracked by @att

()***++,,-/6:=AFIIILNNR[[[[[[]]]]]]__bbeefgmmoorrsuxxxyyy

Unsure if it is generally accepted to answer your own challenges or not, I just wanted to attempt it for fun.

Rounds to 6 sig figs (5 decimal places), like Greg Martin's 13-byte solution.

Intended solution:

f[x_,y_]:=NumberForm[Re[N[-I*Log[(x+I*y)/Abs[x+I*y]]]],6]

\$\endgroup\$
1
  • \$\begingroup\$ Cracked \$\endgroup\$
    – att
    Commented Mar 18 at 19:45
0
\$\begingroup\$

Wolfram Language (Mathematica), 31 bytes, cracked by Greg Martin

*+,6FIILNN[[[[]]]]begmmmoorruxy

Hopefully lasts more than 5 hours this time, also uses a different method. Lasted 10 hours! still cracked though :9

Intended sol:

NumberForm[N[Im[Log[x+I*y]]],6]

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

Wolfram Language (Mathematica), 18 bytes, safe

Yet again rounds to 6 sig figs. (also hopefully lasts more than 10 hours lol)

*+,6@IILN[[]]gmoxy

Solution:

N[Im@Log[x+I*y],6]

\$\endgroup\$
1
  • \$\begingroup\$ I strongly suspect the intended crack takes input in a nonstandard way. \$\endgroup\$
    – att
    Commented Apr 7 at 5:56

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.