Skip to content

Instantly share code, notes, and snippets.

@arodland

arodland/1.raku Secret

Last active December 1, 2021 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arodland/2f61f623aa1aee8d18508e06baf06c7c to your computer and use it in GitHub Desktop.
Save arodland/2f61f623aa1aee8d18508e06baf06c7c to your computer and use it in GitHub Desktop.
my $ct = 0;
my $prev;
for "input.txt".IO.lines -> $num {
$ct++ if defined($prev) && $num > $prev;
$prev = $num;
}
say $ct;
my $ct = 0;
my $prev;
my @window = ();
for "input.txt".IO.lines -> $num {
@window.push($num);
next if @window.elems < 3;
@window.shift while @window.elems > 3;
my $sum = [+] @window;
$ct++ if defined($prev) && $sum > $prev;
$prev = $sum;
}
say $ct;
my $ct = 0;
my $prev;
for "input.txt".IO.lines.rotor(3 => -2) -> @window {
my $sum = [+] @window;
$ct++ if defined($prev) && $sum > $prev;
$prev = $sum;
}
say $ct;
say "input.txt".IO.lines
.rotor(3 => -2)
.map(*.sum)
.rotor(2 => -1)
.grep({ $_[1] > $_[0] })
.elems;
say "input.txt".IO.lines
.rotor(3 => -2)
.map(*.sum)
.rotor(2 => -1)
.flat
.grep(&[<])
.elems;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment