2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -2,8 +2,8 @@
|
|||
open Str
|
||||
|
||||
let strip_cr str =
|
||||
let last = pred(String.length str) in
|
||||
if str.[last] <> '\r' then (str) else (String.sub str 0 last)
|
||||
let last = pred (String.length str) in
|
||||
if str.[last] <> '\r' then str else String.sub str 0 last
|
||||
|
||||
let map_records =
|
||||
let rec aux acc = function
|
||||
|
|
@ -11,7 +11,7 @@ let map_records =
|
|||
let e = (float_of_string value, int_of_string flag) in
|
||||
aux (e::acc) tail
|
||||
| [_] -> invalid_arg "invalid data"
|
||||
| [] -> (List.rev acc)
|
||||
| [] -> List.rev acc
|
||||
in
|
||||
aux [] ;;
|
||||
|
||||
|
|
@ -24,17 +24,17 @@ let duplicated_dates =
|
|||
| _::tl ->
|
||||
aux acc tl
|
||||
| [] ->
|
||||
(List.rev acc)
|
||||
List.rev acc
|
||||
in
|
||||
aux [] ;;
|
||||
|
||||
let record_ok (_,record) =
|
||||
let is_ok (_,v) = (v >= 1) in
|
||||
let is_ok (_,v) = v >= 1 in
|
||||
let sum_ok =
|
||||
List.fold_left (fun sum this ->
|
||||
if is_ok this then succ sum else sum) 0 record
|
||||
in
|
||||
(sum_ok = 24)
|
||||
sum_ok = 24
|
||||
|
||||
let num_good_records =
|
||||
List.fold_left (fun sum record ->
|
||||
|
|
@ -43,18 +43,18 @@ let num_good_records =
|
|||
let parse_line line =
|
||||
let li = split (regexp "[ \t]+") line in
|
||||
let records = map_records (List.tl li)
|
||||
and date = (List.hd li) in
|
||||
and date = List.hd li in
|
||||
(date, records)
|
||||
|
||||
let () =
|
||||
let ic = open_in "readings.txt" in
|
||||
let rec read_loop acc =
|
||||
try
|
||||
let line = strip_cr(input_line ic) in
|
||||
read_loop ((parse_line line) :: acc)
|
||||
with End_of_file ->
|
||||
close_in ic;
|
||||
(List.rev acc)
|
||||
let line_opt = try Some (strip_cr (input_line ic))
|
||||
with End_of_file -> None
|
||||
in
|
||||
match line_opt with
|
||||
None -> close_in ic; List.rev acc
|
||||
| Some line -> read_loop (parse_line line :: acc)
|
||||
in
|
||||
let inputs = read_loop [] in
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue