Generics and parametric polymorphism

F-GENERIC-V4-3hard

Average the quantities

The first helper must return the original record with the highest quoted price; the callback tells it how to read a price without assuming a particular product shape. The first-value helper feeds a price-series report where an empty series means none and a genuine first price of 0 remains 0. The average helper formats integral quantity observations to two decimal places, including their fractional mean.

What needs to change

Repair Average so the average keeps its fraction.

Reproduce

  1. Pipe the sample quantities into go run main.go and compare the average line.

Acceptance criteria

Your review marks · Saved in this browser. Test acceptance is tracked separately.

Notes

The file contains its imports, readLines, the Number constraint and the complete main, which passes []int.

Input: 1 to 100 decimal whole-number quantities from 0 to 300, one per line. The report rounds the computed binary64 mean to two decimals, with exact halfway ties away from zero; formatting is supplied in the native caller. The supplied reader receives valid data.

Sign in to open this exercise

The ticket brief is public. Sign in to access the exercise. Paid exercises require Pro.

Sign in