]> www.fi.muni.cz Git - aoc.git/commitdiff
Day 1. Got 504 gateway timeout :(
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 1 Dec 2021 05:11:09 +0000 (06:11 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 1 Dec 2021 05:11:09 +0000 (06:11 +0100)
01.pl [new file with mode: 0755]
02.pl [new file with mode: 0755]

diff --git a/01.pl b/01.pl
new file mode 100755 (executable)
index 0000000..f1912b2
--- /dev/null
+++ b/01.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+my $prev;
+my $inc;
+while (<>) {
+       chomp;
+       $inc++ if $prev && $_ > $prev;
+       $prev = $_;
+}
+
+print $inc, "\n";
+
diff --git a/02.pl b/02.pl
new file mode 100755 (executable)
index 0000000..b9fbfb5
--- /dev/null
+++ b/02.pl
@@ -0,0 +1,15 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+chomp (my @a = <>);
+my $prev;
+my $inc;
+
+for my $i (0 .. $#a-2) {
+       my $sum = $a[$i]+$a[$i+1]+$a[$i+2];
+       $inc++ if $prev && $sum > $prev;
+       $prev = $sum;
+}
+
+print "$inc\n";