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\$
  • 2
    \$\begingroup\$ Related. (Same CnR rules, different task.) \$\endgroup\$ – Martin Ender Apr 3 '17 at 12:57
  • 2
    \$\begingroup\$ @MartinEnder If the task is the only thing differing, then isn't it a duplicate? \$\endgroup\$ – Nathan Merrill Apr 3 '17 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\$ – Martin Ender Apr 3 '17 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 '17 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\$ – fəˈnɛtɪk Apr 3 '17 at 16:19

66 Answers 66

1
\$\begingroup\$

Java 7, 224 bytes (safe)

      ""&&((((((((()))))))))***++++++,,,,,,,-......//000000001113344556677;;;;;;;;;;<<======>>LLSS[\\\\\]aaaaaaaabbbbcccccccccdddddddddeeeeffffggggggiiiiiiiklllmmmnnnnnnnoooooooopprrrrrrssssssssssssstttttttttttuuuuuuuuvy{{}}

Look I know it's a lot of bytes but it's a full java program so you can expect a good portion of it to be basic boiler plate... and surely there are no tricks being employed. Output has 3 decimal places and operates the same as the examples in the challenge. I could probably make this harder but part of the fun is seeing how you end up breaking this and solving it in an unintended way. Good luck!

P.S. that's 6 spaces in case you're curious.

Example Runs

0    ->          0.000
4    ->         32.000
6    ->         88.182
25   ->       3125.000
7131 -> 4294138928.897

Solution:

class u{static double s,a,c,n,d,g,t;public static void main(String...u)\u007bd=Long.parseLong(u[0]);n=d/(c+++1);for(;g<(t=13);g++){for(;s<n;s+=c)if(s*s>d&&(s-=c)>0)break;c/=t;}System.out.format("\045\0563\146",s*d*d);}\u007d

Ungolfed:

class u{
static double s,a,c,n,d,g,t;               // static doubles default to 0.0
public static void main(String...u)\u007b  // had to use 1 or 2 unicode escapes for fun

d=Long.parseLong(u[0]);
n=d/(c+++1);                              // get d/2 while also making c=1

for(;g<(t=13);g++){                       // get 13 decimals of precision
  for(;s<n;s+=c)                          // increment the current decimal position
    if(s*s>d&&(s-=c)>0)break;             // square the current value and make sure we're still below the target
  c/=t;
}
System.out.format("\045\0563\146",s*d*d); // java also has octal string escapes
}
\u007d
\$\endgroup\$
0
\$\begingroup\$

Python 2, 39 bytes (cracked by @Mr. Xcoder)

q=a(lxt)mh*mprf.hr
ax tttaixxmb :m*asod

Standard Python float rounding.

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

Python 2.7, 41 bytes

(sexypint=='pint')**(55.0)**fur==(.3%0%y)

rounding done by "%.3f"

\$\endgroup\$
  • 1
    \$\begingroup\$ Cracked! \$\endgroup\$ – ovs Apr 8 '17 at 14:46
0
\$\begingroup\$

Python 3.6 - 64 bytes (Cracked by user4867444)

f1;7*x0d/2p6*mm1i*99 5 a o o t(a bphpx:m38af4r*1221=s2rm.0itlpa)

Extremely high precision. No rounding.

ORIGINAL SOLUTION:

from math import pi as p;f=lambda x:x**(p**3/12.402510672119928)

\$\endgroup\$
  • \$\begingroup\$ Cracked! \$\endgroup\$ – Kyle Gullion Apr 6 '17 at 1:40
  • \$\begingroup\$ @KyleGullion not very creative, but smart. I'll post the original solution shortly \$\endgroup\$ – Mr. Xcoder Apr 6 '17 at 4:32
0
\$\begingroup\$

C#, 179 bytes, safe

(((((((((((((())))))))))))))*****++,,,,,-..///////000000000111112222222222:;;;<=====>>>>?AFM[[[[[[[[[[[]]]]]]]]]]]abbbcdddddeeeeehllllnnnnnnnnnnnnnooooooooooorrrrrsttuuuuuww{{{}}}

There is no rounding. The code forms a lambda that takes an int and returns a double.


Solution

n=>{Func<double[],double>r=null;return(r=(o)=>(Math.Abs(o[1]-o[2])>=0.0000001)?r(new[]{o[0],o[2],(o[2]+(o[0]/o[2]))/2}):o[2])(new[]{n,(n*1d)/2,((n*1d)/2+(n/(n*1d)/2))/2})*(n*n);};

Exploded Solution

(int n) => 
{
    Func<double[], double>r = null;

    r = (double[] o) =>
    { 
        if(Math.Abs(o[1]-o[2]) >= 0.0000001))
        {
            return r(new[]{ o[0], o[2], (o[2] + (o[0] / o[2])) / 2 });
        }
        else
        {
            return o[2];
        }
    };

    var initialO = new[]
    { 
        n, 
        (n * 1d) / 2, 
        ((n * 1d) / 2 + (n / (n * 1d) / 2)) / 2 
    };

    return r(initialO) * (n * n);
};
\$\endgroup\$
0
\$\begingroup\$

PHP, 61 Bytes (Safe)

No rounding

a$rians=)n$$/rnd=aa(*gt$)gg*g)(g)$(r|pg-n(+(;$r($)(tr)=r)ngq.

Original Solution

print($argn**(sqrt(((a|n).rd)($g=$argn==$argn))/($g+$g)-$g));
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.