Five programming problems every Software Engineer should be able to solve in less than 1 hour

Jerry Jensen jhj at jhj.com
Sun May 10 02:12:08 CEST 2015


We went through this a while ago, I think a challenge forwarded by Mark Wieder. The problem is that integers overflow and start giving wrong answers part way to 100. I forget the exact place it happens.

I wrote a few that did it the hard way (character by character arithmetic) - I’ll see if I can find them.
.Jerry

> On May 9, 2015, at 4:32 PM, Geoff Canyon <gcanyon at gmail.com> wrote:
> 
> Problem 3
> 
> Write a function that computes the list of the first 100 Fibonacci numbers.
> By definition, the first two numbers in the Fibonacci sequence are 0 and 1,
> and each subsequent number is the sum of the previous two. As an example,
> here are the first 10 Fibonnaci numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, and
> 34.
> 
> I didn't hard code, instead taking an argument for the number of Fibonnaci
> numbers to return:
> 
> function fib N
>   put "0,1" into R
>   if N <= 2 then return item 1 to N of R
>   put 0 into F1
>   put 1 into F2
>   repeat N - 2
>      put F1 + F2 into F3
>      put "",F3 after R
>      put F2 into F1
>      put F3 into F2
>   end repeat
>   return R
> end fib
> 
> Test Data
> 0
> 1
> 2
> 20
> 
> Test Results
> 
> 0
> 0,1
> 0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the use-livecode mailing list