Skip to content

Latest commit

 

History

History
68 lines (49 loc) · 2.51 KB

PROMPT.md

File metadata and controls

68 lines (49 loc) · 2.51 KB
  1. Write a command-line binary that reads numbers in from the command line (as arguments) and computes some stats (min, max, mean, sum, size).

See if you can ensure that the stats are computed iteratively, so you don't ever need to hold the entire data set in memory.

For example, you could have a struct like:

struct Stats {
    max: f64,
    mean: f64,
    min: f64,
    size: u64,
    sum: f64,
}

...with a method update(&mut self, val: f64) that, given the the stats so far (self) and the value of the next sample point (val) computes the summary stats for the new data set which includes val.

  1. Read numbers from a file and compute stats on the file's numbers. You can just panic! if the file contains invalid lines, or the filename is invalid.
  1. Use serde and serde_derive to output the stats as valid JSON.

  2. Add a from_iter ctor for Stats that accepts an iterator of f64 values as its argument, and returns a new Stats struct.

  1. Add your own error type that implements std::error::Error, and replace the unwrap() and panics with use of ? and Result.
  1. Use clap to add a nicer CLI interface and allow an option that ignores blank lines in the input file.
  1. Add a DataFileIterator struct that impls Iterator with and Iterator::Item = f64, and use that to encapsulate file handling.
  1. Add a command-line option to read sample points from stdin.
  1. Add a command-line option to write all computed stats to a file as JSON.