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\$ Commented Apr 3, 2017 at 12:57
  • 3
    \$\begingroup\$ @MartinEnder If the task is the only thing differing, then isn't it a duplicate? \$\endgroup\$ Commented 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\$ Commented 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
    Commented 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\$ Commented Apr 3, 2017 at 16:19

68 Answers 68

1 2
3
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
1
\$\begingroup\$

Vyxal, 12 bytes, Cracked by lyxal

`25/n:([|eĖĖ

Have fun!

\$\endgroup\$
1
  • \$\begingroup\$ lol \$\endgroup\$
    – lyxal
    Commented Nov 25, 2021 at 6:55
1
\$\begingroup\$

Vyxal, 14 bytes

`25/$n:([|tėĖĖ

On to round 2!

\$\endgroup\$
2
  • \$\begingroup\$ Community has flagged this answer as a duplicate of your last answer btw. Took me a while to spot the difference myself. \$\endgroup\$
    – Wheat Wizard
    Commented Nov 25, 2021 at 9:33
  • \$\begingroup\$ @GrainGhost I made a mistake in the previous, so did another one. I can see why this happened, it's not a big difference. \$\endgroup\$
    – emanresu A
    Commented Nov 25, 2021 at 9:35
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\$
1
0
\$\begingroup\$

Python 2.7, 41 bytes

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

rounding done by "%.3f"

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Cracked! \$\endgroup\$
    – ovs
    Commented Apr 8, 2017 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\$
2
  • \$\begingroup\$ Cracked! \$\endgroup\$
    – Kyle G
    Commented Apr 6, 2017 at 1:40
  • \$\begingroup\$ @KyleGullion not very creative, but smart. I'll post the original solution shortly \$\endgroup\$
    – Mr. Xcoder
    Commented Apr 6, 2017 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\$
1 2
3

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.