On 25-Jun-97, Olga Tuzova wrote:
>> to happy.test :i
>> op equalp (sum first :i first bf :i first bf bf :i) ~
>> (sum last :i last bl :i last bl bl :i)
>> end
>Oh, is it really more natural?
I think it is more natural, based on the way you defined the problem.
>But I'd like my students to know that
>number is a number, not just a word, and it's components (digits)
>have some special qualities. And I want them to introduce to the
>position system of numeration (?) and I'm going to do it with the
>help of Logo.
I'm not sure exactly what you mean by the position system of numeration.
However, I think it's useful to compare the two functions and see why they
give the same results -- and why my function would *not* work with anything
other than base-10 numbers. :-)
In fact, consider this... You can divide an integer in Logo by ten this way,
discarding the remainder:
(print :num [ divided by ten equals ] butlast :num)
In C you can do something similar...
printf("%d divided by two equals %d\n",num,num>>1);
But why does C divide by two instead of by ten? It is only because C
considers integers to be base-two numbers instead of base-ten!
Some dialects of Logo can also do that. This works in Berkeley Logo:
(print :num [ divided by two equals ] ashift :num -1)
--
Tony Belding
http://hamilton.htcomp.net/tbelding/
---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org. Mail
questions about the list administration to logofdn@gsn.org. To
unsubscribe send unsubscribe logo-l to majordomo@gsn.org.
Global SchoolNet Foundation -
Linking Kids Around the World!
Copyright GSN - All Rights Reserved
- Comments
& Questions
Visit GSN's
Global
Schoolhouse for more exciting learning resources!
Search our Site
-
Home