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 cops-and-robbers, 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.
-
2\$\begingroup\$ Related. (Same CnR rules, different task.) \$\endgroup\$Martin Ender– Martin Ender2017年04月03日 12:57:21 +00:00Commented Apr 3, 2017 at 12:57
-
3\$\begingroup\$ @MartinEnder If the task is the only thing differing, then isn't it a duplicate? \$\endgroup\$Nathan Merrill– Nathan Merrill2017年04月03日 14:48:24 +00:00Commented 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\$Martin Ender– Martin Ender2017年04月03日 14:50:32 +00:00Commented 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– Mr. Xcoder2017年04月03日 15:23:43 +00:00Commented 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\$fəˈnɛtɪk– fəˈnɛtɪk2017年04月03日 16:19:16 +00:00Commented Apr 3, 2017 at 16:19
68 Answers 68
Python 3, 44 bytes (cracked)
'**:(((paraboloid / rabid,mad,immoral))):**'
No rounding. Floating point accuracy.
-
5\$\begingroup\$ Come on, this deserves more points, it's so creative! There is symmetry, and all words are real words. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2017年04月08日 18:12:40 +00:00Commented Apr 8, 2017 at 18:12
-
1
MATL, 12 bytes (cracked by @tehtmi)
'Un&0P'/^:+1
No rounding; uses floating point.
Intended solution (different from that found by @tehtmi):
:&+n10U'P'/^
Explanation
:&+ % Create a matrix of size n ×ばつ n, where n is implicit input
n % Number of elements. Gives n^2
10U % 10 squared. Gives 100
'P' % 'P' (ASCII code 80)
/ % Divide. Gives 1.25
^ % Power. Implicit display
-
1
-
\$\begingroup\$ @tehtmi Indeed! Well done! My intended solution was different; I just posted it \$\endgroup\$Luis Mendo– Luis Mendo2017年04月06日 09:20:42 +00:00Commented Apr 6, 2017 at 9:20
Röda, 28 bytes (Cracked by @tehtmi)
(),.025^^cdfhnnnopprstuu{|}
Note the space at the beginning. No rounding, but it uses floating point numbers so precision is limited.
-
\$\begingroup\$ Is this an anonymous function, or a "full" function? \$\endgroup\$user41805– user418052017年04月03日 16:12:11 +00:00Commented Apr 3, 2017 at 16:12
-
\$\begingroup\$ @KritixiLithos if the cop does not want to give clues, it is not supposed to \$\endgroup\$Mr. Xcoder– Mr. Xcoder2017年04月03日 16:15:01 +00:00Commented Apr 3, 2017 at 16:15
-
Perl, 42 bytes (Safe)
There are 41 bytes of code and -p flag (no other flags).
/"/4~~r..rso4r<_4ドルva=eg1de|i/h0-&$c={}l+"
The result isn't rounded (or rather rounded up to the same point Perl would have round up by doing $_ = (sqrt $_) * ($_ ** 2)).
Solution:
$_=eval".i44<4}{|~"=~s/./chr-10+ord$\&/gre
(without the\before the&- markdown spoiler seems to dislike$followed by&)
Try it online!
Explanation:
.i44<4}{|~is$_**2*sqrtbut with every character replaced by the character with its ascii code + 10. (ascii code of$is36, so it becomes.whose ascii code is46, etc.).
The purpose ofs/./chr-10+ord$\&/greis then to undo this transformation: it replaces each character by the character with ascii code 10 lower. (chr-10+ord$\&is probably clearer aschr(ord($\&)-10)wherechrreturns the character corresponding to an ascii code, andordreturns the ascii code corresponding to a character).
finally,evalevaluates this string, and thus computes the result, which is stored in$_, which is implicitly printed at the end thanks to-pflag.
-
\$\begingroup\$ True. I was trying to edit quickly because I saw 4 reopen votes and hoped to get the question fixed before the 5th was cast. If the question had been left in the sandbox until it was ready, it would have been better for all involved. \$\endgroup\$Peter Taylor– Peter Taylor2017年04月03日 15:57:48 +00:00Commented Apr 3, 2017 at 15:57
-
\$\begingroup\$ @PeterTaylor Sure, no problem, and anyway it was bold so fairly visible (I wasn't blaming anyone, but merely pointing a minor flow (that I corrected right away (introducing typos in the process))). And I couldn't agree more about the sandbox part. \$\endgroup\$Dada– Dada2017年04月03日 16:04:43 +00:00Commented Apr 3, 2017 at 16:04
-
\$\begingroup\$ can you explain it a bit? \$\endgroup\$phuclv– phuclv2017年04月05日 06:47:30 +00:00Commented Apr 5, 2017 at 6:47
-
\$\begingroup\$ @LưuVĩnhPhúc You mean if I can give you a little bit of help to crack it? mmh... the code starts with
$_=. And there is aevalsomewhere. (that's not a lot but I feel I can't give you more without giving you too much information) \$\endgroup\$Dada– Dada2017年04月07日 09:24:21 +00:00Commented Apr 7, 2017 at 9:24
Octave, 43 bytes (Safe)
$'()*+,-/23579:[]aelnouv'*,-23:[]lu',-23]',
This is a script that requires input from the command line (it's not a function). It's floating point accuracy (so no rounding).
Solution:
eval(-[5,-2:3,-3:2]+['nlouu*$$',39,']2/7'])
Explanation:
eval( <string> ) % Evaluated the string inside the brackets and executes it
Everything inside theevalcall gets evaluated toinput('')^2.5
How?
-[5,-2:3,-3:2] % A vector: [-5, 2, 1, 0, -1, -2, -3, 3, 2, 1, 0, -1, -2]
['nlouu**$$',39,']2/7'] % This is a string: nlouu**$ concatenated with the number
. % 39 (ASCII ']'), and ']2/7'. Thus, combined: 'nlouu**$$']2/7'
Adding the first vector to this string will convert it to the integer vector:
[105, 110, 112, 117, 116, 40, 39, 39, 41, 94, 50, 46, 53]
evalimplicitly converts this to a string, and these numbers just so happens to be:input('')^2.5
-
1\$\begingroup\$ This was hard. Well done! \$\endgroup\$Luis Mendo– Luis Mendo2017年04月09日 02:08:30 +00:00Commented Apr 9, 2017 at 2:08
C, 50 bytes (Cracked by fergusq)
%(()) ,-12225;>\\aaabbdddeeefffllnoooprrttuuuuw{
Uses standard IEEE754 rounding. As noted by fergusq's answer, may require -lm depending on your compiler.
-
-
\$\begingroup\$ @fergusq correct, and almost exactly what I had. Well done; I thought I'd left enough red-herrings in there to keep people busy a lot longer! \$\endgroup\$Dave– Dave2017年04月04日 11:56:38 +00:00Commented Apr 4, 2017 at 11:56
-
\$\begingroup\$ @Dave Wow, that looks like a syntax error at first. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2017年04月04日 17:08:34 +00:00Commented Apr 4, 2017 at 17:08
Mathematica, 131 bytes, non-competing?, cracked
This has been cracked by @lanlock4 ! However, I still have internet points to bestow on someone who finds the original solution, where all the characters are actually needed....
f[y_]:=With[{x=@@@@@@#####^^&&&(((()))){{}}111111,,+-/y},Print[#,".",IntegerString[Round@#2,10,3]]&@@QuotientRemainder[1000x,1000]]
This is intended as a puzzle. Although you may use the above characters however you want, I certainly intend for the answer to follow the form
f[y_]:=With[{x=
@@@@@@#####^^&&&(((()))){{}}111111,,+-/y
},Print[#,".",IntegerString[Round@#2,10,3]]&@@QuotientRemainder[1000x,1000]]
where the first and third lines are just a wrapper to make the rounding and display legal (it writes every output to exactly three decimal places, rounded), and the second line is the scrambled version of the guts of the code. Sample outputs:
6 -> 88.182
9 -> 243.000
9999 -> 9997500187.497
(Mathematica is non-free software, but there is a Wolfram sandbox where it is possible to test modest amounts of code. For example, cutting and pasting the code
f[y_]:=With[{x=
y^2.5
},Print[#,".",IntegerString[Round@#2,10,3]]&@@QuotientRemainder[1000x,1000]]
defines a function, which you can subsequently call like f@6 or f[9], that does the same thing as the unscrambled version of the code above. So does this really have to be non-competing?)
-
\$\begingroup\$ Cracked it! \$\endgroup\$Not a tree– Not a tree2017年04月04日 00:50:55 +00:00Commented Apr 4, 2017 at 0:50
Swift - 64 bytes (Safe)
prot Fdnufi;nooitamunc xetgru(->atl)Ior:n{tFn pg,F(ao.o25t)(w)l}
No rounding, and displays a .0 even if the result is an integer.
R, 28 bytes (Cracked by @Flounderer)
funny(p1)-tio(^*^)/pc(2)<p2;
Standard R floating-point accuracy.
-
\$\begingroup\$ Is this it? codegolf.stackexchange.com/a/115132/26905 \$\endgroup\$Flounderer– Flounderer2017年04月03日 22:31:14 +00:00Commented Apr 3, 2017 at 22:31
-
\$\begingroup\$ @Flounderer Yes, it is. \$\endgroup\$Steadybox– Steadybox2017年04月03日 23:05:15 +00:00Commented Apr 3, 2017 at 23:05
C#, 172 bytes (Cracked by SLuck49)
(((((())))))***,,,,......1225;;;;;;<====>CFLMMMMMPPPRSSSSSWaaaaaaabbbbcccddddddeeeeeeeeeeegghiiiiiiiillllllmmnnnnnnnooooooooqqqqrrrssssssssstttttttttuuuuuuuvvwyy{{}}
This code is a full program.
There are seven space characters at the start.
The input is read form STDIN and printed to STDOUT. The result is in double, no rounding done.
Original Code ungolfed:
using System;
using S = System.Console;
class P
{
static void Main()
{
var t = S.ReadLine();
double q = int.Parse(t);
Func<double, double, double> M = Math.Pow;
S.Write(M(q, 2 * .25) * M(q * q, 1));
}
}
Ohm, 11 bytes
M n¡D1⁄41⁄2;+1I
Use with -c flag. Uses CP-437 encoding.
-
\$\begingroup\$ I'm sorry, but are you quite sure this is correct? \$\endgroup\$user4867444– user48674442017年04月07日 20:51:06 +00:00Commented Apr 7, 2017 at 20:51
-
\$\begingroup\$ Now that no one has cracked it in the imparted time, mind sharing your solution please? I'm very curious :) \$\endgroup\$user4867444– user48674442017年04月10日 00:51:50 +00:00Commented Apr 10, 2017 at 0:51
-
\$\begingroup\$ For now, this is the shortest answer considered safe. I will accept it, but if you do not post your original code in 5 days, I will uncheck this, since I am not sure this is possible. EAGER too see your solution \$\endgroup\$Mr. Xcoder– Mr. Xcoder2017年05月01日 16:23:14 +00:00Commented May 1, 2017 at 16:23
-
2\$\begingroup\$ @RomanGräf try to find your solution, please. Otherwise I will uncheck this... \$\endgroup\$Mr. Xcoder– Mr. Xcoder2017年05月06日 10:37:34 +00:00Commented May 6, 2017 at 10:37
-
1\$\begingroup\$ @RomanGräf : ping? Still very eager to see that solution :) \$\endgroup\$user4867444– user48674442017年05月09日 04:41:29 +00:00Commented May 9, 2017 at 4:41
JavaScript (ES7), 20 bytes (Cracked by @IlmariKaronen)
****..22255666=>____
Standard JavaScript precision.
-
\$\begingroup\$ Cracked. (Oops, posted in the wrong thread at first.) \$\endgroup\$Ilmari Karonen– Ilmari Karonen2017年04月03日 23:56:20 +00:00Commented Apr 3, 2017 at 23:56
-
\$\begingroup\$ Such a clever approach! +1 :) \$\endgroup\$Arjun– Arjun2017年04月05日 10:01:49 +00:00Commented Apr 5, 2017 at 10:01
Python 2, 60 Bytes (Cracked by @notjagan)
3n0)4 5)594p3(p5*5i9t4542)0/*((8(t.84- 90945 u)i*48/95n8r8
No rounding involved. Accurate up to 10 decimal digits.
Python 3.6, 59 bytes
ba(,b5,d' (,a/([m:'-)oa)(bl*aadplma dba](r)d )l*d,:)*m:-mml
No rounding. Floating point accuracy.
-
\$\begingroup\$ Really, 3 lambdas? \$\endgroup\$Mr. Xcoder– Mr. Xcoder2017年04月05日 15:48:22 +00:00Commented Apr 5, 2017 at 15:48
Haskell, 64 bytes, (cracked by Laikoni)
$$$$$$(((((())))))**,...0<<<>>>[]cccccdddeffiiiiilloopppprrsstuu
Standard Haskell floating point operations.
My original version is:
product.((($succ$cos0ドル)(flip(**).)[id,recip])).flip(id)
-
-
\$\begingroup\$ @Laikoni: well done! \$\endgroup\$nimi– nimi2017年04月04日 14:21:12 +00:00Commented Apr 4, 2017 at 14:21
Fourier, (削除) 124 (削除ここまで) 119 Bytes
((()))*******--011111<=>>>HHINNNN^^^eeehhhhkkkkmmmmmmmmmmmmmmmmossuuuuuuuuuuuuuuuuu{{{{{{{{{{}}}}}}}}}}~~~~~~~~~~~~~~~~
There are no whitespaces or newline characters.
Square root is rounded to the nearest whole number because Fourier doesn't seem to handle anything other than integers (and since @ATaco got permission, I hope this is ok)
fixed an editing mistake, if you were already cracking this, the previous was functional
Realized that I had misunderstood part of the code, and was using more characters than I needed to
If I missed anything let me know
Inform 7, 71 bytes (Cracked by @Ilmari Karonen)
""()**-..:[]
RT
aaaabeeeffilmmnnnnnooooooqrrrrrssstuuy
The code includes 17 spaces and 2 new lines. This is a full Infrom 7 program defining a function that prints the result with a precision of 5 decimal places.
-
\$\begingroup\$ Cracked. \$\endgroup\$Ilmari Karonen– Ilmari Karonen2017年04月03日 22:59:29 +00:00Commented Apr 3, 2017 at 22:59
R, 19 bytes (Cracked by @Steadybox)
mensana(4*5*c(.1)):
Standard rounding
R, 33 bytes (Cracked by @plannapus)
(rofl(17)^coins(2*e)/pisan(10))--
R, 31 bytes (Cracked by @plannapus)
h=f`l`u`n`c`t`i`o`n([],[])^(.9)
Octave, 30 bytes (Safe)
(((((())))))**++/:@eeeiiijmsu~
A bit simpler than my first one. Shouldn't be too hard, but it's hopefully a fun puzzle.
-
2\$\begingroup\$ No
^? Hmmm... \$\endgroup\$Luis Mendo– Luis Mendo2017年04月04日 09:53:00 +00:00Commented Apr 4, 2017 at 9:53 -
1\$\begingroup\$ Came up with this
@(e)(e**((i/(i+i))+~sum(e:j)))but it's onlyn^1.5...this one's tricky. \$\endgroup\$Kyle G– Kyle G2017年04月09日 00:47:01 +00:00Commented Apr 9, 2017 at 0:47
05AB1E, 20 bytes - safe
Another totally different approach from my previous answers.
****++/133DDFPTs}11Ð
No rounding.
Example runs
In -> Out
0 -> 0
4 -> 32.0
6 -> 88.18163074019441
25 -> 3125.0
7131 -> 4294138928.896773
I have no doubt @Emigna is going to crack it in a jiffy, but eh, one has to try! :-D
Solution
D1TFÐ*D13*+s3*1+/*}P
This is using the fact that this sequence:
u_0 = 1, u_{n+1} = u_n * (u_n ^ 2 + 3 x) / (3 u_n ^ 2 + x)
converges to sqrt(x), and cubically fast at that (sorry, didn't find how to format math equations in PCG).
Detailed explanation
D1TFÐ*D13*+s3*1+/*}P
D1 # Duplicate the input, then push a 1: stack is now [x, x, 1] (where x is the input)
TF # 10 times (enough because of the cubic convergence) do
Ð # triplicate u_n
* # compute u_n ^ 2
D # and duplicate it
13*+ # compute u_n ^ 2 + 3 x
s # switch that last term with the second copy of u_n ^ 2
3*1+ # compute 3 u_n ^ 2 + x
/ # compute the ratio (u_n ^ 2 + 3 x) / (3 u_n ^ 2 + x)
* # compute u_n * (u_n ^ 2 + 3 x) / (3 u_n ^ 2 + x), i.e. u_{n+1}, the next term of the sequence
} # end of the loop
P # compute the product of the whole stack, which at that point contains u_10 (a sufficiently good approximation of sqrt(x)), and the 2 copies of the input from the initial D: we get x ^ 2 * sqrt(x)
-
3
Javascript, 123 bytes, Cracked by notjagan
""""""((((((((()))))))))********,--.....//2;;======>>Seeeeeeegggggggggggghhhhhhhhhhhilllllnnnnnnnnnnorrrsstttttttttttttu{}
This code is a full function
There is one space character at the very start of the list of characters
The rounding of this answer is the floating point precision for Javascript, accuracy is within 10^-6 for every answer.
Got shorter because the precision didn't need to be maintained quite as high as I thought it did.
I had realized that it would be much easier to solve than I initially had made it but it was already there :P
Initial code:
g=t=>t-(t*t-n)/("le".length*t);e=h=>{n=h*h*h*h*h,s=2**(n.toString("ng".length).length/"th".length);return g(g(g(g(g(s)))))}
Newtons method, applied 5 times from the closest power of 2
Python 3.6 - 52 bytes (Cracked by @xnor)
f=lambda x:x**125*77*8+8/5/((('aafoort.hipie.xml')))
Standard Python rounding
CJam, 8 bytes (Cracked by E(削除) n (削除ここまで)mig(削除) m (削除ここまで)na)
WYdYl##+
No rounding. Uses double precision.
R, 32 bytes (Cracked by @plannapus)
i=na*0.5f*n(2*s*cos(t))*22*s*12u
Standard floating-point accuracy.
Excel, 26 bytes
=(())*//11122AAAIINPQRSST^
No rounding.
Note: As Excel is paid software, this works also in free LibreOffice
-
1\$\begingroup\$ Is there a way to run this without buying Excel? Currently it is the consensus that non free languages cannot be used in cops and robbers. \$\endgroup\$2017年04月04日 15:22:59 +00:00Commented Apr 4, 2017 at 15:22
-
1\$\begingroup\$ Should work in free Libreoffice, but I'll check and reach back. \$\endgroup\$pajonk– pajonk2017年04月04日 15:28:00 +00:00Commented Apr 4, 2017 at 15:28
-
1\$\begingroup\$ Works just fine. \$\endgroup\$pajonk– pajonk2017年04月04日 15:34:23 +00:00Commented Apr 4, 2017 at 15:34
-
\$\begingroup\$ Cracked codegolf.stackexchange.com/questions/115034/… \$\endgroup\$Jörg Hülsermann– Jörg Hülsermann2017年04月04日 21:27:07 +00:00Commented Apr 4, 2017 at 21:27
-
\$\begingroup\$ @WheatWizard, not relevant anymore, but I think the consensus is: Non-free languages can be used, but should be marked as non-competing. \$\endgroup\$Stewie Griffin– Stewie Griffin2017年04月05日 19:40:59 +00:00Commented Apr 5, 2017 at 19:40
RProgN 2, 6 Bytes (Cracked by @notjagan)
š2]^*\
No rounding, displays many decimal places. Does not display any for an integer solution.
-
2\$\begingroup\$ Does this really perform
n²√n? I can easily get it to calculaten² + √n, but I can't for the life of me see how you got the terms to multiply. \$\endgroup\$notjagan– notjagan2017年04月04日 13:36:28 +00:00Commented Apr 4, 2017 at 13:36 -
\$\begingroup\$ @notjagan me too... have been trying for 2 hours to crack it and nothing works. ATaco are you sure that the source is correct? \$\endgroup\$Mr. Xcoder– Mr. Xcoder2017年04月04日 18:07:24 +00:00Commented Apr 4, 2017 at 18:07
-
\$\begingroup\$ @Mr.Xcoder Ah, you're quite correct. Sorry for wasting your collective times! Please see the edited source. \$\endgroup\$ATaco– ATaco2017年04月04日 20:51:09 +00:00Commented Apr 4, 2017 at 20:51
-
\$\begingroup\$ Now it makes sense! \$\endgroup\$Mr. Xcoder– Mr. Xcoder2017年04月04日 20:52:00 +00:00Commented Apr 4, 2017 at 20:52
-
Explore related questions
See similar questions with these tags.