Text processing/1: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
m (bugfix)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 119:
Max. 589 false readings start at 1136:20 stamped 1993-2-9
</pre>
 
=={{header|Aime}}==
<lang aime>integer bads, count, max_bads;
file f;
list l;
real s;
text bad_day, worst_day;
 
f.stdin;
 
max_bads = count = bads = s = 0;
 
while (f.list(l, 0) ^ -1) {
integer i;
 
i = 2;
while (i < 49) {
if (0 < atoi(l[i])) {
count += 1;
s += atof(l[i - 1]);
if (max_bads < bads) {
max_bads = bads;
worst_day = bad_day;
}
bads = 0;
} else {
if (!bads) {
bad_day = l[0];
}
bads += 1;
}
i += 2;
}
}
 
o_form("Averaged /d3/ over ~ readings.\n", s / count, count);
o_("Longest bad run ", max_bads, ", started ", worst_day, ".\n");</lang>
Run as:
<pre>cat readings.txt | tr -d \\r | aime SOURCE_FILE</pre>
{{out}}
<pre>Averaged 10.497 over 129403 readings.
Longest bad run 589, started 1993-02-09.</pre>
 
=={{header|ALGOL 68}}==
Line 238 ⟶ 280:
Maximum run of 24 consecutive false readings ends at line starting with date: 1991-04-01
</pre>
 
=={{header|Aime}}==
<lang aime>integer bads, count, max_bads;
file f;
list l;
real s;
text bad_day, worst_day;
 
f.stdin;
 
max_bads = count = bads = s = 0;
 
while (f.list(l, 0) ^ -1) {
integer i;
 
i = 2;
while (i < 49) {
if (0 < atoi(l[i])) {
count += 1;
s += atof(l[i - 1]);
if (max_bads < bads) {
max_bads = bads;
worst_day = bad_day;
}
bads = 0;
} else {
if (!bads) {
bad_day = l[0];
}
bads += 1;
}
i += 2;
}
}
 
o_form("Averaged /d3/ over ~ readings.\n", s / count, count);
o_("Longest bad run ", max_bads, ", started ", worst_day, ".\n");</lang>
Run as:
<pre>cat readings.txt | tr -d \\r | aime SOURCE_FILE</pre>
{{out}}
<pre>Averaged 10.497 over 129403 readings.
Longest bad run 589, started 1993-02-09.</pre>
 
=={{header|AutoHotkey}}==
Line 2,695:
 
$</pre>
 
=={{header|Perl 6}}==
<lang perl6>my @gaps;
my $previous = 'valid';
 
for $*IN.lines -> $line {
my ($date, @readings) = split /\s+/, $line;
my @valid;
my $hour = 0;
for @readings -> $reading, $flag {
if $flag > 0 {
@valid.push($reading);
if $previous eq 'invalid' {
@gaps[*-1]{'end'} = "$date $hour:00";
$previous = 'valid';
}
}
else
{
if $previous eq 'valid' {
@gaps.push( {start => "$date $hour:00"} );
}
@gaps[*-1]{'count'}++;
$previous = 'invalid';
}
$hour++;
}
say "$date: { ( +@valid ?? ( ( [+] @valid ) / +@valid ).fmt("%.3f") !! 0 ).fmt("%8s") }",
" mean from { (+@valid).fmt("%2s") } valid.";
};
 
my $longest = @gaps.sort({-$^a<count>})[0];
 
say "Longest period of invalid readings was {$longest<count>} hours,\n",
"from {$longest<start>} till {$longest<end>}."</lang>
{{out}}
<pre>
1990-01-01: 26.818 mean from 22 valid.
1990-01-02: 17.083 mean from 24 valid.
1990-01-03: 58.958 mean from 24 valid.
1990-01-04: 75.000 mean from 24 valid.
1990-01-05: 47.083 mean from 24 valid.
...
(many lines omitted)
...
2004-12-27: 2.483 mean from 23 valid.
2004-12-28: 3.383 mean from 23 valid.
2004-12-29: 2.448 mean from 23 valid.
2004-12-30: 2.839 mean from 23 valid.
2004-12-31: 2.057 mean from 23 valid.
Longest period of invalid readings was 589 hours,
from 1993-02-09 1:00 till 1993-03-05 14:00.
</pre>
 
=={{header|Phix}}==
Line 3,161 ⟶ 3,108:
 
Maximum run(s) of 589 consecutive false readings ends at line starting with date(s): 1993-03-05</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
<lang perl6>my @gaps;
my $previous = 'valid';
 
for $*IN.lines -> $line {
my ($date, @readings) = split /\s+/, $line;
my @valid;
my $hour = 0;
for @readings -> $reading, $flag {
if $flag > 0 {
@valid.push($reading);
if $previous eq 'invalid' {
@gaps[*-1]{'end'} = "$date $hour:00";
$previous = 'valid';
}
}
else
{
if $previous eq 'valid' {
@gaps.push( {start => "$date $hour:00"} );
}
@gaps[*-1]{'count'}++;
$previous = 'invalid';
}
$hour++;
}
say "$date: { ( +@valid ?? ( ( [+] @valid ) / +@valid ).fmt("%.3f") !! 0 ).fmt("%8s") }",
" mean from { (+@valid).fmt("%2s") } valid.";
};
 
my $longest = @gaps.sort({-$^a<count>})[0];
 
say "Longest period of invalid readings was {$longest<count>} hours,\n",
"from {$longest<start>} till {$longest<end>}."</lang>
{{out}}
<pre>
1990-01-01: 26.818 mean from 22 valid.
1990-01-02: 17.083 mean from 24 valid.
1990-01-03: 58.958 mean from 24 valid.
1990-01-04: 75.000 mean from 24 valid.
1990-01-05: 47.083 mean from 24 valid.
...
(many lines omitted)
...
2004-12-27: 2.483 mean from 23 valid.
2004-12-28: 3.383 mean from 23 valid.
2004-12-29: 2.448 mean from 23 valid.
2004-12-30: 2.839 mean from 23 valid.
2004-12-31: 2.057 mean from 23 valid.
Longest period of invalid readings was 589 hours,
from 1993-02-09 1:00 till 1993-03-05 14:00.
</pre>
 
=={{header|REXX}}==
10,327

edits