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

Re: LOGO-L> Inverting Numbers



Olga Tuzova wrote:
> 
> > 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.

Olga,

You might remember that 007 was the name of a really nice detective
(James Bond)... But "nice" is a relative virtue, not absolut.

My REVERSE function keeps the convention of:
         (REVERSE REVERSE someting) = something

while this convention isn't observed by your procedure.

If leading zeros are found disturbing, they can be easily removed by:
	 PR INT REVERSE :NUM

Of course you can also write a function to remove leading zeros.

Best Regards...

[[Yehuda]]


---------------------------------------------------------------
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