37
\$\begingroup\$

Note: This is the cops' 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.


Task: Write the shortest safe program which multiplies the square root of an integer n by the square of n

This is , so the rules are:

  • In your answer, post a scrambled version of your source code (the characters should be written in any order). The scrambled version should not work!
  • You can take input in any standard way, the same goes for output. Hardcoding is forbidden
  • After the code is cracked by the robbers (if this happens), you must mention that your code has been cracked in your title and add a spoiler to your answer's body with your exact code
  • The same applies to safe answers (mention that it's safe and add the spoiler)
  • The code is considered safe if nobody has cracked it in 5 days after posting it and you can optionally specify that in the title
  • You must specify your programming language
  • You should specify your byte count
  • You must state the rounding mechanism in your answer (see below)

You can assume that the result is lower than 232 and n is always positive. If the result is an integer, you must return the exact value with or without a decimal point; otherwise the minimum decimal precision will be 3 decimal places with any rounding mechanism of your choice, but can include more. You must state the rounding mechanism in your answer. You are not allowed to return as fractions (numerator, denominator pairs - sorry, Bash!)

Examples:

In -> Out

4 -> 32.0 (or 32)
6 -> 88.18163074019441 (or 88.182 following the rules above)
9 -> 243.0
25 -> 3125.0

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

\$\endgroup\$
26
  • 2
    \$\begingroup\$ Related. (Same CnR rules, different task.) \$\endgroup\$ Apr 3, 2017 at 12:57
  • 3
    \$\begingroup\$ @MartinEnder If the task is the only thing differing, then isn't it a duplicate? \$\endgroup\$ Apr 3, 2017 at 14:48
  • 1
    \$\begingroup\$ @NathanMerrill I don't know, I don't think we have any established duplicate guidelines for cops and robbers challenge, but if I ask a new code-golf challenge, where the "only" thing that's different from a previous code golf is the task, it's usually not considered a duplicate. ;) (That said, I agree that CnRs are probably more interesting if we change up the CnR-part of the challenge, not the underlying task.) \$\endgroup\$ Apr 3, 2017 at 14:50
  • 1
    \$\begingroup\$ Good luck everyone! I am really glad that you have decided to reopen this. Looking forward to see interesting answers! \$\endgroup\$
    – Mr. Xcoder
    Apr 3, 2017 at 15:23
  • 2
    \$\begingroup\$ I had written my code to work for an input up to 2^32... Which is why I asked about rounding errors, got rather off the mark at that point \$\endgroup\$ Apr 3, 2017 at 16:19

68 Answers 68

18
\$\begingroup\$

Python 3, 44 bytes (cracked)

'**:(((paraboloid / rabid,mad,immoral))):**'

No rounding. Floating point accuracy.

\$\endgroup\$
2
  • 4
    \$\begingroup\$ Come on, this deserves more points, it's so creative! There is symmetry, and all words are real words. \$\endgroup\$ Apr 8, 2017 at 18:12
  • \$\begingroup\$ If I didn't make any silly mistakes... Cracked \$\endgroup\$
    – KSab
    Apr 12, 2017 at 14:17
11
\$\begingroup\$

MATL, 12 bytes (cracked by @tehtmi)

'Un&0P'/^:+1

No rounding; uses floating point.

Intended solution (different from that found by @tehtmi):

:&+n10U'P'/^

Explanation

:&+ % Create a matrix of size n × n, where n is implicit input
n % Number of elements. Gives n^2
10U % 10 squared. Gives 100
'P' % 'P' (ASCII code 80)
/ % Divide. Gives 1.25
^ % Power. Implicit display

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Crack? \$\endgroup\$
    – tehtmi
    Apr 6, 2017 at 5:16
  • \$\begingroup\$ @tehtmi Indeed! Well done! My intended solution was different; I just posted it \$\endgroup\$
    – Luis Mendo
    Apr 6, 2017 at 9:20
10
\$\begingroup\$

Röda, 28 bytes (Cracked by @tehtmi)

 (),.025^^cdfhnnnopprstuu{|}

Note the space at the beginning. No rounding, but it uses floating point numbers so precision is limited.

\$\endgroup\$
3
  • \$\begingroup\$ Is this an anonymous function, or a "full" function? \$\endgroup\$
    – user41805
    Apr 3, 2017 at 16:12
  • \$\begingroup\$ @KritixiLithos if the cop does not want to give clues, it is not supposed to \$\endgroup\$
    – Mr. Xcoder
    Apr 3, 2017 at 16:15
  • \$\begingroup\$ Cracked? \$\endgroup\$
    – tehtmi
    Apr 6, 2017 at 4:16
