Skip to content

Instantly share code, notes, and snippets.

@mrpmorris
Last active June 7, 2022 19:53
Show Gist options
  • Save mrpmorris/2f1feb22cfbd7b0efca8b04672bd71e7 to your computer and use it in GitHub Desktop.
Save mrpmorris/2f1feb22cfbd7b0efca8b04672bd71e7 to your computer and use it in GitHub Desktop.
open System
open System.IO
let printMeanScore(row: string) =
let columns = row.Split('\t')
let name = columns.[0]
let id = columns.[1]
let scores = columns |> Array.skip 2 |> Array.map float
let avg = scores |> Array.average
let min = scores |> Array.min
let max = scores |> Array.max
printfn $"Student %s{id} (%s{name}) has an average score of %0.1f{avg}, lowest score of %0.1f{min}, and highest %0.1f{max}"
let summarizeFile filePath =
let rows = filePath |> File.ReadAllLines
let studentCount = (rows |> Array.length ) - 1
printfn $"There are %i{studentCount} students"
rows
|> Array.skip 1
|> Array.iter printMeanScore
let processFile(arg: string) =
let folderPath = Directory.GetCurrentDirectory()
let filePath = Path.Combine(folderPath, arg)
if filePath |> File.Exists then
summarizeFile filePath
true
else
printfn $"File %s{filePath} does not exist"
false
[<EntryPoint>]
let main argv =
if argv |> Array.length = 1 then
if processFile argv.[0] then 0 else 1
else
printfn "Please specify a single file"
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment