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.
:
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? \$\endgroup\$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. \$\endgroup\$import function from module as aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
\$\endgroup\$