[REBOL] Re: New competition: do you accept the challenge?! :-)
From: sant4::wanadoo::fr at: 8-Nov-2007 22:47
; Seems that first send failed.
; First attempt using Rebcode
print "START..."
s1: now/time/precise
str: make string! 5000
finale: make string! 50000
blk: [i #"," j #"-"]
do rebcode [][
repeat i 10000 [
head str
clear str
head str
poke blk 1 i
repeat j 500 [
poke blk 3 j
apply tmp to [string! blk]
insert str tmp -1
tail str
]
head str
next str
insert finale str 4
tail finale
]
head finale
]
print "STOP!"
print length? finale
print (now/time/precise - s1)
; It' fast but not so much because of the use of the command 'apply to convert integers
into strings.
; I tried to compose the convertion by myself, by using a table of constants and a (not
so) tricky algorytm
; to compose big numbers with single digits.
print "START..."
s1: now/time/precise
str: make string! 5000
finale: make string! 50000
digit: 0
digits: make block! 500
insert digits "0"
repeat n 500 [insert tail digits form n]
n: 0
do rebcode [][
repeat i 10000 [
head str
clear str
head str
copy stri "," -1
set.i n i
until [
;concat digits to form a big number
set.i digit n
rem.i digit 10
div.i n 10
pickz char digits digit
insert stri char -1
eq.i n 0
]
repeat j 500 [
insert str #"-" -1
pickz char digits j
insert str char -1
insert str stri -1
tail str
]
head str
next str
insert finale str 4
tail finale
]
head finale
]
print "STOP!"
print length? finale
print (now/time/precise - s1)
; We gained more speed but the Rebolish way "keep it simple" is gone