[REBOL] looping - path problem
From: rcm:formix:au at: 25-Apr-2006 15:03
Hello Rebol-Org,
I am having a problem trying to "shrink" some code. These are the initial
values -
random/seed now
digits: [1 2 3 4 5 6 7 8 9 0]
target: copy []
;;; then target becomes a fairly random 4-digit number
target: to-string random/secure digits
remove/part target 6
I want to compare the target with the user's answer, but I can't make a
for or repeat loop
work
because I get invalid path errors. Even though it returns approptiate
results, what follows
is
obviously inefficient so I would be very glad to know the way to make it
leaner.
Regards, Rosemary
get-answer: does [
ans: to-string num/text
answer: copy []
bulls: shots: 0
if find target ans/1 [
either ans/1 == target/1
[bulls: bulls + 1] [shots: shots + 1]]
if find target ans/2 [
either ans/2 == target/2
[bulls: bulls + 1][shots: shots + 1]]
if find target ans/3 [
either ans/3 == target/3
[bulls: bulls + 1][shots: shots + 1]]
if find target ans/4 [
either ans/4 == target/4
[bulls: bulls + 1][shots: shots + 1]]
tries: tries + 1
either ( tries <= 9 )
[answer: rejoin ["0" tries ": " ans " " bulls " " shots]]
[answer: rejoin [tries ": " ans " " bulls " " shots]]
]
--
Formix Australia - www.formix.com.au
613 9354 9585
PO Box 261 Nth Carlton Vic 3054