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

Re: LOGO-L> Pascal, Numbers or Words?



At 09:21 29-06-97 -0600, Tony Belding wrote:
[...]
>>After 760 seconds my home-made PC with a cheap Amd processor discovered,
>>that factorial of 100 has 158 digits, starts with 933262... and ends with 24
>>zeros. 
>>UCBLogo need about 28 min to do so.
>
>It took UCB Logo over three hours to do the same on my Amiga 4000/040.
>

Oops

1. It was actually BL.EXE Berkeley Logo 3.4c for PC 640kB memory model which
I used to calculate 100! 

2. Mutliplying method used in function razy1cyf is extremely stupid. It
works by adding multipiers one by one. We can use more advanced and get
extra speed - about 9x :-) 

to razy2cyf :liczba :bin
 if equalp :bin 0 [output 0]
 if equalp :bin 1 [output :liczba]
 output suma razy2cyf  suma :liczba :liczba bl :bin razy2cyf :liczba last :bin
end

; we need decimal to binary convertion do do above

to num2bin :num
 if :num<2 [output :num]
 output word num2bin int quotient :num 2 remainder :num 2
end

; the rest of factorial program would be as follows

to factorial.b :k
 if :k=0 [output 1]
 if :k=1 [output 1]
 output razy.b factorial.b :k-1 :k
end

to razy.b :a :b
; this is a PRODUCT of :a :b of any length
 if emptyp bl :b [output razy2cyf :a num2bin last :b]
 output suma word razy.b :a bl :b "0 razy2cyf :a num2bin last :b
end

to suma :a :b
; this is a SUM of :a :b of any length
 output dodaj :a :b 0
end

to dodaj :a :b :c
 if and emptyp :a emptyp :b [ifelse :c=1 [output "1][output " ]]
 if emptyp :a [output dodaj :b :c "0]
 if emptyp :b [output dodaj :a :c "0]
 ifelse(sum last :a last :b :c)>9~
  [output word dodaj bl :a bl :b "1 last (sum last :a last :b :c) ]~
  [output word dodaj bl :a bl :b "0 last (sum last :a last :b :c) ]
end

; now we get a material to do a sculpture:

to n.hist :num :d
 if emptyp :num [output :num]
 if equalp :d first :num [output word :d n.hist butfirst :num :d]
 output n.hist butfirst :num :d
end

to n.hist.all :num
 show n.hist :num 0
 show n.hist :num 1
 show n.hist :num 2
 show n.hist :num 3
 show n.hist :num 4
 show n.hist :num 5
 show n.hist :num 6
 show n.hist :num 7
 show n.hist :num 8
 show n.hist :num 9
end

Try n.hist.all factorial.b 35 and enjoy...

3. One more comment. This is no numbers and words mixture in above program.
I found it to be WORDS only. Some operation on them may be similar to
arithmetic, but it's only coincidense. I even don't imagine symbols like
9332621544394415268169923885626670049071596826438162146859296389521759999322
9915608941463976156518286253697920827223758251185210916864000000000000000000
000000 as a number.

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