18
\$\begingroup\$

Task: Crack the scrambled code for multiplying the square root of an integer n by the square of it!

You must post a comment in the cops' thread with a link to your working source, mentioning clearly that you have Cracked it. In your answer's title, you must include the link to the original answer.

Rules:

  • You may only change the order of the characters in the original source.
  • Safe answers cannot be cracked anymore.
  • The other rules mentioned in the cops' thread
  • Please edit the answer you crack

WINNER: Emigna - 10 submissons (had some trouble counting)

Honorable mentions: Notjagan, Plannapus, TEHTMI

| improve this question | | | | |
\$\endgroup\$

47 Answers 47

1
2
2
\$\begingroup\$

CJam, 8 bytes, Roman Gräf

My First ever CJam answer.
CnR are great for testing new languages :)

ldYYW#+#

Try it online!

Explanation

ld         % double(input)
       #   %              ^
  Y        %               (2
      +    %                 +
   Y       %                  2
     #     %                   ^
    W      %                    -1)
| improve this answer | | | | |
\$\endgroup\$
2
\$\begingroup\$

HODOR, 171 bytes, wwj

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

Explanation

  • Increment accumulator to 5
  • Divide accumulator by 2
  • Save a copy of accumulator value
  • Set accumulator to 0
  • Read input
  • Raise input to the value of the stored copy (2.5)
  • Output as number
| improve this answer | | | | |
\$\endgroup\$
  • \$\begingroup\$ back to the drawing board \$\endgroup\$ – wwj Apr 5 '17 at 15:07
2
\$\begingroup\$

JavaScript, 39 bytes, SLuck49

x=>(l=Math).cbrt(l.exp(l.log(x)*7.5))

or similarly

x=>(l=Math).exp(l.log(l.cbrt(x))*7.5)

Test:

alert((

x=>(l=Math).cbrt(l.exp(l.log(x)*7.5))

)(prompt()));

| improve this answer | | | | |
\$\endgroup\$
2
\$\begingroup\$

C, 115 bytes, user4867444

New solution that works for 0.

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

Old solution that doesn't work for 0:

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

Applying Newton's method (for square root) a very large fixed number of times seems to give adequate precision for numbers in the required range. I did some character wasting in the first two for loop clauses.

| improve this answer | | | | |
\$\endgroup\$
  • \$\begingroup\$ Close, but not quite, as it returns nan for 0 (not sure we care about that case, asked the OP in a comment) \$\endgroup\$ – user4867444 Apr 6 '17 at 15:37
  • \$\begingroup\$ As specified by the OP, our programs must return 0 for 0, so I'm afraid your solution doesn't work. \$\endgroup\$ – user4867444 Apr 6 '17 at 16:59
  • \$\begingroup\$ @user4867444: Sorry, I didn't understand that it must work for 0. I've provided a modified solution that should work for 0. \$\endgroup\$ – tehtmi Apr 6 '17 at 17:48
  • 1
    \$\begingroup\$ 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 nice magic constant to only do a few Newton iterations as opposed to thousands - but great job! \$\endgroup\$ – user4867444 Apr 6 '17 at 18:33
2
\$\begingroup\$

05AB1E, 22 bytes, Emigna

蛹DDLÏ_zTnF©¹®/+;}¹DP

Most probably not what was intended, but works ;)

Everything before T is just byte wasting (but which leaves the stack empty), then it does a 100 Newton iterations, which yields a good enough approximation of the square root, then pushes the input twice and returns the product of the whole stack, thus giving the desired output.

Example runs:

$ echo 0 | ./05AB1E.py -e '蛹DDLÏ_zTnF©¹®/+;}¹DP'
0.0
$ echo 4 | ./05AB1E.py -e '蛹DDLÏ_zTnF©¹®/+;}¹DP'
32.0
$ echo 6 | ./05AB1E.py -e '蛹DDLÏ_zTnF©¹®/+;}¹DP'
88.18163074019441
$ echo 25 | ./05AB1E.py -e '蛹DDLÏ_zTnF©¹®/+;}¹DP'
3125.0
$ echo 7131 | ./05AB1E.py -e '蛹DDLÏ_zTnF©¹®/+;}¹DP'
4294138928.896773
| improve this answer | | | | |
\$\endgroup\$
  • \$\begingroup\$ Nice one! Didn't think of that :P \$\endgroup\$ – Emigna Apr 7 '17 at 16:30
2
\$\begingroup\$

05AB1E, 15 bytes, user4867444

DMžDFD¹s/+;}01P

Try it online!

Explanation

D                 # duplicate input
 M                # push the largest value on the stack (the input)
  žDF             # 4096 times do:
     D            # current value
         +        # added to
      ¹s/         # input divided by current value
          ;       # divide sum by 2
           }      # end loop
            01    # push 1
              P   # product of the stack
| improve this answer | | | | |
\$\endgroup\$
2
\$\begingroup\$

05AB1E, 23 bytes, user4867444

