Verified Commit 994080a0 authored by Roman Lacko's avatar Roman Lacko
Browse files

Add day 09, part 2

parent dac6b14d
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
@@ -14,3 +14,14 @@ sub next-value(@measurement) {
our sub part1(IO::Handle $in) {
our sub part1(IO::Handle $in) {
	[+] $in.lines.map(*.split(/\s/)>>.Int).map(&next-value)
	[+] $in.lines.map(*.split(/\s/)>>.Int).map(&next-value)
}
}

sub prev-value(@measurement) {
	return 0 if @measurement.all == 0;

	my @Δ = (0 .. (@measurement.elems - 2)).map({ [-] @measurement[$^a + 1, $^a] });
	return @measurement[0] - prev-value(@Δ);
}

our sub part2(IO::Handle $in) {
	[+] $in.lines.map(*.split(/\s/)>>.Int).map(&prev-value)
}