10
\$\begingroup\$

Perl, 42 bytes (Safe)

There are 41 bytes of code and -p flag (no other flags).

/"/4~~r..rso4r<_$4va=eg1de|i/h0-&$c={}l+"

The result isn't rounded (or rather rounded up to the same point Perl would have round up by doing $_ = (sqrt $_) * ($_ ** 2)).

Solution:

$_=eval".i44<4}{|~"=~s/./chr-10+ord$\&/gre
(without the \ before the & - markdown spoiler seems to dislike $ followed by &)
Try it online!

Explanation:

.i44<4}{|~ is $_**2*sqrt but with every character replaced by the character with its ascii code + 10. (ascii code of $ is 36, so it becomes . whose ascii code is 46, etc.).
The purpose of s/./chr-10+ord$\&/gre is then to undo this transformation: it replaces each character by the character with ascii code 10 lower. (chr-10+ord$\& is probably clearer as chr(ord($\&)-10) where chr returns the character corresponding to an ascii code, and ord returns the ascii code corresponding to a character).
finally, eval evaluates this string, and thus computes the result, which is stored in $_, which is implicitly printed at the end thanks to -p flag.

\$\endgroup\$
4
  • \$\begingroup\$ True. I was trying to edit quickly because I saw 4 reopen votes and hoped to get the question fixed before the 5th was cast. If the question had been left in the sandbox until it was ready, it would have been better for all involved. \$\endgroup\$ Apr 3, 2017 at 15:57
  • \$\begingroup\$ @PeterTaylor Sure, no problem, and anyway it was bold so fairly visible (I wasn't blaming anyone, but merely pointing a minor flow (that I corrected right away (introducing typos in the process))). And I couldn't agree more about the sandbox part. \$\endgroup\$
    – Dada
    Apr 3, 2017 at 16:04
  • \$\begingroup\$ can you explain it a bit? \$\endgroup\$
    – phuclv
    Apr 5, 2017 at 6:47
  • \$\begingroup\$ @LưuVĩnhPhúc You mean if I can give you a little bit of help to crack it? mmh... the code starts with $_=. And there is a eval somewhere. (that's not a lot but I feel I can't give you more without giving you too much information) \$\endgroup\$
    – Dada
    Apr 7, 2017 at 9:24
8
\$\begingroup\$

Octave, 43 bytes (Safe)

$'()*+,-/23579:[]aelnouv'*,-23:[]lu',-23]',

This is a script that requires input from the command line (it's not a function). It's floating point accuracy (so no rounding).

Solution:

eval(-[5,-2:3,-3:2]+['nlouu*$$',39,']2/7'])

Explanation:

eval( <string> ) % Evaluated the string inside the brackets and executes it
Everything inside the eval call gets evaluated to input('')^2.5

How?

-[5,-2:3,-3:2] % A vector: [-5, 2, 1, 0, -1, -2, -3, 3, 2, 1, 0, -1, -2]
['nlouu**$$',39,']2/7'] % This is a string: nlouu**$ concatenated with the number
. % 39 (ASCII ']'), and ']2/7'. Thus, combined: 'nlouu**$$']2/7'

Adding the first vector to this string will convert it to the integer vector:
[105, 110, 112, 117, 116, 40, 39, 39, 41, 94, 50, 46, 53]

eval implicitly converts this to a string, and these numbers just so happens to be: input('')^2.5

\$\endgroup\$
1
  • 1
    \$\begingroup\$ This was hard. Well done! \$\endgroup\$
    – Luis Mendo
    Apr 9, 2017 at 2:08
7
\$\begingroup\$

C, 50 bytes (Cracked by fergusq)

%(())   ,-12225;>\\aaabbdddeeefffllnoooprrttuuuuw{

Uses standard IEEE754 rounding. As noted by fergusq's answer, may require -lm depending on your compiler.

\$\endgroup\$
3
  • \$\begingroup\$ Cracked? \$\endgroup\$
    – fergusq
    Apr 4, 2017 at 8:33
  • \$\begingroup\$ @fergusq correct, and almost exactly what I had. Well done; I thought I'd left enough red-herrings in there to keep people busy a lot longer! \$\endgroup\$
    – Dave
    Apr 4, 2017 at 11:56
  • \$\begingroup\$ @Dave Wow, that looks like a syntax error at first. \$\endgroup\$ Apr 4, 2017 at 17:08
6
\$\begingroup\$

Mathematica, 131 bytes, non-competing?, cracked

This has been cracked by @lanlock4! However, I still have internet points to bestow on someone who finds the original solution, where all the characters are actually needed....

f[y_]:=With[{x=@@@@@@#####^^&&&(((()))){{}}111111,,+-/y},Print[#,".",IntegerString[Round@#2,10,3]]&@@QuotientRemainder[1000x,1000]]

This is intended as a puzzle. Although you may use the above characters however you want, I certainly intend for the answer to follow the form

f[y_]:=With[{x=
    @@@@@@#####^^&&&(((()))){{}}111111,,+-/y
},Print[#,".",IntegerString[Round@#2,10,3]]&@@QuotientRemainder[1000x,1000]]

where the first and third lines are just a wrapper to make the rounding and display legal (it writes every output to exactly three decimal places, rounded), and the second line is the scrambled version of the guts of the code. Sample outputs:

6 -> 88.182
9 -> 243.000
9999 -> 9997500187.497

(Mathematica is non-free software, but there is a Wolfram sandbox where it is possible to test modest amounts of code. For example, cutting and pasting the code

f[y_]:=With[{x=
    y^2.5
},Print[#,".",IntegerString[Round@#2,10,3]]&@@QuotientRemainder[1000x,1000]]

defines a function, which you can subsequently call like f@6 or f[9], that does the same thing as the unscrambled version of the code above. So does this really have to be non-competing?)

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

Swift - 64 bytes (Safe)

prot Fdnufi;nooitamunc xetgru(->atl)Ior:n{tFn pg,F(ao.o25t)(w)l}

No rounding, and displays a .0 even if the result is an integer.

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

Haskell, 16 bytes (Cracked by @nimi)

()*...25=eglopxx

No particular rounding

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

R, 28 bytes (Cracked by @Flounderer)

funny(p1)-tio(^*^)/pc(2)<p2;

Standard R floating-point accuracy.

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

C#, 172 bytes (Cracked by SLuck49)

       (((((())))))***,,,,......1225;;;;;;<====>CFLMMMMMPPPRSSSSSWaaaaaaabbbbcccddddddeeeeeeeeeeegghiiiiiiiillllllmmnnnnnnnooooooooqqqqrrrssssssssstttttttttuuuuuuuvvwyy{{}}

This code is a full program.

There are seven space characters at the start.

The input is read form STDIN and printed to STDOUT. The result is in double, no rounding done.

Original Code ungolfed:

using System;
using S = System.Console;

class P
{
    static void Main()
    {
        var t = S.ReadLine();
        double q = int.Parse(t);
        Func<double, double, double> M = Math.Pow;
        S.Write(M(q, 2 * .25) * M(q * q, 1));
    }
}
\$\endgroup\$
1
  • \$\begingroup\$ Cracked \$\endgroup\$
    – SLuck49
    Apr 5, 2017 at 15:06
4
\$\begingroup\$

Ohm, 11 bytes

M ⁿ¡D¼½;+1I

Use with -c flag. Uses CP-437 encoding.

\$\endgroup\$
12
  • \$\begingroup\$ I'm sorry, but are you quite sure this is correct? \$\endgroup\$ Apr 7, 2017 at 20:51
  • \$\begingroup\$ Now that no one has cracked it in the imparted time, mind sharing your solution please? I'm very curious :) \$\endgroup\$ Apr 10, 2017 at 0:51
  • \$\begingroup\$ For now, this is the shortest answer considered safe. I will accept it, but if you do not post your original code in 5 days, I will uncheck this, since I am not sure this is possible. EAGER too see your solution \$\endgroup\$
    – Mr. Xcoder
    May 1, 2017 at 16:23
  • 2
    \$\begingroup\$ @RomanGräf try to find your solution, please. Otherwise I will uncheck this... \$\endgroup\$
    – Mr. Xcoder
    May 6, 2017 at 10:37
  • 1
    \$\begingroup\$ @RomanGräf : ping? Still very eager to see that solution :) \$\endgroup\$ May 9, 2017 at 4:41
3
\$\begingroup\$

JavaScript (ES7), 20 bytes (Cracked by @IlmariKaronen)

****..22255666=>____

Standard JavaScript precision.

\$\endgroup\$
2
  • \$\begingroup\$ Cracked. (Oops, posted in the wrong thread at first.) \$\endgroup\$ Apr 3, 2017 at 23:56
  • \$\begingroup\$ Such a clever approach! +1 :) \$\endgroup\$
    – Arjun
    Apr 5, 2017 at 10:01
3
\$\begingroup\$

Python 2, 60 Bytes (Cracked by @notjagan)

 3n0)4  5)594p3(p5*5i9t4542)0/*((8(t.84- 90945 u)i*48/95n8r8

No rounding involved. Accurate up to 10 decimal digits.

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

Python 3.6, 59 bytes

ba(,b5,d' (,a/([m:'-)oa)(bl*aadplma dba](r)d )l*d,:)*m:-mml

No rounding. Floating point accuracy.

\$\endgroup\$
1
  • \$\begingroup\$ Really, 3 lambdas? \$\endgroup\$
    – Mr. Xcoder
    Apr 5, 2017 at 15:48
3
\$\begingroup\$

Haskell, 64 bytes, (cracked by Laikoni)

$$$$$$(((((())))))**,...0<<<>>>[]cccccdddeffiiiiilloopppprrsstuu

Standard Haskell floating point operations.

My original version is:

product.((($succ$cos$0)(flip(**).)[id,recip])).flip(id)

\$\endgroup\$
2
  • \$\begingroup\$ Cracked! \$\endgroup\$
    – Laikoni
    Apr 4, 2017 at 14:13
  • \$\begingroup\$ @Laikoni: well done! \$\endgroup\$
    – nimi
    Apr 4, 2017 at 14:21
3
\$\begingroup\$

Fourier, 124 119 Bytes

((()))*******--011111<=>>>HHINNNN^^^eeehhhhkkkkmmmmmmmmmmmmmmmmossuuuuuuuuuuuuuuuuu{{{{{{{{{{}}}}}}}}}}~~~~~~~~~~~~~~~~

There are no whitespaces or newline characters.

Square root is rounded to the nearest whole number because Fourier doesn't seem to handle anything other than integers (and since @ATaco got permission, I hope this is ok)

fixed an editing mistake, if you were already cracking this, the previous was functional

Realized that I had misunderstood part of the code, and was using more characters than I needed to

If I missed anything let me know

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

Inform 7, 71 bytes (Cracked by @Ilmari Karonen)

""()**-..:[]
                 RT
aaaabeeeffilmmnnnnnooooooqrrrrrssstuuy

The code includes 17 spaces and 2 new lines. This is a full Infrom 7 program defining a function that prints the result with a precision of 5 decimal places.

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

R, 19 bytes (Cracked by @Steadybox)

mensana(4*5*c(.1)):

Standard rounding

R, 33 bytes (Cracked by @plannapus)

(rofl(17)^coins(2*e)/pisan(10))--

R, 31 bytes (Cracked by @plannapus)

h=f`l`u`n`c`t`i`o`n([],[])^(.9)

\$\endgroup\$
3
  • \$\begingroup\$ Cracked the 19-byte answer. \$\endgroup\$
    – Steadybox
    Apr 3, 2017 at 23:16
  • \$\begingroup\$ Cracked the 33-byte solution. \$\endgroup\$
    – plannapus
    Apr 4, 2017 at 14:50
  • \$\begingroup\$ Cracked the 31-byte solution! \$\endgroup\$
    – plannapus
    Apr 10, 2017 at 8:28
3
\$\begingroup\$

Octave, 30 bytes (Safe)

(((((())))))**++/:@eeeiiijmsu~

A bit simpler than my first one. Shouldn't be too hard, but it's hopefully a fun puzzle.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ No ^? Hmmm... \$\endgroup\$
    – Luis Mendo
    Apr 4, 2017 at 9:53
  • 1
    \$\begingroup\$ Came up with this @(e)(e**((i/(i+i))+~sum(e:j))) but it's only n^1.5...this one's tricky. \$\endgroup\$
    – Kyle G
    Apr 9, 2017 at 0:47
2
\$\begingroup\$

05AB1E, 20 bytes - safe

Another totally different approach from my previous answers.

****++/133DDFPTs}¹¹Ð

No rounding.

Example runs

In   -> Out
0    -> 0
4    -> 32.0
6    -> 88.18163074019441
25   -> 3125.0
7131 -> 4294138928.896773

I have no doubt @Emigna is going to crack it in a jiffy, but eh, one has to try! :-D


Solution

D1TFÐ*D¹3*+s3*¹+/*}P

This is using the fact that this sequence:

u_0 = 1, u_{n+1} = u_n * (u_n ^ 2 + 3 x) / (3 u_n ^ 2 + x)

converges to sqrt(x), and cubically fast at that (sorry, didn't find how to format math equations in PCG).

Detailed explanation

D1TFÐ*D¹3*+s3*¹+/*}P
D1                   # Duplicate the input, then push a 1: stack is now [x, x, 1] (where x is the input)
  TF                 # 10 times (enough because of the cubic convergence) do
    Ð                # triplicate u_n
     *               # compute u_n ^ 2
      D              # and duplicate it
       ¹3*+          # compute u_n ^ 2 + 3 x
           s         # switch that last term with the second copy of u_n ^ 2
            3*¹+     # compute 3 u_n ^ 2 + x
                /    # compute the ratio (u_n ^ 2 + 3 x) / (3 u_n ^ 2 + x)
                 *   # compute u_n * (u_n ^ 2 + 3 x) / (3 u_n ^ 2 + x), i.e. u_{n+1}, the next term of the sequence
                  }  # end of the loop
                   P # compute the product of the whole stack, which at that point contains u_10 (a sufficiently good approximation of sqrt(x)), and the 2 copies of the input from the initial D: we get x ^ 2 * sqrt(x)

Try it online!

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

OCaml, 13 bytes (Cracked by @Dada)

2*fn-5f>f*u .

No rounding (within IEEE 754 scope).

\$\endgroup\$
1
  • 3
    \$\begingroup\$ cracked. \$\endgroup\$
    – Dada
    Apr 3, 2017 at 17:38
2
\$\begingroup\$

Javascript, 123 bytes, Cracked by notjagan

 """"""((((((((()))))))))********,--.....//2;;======>>Seeeeeeegggggggggggghhhhhhhhhhhilllllnnnnnnnnnnorrrsstttttttttttttu{}

This code is a full function

There is one space character at the very start of the list of characters

The rounding of this answer is the floating point precision for Javascript, accuracy is within 10^-6 for every answer.

Got shorter because the precision didn't need to be maintained quite as high as I thought it did.

I had realized that it would be much easier to solve than I initially had made it but it was already there :P

Initial code:

g=t=>t-(t*t-n)/("le".length*t);e=h=>{n=h*h*h*h*h,s=2**(n.toString("ng".length).length/"th".length);return g(g(g(g(g(s)))))}

Newtons method, applied 5 times from the closest power of 2

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

Python 3.6 - 52 bytes (Cracked by @xnor)

f=lambda x:x**125*77*8+8/5/((('aafoort.hipie.xml')))

Standard Python rounding

\$\endgroup\$
1
  • \$\begingroup\$ Cracked \$\endgroup\$
    – xnor
    Apr 4, 2017 at 5:11
2
\$\begingroup\$

Ruby, 35 bytes (cracked by xsot)

'a'0-a<2<e<2<l<3<v<4<4<4<5<5<6>7{9}

No rounding. Floating point accuracy.

\$\endgroup\$
1
  • \$\begingroup\$ Cracked \$\endgroup\$
    – xsot
    Apr 4, 2017 at 7:53
2
\$\begingroup\$

05AB1E, 47 bytes

)*.2555BFHIJJKKKPQRST``cgghilnstwx}«¹¹Áöž‚„…………

Does not round, uses floating point accuracy.

\$\endgroup\$
1
  • \$\begingroup\$ Cracked \$\endgroup\$
    – Emigna
    Apr 4, 2017 at 11:17
2
\$\begingroup\$

CJam, 8 bytes (Cracked by Enmigmna)

WYdYl##+

No rounding. Uses double precision.

\$\endgroup\$
1
  • \$\begingroup\$ Cracked \$\endgroup\$
    – Emigna
    Apr 4, 2017 at 11:25
2
\$\begingroup\$

R, 32 bytes (Cracked by @plannapus)

i=na*0.5f*n(2*s*cos(t))*22*s*12u

Standard floating-point accuracy.

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

Excel, 26 bytes

=(())*//11122AAAIINPQRSST^

No rounding.

Note: As Excel is paid software, this works also in free LibreOffice

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

RProgN 2, 6 Bytes (Cracked by @notjagan)

š2]^*\

No rounding, displays many decimal places. Does not display any for an integer solution.

\$\endgroup\$
5
  • 2
    \$\begingroup\$ Does this really perform n²√n? I can easily get it to calculate n² + √n, but I can't for the life of me see how you got the terms to multiply. \$\endgroup\$
    – notjagan
    Apr 4, 2017 at 13:36
  • \$\begingroup\$ @notjagan me too... have been trying for 2 hours to crack it and nothing works. ATaco are you sure that the source is correct? \$\endgroup\$
    – Mr. Xcoder
    Apr 4, 2017 at 18:07
  • \$\begingroup\$ @Mr.Xcoder Ah, you're quite correct. Sorry for wasting your collective times! Please see the edited source. \$\endgroup\$
    – ATaco
    Apr 4, 2017 at 20:51
  • \$\begingroup\$ Now it makes sense! \$\endgroup\$
    – Mr. Xcoder
    Apr 4, 2017 at 20:52
  • \$\begingroup\$ A bit late because I was busy, but cracked. \$\endgroup\$
    – notjagan
    Apr 4, 2017 at 23:03

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.