# Cops - square times square root

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.

• Related. (Same CnR rules, different task.) – Martin Ender Apr 3 '17 at 12:57
• @MartinEnder If the task is the only thing differing, then isn't it a duplicate? – Nathan Merrill Apr 3 '17 at 14:48
• @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.) – Martin Ender Apr 3 '17 at 14:50
• Good luck everyone! I am really glad that you have decided to reopen this. Looking forward to see interesting answers! – Mr. Xcoder Apr 3 '17 at 15:23
• 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 – fəˈnɛtɪk Apr 3 '17 at 16:19

# 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!

# Python 3, 44 bytes (cracked)

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


No rounding. Floating point accuracy.

• Come on, this deserves more points, it's so creative! There is symmetry, and all words are real words. – Erik the Outgolfer Apr 8 '17 at 18:12
• If I didn't make any silly mistakes... Cracked – KSab Apr 12 '17 at 14:17

# 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

• Crack? – tehtmi Apr 6 '17 at 5:16
• @tehtmi Indeed! Well done! My intended solution was different; I just posted it – Luis Mendo Apr 6 '17 at 9:20

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

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

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

• 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. – Peter Taylor Apr 3 '17 at 15:57
• @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. – Dada Apr 3 '17 at 16:04
• can you explain it a bit? – phuclv Apr 5 '17 at 6:47
• @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) – Dada Apr 7 '17 at 9:24 # 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 • This was hard. Well done! – Luis Mendo Apr 9 '17 at 2:08 # 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. • Cracked? – fergusq Apr 4 '17 at 8:33 • @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! – Dave Apr 4 '17 at 11:56 • @Dave Wow, that looks like a syntax error at first. – Erik the Outgolfer Apr 4 '17 at 17:08 # 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?) # 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. # Haskell, 16 bytes (Cracked by @nimi) ()*...25=eglopxx  No particular rounding # R, 28 bytes (Cracked by @Flounderer) funny(p1)-tio(^*^)/pc(2)<p2;  Standard R floating-point accuracy. # 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)); } }  • Cracked – SLuck49 Apr 5 '17 at 15:06 ## JavaScript (ES7), 20 bytes (Cracked by @IlmariKaronen) ****..22255666=>____  Standard JavaScript precision. • Cracked. (Oops, posted in the wrong thread at first.) – Ilmari Karonen Apr 3 '17 at 23:56 • Such a clever approach! +1 :) – Arjun Apr 5 '17 at 10:01 # 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. # 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. • Really, 3 lambdas? – Mr. Xcoder Apr 5 '17 at 15:48 ## 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)

• Cracked! – Laikoni Apr 4 '17 at 14:13
• @Laikoni: well done! – nimi Apr 4 '17 at 14:21

# 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

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

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


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.

## 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=flunction([],[])^(.9)

• Cracked the 19-byte answer. – Steadybox Apr 3 '17 at 23:16
• Cracked the 33-byte solution. – plannapus Apr 4 '17 at 14:50
• Cracked the 31-byte solution! – plannapus Apr 10 '17 at 8:28

# Octave, 30 bytes (Safe)

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


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

• No ^? Hmmm... – Luis Mendo Apr 4 '17 at 9:53
• Came up with this @(e)(e**((i/(i+i))+~sum(e:j))) but it's only n^1.5...this one's tricky. – Kyle Gullion Apr 9 '17 at 0:47

## Ohm, 11 bytes

M ⁿ¡D¼½;+1I


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

• I'm sorry, but are you quite sure this is correct? – user4867444 Apr 7 '17 at 20:51
• Now that no one has cracked it in the imparted time, mind sharing your solution please? I'm very curious :) – user4867444 Apr 10 '17 at 0:51
• 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 – Mr. Xcoder May 1 '17 at 16:23
• @RomanGräf try to find your solution, please. Otherwise I will uncheck this... – Mr. Xcoder May 6 '17 at 10:37
• @RomanGräf : ping? Still very eager to see that solution :) – user4867444 May 9 '17 at 4:41

## OCaml, 13 bytes (Cracked by @Dada)

2*fn-5f>f*u .


No rounding (within IEEE 754 scope).

• – Dada Apr 3 '17 at 17:38

# 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

# Python 3.6 - 52 bytes (Cracked by @xnor)

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


Standard Python rounding

• Cracked – xnor Apr 4 '17 at 5:11

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

• Cracked – xsot Apr 4 '17 at 7:53

# 05AB1E, 47 bytes

)*.2555BFHIJJKKKPQRSTcgghilnstwx}«¹¹Áöž‚„…………


Does not round, uses floating point accuracy.

• Cracked – Emigna Apr 4 '17 at 11:17

## CJam, 8 bytes (Cracked by Enmigmna)

WYdYl##+


No rounding. Uses double precision.

• Cracked – Emigna Apr 4 '17 at 11:25

# R, 32 bytes (Cracked by @plannapus)

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


Standard floating-point accuracy.

• – plannapus Apr 4 '17 at 14:37

## Excel, 26 bytes

=(())*//11122AAAIINPQRSST^


No rounding.

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

• Is there a way to run this without buying Excel? Currently it is the consensus that non free languages cannot be used in cops and robbers. – Post Rock Garf Hunter Apr 4 '17 at 15:22
• Should work in free Libreoffice, but I'll check and reach back. – pajonk Apr 4 '17 at 15:28
• Works just fine. – pajonk Apr 4 '17 at 15:34
• – Jörg Hülsermann Apr 4 '17 at 21:27
• @WheatWizard, not relevant anymore, but I think the consensus is: Non-free languages can be used, but should be marked as non-competing. – Stewie Griffin Apr 5 '17 at 19:40

# RProgN 2, 6 Bytes (Cracked by @notjagan)

š2]^*\


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

• 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. – notjagan Apr 4 '17 at 13:36
• @notjagan me too... have been trying for 2 hours to crack it and nothing works. ATaco are you sure that the source is correct? – Mr. Xcoder Apr 4 '17 at 18:07
• @Mr.Xcoder Ah, you're quite correct. Sorry for wasting your collective times! Please see the edited source. – ATaco Apr 4 '17 at 20:51
• Now it makes sense! – Mr. Xcoder Apr 4 '17 at 20:52
• A bit late because I was busy, but cracked. – notjagan Apr 4 '17 at 23:03