Anonymous user
Check Machin-like formulas: Difference between revisions
+J (note: I developed & posted this solution entirely on my iPad, so it may have some display issues).
(Go solution) |
(+J (note: I developed & posted this solution entirely on my iPad, so it may have some display issues).) |
||
Line 188:
putStr "\nnot Machin: "; print not_machin
print (tans not_machin)</lang>
=={{header|J}}==
'''Solution''':<lang j> machin =: 1r4p1 = [: +/ ({. * _3 o. %/@:}.)"1@:x:</lang>
'''Example''':<lang j> R =: <@:(0&".);._2 ];._2 noun define
1 1 2
1 1 3
------------
2 1 3
1 1 7
------------
4 1 5
_1 1 239
------------
5 1 7
2 3 79
------------
5 29 278
7 3 79
------------
1 1 2
1 1 5
1 1 8
------------
4 1 5
_1 1 70
1 1 99
------------
5 1 7
4 1 53
2 1 4443
------------
6 1 8
2 1 57
1 1 239
------------
8 1 10
_1 1 239
_4 1 515
------------
12 1 18
8 1 57
_5 1 239
------------
16 1 21
3 1 239
4 3 1042
------------
22 1 28
2 1 443
_5 1 1393
_10 1 11018
------------
22 1 38
17 7 601
10 7 8149
------------
44 1 57
7 1 239
_12 1 682
24 1 12943
------------
88 1 172
51 1 239
32 1 682
44 1 5357
68 1 12943
------------
)
machin&> R
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1</lang>
'''Notes''': The function <tt>machin</tt> compares the results of each formula to π/4 (expressed as <tt>1r4p1</tt> in J's numeric notation). The last expression above shows the results of these comparisons for each formula (with 1 for true and 0 for false). In J, arctan is expressed as <tt>3 o. ''values''</tt> and the function <tt>x:</tt> coerces values to extended precision; J maintains this precision as far as possible.
=={{header|OCaml}}==
|