odd and even numbers

Alex Tweedly alex at tweedly.net
Mon Aug 5 19:15:37 EDT 2013


On 05/08/2013 23:53, Paul D. DeRocco wrote:
>> .
>>
>> I thought the original question stated the assumption that the number was
>> whole. Normally, one tests to see if a number is an integer by comparing it
>> to its integer part. In LC you just ask if it "is an integer".

No, it didn't. That was precisely my point. The original question said:

> How do you test a number to see if it is a whole odd or even number? 
i.e. "test a number" (no explicit assumptions about that number 
included) to see whether or not it is a "whole odd or even" number.
My question (and attempted re-stating of the original) was intended to 
make it clear whether "wholeness" is a valid assumption or is part of 
the investigation.

btw - not trying to pick on Jacque, but even if you assume the value is 
an integer, then her solution will fail in some cases. Why? Because if 
you test "2." LC will tell you it is an integer - but although it should 
be "even", it does not finish with any of 02468 ?!


function aa p
return p && (p is an integer)
end aa

on mouseUp
    put aa(2.)
    exit mouseUp

Of course, if it is part of the "investigation" then we can then talk 
about the exact definition of "whole number" - it's not as widely agreed 
or unambiguous as I thought it was.

Your points about the interesting differences between this question in 
LC vs the same question in C are absolutely right and interesting..

-- Alex.





More information about the use-livecode mailing list