Just uses the simple formule 180-360/n
used on other answers.
Due to ... sub-optimal ... math support, the formule was adapted to (-360/$n)+180
(it's almost the same, calculated in a different order).
{@set/A-360 argv}{@incby180A}{@echoA}
You can try it on: http://sandbox.onlinephpfunctions.com/code/00b314dee3c10139928928d124be9fc1c59ef4bf
On line 918, you can change between golfed
, ungolfed
and fn
, to try the variants below.
Ungolfed:
{@set/ A -360 argv}
{@inc by 180 A}
{@echo A}
Yeah, there's not much to ungolf...
Explanation:
{@set/ A -360 argv}
- Stores in A
the result of -360/argv
.
argv
is a variable that holds all passed arguments (in a function or when running the code).
A
is now an array with argc
elements (argc
holds the number of aguments passed).
{@inc by 180 A}
- Increments all values of A
by 180 (A+180
, basically)
{@echo A}
- Outputs the values of A, without delimiter.
One could use {@return A}
if inside a function, to get an usable array.
Function alternative:
Converting to a function to get an usable array is easy:
{@fn N}
{@set/ A -360 argv}
{@inc by 180 A}
{@return A}
{@/}
Creates a function N
that takes multiple arguments and returns an array.
Just call it as {@call N into <variable> <argument, arguments...>}
.
If you are curious, this code compiles to the following:
// {@set/A-360 argv}
$DATA['A'] = array_map(function($value)use(&$DATA){return (-360 / $value);}, $FN['array_flat']((isset($DATA['argv'])?$DATA['argv']:null)));
// {@incby180A}
$DATA['A'] = $FN['inc'](isset($DATA['A'])?$DATA['A']:0, 180);
// {@echoA}
echo implode('', $FN['array_flat']((isset($DATA['A'])?$DATA['A']:null)));
1Degrees, radians, grads, or user discretion? – Jeff Zeitlin – 2019-10-22T15:12:55.477
@JeffZeitlin user discretion, will edit to clarify – Jachdich – 2019-10-22T15:13:51.003
Do you mean the sum of the internal angles or the value of one of the angles? – HiddenBabel – 2019-10-22T15:16:42.383
@HiddenBabel value of one. I'll edit to clarify – Jachdich – 2019-10-22T15:18:14.627
2Is there a higher/lower bound on what we have to support? i've got an idea for an answer with a microcontroller language but it can only really support upto 255 – Alex Robinson – 2019-10-24T09:39:57.647
1@AlexRobinson yeah that's fine, just specify in your answer. – Jachdich – 2019-10-24T10:00:21.100