Ready to begin
No records have been processed. Start with Next step.
![Rida’s triple [3,42,53] keeps identity and two subject marks. The middle component is first(rest(Triple)).](/images/computational-thinking/week-5/score-triple.png)
Follow one occurrence at a time. Choose another input to test empty lists, repeated IDs and different parameters.
Ready
No records have been processed. Start with Next step.
Predict the next change, then step through the list. The original course records remain unchanged.
A triple is a list of exactly three components. For [ID,Maths,Physics], first gives ID, first(rest(Triple)) gives Maths, and last gives Physics. last(init(Triple)) is another way to obtain the middle value. A list of these triples keeps both subject marks attached to the same student.
Triples = []
foreach X in ScoreRecords:
Triples = Triples ++ [[X.CardNo,X.Mathematics,X.Physics]]
MathsSum = 0; PhysicsSum = 0; Count = 0
foreach T in Triples:
MathsSum = MathsSum + first(rest(T))
PhysicsSum = PhysicsSum + last(T)
Count = Count + 1
# If Count > 0, compute the two means. Then classify in a second pass.The real means are Maths 2171/30 = 72.3667 approximately, and Physics 2189/30 = 72.9667 approximately. In the second pass, select students with Maths strictly above its mean and Physics strictly below its mean, OR the opposite. The exact fractions determine the comparisons; rounded displays are only for reading.
The result has 13 IDs: [4,5,8,9,13,14,15,17,18,19,20,21,26]. We describe performance relative to these subject means, not a general label about a person’s ability. A mark exactly equal to a mean would enter neither strict above/below branch. Empty input requires handling Count = 0 before dividing.
How do you extract the middle value from [3,42,53]?
first(rest([3,42,53])) = first([42,53]) = 42. Equivalently, last(init(...)) = last([3,42]) = 42.
Why not compare a mark with a running average while collecting the sums?
The final means are not yet known. Complete the aggregate pass, then classify against fixed means in a second pass.
Why include ID rather than just [Maths,Physics]?
The marks can still be compared, but the ID lets you identify each selected student and reconnect to their record.