$DDžHGD¹s/+;}0@rrzz2+\P

Try it online!

Explanation

$                        # push 1 and input
 DD                      # duplicate the input twice
   žHG                   # 65536 times do:
      D                  # duplicate current value
       ¹s/               # divide input by current value
          +              # add result of division to current value
           ;             # divide by 2
            }            # end loop
             0@          # get the bottom value of the stack (the 1)
               rr        # reverse the stack twice (no-op)
                 zz      # calculate 1/(1/1), a no-op
                   2+    # add 2
                     \   # discard top of stack (the 3)
                      P  # product of stack
| improve this answer | | | | |
\$\endgroup\$
2
\$\begingroup\$

JavaScript, SIGSEGV

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

Try it online!

| improve this answer | | | | |
\$\endgroup\$
  • \$\begingroup\$ You got it! Kudos for you ;) \$\endgroup\$ – Matthew Roh Apr 12 '17 at 11:32
1
\$\begingroup\$

Python - SparklePony

import math
f=lambda x:x*x*math.sqrt(x)
| improve this answer | | | | |
\$\endgroup\$
  • \$\begingroup\$ That was very fast! \$\endgroup\$ – Comrade SparklePony Apr 3 '17 at 18:00
  • \$\begingroup\$ Thanks @SparklePony. It was very similar to mine, done it right away \$\endgroup\$ – Mr. Xcoder Apr 3 '17 at 18:01
  • \$\begingroup\$ @SparklePony please accept the edit... \$\endgroup\$ – Mr. Xcoder Apr 3 '17 at 18:01
  • \$\begingroup\$ I think I have done it... first time accepting an edit! \$\endgroup\$ – Comrade SparklePony Apr 3 '17 at 19:34
1
\$\begingroup\$

Scala, corvus_192

d=>math.pow(d,5/2d)

Try it here!

Simple lambda expression

| improve this answer | | | | |
\$\endgroup\$
1
\$\begingroup\$

05AB1E - P. Knops

t¹n*

Was quite easy :)

| improve this answer | | | | |
\$\endgroup\$
1
\$\begingroup\$

C, Steadybox

float q(float b){return(b-b>0.*4*1/1)-sqrtf(b)*pow(b,2)*-1;}

Not sure what the original did; I had to discard a lot of random operators and numbers, but once the available words were clear it wasn't too hard to piece together the general idea.

| improve this answer | | | | |
\$\endgroup\$
  • \$\begingroup\$ Oops; noticed I'd accidentally included an extra space than the original; fixed. \$\endgroup\$ – Dave Apr 3 '17 at 20:15
  • \$\begingroup\$ Here's the original function: float q(float b){return-1*pow(b,(b>-12)/sqrt(4.0f))*b*b*-1;} \$\endgroup\$ – Steadybox Apr 3 '17 at 20:46
1
\$\begingroup\$

R, Flounderer

scan()**mean(1:4.5)

Try it online!

| improve this answer | | | | |
\$\endgroup\$
1
\$\begingroup\$

Python 3.6, c..

f=lambda x:x**2.5or'1*77*8+8/5/(((aafothipie.xml)))'

Try it online!

Stuffs all the unneeded characters into a string after the or. Since x**2.5 is nonzero and so truthy, the part after the or isn't evaluated. Any syntactically valid expression would be OK here.

Python parses 2.5 and or as separate tokens in 2.5or, though the syntax highlighter for the code doesn't recognize this.

| improve this answer | | | | |
\$\endgroup\$
  • \$\begingroup\$ I think you meant x**2.5? Damn Python, I'm doing the next one without strings. \$\endgroup\$ – c.. Apr 4 '17 at 5:25
  • \$\begingroup\$ @c.. Yes, 2.5, thanks. \$\endgroup\$ – xnor Apr 4 '17 at 5:27
1
\$\begingroup\$

Ruby, G B

->a{eval''<<97<<42<<42<<50<<46<<53}
| improve this answer | | | | |
\$\endgroup\$
  • \$\begingroup\$ Nice, I was expecting that, maybe not so fast. :-) \$\endgroup\$ – G B Apr 4 '17 at 8:13
1
\$\begingroup\$

C#, 135 bytes, Jan Ivan

This was a lot of fun, I particularly liked the use of using static.

using System;using static System.Math;class P{static void Main(){Console.Write(Pow(long.Parse(Console.ReadLine()),1/Round(PI-E,1)));}}
| improve this answer | | | | |
\$\endgroup\$
1
\$\begingroup\$

JavaScript, SIGSEGV

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

Try it online!

| improve this answer | | | | |
\$\endgroup\$
  • \$\begingroup\$ Well, not the same, but well, that works too. maybeIshouldn'tuseasterisks \$\endgroup\$ – Matthew Roh Apr 12 '17 at 11:56
  • \$\begingroup\$ @SIGSEGV: I'd be interested to see what the intended version was then :) \$\endgroup\$ – Emigna Apr 12 '17 at 12:03
1
2

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.