>> > make "a "1
>> > make "b 2
>> > show :a+:b
>> > And you'll get 3!
>> The above code you listed should generate a bug because you usually do
>> not want to mix datatypes unless you explicity tell it you want to.
So who is mixing datatypes? Logo only has two datatypes: words and lists!
All the above are words.
>> It's
>> helping you to stay out of trouble. For example the code you wrote
>> above in many lauguages would give the ascii value of 1 plus 2 and the
>> answer would be "c :-).
Logo doesn't give you the ASCII value unless you ask for it. Anyhow, "many
languages" do things in a way that is natural for computers, not for human
beings. Logo tries to work more like people.
>Find all "happy" 6-digital (? sorry if the terminology isn't
>correct) integers. The integer is called "happy" if the sum of the
>first three digits is equal to the sum of the last three ones.
>My proposal for a solution:
>to happy
>ct
>for [i 100000 999999][if happy.test :i [pr :i]]
>end
>to happy.test :i
>localmake "s1 0
>localmake "s2 0
>repeat 3 [make "s1 :s1+remainder :i 10
> make "i int :i/10]
>repeat 3 [make "s2 :s2+remainder :i 10
> make "i int :i/10]
>op :s1=:s2
>end
That's about the way I would do it in C. I think the nature of Logo
suggests a different approach, though. Try this...
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
--
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