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
49 Answers 49
05AB1E, 22 bytes, P. Knops
n1t*qA9\="'?:@->%#[{!.
Explanation
n # square of input
* # times
1t # square root of input
q # end program
The rest of the operations never get executed.
We could have done it without the q as well by having ? after the calculation and escaping the equality sign for example with '=.
CJam, 8 bytes, Roman Gräf
My First ever CJam answer.
CnR are great for testing new languages :)
ldYYW#+#
Explanation
ld % double(input)
# % ^
Y % (2
+ % +
Y % 2
# % ^
W % -1)
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
-
\$\begingroup\$ back to the drawing board \$\endgroup\$wwj– wwj2017年04月05日 15:07:28 +00:00Commented Apr 5, 2017 at 15:07
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()));
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.
-
\$\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– user48674442017年04月06日 15:37:04 +00:00Commented Apr 6, 2017 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– user48674442017年04月06日 16:59:45 +00:00Commented Apr 6, 2017 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– tehtmi2017年04月06日 17:48:34 +00:00Commented Apr 6, 2017 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– user48674442017年04月06日 18:33:16 +00:00Commented Apr 6, 2017 at 18:33
05AB1E, 22 bytes, Emigna
è›1DDLÏ_zTnF©1®/+;}1DP
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 'è›1DDLÏ_zTnF©1®/+;}1DP'
0.0
$ echo 4 | ./05AB1E.py -e 'è›1DDLÏ_zTnF©1®/+;}1DP'
32.0
$ echo 6 | ./05AB1E.py -e 'è›1DDLÏ_zTnF©1®/+;}1DP'
88.18163074019441
$ echo 25 | ./05AB1E.py -e 'è›1DDLÏ_zTnF©1®/+;}1DP'
3125.0
$ echo 7131 | ./05AB1E.py -e 'è›1DDLÏ_zTnF©1®/+;}1DP'
4294138928.896773
-
\$\begingroup\$ Nice one! Didn't think of that :P \$\endgroup\$Emigna– Emigna2017年04月07日 16:30:19 +00:00Commented Apr 7, 2017 at 16:30
05AB1E, 15 bytes, user4867444
DMžDFD1s/+;}01P
Explanation
D # duplicate input
M # push the largest value on the stack (the input)
žDF # 4096 times do:
D # current value
+ # added to
1s/ # input divided by current value
; # divide sum by 2
} # end loop
01 # push 1
P # product of the stack
05AB1E, 23 bytes, user4867444
$DDžHGD1s/+;}0@rrzz2+\P
Explanation
$ # push 1 and input
DD # duplicate the input twice
žHG # 65536 times do:
D # duplicate current value
1s/ # 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
-
\$\begingroup\$ You got it! Kudos for you ;) \$\endgroup\$Matthew Roh– Matthew Roh2017年04月12日 11:32:37 +00:00Commented Apr 12, 2017 at 11:32
Python - SparklePony
import math
f=lambda x:x*x*math.sqrt(x)
-
\$\begingroup\$ That was very fast! \$\endgroup\$sporkl– sporkl2017年04月03日 18:00:55 +00:00Commented Apr 3, 2017 at 18:00
-
\$\begingroup\$ Thanks @SparklePony. It was very similar to mine, done it right away \$\endgroup\$Mr. Xcoder– Mr. Xcoder2017年04月03日 18:01:18 +00:00Commented Apr 3, 2017 at 18:01
-
\$\begingroup\$ @SparklePony please accept the edit... \$\endgroup\$Mr. Xcoder– Mr. Xcoder2017年04月03日 18:01:46 +00:00Commented Apr 3, 2017 at 18:01
-
\$\begingroup\$ I think I have done it... first time accepting an edit! \$\endgroup\$sporkl– sporkl2017年04月03日 19:34:26 +00:00Commented Apr 3, 2017 at 19:34
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.
-
\$\begingroup\$ Oops; noticed I'd accidentally included an extra space than the original; fixed. \$\endgroup\$Dave– Dave2017年04月03日 20:15:05 +00:00Commented Apr 3, 2017 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– Steadybox2017年04月03日 20:46:18 +00:00Commented Apr 3, 2017 at 20:46
Ruby, G B
->a{eval''<<97<<42<<42<<50<<46<<53}
-
\$\begingroup\$ Nice, I was expecting that, maybe not so fast. :-) \$\endgroup\$G B– G B2017年04月04日 08:13:03 +00:00Commented Apr 4, 2017 at 8:13
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)));}}
-
\$\begingroup\$ Well, not the same, but well, that works too. maybeIshouldn'tuseasterisks \$\endgroup\$Matthew Roh– Matthew Roh2017年04月12日 11:56:16 +00:00Commented Apr 12, 2017 at 11:56
-
\$\begingroup\$ @SIGSEGV: I'd be interested to see what the intended version was then :) \$\endgroup\$Emigna– Emigna2017年04月12日 12:03:39 +00:00Commented Apr 12, 2017 at 12:03
Python 2, 174 bytes, cracks penalosa
print str(input()**(5. * .5))or ()/22*2444599.9.HHHWWW_______________aaaaabbbcccccccccddddddeeeeeeeeeeeefffgghhhhiiiiiiikkkkkkkkkllllllllmmnnnooooooooprrrrrrrrrrrt.tttuuuuuu;
Vyxal, cracks emanresuA's answer
5|2/en[(`ĖĖ:
Easy. I came up with the solution in the shower that's how easy it is.
-
\$\begingroup\$ So you have, thanks to an oversight of mine. On to round 2 \$\endgroup\$emanresu A– emanresu A2021年11月25日 07:47:03 +00:00Commented Nov 25, 2021 at 7:47
Explore related questions
See similar questions with these tags.