Created
March 18, 2019 09:47
-
-
Save lukaskollmer/0d73a44159ca129df4b11d570268d3a4 to your computer and use it in GitHub Desktop.
An OCaml program to calculate your TUM CS GPA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ocaml | |
(* | |
gpa.ml | |
An OCaml program to calculate your TUM CS GPA | |
Made by Lukas Kollmer ([email protected]) | |
*) | |
(* grades is a two-dimensional a list, containing all grades sorted by semester *) | |
(* Note that if a course is half-weighed, you have to asjust the ects (see info1 in the example below) *) | |
type grade = float * float * string (* ects, value, course *) | |
let grades: grade list list = [ | |
[ (* 1. semester*) | |
(6., 1.0, "pgdp"); | |
(3., 2.4, "info1"); | |
... | |
]; | |
[ (* 2. semester*) | |
(8., 1.7, "era praktikum"); | |
(6., 1.7, "eist"); | |
... | |
]; | |
... | |
] | |
let () = | |
let rec calc_sem (x, y) = function | |
| [] -> x, y | |
| (e, v, _) :: grades -> | |
calc_sem (x +. e *. v, y +. e) grades | |
in | |
Printf.printf "GPA after semester:\n" ; | |
List.fold_left (fun acc sem -> | |
calc_sem (List.hd acc) sem :: acc | |
) [0., 0.] grades | |
|> List.rev |> List.tl | |
|> List.iteri (fun i (x, y) -> Printf.printf "%i.: %f\n" (i+1) (x/.y)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment