Raku: Advent of Code 2020 - Day One

Advent of Code is a fun way to try out a new programming language or brush the rust off an old one. From December 1st until the 25th, you will find a new puzzle to solve.

This year I will be learning and writing solutions in Raku. Raku is an extremely full featured, consistent, and flexible programming language. Here is a solution to the puzzle for Day One:

[01.raku]

my @input = 'input'.IO.lines;

# Part One
for @input.combinations(2) -> @a {
if (@a.sum == 2020) {
say "sum of " ~ @a ~ " = " ~ [+] @a;
say "product of " ~ @a ~ " = " ~ [*] @a;
last;
}
}

# Part Two
for @input.combinations(3) -> @a {
if (@a.sum == 2020) {
say "sum of " ~ @a ~ " = " ~ [+] @a;
say "product of " ~ @a ~ " = " ~ [*] @a;
last;
}
}

 



Comments

Popular posts from this blog

Raku: Advent of Code 2020 - Day Twelve

Raku: Advent of Code 2020 - Day Thirteen

Raku: Advent of Code 2020 - Day Ten