September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -1,29 +1,29 @@
void
check_format(list l)
{
integer i;
text s;
if (~l != 49) {
error("wrong number of fields");
error("bad field count");
}
s = l[0];
if (~s != 10 || s[4] != '-' || s[7] != '-') {
if (match("????-??-??", s)) {
error("bad date format");
}
l[0] = atoi(delete(delete(s, 7), 4));
l[0] = s.delete(7).delete(4).atoi;
i = 1;
while (i < 49) {
l[i] = atof(l[i]);
atof(l[i]);
i += 1;
l[i] = atoi(l[i]);
l[i >> 1] = atoi(l[i]);
i += 1;
}
l.erase(25, -1);
}
integer
main(void)
{
integer goods, i, v;
@ -37,25 +37,17 @@ main(void)
while (f.list(l, 0) != -1) {
if (!trap(check_format, l)) {
if (x.key(v = lf_pick(l))) {
if ((x[v = lf_x_integer(l)] += 1) != 1) {
v_form("duplicate ~ line\n", v);
}
x[v] = 0;
i = 1;
while (i < 48) {
if (l[i] < 1) {
break;
}
i += 2;
}
if (48 < i) {
goods += 1;
}
l.ucall(min_i, 1, i);
goods += iclip(0, i, 1);
}
}
o_(goods, " good lines\n");
return 0;
0;
}

View file

@ -0,0 +1,33 @@
sequence lines = read_lines("demo\\rosetta\\readings.txt")
include builtins\timedate.e
integer all_good = 0
string fmt = "%d-%d-%d\t"&join(repeat("%f",48),'\t')
sequence extset = sq_mul(tagset(24),2) -- {2,4,6,..48}
--The extract routine has been added as a builtin for 0.8.0+. If you don't yet have it, just use this:
--function extract(sequence source, indexes)
-- for i=1 to length(indexes) do
-- indexes[i] = source[indexes[i]]
-- end for
-- return indexes
--end function
for i=1 to length(lines) do
string li = lines[i]
sequence r = scanf(li,fmt), this, last
if length(r)!=1 then
printf(1,"bad line [%d]:%s\n",{i,li})
else
this = r[1][1..3]
if i>1 and this=last then
printf(1,"duplicate line for %04d/%02d/%02d\n",last)
end if
last = this
all_good += sum(sq_le(extract(r[1][4..$],extset),0))=0
end if
end for
printf(1,"Valid records %d of %d total\n",{all_good, length(lines)})