Anonymous user
Text processing/1: Difference between revisions
Actually done the changes described in previous edit.
(Updated to work with Nim 1.4: replaced [1..-1]" with "[1..^1]. Changed output formatting to use the more friendly "strformat". Done miscellaneous other changes.) |
(Actually done the changes described in previous edit.) |
||
Line 2,442:
=={{header|Nim}}==
{{trans|Python}}
<lang nim>import os, sequtils, strutils,
var
nodata = 0
nodataMax = -1
nodataMaxLine: seq[string
totFile = 0.0
Line 2,453:
for filename in commandLineParams():
var
totLine = 0.0
numLine = 0
let fields = line.split()
let date = fields[0]
if i mod 2 == 0: data.add parseFloat(f)▼
else: flags.add parseInt(f)▼
for
for datum, flag in zip(data, flags).items:
if flag < 1:
inc nodata
Line 2,483:
numFile += numLine
echo &"Line:
&"LineTot:
echo &"Total = {totFile:.2f}"
echo ""
echo &"Maximum run(s) of
▲echo "File(s) = ", commandLineParams().join(" ")
&"""ends at line starting with date(s): {nodataMaxLine.join(" ")}."""</lang>
▲echo "Readings = ", numFile
{{out}}
▲echo "Average = ", formatFloat(totFile / float(numFile), precision = 0)
▲echo ""
▲echo "Maximum run(s) of ", nodataMax, " consecutive false readings ends at line starting with date(s): ", nodataMaxLine.join(" ")</lang>
<pre>$ ./textproc1 readings.txt | tail
Line: 2004-12-29 Reject: 1 Accept: 23 LineTot: 56.30 LineAvg: 2.45
|