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

Re: LOGO-L> Inverting Numbers



> Date:          Fri, 20 Jun 1997 18:50:17 +0300
> From:          Yehuda Katz <yehuka@beitberl.beitberl.ac.il>
> Reply-to:      yehuka@beitberl.beitberl.ac.il
> To:            Olga Tuzova <olgatu@ort.spb.ru>
> Cc:            logo-l@gsn.org
> Subject:       Re: LOGO-L> Inverting Numbers

> Olga Tuzova wrote:
> > 

> > to how_digits? :n
> > ;counts the "sensible"(?) digits of the number
> > if emptyp :n [op 0]
> > ifelse not (first :n)=0[op count :n]~
> >                        [op how_digits? butfirst :n]
> > end
> > 
> > to invert :n
> > op inverty how_digits? :n :n 0
> > end
> > 
> > to inverty :k :n :new_n
> > ; inverts the initial number :n and returnes it as :new_n
> > if :k=0 [op :new_n]
> > op inverty :k-1 int :n/10 10*:new_n+remainder :n 10
> > end
> > 
> > to main
> > pr [input any number, it may begin with 0  ==>]
> > pr  invert rw
> > end
> > ------------------------------------------------------
> 
> 
> Hello Olga,
> 
> You can reverse ANY word, not only numbers, by the following function:
> 
> =================================
> to reverse :wrd
> if 2>count :wrd[op :wrd]
> op word last :wrd reverse bl :wrd
> end
> =================================
> 
> Try it by PR REVERSE 1997 or PR REVERSE "H2SO4
> 


But if I take 900 as an input, I'll get 009 and I don't think this 
number looks nice. 

There is another thing there. It seems my experience of teaching 
Pascal began to play bad tricks with me. In Pascal program all the 
variables are to be described in the very beginning of the program. 
And then you can't summaries variables a and b if a defined as a char 
and b - as a number, or if they both defined as a char type. But, in 
Logo it proves to be not forbidden. The following lines works 
wonderfully: 
make "a "1
make "b 2
show :a+:b
And you'll get 3!

I was going to share some tasks which use the described above process 
of number digits definition. But it seems to be much easier to define 
them looking at a number as it being just a word. 

There is something I don't like. May be, it's just hard to get rid of
the old programming heritage :-). But when we work with the 
senior students with spreadsheets (Excel, for example), the cells 
there could be also taken as a variables. And "1 or "2 there mean 
text and the attempt to summaries them will draw to an error. And the 
students won't do that if they are acquainted with the variables 
types.  

So, sorry for all this mess. Though, may be it's just useful 
for students to compare:

Let "N be a number, then

last :n = remainder :n 10
bl :n    = int :n/10    and so on.

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