[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> Numbers or Words?



> Date:          Tue, 24 Jun 1997 00:46:14 -0400
> From:          George Mills <mills@softronix.com>
> To:            Olga Tuzova <olgatu@ort.spb.ru>
> Cc:            logo-l@gsn.org
> Subject:       Re: LOGO-L> Inverting Numbers
> Reply-to:      George Mills <mills@softronix.com>

> Olga Tuzova wrote:

>> The following lines works wonderfully:
> > 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. 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 :-). Which is correct 3 or "c. Pascal does not allow
> you to be ambiguous, it's "Strict".


... And I prefer to deal with a number as a number.

Here is a problem which might be interesting I think. It is based on 
the definition of the digits of an integer number.

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

A lot of "makes" ... Sorry. But note, some of them are local. :-)
I'm sure, much better solutions may be found. 

Regards,
Olga.
---------------------------------------------------------------
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