Text processing/1: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: syntax coloured, made p2js compatible) |
|||
Line 2,937: | Line 2,937: | ||
Maximum run of 589 consecutive false readings starting: 09/02/1993 |
Maximum run of 589 consecutive false readings starting: 09/02/1993 |
||
</pre> |
</pre> |
||
=={{header|Picat}}== |
|||
{{trans|Ruby}} |
|||
<lang Picat>go => |
|||
File = "readings.txt", |
|||
Total = new_map([num_readings=0,num_good_readings=0,sum_readings=0.0]), |
|||
InvalidCount = 0, |
|||
MaxInvalidCount = 0, |
|||
InvalidRunEnd = "", |
|||
Id = 0, |
|||
foreach(Line in read_file_lines(File)) |
|||
Id := Id + 1, |
|||
NumReadings = 0, |
|||
NumGoodReadings = 0, |
|||
SumReadings = 0, |
|||
Fields = Line.split, |
|||
Rec = Fields.tail.map(to_float), |
|||
foreach([Reading,Flag] in chunks_of(Rec,2)) |
|||
NumReadings := NumReadings + 1, |
|||
if Flag > 0 then |
|||
NumGoodReadings := NumGoodReadings + 1, |
|||
SumReadings := SumReadings + Reading, |
|||
InvalidCount := 0 |
|||
else |
|||
InvalidCount := InvalidCount + 1, |
|||
if InvalidCount > MaxInvalidCount then |
|||
MaxInvalidCount := InvalidCount, |
|||
InvalidRunEnd := Fields[1] |
|||
end |
|||
end |
|||
end, |
|||
Total.put(num_readings,Total.get(num_readings) + NumReadings), |
|||
Total.put(num_good_readings,Total.get(num_good_readings) + NumGoodReadings), |
|||
Total.put(sum_readings,Total.get(sum_readings) + SumReadings), |
|||
if Id <= 3 then |
|||
printf("date:%w accept:%w reject:%w sum:%w\n", Fields[1],NumGoodReadings, |
|||
NumReadings-NumGoodReadings, |
|||
SumReadings) |
|||
end |
|||
end, |
|||
nl, |
|||
printf("readings: %d good readings: %d sum: %0.3f avg: %0.3f\n",Total.get(num_readings), |
|||
Total.get(num_good_readings), |
|||
Total.get(sum_readings), |
|||
Total.get(sum_readings) / Total.get(num_good_readings)), |
|||
nl, |
|||
println(maxInvalidCount=MaxInvalidCount), |
|||
println(invalidRunEnd=InvalidRunEnd), |
|||
nl.</lang> |
|||
{{out}} |
|||
<pre> |
|||
date:1990-01-01 accept:22 reject:2 sum:590.0 |
|||
date:1990-01-02 accept:24 reject:0 sum:410.0 |
|||
date:1990-01-03 accept:24 reject:0 sum:1415.0 |
|||
readings: 131304 good readings: 129403 sum: 1358393.400 avg: 10.497 |
|||
maxInvalidCount = 589 |
|||
invalidRunEnd = 1993-03-05</pre> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |