Hi, my solution using Parse (I think, that it is much faster, than other 
solutions):

   scores: clear []
   loop 30 [append scores random 20]
   group: [p: set i integer! any i q: (print ["score:" i "tallies:" 
offset? p q])]
   parse probe sort scores [any group]

Anton Rolls napsal(a):

>
>-----Original Message-----
>From: Anton Rolls [mailto:[EMAIL PROTECTED]
>Sent: Wednesday, 19 November 2003 12:36 pm
>To: [EMAIL PROTECTED]
>Subject: RE: [REBOL] Re: [append][series]Appending to a series of
>strings
>
>
>How about this?
>
>; initialize some random scores
>scores: clear []
>loop 30 [append scores random 20]
>
>; figure out how many of each score
>tallies: clear []
>foreach uscore sort unique scores [
>       append/only tallies reduce [uscore length? remove-each score copy scores
>[uscore <> score]]
>]
>
>Anton.
>
>  
>
>>Suppose one has a collection of small natural numbers (such as
>>test scores ranging from 0 to 100) and one wants to know how many
>>occurrences of each distinct number there are.
>>
>>Using Perl arrays:
>>
>>     # assume @scores contains the raw data with dups
>>     @tallies = ();
>>     foreach $score (@scores) {
>>         ++$tallies[$score];
>>     }
>>     foreach $score (0..$#tallies) {
>>         print "$score: $tallies[$score]\n" if $tallies[$score];
>>     }
>>
>>Using REBOL blocks:
>>
>>     ; assume SCORES contains the raw data with dups
>>     tallies: []
>>     foreach score scores [
>>         insert/dup tail tallies 0 score + 1 - length? tallies
>>         change at tallies score + 1 1 + pick tallies score + 1
>>     ]
>>     forall tallies [
>>         if 0 < tallies/1 [print [-1 + index? tallies ":" tallies/1]]
>>     ]
>>
>>or
>>
>>     ; assume SCORES contains the raw data with dups
>>     tallies: []
>>     foreach score scores [
>>         either found? here: select tallies score [
>>             here/1: here/1 + 1
>>         ][
>>             append tallies reduce [score copy [1]]
>>         ]
>>     ]
>>     foreach [score tally] sort/skip tallies 2 [
>>         print [score ";" tally/1]
>>     ]
>>
>>REBOL is much more "literal"; there are no values that one does not
>>explicitly create (although it is possible to be implicitly explicit
>>at times ;-).  On the other hand, it is necessary explicitly to
>>manage details that aren't at the same logical level as the original
>>problem (making sure that there enough "places" to store the next
>>tally needed, etc).
>>
>>I'd be interested in any *self-contained* solutions to the above task
>>that might be clearer than the above.
>>
>>-jn-
>>    
>>
>
>
>  
>



-- 
To unsubscribe from this list, just send an email to
[EMAIL PROTECTED] with unsubscribe as the subject.

Reply via email to