2022-08-15 18:52:32 +03:00
|
|
|
[
|
|
|
|
{
|
|
|
|
fn: {
|
2022-08-18 14:12:51 +03:00
|
|
|
name: "fact_loop",
|
2022-08-15 18:52:32 +03:00
|
|
|
args: ["n"],
|
|
|
|
body: [
|
2022-08-18 14:12:51 +03:00
|
|
|
{ let: { result: { var: "n" } } },
|
2022-08-15 18:52:32 +03:00
|
|
|
{
|
|
|
|
loop: [
|
2022-08-18 14:12:51 +03:00
|
|
|
//using loop because recursion is not supported*
|
|
|
|
//* - already supported
|
2022-08-15 18:52:32 +03:00
|
|
|
{
|
|
|
|
if: {
|
2022-08-18 14:12:51 +03:00
|
|
|
condition: { comp: [{ var: "n" }, ">", 1] },
|
2022-08-15 18:52:32 +03:00
|
|
|
body: [
|
|
|
|
{
|
|
|
|
assign: {
|
2022-08-18 14:12:51 +03:00
|
|
|
n: {
|
|
|
|
calc: [{ var: "n" }, "-", 1],
|
2022-08-15 18:52:32 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
assign: {
|
|
|
|
result: {
|
2022-08-18 14:12:51 +03:00
|
|
|
calc: [{ var: "result" }, "*", { var: "n" }],
|
2022-08-15 18:52:32 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
else: ["break"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ return: { var: "result" } },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-08-18 14:12:51 +03:00
|
|
|
{
|
|
|
|
fn: {
|
|
|
|
name: "fact",
|
|
|
|
args: ["n"],
|
|
|
|
body: [
|
|
|
|
{
|
|
|
|
if: {
|
|
|
|
condition: { comp: [{ var: "n" }, "==", 1] },
|
|
|
|
body: [{ return: 1 }],
|
|
|
|
else: [
|
|
|
|
{
|
|
|
|
return: {
|
|
|
|
calc: [
|
|
|
|
{ var: "n" },
|
|
|
|
"*",
|
|
|
|
{ fact: [{ calc: [{ var: "n" }, "-", 1] }] },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-08-15 18:52:32 +03:00
|
|
|
{
|
|
|
|
fn: {
|
|
|
|
name: "_eq",
|
|
|
|
args: ["a", "b"],
|
2022-08-18 14:12:51 +03:00
|
|
|
body: [{ return: { comp: [{ var: "a" }, "==", { var: "b" }] } }],
|
2022-08-15 18:52:32 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
["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] },
|
|
|
|
],
|
2022-08-18 14:12:51 +03:00
|
|
|
"",
|
|
|
|
["(loop) 10! == 3 628 800: ", { _eq: [{ fact_loop: [10] }, 3628800] }],
|
|
|
|
["(loop) 11! == 39 916 800: ", { _eq: [{ fact_loop: [11] }, 39916800] }],
|
|
|
|
|
2022-08-15 18:52:32 +03:00
|
|
|
// [
|
|
|
|
// "21! == 51 090 942 171 709 440 000: ",
|
|
|
|
// { _eq: [{ fact: [21] }, 51090942171709440000] },
|
|
|
|
// ], some json and yaml troubles with number `51090942171709440000`
|
|
|
|
]
|