Text processing/1: Difference between revisions

Line 2,750:
 
=={{header|Phix}}==
<lang Phix>constant lines = splitread_lines(data,'"demo\n'\rosetta\\readings.txt")
As the link to the data file is broken, this is limited to the 6 lines shown in the task description for testing purposes.<br>
(first constant shown in a smaller font, it actually fits at 4px but...)
<pre style="font-size: 6px">
constant data="""
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
1991-04-01 0.000 -2 13.000 1 16.000 1 21.000 1 24.000 1 22.000 1 20.000 1 18.000 1 29.000 1 44.000 1 50.000 1 43.000 1 38.000 1 27.000 1 27.000 1 24.000 1 23.000 1 18.000 1 12.000 1 13.000 1 14.000 1 15.000 1 13.000 1 10.000 1
1991-04-02 8.000 1 9.000 1 11.000 1 12.000 1 12.000 1 12.000 1 27.000 1 26.000 1 27.000 1 33.000 1 32.000 1 31.000 1 29.000 1 31.000 1 25.000 1 25.000 1 24.000 1 21.000 1 17.000 1 14.000 1 15.000 1 12.000 1 12.000 1 10.000 1
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>
<lang Phix>constant lines = split(data,'\n')
 
include builtins\timedate.e
Line 2,782 ⟶ 2,771:
 
for i=1 to length(lines) do
sequence oneline = split(lines[i],'\t',no_empty:=true), r
if length(oneline)!=49 then
?"bad line (length!=49)"
Line 2,820 ⟶ 2,809:
end if
end for
ifreadtot rejects+=0 thenreadsum
readtotntot += readsumaccepts
ntot += 1
end if
-- readtot += readsum
-- ntot += accepts
printf(1,"Date: %s, Rejects: %2d, Accepts: %2d, Line total: %7.3f, Average %6.3f\n",
{format_timedate(td,"DD/MM/YYYY"),rejects, accepts, readsum, readsum/accepts})
Line 2,832 ⟶ 2,817:
end for
 
printf(1,"Average: %.3f (of %d entirely valid daysreadings)\n",{readtot/(24*ntot),ntot})
--printf(1,"Average: %.3f\n",{readtot/ntot})
end_bad_run()
if max_count then
Line 2,839 ⟶ 2,823:
{max_count,format_timedate(max_start,"DD/MM/YYYY")})
end if</lang>
I opted to show an average of entirely good days; the commented out alternative matches Kotlin (18.242).
{{out}}
<pre>
Date: 3029/0312/19912004, Rejects: 01, Accepts: 2423, Line total: 240 56.000300, Average 10 2.000448
Date: 3130/0312/19912004, Rejects: 01, Accepts: 2423, Line total: 565 65.000300, Average 23 2.542839
Date: 31/0312/19912004, Rejects: 23 1, Accepts: 123, Line total: 4047.000300, Average 40 2.000057
Average: 10.497 (of 129403 readings)
Date: 01/04/1991, Rejects: 1, Accepts: 23, Line total: 534.000, Average 23.217
Maximum run of 24589 consecutive false readings starting: 3109/0302/19911993
Date: 02/04/1991, Rejects: 0, Accepts: 24, Line total: 475.000, Average 19.792
Date: 03/04/1991, Rejects: 0, Accepts: 24, Line total: 335.000, Average 13.958
Average: 16.823 (of 4 entirely valid days)
Maximum run of 24 consecutive false readings starting: 31/03/1991
</pre>
 
7,794

edits