I’m hoping that you can do recursion with ZScript:
[VarDef, myNumber, 1]
// 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 …
[RoutineDef, fibonacci,
[If, n <= 2
, // Then…
[VarSet, n, 1]
, // Else…
[VarSet, n, [RoutineCall, fibonacci, n-1] + [RoutineCall, fibonacci, n-2]]
]
,n]
[IButton, “Fibonacci”, “Fibonacci Sequence”,
// call the routine
[RoutineCall, fibonacci, myNumber]
[Note, myNumber, 1]
]/End of ZScript/
I get a closing bracket error - but I suspect it’s actually setting n as the routine call which is wrong. Any pointers, Marcus?