RosettaCodeData/Task/Text-processing-2/Aime/text-processing-2.aime

54 lines
847 B
Text
Raw Permalink Normal View History

2013-10-27 22:24:23 +00:00
check_format(list l)
{
integer i;
text s;
2018-06-22 20:57:24 +00:00
if (~l != 49) {
2019-09-12 10:33:56 -07:00
error("bad field count");
2013-10-27 22:24:23 +00:00
}
2018-06-22 20:57:24 +00:00
s = l[0];
2019-09-12 10:33:56 -07:00
if (match("????-??-??", s)) {
2013-10-27 22:24:23 +00:00
error("bad date format");
}
2019-09-12 10:33:56 -07:00
l[0] = s.delete(7).delete(4).atoi;
2013-10-27 22:24:23 +00:00
i = 1;
while (i < 49) {
2019-09-12 10:33:56 -07:00
atof(l[i]);
2013-10-27 22:24:23 +00:00
i += 1;
2019-09-12 10:33:56 -07:00
l[i >> 1] = atoi(l[i]);
2013-10-27 22:24:23 +00:00
i += 1;
}
2019-09-12 10:33:56 -07:00
l.erase(25, -1);
2013-10-27 22:24:23 +00:00
}
main(void)
{
2018-06-22 20:57:24 +00:00
integer goods, i, v;
2013-10-27 22:24:23 +00:00
file f;
list l;
2018-06-22 20:57:24 +00:00
index x;
2013-10-27 22:24:23 +00:00
goods = 0;
2018-06-22 20:57:24 +00:00
f.affix("readings.txt");
2013-10-27 22:24:23 +00:00
2018-06-22 20:57:24 +00:00
while (f.list(l, 0) != -1) {
2013-10-27 22:24:23 +00:00
if (!trap(check_format, l)) {
2019-09-12 10:33:56 -07:00
if ((x[v = lf_x_integer(l)] += 1) != 1) {
2018-06-22 20:57:24 +00:00
v_form("duplicate ~ line\n", v);
}
2013-10-27 22:24:23 +00:00
2018-06-22 20:57:24 +00:00
i = 1;
2019-09-12 10:33:56 -07:00
l.ucall(min_i, 1, i);
goods += iclip(0, i, 1);
2013-10-27 22:24:23 +00:00
}
}
2018-06-22 20:57:24 +00:00
o_(goods, " good lines\n");
2013-10-27 22:24:23 +00:00
2019-09-12 10:33:56 -07:00
0;
2013-10-27 22:24:23 +00:00
}