SP1 Exercise 2 Index   <<   >>


 

In Utopia young people spend their days as follows:

Age   Category
 
0 to 3 day care
4 and 5 kindergarten
6 to 11 elementary school
12, 13, and 14 middle school
15, 16, and 17 high school
over 18 uni

Given a random sample of Utopian ages (integers) from
0 to 21, find out how many are in each category.

Provide two “completely different” solutions.






















f0←{¯1+{≢⍵}⌸(⍳6),0 4 6 12 15 18⍸⍵}

f1←{
 ⎕io←0
 z←22⍴0
 z[⍵]+←1
 {+/z[⍵]}¨ (⍳4) (4 5) (6+⍳6) (12 13 14) (15 16 17) (18+⍳4)
}

   a←¯1+?1e5⍴22

   f0 a
17967 9119 27256 13639 13799 18220
   f1 a
17967 9119 27256 13639 13799 18220