# 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, 35 bytes

ö£=s‰sr2xöR+RM0.T"YVBYCDž„¨¨"6£H-L


This one took me a while to make.

There's some double quotes in there, so you can surround as much of the code as you want in them.

No rounding, decimal point precision.

# Fireball, 8 bytes (Cracked by Roman Gräf)

♥1Z*^²/♥


Does not round, uses floating point precision.

Code surrounded with hearts ;)

Should pretty easy to crack, once you have a look into Fireball.

## C#, 112 bytes (cracked by Emigna)

     ((((())))),.....25;;;=CCLMMPPPRSWaaaaaaabbbccdddeeeeeeeeghiiiiiillllmnnnnnooooooorrrsssssssstttttuuvvwy{{}}


no rounding done

using System;
class P
{
static void Main()
{
Console.Write(Math.Pow(b,2.5));
}
}

• Cracked – Emigna Apr 4 '17 at 8:48
• You are free to add more cops if you have more ideas, but you should post them in separate answers instead of adding to an existing one. – Emigna Apr 6 '17 at 9:31
• – Jan Ivan Apr 6 '17 at 9:40

# NO!, 41 bytes (Cracked by Emigna)

NOOO! NO! can finally compete! Although no-one will be bothered to crack this anyway :(

Anyway sigh here's the code:

NNNOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO??
nnno!


Full list of commands here. Coded in Python so uses Python rounding.

NOOOOOOOOO!!!!!!!! Someone cracked it. (Curse you Emigna!) (just kidding!)

• Introducing a new language will be fun ... Cannot wait ro strugle to crack it😂 – Mr. Xcoder Apr 4 '17 at 18:04
• @Mr.Xcoder can I add another one? I think I might add it to this post for convenience. – caird coinheringaahing Apr 4 '17 at 18:57
• Post another answer to NOT! mess up the two @ThisGuy – Mr. Xcoder Apr 4 '17 at 18:58
• I think you mean "consonants" in your documentation (not constants). – Dave Apr 5 '17 at 19:37
• @Dave D'oh! 🙃☺️ – caird coinheringaahing Apr 5 '17 at 19:41

## C, 115 bytes, (Cracked by @tehtmi)

""%&&((((((()))))))******++++,..//01122233388;;;;;;<====>>   bbbdddeeeefffggillllllllllnnnnnnnnoooooooooooprrtuuu{}


Notice that it does include 3 spaces.

Always outputs 3 exact decimals, rounded to the closest thousandth.

Should be rather fun to crack as it doesn't involve any built-in to compute powers or square roots, as opposed to most (cracked) solutions so far.

Example run (which also gives you a few small hints):

int main() {
int n[] = {4, 6, 9, 25};
for (int i = 0; i < 4; i++) {
printf("%i => ", n[i]);
o(n[i]);
printf("\n");
}
}


outputs:

4 => 32.000
6 => 88.182
9 => 243.000
25 => 3125.000


Tested with both gcc and clang, with no compilation flag needed.

It's been cracked; the original solution was

o(double n){long o=2.303e18+(*(long*)&n>>1);double l=*(double*)&o;for(o=2;o++<8;)l=(l+n/l)/2;printf("%.3f",l*n*n);}


which uses a magic constant in the same spirit as the infamous fast inverse square root algorithm to do just a handful of Newton iterations (as opposed to several thousands in the cracked solution)

• It could actually be 3 bytes shorter, at a cost of completely sacrificing performance though :) (as in, becomes really, really slow) – user4867444 Apr 5 '17 at 1:58
• Crack? Probably not exactly what you're going for, but maybe similar and I think it is okay. – tehtmi Apr 6 '17 at 8:25
• @tehtmi not quite, see my comment there (your solution does not return correctly for input 0) – user4867444 Apr 6 '17 at 17:00

# 05AB1E, 23 bytes (Cracked by Emigna)

A totally different approach than my previous answers :)

$++/02;@DDDGHP\rrszz}¹ž  No rounding. Example runs In -> Out 0 -> 0 4 -> 32.0 6 -> 88.18163074019441 25 -> 3125.0 7131 -> 4294138928.8967724  • Cracked – Emigna Apr 7 '17 at 16:51 • Dammit :-D ! This wasn't the intended solution, mine was $žHGDzrDz0@+2s/r+;}\¹DP, using the convergent sequences u_0 = 1, v_0 = x, u_(n+1) = 2 / (1/u_n + 1/v_n), v_(n+1) = (u_n + v_n) /2 to compute the square root. But very well done! – user4867444 Apr 7 '17 at 17:14
• The thing is, it's hard to come up with an approximation method that can't be tweaked back into Newtons' iterations, mmh... – user4867444 Apr 7 '17 at 17:15
• Oooh, that was a cool implementation. I figured my crack wasn't the intended :) – Emigna Apr 7 '17 at 17:19

