You could use foreach to iterate through one series to find the number
of bulls-eyes (but you have to handle the iteration of the other series
yourself) and then use intersect of the two series to determine the
number of shots:
foreach attempt ans [
if attempt = first target [bulls: bulls + 1]
ans: next ans
]
shots: shots + length? intersect head ans target
Regards
Peter
On Tuesday, Apr 25, 2006, at 13:03 Asia/Kuala_Lumpur, Rosemary de Dear
wrote:
>
> Hello Rebol-Org,
>
> I am having a problem trying to "shrink" some code. These are the
> initial=
> =20
> 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 =20
> for or repeat loop
> work
> because I get invalid path errors. Even though it returns approptiate
> =20
> results, what follows
> is
> obviously inefficient so I would be very glad to know the way to make
> it =
> =20
> leaner.
>
> Regards, Rosemary
>
>
> get-answer: does [
> ans: to-string num/text
> answer: copy []
> bulls: shots: 0
>
> if find target ans/1 [
> either ans/1 =3D=3D target/1
> [bulls: bulls + 1] [shots: shots + 1]]
>
> if find target ans/2 [
> either ans/2 =3D=3D target/2
> [bulls: bulls + 1][shots: shots + 1]]
>
> if find target ans/3 [
> either ans/3 =3D=3D target/3
> [bulls: bulls + 1][shots: shots + 1]]
>
> if find target ans/4 [
> either ans/4 =3D=3D target/4
> [bulls: bulls + 1][shots: shots + 1]]
>
> tries: tries + 1
> either ( tries <=3D 9 )
> [answer: rejoin ["0" tries ": " ans " " bulls " " shots]]
> [answer: rejoin [tries ": " ans " " bulls " " shots]]
> ]
>
>
> --=20
>
> Formix Australia - www.formix.com.au
>
> 613 9354 9585
> PO Box 261 Nth Carlton Vic 3054
> --
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
>
--
To unsubscribe from the list, just send an email to
lists at rebol.com with unsubscribe as the subject.