Advent of Code 2020, now in the most terse and awful python possible
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
862 B

#!/bin/sh
tmp="$(mktemp -d)"
trap "rm -rf '$tmp'" EXIT
set -ex
cat "$1" | tr '\n' - | sed -e 's/--.*//' | tr - '\n' | tr '"' \' | sed -e 's/[0-9]\+/_&/g' -e 's/$/;/' > "$tmp/r"
cat "$1" | tr '\n' - | sed -e 's/.*--//' | tr - '\n' > "$tmp/m"
cat > "$tmp/run.y" << EOF
%code top {
#include <stdio.h>
int yylex() { return getchar(); }
void yyerror() {}
int count = 0;
}
%glr-parser
%%
input: %empty | input line;
line: '\n' | _0 '\n' { count++; } | error '\n' { yyerrok; };
$(cat "$tmp/r")
%%
int main()
{
yyparse();
printf("%d\n", count);
}
EOF
#cat "$tmp/run.y"
#cat "$tmp/m"
sed -e '/^_8:/c_8: _42 | _42 _8;' -e '/^_11:/c_11: _42 _31 | _42 _11 _31;' "$tmp/run.y" > "$tmp/run2.y"
bison -o /dev/stdout "$tmp/run.y" | cc -o "$tmp/run" -xc -
bison -o /dev/stdout "$tmp/run2.y" | cc -o "$tmp/run2" -xc -
cat "$tmp/m" | "$tmp/run"
cat "$tmp/m" | "$tmp/run2"