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

Mike Bonner bonnmike at gmail.com
Sat May 9 18:33:57 EDT 2015


What is the recursion limit? I decided to do a speed test on larger lists,
and strangely, if I have a list that is 704 lines (I used lines rather than
items)  things work fine.  As soon as I hit 705, I get the following:

executing at 4:30:55 PM
Type Function: error in function handler
Object Button
Line return (line 1 of pList + withRecurse( line 2 to -1 of pList))
Hint withRecurse

dropping back to 704, (no changes to my script)  and viola' it works again.

Needless to say, if I'm hitting a recursion limit, a better error message
would be nice.  This is using 6.6.2.

On Sat, May 9, 2015 at 3:55 PM, Geoff Canyon <gcanyon at gmail.com> wrote:

> Problem 1
>
> Write three functions that compute the sum of the numbers in a given list
> using a for-loop, a while-loop, and recursion.
>
> Note that he doesn't provide any test cases, so for each problem I provided
> my own in a field, and then called the functions for each line in the test
> field, putting the output in another field. On to the functions:
>
> function sumFunction X
>   -- just because I could, not part of the original requirements
>    return sum(X)
> end sumFunction
>
> function sumFor X
>    repeat for each item i in X
>       add i to R
>    end repeat
>    return R
> end sumFor
>
> function sumWhile X
>    repeat while X is not empty
>       add item 1 of X to R
>       delete item 1 of X
>    end repeat
>    return R
> end sumWhile
>
> function sumRecurse X
>    if the number of items of X <= 1
>      then return X
>      else return item 1 of X + sumRecurse(item 2 to -1 of X)
> end sumRecurse
>
> Test data (first line was blank on purpose):
>
> 5
> 2,3,5,6,2,3,1
> -4,4
> -4,4,-5,5
>
> Test output (not entirely happy about the disparity in results for empty
> input):
> 0
> 5 5 5 5
> 22 22 22 22
> 0 0 0 0
> 0 0 0 0
> _______________________________________________
> 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