Anonymous user
Text processing/2: Difference between revisions
Done some formatting changes. Replaced output of number of good records with output of number of records with wrong format. Added output.
(Added Wren) |
(Done some formatting changes. Replaced output of number of good records with output of number of records with wrong format. Added output.) |
||
Line 1,805:
=={{header|Nim}}==
<lang Nim>import strutils, tables
const NumFields = 49
Line 1,812 ⟶ 1,811:
const FlagGoodValue = 1
var badRecords: int
var totalRecords: int
var badInstruments: int #
var seenDates:
proc checkFloats(floats: seq[string]): bool =▼
##
▲proc checkFloats(floats:seq[string]): bool =
for index in 1..<NumFields
try:
#
discard parseFloat(floats[index])
except ValueError:
Line 1,827 ⟶ 1,826:
true
# ensure that all sensor flags are ok▼
proc areAllFlagsOk(instruments: seq[string]): bool =
#flags start at index 2, and occur every 2 fields▼
for index in countup(2,NumFields,2):▼
# we're assuming all instrument flags are floats not integers▼
▲ for index in countup(2, NumFields, 2):
var flag = parseFloat(instruments[index])
if flag < FlagGoodValue: return false
Line 1,837:
# Note: we're not checking the format of the date stamp.
#
var currentLine: int▼
for line in
currentLine.inc
if line.len == 0: continue #
var tokens = line.split({' ','\t'})▼
▲ var tokens = line.split({' ', '\t'})
totalRecords.inc
if tokens.len != NumFields:
badRecords.inc
continue
Line 1,866 ⟶ 1,863:
echo tokens[DateField], " duplicated on line ", currentLine
echo "Total Records: ", totalRecords▼
echo "Records with wrong format: ", badRecords
{{out}}
▲echo "Total Records:", totalRecords
<pre>1990-03-25 duplicated on line 85
1991-03-31 duplicated on line 456
▲echo "Records where all instuments were OK:", goodInstruments
1992-03-29 duplicated on line 820
1993-03-28 duplicated on line 1184
1995-03-26 duplicated on line 1911
Total Records: 5471
Records with wrong format: 0
Records where all instruments were OK: 5017</pre>
=={{header|OCaml}}==
|