My attempt is to, using design script in a code block, create a Definition to create a Fibonacci sequence of a given length. I was able to complete this same task utilzing Swift on a Ipad. However having trouble getting the write syntax and equvilant opperations in Dynamo.
When ever i attempt to run, Dynamo will Run until I kill the process.
@Mike_Engel1 The problem lies in your while block ( i increment and List.AddItemToEnd )

def fib(n)
{
return = [Imperative]
{
sequence = {0,1};
i = List.Count(sequence);
if (n<=2)
{
return = "Sorry";
}
while (i != n)
{
results = sequence[i-1] + sequence[i-2];
sequence = List.AddItemToEnd(results,sequence);
i=i+1;
}
return = sequence;
}
};
Thanks, new I was close just couldn’t see it. And that I now do, it seems obvious - particularly because I had the same issue when appending the list. For some reason in Swift one doesn’t have “=” it just some how knows.
Working…
Mostly…
I’m lost as to why once i get above the 48 item the numbers intermitantly come back as a negative. Is this a limitation to the number of digits availble in Dynamo?
1 Like
@Mike_Engel1 That’s not good. Kindly report the issue here
Interesting. Never really thought about that.
The best course of option would be create a step to generate a Message if to large of value is created.
Also Interesting is that my experimenting in Swift does not have this issue (though it also errors out the 93rd item on the list 7,540,113,804,746,346,429)
Your Swift code is most likely using int64 instead.
Type Capacity
Int16 -- (-32,768 to +32,767)
Int32 -- (-2,147,483,648 to +2,147,483,647)
Int64 -- (-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807)
2 Likes