mirror of
https://github.com/artegoser/ONLang
synced 2024-12-22 17:13:46 +03:00
doc: factorial
This commit is contained in:
parent
f1475c60e3
commit
db95b092e5
1 changed files with 77 additions and 0 deletions
77
examples/factorial.json5
Normal file
77
examples/factorial.json5
Normal file
|
@ -0,0 +1,77 @@
|
|||
[
|
||||
{
|
||||
fn: {
|
||||
name: "fact",
|
||||
args: ["n"],
|
||||
body: [
|
||||
{ let: { result: { var: "fact.n" } } },
|
||||
{
|
||||
loop: [
|
||||
//using loop because recursion is not supported
|
||||
{
|
||||
if: {
|
||||
condition: { comp: [{ var: "fact.n" }, ">", 1] },
|
||||
body: [
|
||||
{
|
||||
assign: {
|
||||
"fact.n": {
|
||||
calc: [{ var: "fact.n" }, "-", 1],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
assign: {
|
||||
result: {
|
||||
calc: [{ var: "result" }, "*", { var: "fact.n" }],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
else: ["break"],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{ return: { var: "result" } },
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
fn: {
|
||||
name: "_eq",
|
||||
args: ["a", "b"],
|
||||
body: [{ return: { comp: [{ var: "_eq.a" }, "==", { var: "_eq.b" }] } }],
|
||||
},
|
||||
},
|
||||
|
||||
["10! == 3 628 800: ", { _eq: [{ fact: [10] }, 3628800] }],
|
||||
["11! == 39 916 800: ", { _eq: [{ fact: [11] }, 39916800] }],
|
||||
|
||||
["12! == 479 001 600: ", { _eq: [{ fact: [12] }, 479001600] }],
|
||||
["13! == 6 227 020 800: ", { _eq: [{ fact: [13] }, 6227020800] }],
|
||||
|
||||
["14! == 87 178 291 200: ", { _eq: [{ fact: [14] }, 87178291200] }],
|
||||
["15! == 1 307 674 368 000: ", { _eq: [{ fact: [15] }, 1307674368000] }],
|
||||
|
||||
["16! == 20 922 789 888 000: ", { _eq: [{ fact: [16] }, 20922789888000] }],
|
||||
["17! == 355 687 428 096 000: ", { _eq: [{ fact: [17] }, 355687428096000] }],
|
||||
|
||||
[
|
||||
"18! == 6 402 373 705 728 000: ",
|
||||
{ _eq: [{ fact: [18] }, 6402373705728000] },
|
||||
],
|
||||
[
|
||||
"19! == 121 645 100 408 832 000: ",
|
||||
{ _eq: [{ fact: [19] }, 121645100408832000] },
|
||||
],
|
||||
|
||||
[
|
||||
"20! == 2 432 902 008 176 640 000: ",
|
||||
{ _eq: [{ fact: [20] }, 2432902008176640000] },
|
||||
],
|
||||
// [
|
||||
// "21! == 51 090 942 171 709 440 000: ",
|
||||
// { _eq: [{ fact: [21] }, 51090942171709440000] },
|
||||
// ], some json and yaml troubles with number `51090942171709440000`
|
||||
]
|
Loading…
Add table
Reference in a new issue