## Excel VBA, 59 bytes (Safe)

?(())*..//11124AAAAFPSW[[]]^acceehiiiiklnnnnoooppqrrstttttu


No particular rounding.
Uses the Immediate Window.

# Octave, 42 bytes (Safe)

((((()))))+,,,-//01111111@[]^mnooorrssst~~


No rounding. Floating point accuracy.

### Intended solution

@(s)norm(roots([-1,~1,s^(10/(1+1))]),1/~1)

Try it online!

• Was this close? f=@(s)s^norm(roots([1,2.5,1]),1)? I didn't find a way to make those remaining numbers and +-~~ become 2.5. I had some other attempts that were quite similar (changed the numbers a bit), but I couldn't get it correct. – Stewie Griffin Apr 8 '17 at 17:56
• @StewieGriffin It was! I have posted the intended solution – Luis Mendo Apr 9 '17 at 2:07

# Lua 5.3, 110 bytes (safe)

((((()))))**,,,,,-....=====>~             aaaaaaaaacddddeeeffhhhiiiiiiilllmmnnnnnnooopppppprrrrrrrsssssssstttt


Calculations are standard using Lua numbers (ie double in common implementations). Tested using PUC-Rio interpreter. (I hope I didn't do anything bad, but I think it is reasonable...)

This is a full program with input from the command line.

Original solution:

for a,r in pairs(math)do l,s=pcall(r,-math.pi)if s~=s and a>=(i or a)then i,p=a,r end end s=...print(s*s*p(s))

Explanation:

math.sqrt is retrieved from the math library by looping through the math table and looking for functions that return NaN (and don't throw an error) when applied to negative pi. There are only a few functions like this, and sqrt is alphabetically last.

# Javascript, 15 17 bytes, Cracked by @Emigna

(x=>x****-125*10)


Solution:

x=>x**(25*10**-1)

# Javascript, 18 bytes, Again, Cracked.

x=>x**-(!3.5++)[];


Solution:

x=>x**(3-!+[]+.5);

• Cracked. I was really wondering how to do it without the parenthesis ;) – Emigna Apr 12 '17 at 11:31
• Cracked 2nd – Emigna Apr 12 '17 at 11:52

# HODOR, 172 bytes, Cracked by Emigna

Walder
Hodor Hodor Hodor Hodor Hodor Hodor
Hodor Hodor Hodor Hodor Hodor
Hodor Hodor Hodor Hodor
Hodor Hodor Hodor
Hodor Hodor
Hodor
hodor hodor
HODOR HODOR!!!!!!!,,,,,,..?


let me know if I missed anything

• Nope, this is scrambled – wwj Apr 5 '17 at 14:26
• just approved your edit, I wrote this up last night... I think the interpreter I was using might have been out of date... I will need to check to make sure the code still works when I get home – wwj Apr 5 '17 at 14:32
• I'm checking it now. See if I can crack it – caird coinheringaahing Apr 5 '17 at 14:33
• Cracked – Emigna Apr 5 '17 at 15:01

# Python 3.6 - 15 bytes (Cracked by Kritixi Lithos)

axx 2*d:b.*5mal


Standard rounding precision of Python

• Cracked! – user41805 Apr 3 '17 at 16:20
• @KritixiLithos well done +1 – Mr. Xcoder Apr 3 '17 at 16:21

# C++, 100 bytes (Cracked by @fergusq)

#.leiha2dm"
tuchn"crmueie<linaatt#dso
fameng pcae sli;t>dt nnsiuno;s mnpti;ouic(<){n(a;>w<n>n)co.,5}


Standard C++ rounding precision

# Python 2, 44 Bytes (Cracked by @fəˈnɛtɪk)

np5w***i0(0(0r0n0t+iarn00p0)_(0tu00i50.0)) t


Has accuracy up to 10 decimal digits (I think). No rounding involved and there is a space involved.

• Cracked! – fəˈnɛtɪk Apr 3 '17 at 17:38
• @fəˈnɛtɪk you should edit the answer you've cracked. Well done! – Mr. Xcoder Apr 3 '17 at 17:45

# Scala, 19 bytes (Cracked by @math_junkie)

)>,/2(=addd.hmoptw5


This is a function of type Int=>Double.

# 05AB1E, 4 bytes (Cracked by @Mr. Xcoder)

Must be really easy to crack, but I'll still post it here

n*t¹


Normal rounding

# C, 60 bytes (Cracked by @Dave)

1(root, flat*fat bern**lotr);pw(f{bus(--q.b4/q0*1-2)})(b>1)b


Standard C float accuracy.

• – Dave Apr 3 '17 at 20:04

# 05AB1E, 23 bytes (Cracked by Emigna)

Another try

A9n*¥="'q?:@->%t#[{¹!.


Normal rounding

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

# HODOR, 198 bytes (Cracked by wwj)

NB: Had to correct the code!

Uses the brand-new hodor command (Updated Saturday)! Yes, I know I'm not supposed to say but it's pretty obvious anyway and (as far as I know) I'm the only person who can code in Hodor so worth some help :)

This is the code: and the full list of commands is here

H!HDHrlrHrhoooo!h, oo!do ordoH!oHHd
dodHrodorooooHdddoooOOo ddro roorrro.r,H
ooO ooHr,
HdHo oo H!O?Hd, oo,, Hdodhd oor, dd!HHrDo aod
rdroHdH,HrRr
o o RHrdHoo,oro Hr
oo
oHoer o r oddodo,rr
rdd!WrH d

• Can you please mark this as non-competing, since nobody uses this language? Also, please edit the link – Mr. Xcoder Apr 4 '17 at 19:39
• The fact that nobody uses the language doesn't mean it should be non-competing. non-competing only applies for language (or features) that postdate the challenge. So if your solution works on Hodor as it was before the challenge, then it's competing. – Dada Apr 5 '17 at 8:05
• How do I run the Hodor interpreter? – Emigna Apr 5 '17 at 12:59
• @Emigna working on a file that will run from command line but for now will add a note in README (English version) – caird coinheringaahing Apr 5 '17 at 13:20
• Is there perhaps a bug on row 118 in the interpreter? I can't get my program to work without changing that. Also, h should be in VALID_CHARS right? – Emigna Apr 5 '17 at 14:17

# Stacked, 64 bytes

:u#{E2t#tv',lnp~.iuP#2qr+t,'3m3em,#9''.::mluls on\ts r:a\:+.S0


Good luck.

Result for 6: 88.181630740194411535.

• Maybe linking to github.com/ConorOBrien-Foxx/stacked would be more helpful. – user4867444 Apr 7 '17 at 1:22
• @user4867444 If you click on "stacked" in the link above it gets your there anyhow. – Conor O'Brien Apr 7 '17 at 1:22
• Takes me to tio.run/nexus/stacked rather, which is not super helpful to learn about the language? – user4867444 Apr 7 '17 at 1:24
• @user4867444 Perhaps my wording is confusing. On the tio.run page, clicking on "stacked" gets you to the github. Shown in this image Admittedly, it's a tad convoluted. – Conor O'Brien Apr 7 '17 at 1:35

# Javascript (ES6), 39 bytes (Cracked)

(((())))*....57===>Mabcefghlllloprttxxx


The rounding is normal floating point precision for Javascript.

• Cracked – GOTO 0 Apr 5 '17 at 19:29

# bash, 158 bytes

This program requires a 64 bit processor to function. Pass input number as argument; result on stdout. I believe rounding is floor function. This program actually does decimal output. If you got integer only keep trying.

^=======|       -!
///////......
''(((((((((((())))))))))))
[]\$****
\\\\\\
#++
000000000000
111111222
bcdddeeeehhhiill
nn
NNNNNNoooOOOOOOO
sssSSSS
tw


# Python 2.7, 174 bytes

_cc*gnta(dkree_rtrto._i9kuc_ l5_r_cctbimWka(Wihlkeu_5_eur_rri_keeluc4clrp ..u_)(HohhH)ap5o(trbnord_ir9/*in)_clrikroap.ie.tg_obkfkseeeel*in2Hkdu*ffmo4lWlrncde_22);doodt a49 hu


# 05AB1E, 15 bytes, (Cracked by Emigna)

+/01;DDDFMPs}¹ž


Normal rounding

Example runs

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

• Cracked, right back at ya :P – Emigna Apr 7 '17 at 16:37
• @Emigna: eh, I figured it was only a question of time, same method ;) good job! – user4867444 Apr 7 '17 at 17:11

## C#, 135 bytes (cracked by SLuck49)

      (((((()))))),,-..../11;;;CCEILMMMPPPRRSSWaaaaaaacccdddeeeeeeeeggghiiiiiiiillllmmnnnnnnnnoooooooorrsssssssssssttttttttuuuvwyy{{}}


no rounding done
(First try)

• Cracked This was fun. – SLuck49 Apr 7 '17 at 20:32

# 05AB1E, 22 bytes, Cracked by user4867444

+/;DDDFLPT_nz}©®¹¹¹Ïè›


Example runs

In -> Out
0  -> 0
4  -> 32.0
6  -> 88.18163074019441


Original solution

LnD¹›_Ï®©èTFD¹/z+;}¹DP

# JavaScript (ES7), 24 bytes (Safe)

()+01488Maabeiijlooqtv


Standard 64 bit floating point rounding.

### Solution

eval(atob8j0+8ioqMi41)

### Tests

console.log(eval(atob8j0+8ioqMi41)(0));    // 0
console.log(eval(atob8j0+8ioqMi41)(1));    // 1
console.log(eval(atob8j0+8ioqMi41)(2));    // 5.656854249492381
console.log(eval(atob8j0+8ioqMi41)(4));    // 32
console.log(eval(atob8j0+8ioqMi41)(10));   // 316.22776601683796

# Javascript (ES7), 53 bytes (safe)

(((())))*++++,,,/0233346=====>>[[]]aaaabbbccelootttuv


The rounding is normal floating point precision for Javascript.

Tested this in the latest Chrome and FF.

### Solution

u=>(o=(t,c,a=o+c,b=a[t])=>eval(a[42]+b+b+3*30/t))(36)

This works because a=o+c is '(t,c,a=o+c,b=a[t])=>eval(a[42]+b+b+3*30/t)undefined'.
So a[42]='u', a[36]='*', 3*30/36=2.5, making eval('u**2.5').

### Tests

var f=u=>(o=(t,c,a=o+c,b=a[t])=>eval(a[42]+b+b+3*30/t))(36);
console.log(f(0));    // 0
console.log(f(1));    // 1
console.log(f(2));    // 5.656854249492381
console.log(f(4));    // 32
console.log(f(10));   // 316.22776601683796

# JavaScript + paper.js, 210 bytes (safe)

This one's fun. No comments for you, and no strings either.

paper.js is a vector graphics framework. This is a full program that takes input via a prompt and outputs graphically, because it's possible. There is no rounding and floating-point accuracy (I think).
Reference
Try code here

Math.tan(prompt(a,0));
leg Rave, ew(0,0),ectoPlasm = Real new qrt(;
marvin atTax M(en) in vr;tent * hat.o = Mat
nottet near(0a,a) w cgee;
brown.cern(lantern) ;( w 0,0.art;vict.o brace
r=v=,h.c.)an=.flClr= Cor0)


Edit: Just noticed (my fault for not reading properly)

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

Well, oops.

Original solution:

var a = prompt(0,0);
var r = new Rectangle(0,0,a,a).area;
var t = new Rectangle(0,0,Math.cbrt(a),Math.sqrt(Math.cbrt(a))).area;
var n = new PointText(view.center);
n.content = r * t;
n.fillColor = new Color(0);


Try code here

# 05AB1E, 27 bytes - safe

Yet another totally different approach from my previous answers.

(/1DFFOOPTins}}©®¹¹Ðèëž‚‚‹


No rounding.

Example runs

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


Solution

Ð(‚žFFDO©n¹‹iT/ë1è®s}‚}O¹P


This is simply computing the square root with a trivial (and very dumb) trial-and-error strategy...

Detailed explanation

Ð(‚žFFDO©n¹‹iT/ë1è®s}‚}O¹P
Ð(‚                         # triplicate the input, reverse the sign of the last copy, and wrap the last 2 items in a list, which going forward is going to be the list of our current sqrt approximation and of the next decrement in our dumb search (so it starts at [x, -x])
žFF                      # 16384(!) times, do
D                     # duplicate the current [value, decrement] list
O©                   # compute the sum value + decrement, and also save it in the register
n                  # compute the square of that potential new approximation of the square root
¹‹                # and compare it with the input
i               # if our new approximation is smaller than the actual square root, then
              # push the flattened [value, decrement] list to the stack as value, decrement
T/            # and divide our decrement by 10
ë           # else (our new approximation is still bigger than the actual square root, then)
1è         # extract the current decrement from the list
®        # retrieve the new approximation from the register
s       # and switch them to again have them in the value, decrement order
}      # end of the if
‚     # no matter which branch of the if we went into, the last 2 items of the stack are now the new approximation and the new decrement, in order: wrap them in a list for the next loop iteration
}    # end of the loop
O   # replaces the output of the loop (the final [value, decrement] list) by its sum, which given the very small value of the decrement at that point is pretty much the same as our final approximation of sqrt(x)
¹  # push another copy of x; the stack is now [x, sqrt(x), x] (where the first x comes from the very first copy of the initial Ð)
P # computes the product of the whole stack
`

Try it online!