3
Your Goal: Estimate pi to at least 10 decimal places. The format is your choice - it can output as a number, as a string, as an output to STDOUT, etc.
Seems easy, right? But wait, it's not as simple as it seems...
The Rules: You get exactly 10 function calls (this includes operators). These functions cannot be ones that naturally induce or define pi, such as the arc-trig functions or a function converting degrees to radians (this also includes any function that operates as a "solver", such as one that can find roots of sin(x)
). If your language has complex number capabilities, this capability cannot be used. All functions must be part of your languages built-in functions or within a standard library (loading the library does not count as an operation, but it must be a standard library, not just a popular one).
All function calls must be crucial to your code - this means that you cannot use division by one, or factorial of two. You also cannot use any literal (except for three digits in the form of one, two, or three integers)*, reading of files of any sort, or a code's ability to convert itself into values (such as a function to get the name of a variable as a string).
*Note: an exception is made for format strings for languages that require them for output. However, only formats, not actual contents, can be found in the format strings, so you can have printf("%f%f",x,y)
, but not printf("%f.%f",x,y)
.
Loops may be used, but will eat up your function calls - the 10 function calls are calls, not total functions used. Assignment does not count as an operation, but operations such as array slicing (including obtaining a single value from an array) count, in which case a[1] would count as two bytes (for []
).
If you think you've found a loophole for the rules, then it's also against the rules. This is not a challenge for finding the best bending of the rules, or the best way of abusing a minor oversight in the challenge question... if your instinct is to call it a "loophole", then post it as a comment to help close it.
Scoring: This is code bowling, so you're after the highest score. But it's not the total number of bytes in your code that is being counted.
Instead, it's the sum of bytes in the functions being used. That is, if you use 4*cos(2/3)
(which happens to be approximately 3.14355), then you have three functions - *
, cos
, and /
, with the total being 5 bytes. If you were to use, for instance (using Julia), sum(map(n->1/n,1:4))
, then the operations are sum
, map
, /
, and :
, for 8 bytes... but as 1/n is being called four times, it uses 7 function calls (sum
, map
, four instances of /
, and :
). User-made functions do not count towards either the function call allowance or the byte count (note: functions used in those user-made functions do count).
Additional emphasis: The point, here, is to find the best way to abuse your language's longest built-in/standard function names in the context of calculating pi. More digits of pi aren't necessary, but I will personally be more likely to upvote an answer that gets more digits than necessary.
Remember, since you're after long function names, you should probably avoid unary and binary operators, as most of these have full function equivalents (in Julia, for instance, *
can be replaced by prod
).
Quick Summary: You have 10 built-in function calls (includes operators/subroutines/etc). You must estimate pi to 10 decimal places. You can use a total of 3 characters for integer literals (so you can have 1 and 36, or 1 and 2 and 3, or 328, but you can't have 22 and 49). Score is count of built-in function name bytes (if the user defines the name, it doesn't count). No functions that calculate or use pi directly. No complex numbers. This is not a challenge to find loopholes.
Can we count TI-BASIC by displayed characters, not tokens? – lirtosiast – 2015-07-22T17:44:21.877
2I don't understand the scoring example. If the
:
counts as a function for the purpose of counting bytes, why does it not count as a function for the purpose of number of invocations? – Peter Taylor – 2015-07-22T18:17:34.33710
If you think you've found a loophole for the rules, then it's also against the rules.
This doesn't excuse you from making precise rules. Some of the fun of code golf is doing things in a clever and unexpected ways. We should not have to guess your intent to do a challenge. – xnor – 2015-07-22T19:33:14.0601Could you summarize the rules. eg 10 function calls only, 3 literals only (must be integer 0 to 999), etc – MickyT – 2015-07-22T21:14:08.757
2Found a loophole capable of giving infinite scores. In python you can do
import function from module as aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
– Maltysen – 2015-07-23T00:00:51.107@PeterTaylor - you're right, that was an oversight. It'll be fixed in a moment. – Glen O – 2015-07-23T03:18:11.723
@xnor - the point was that I had tried to deal with all possible loopholes, but it was possible that I'd missed some. That statement was my way of saying "looking for loopholes that are obviously loopholes and not real opportunities is against the point of this challenge". I may not have closed every loophole, but I was pretty explicit about what the challenge is about. – Glen O – 2015-07-23T03:20:10.980
@Maltysen - I would consider that to be the equivalent of typing
aaaaaaaaaaaaaaaaaaaaa = sum
in Julia - it's a user-defined function name, and thus not counted. – Glen O – 2015-07-23T03:21:18.637Since the built-in name would be
function
, it would count as 8 bytes, no matter how manya
characters are used in the user-defined function name. Also, @MickyT - I've added a quick summary, let me know if there's any issue with it. – Glen O – 2015-07-23T03:37:58.440I was all set for a Monte Carlo approach, until I read the rule about loops. Somehow I don't think I can stick to 10 function calls in several hundred (or thousand) trials... – Tim Pederick – 2015-07-23T09:53:03.110
@TimPederick - yes, that would be quite a challenge. I put the rule about loops in because it's pretty easy to come up with algorithms that use just a few operations within a loop, and with enough iterations, it'll converge. I might try to come up with a code-bowling problem (I'm enjoying the challenge of designing good code-bowling challenges) that could use Monte Carlo or similar approaches soon. – Glen O – 2015-07-23T11:16:17.410
'If you think you've found a loophole for the rules, then it's also against the rules.' You sir, you should be a lawyer. – Zukki – 2015-07-23T14:01:20.137
@Zukki - Can you think of a better way to emphasise it? You wouldn't call it a "loophole" if it was a clearly-acceptable action. – Glen O – 2015-07-23T16:57:17.310
I'm voting to close this as off-topic because, without a clear list of what is and isn't allowed, there is no way to determine if a solution is valid or not. – Mego – 2016-07-14T23:37:51.263
@Mego - can you be more specific? What's something that is unclear in terms of what is and isn't allowed? I'm particularly confused by the "objective primary winning criterion" issue, given that it's quite clear - you count up the bytes used in the built-in names of function calls and equivalent (operators are functions), and the most bytes wins. The only imperfection is the "loophole" line... and that's nothing more than saying "if you see it as a loophole, don't use it". – Glen O – 2016-07-15T06:07:51.270
@GlenO That loophole line is a big part of the problem - what one person may view as a loophole, another may view as a clever solution. It's entirely arbitrary. – Mego – 2016-07-15T06:09:40.993
@Mego - it's not intended as an absolute, but a way to ask people to think about the intent of the rules as well as the explicit wording. There are multiple examples in the "Standard Loopholes" listing on Meta where everyone would recognise it as a loophole irrespective of the problem at hand - for instance, "Optimising for the given test cases". Can you give an example of something that some people might think is a loophole, and others would just call a clever solution? – Glen O – 2016-07-15T06:27:16.290
Note that it specifically says "if your instinct is to call it a "loophole", then post it as a comment to help close it." - in other words, I've tried my best to close all loopholes, but if I've missed one, let me know. – Glen O – 2016-07-15T06:41:50.937