5 use Exporter ('import');
6 our @EXPORT = qw(t asay bsay);
7 use Y::AoC qw(red white grey yellow day year);
10 $SIG{__DIE__} = sub($msg) {
11 $msg =~ s/\A(.*?)( at \S+ )(line \d+)/red($1).$2.white($3)/e
12 if -t STDERR && !$printed_err++;
17 $SIG{__WARN__} = sub($msg) {
18 $msg =~ s/\A(.*?)( at \S+ )(line \d+)/red($1).$2.white($3)/e
19 if -t STDERR && !$printed_err++;
24 sub t($subtest = ()) {
26 $ARGV[0] =~ s/in\.txt/test$subtest.txt/;
38 sub try_submit($part, @msg) {
39 my $msg = join($, // '', @msg);
41 $msg =~ s/(\w+)\z/white($ans = $1)/e;
50 my $url = "https://adventofcode.com/$year/day/$day/answer";
51 my $cachefile = "ans-$year-$day-$part-$ans.html";
53 print "\nSubmit $url\nlevel=", white($part), ' answer=',
54 white($ans), ' ? [Enter]/[Ctrl-C]: ';
61 my $res = Y::AoC::UA::request($url, {
66 cache_to => $cachefile,
69 my $art = $res->find('main > article > p')->join("\n");
76 $art =~ s/(?<=That's )not(?= the right answer)/red($&)/e;
77 my $ok = $art =~ s/(?<=That's the )(right answer)/yellow($&)/e;
78 $art =~ s/(gold stars?)/yellow($&)/e;
79 $art =~ s/(silver star)/grey($&)/e;
80 Y::AoC::UA::cache_del($cachefile)
81 if $msg =~ s/(?<=Please wait ).*?(?= before trying again)/white($&)/e;
82 $art =~ s/(?<=your answer is )([^\.;]+)/red($&)/e;
83 $art =~ s/<code>([^<]+)<\/code>/white($1)/e;
87 system "cp $0 backup/$0-ok-$ans-$part";
97 sub new($class, $year, $day) {