2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -5,7 +5,7 @@ The fields (from the left) are:
|
|||
i.e. a datestamp followed by twenty-four repetitions of a floating-point instrument value and that instrument's associated integer flag. Flag values are >= 1 if the instrument is working and < 1 if there is some problem with it, in which case that instrument's value should be ignored.
|
||||
|
||||
A sample from the full data file [http://rosettacode.org/resources/readings.zip readings.txt], which is also used in the [[Data Munging]] task, follows:
|
||||
<pre style="height:17ex;overflow:scroll">
|
||||
<pre>
|
||||
1991-03-30 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1
|
||||
1991-03-31 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 20.000 1 20.000 1 20.000 1 35.000 1 50.000 1 60.000 1 40.000 1 30.000 1 30.000 1 30.000 1 25.000 1 20.000 1 20.000 1 20.000 1 20.000 1 20.000 1 35.000 1
|
||||
1991-03-31 40.000 1 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2 0.000 -2
|
||||
|
|
@ -14,7 +14,8 @@ A sample from the full data file [http://rosettacode.org/resources/readings.zip
|
|||
1991-04-03 10.000 1 9.000 1 10.000 1 10.000 1 9.000 1 10.000 1 15.000 1 24.000 1 28.000 1 24.000 1 18.000 1 14.000 1 12.000 1 13.000 1 14.000 1 15.000 1 14.000 1 15.000 1 13.000 1 13.000 1 13.000 1 12.000 1 10.000 1 10.000 1
|
||||
</pre>
|
||||
|
||||
The task:
|
||||
;Task:
|
||||
# Confirm the general field format of the file.
|
||||
# Identify any DATESTAMPs that are duplicated.
|
||||
# Report the number of records that have good readings for all instruments.
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -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