main
Yanick Champoux 2021-12-05 11:51:21 -05:00
parent 4a8809eb7f
commit a99feea747
71 changed files with 11246 additions and 0 deletions

200
2020/01/input Normal file
View File

@ -0,0 +1,200 @@
1933
1963
1924
1832
1949
1826
1681
1548
1881
1973
1558
1979
1803
1975
1867
1934
1986
1220
1878
1985
2006
1535
1522
1884
1380
1922
1905
1582
1456
1877
1959
1953
634
1875
366
1968
1887
1848
1779
1894
1606
1429
1900
1309
2007
1944
1901
1559
1484
1996
1837
1892
1989
1684
1952
1990
1974
1890
1883
1993
1592
1889
1735
1577
1568
1957
1980
1537
1992
1950
1836
1397
1660
2010
1627
1991
1888
107
1977
1898
1532
1726
1899
1960
1962
2000
1903
1937
1931
1895
1868
1600
1926
1946
1964
1956
1915
1506
1580
1984
1870
2008
1885
1503
1927
841
1997
2002
1869
1874
1906
1911
508
1718
1961
1909
1914
1940
1879
1965
1929
1932
1579
1902
1783
1983
166
1972
2003
2005
1918
1893
1427
1945
1982
1847
1425
1941
1958
1842
1928
1840
1789
1654
1665
1387
1908
1891
1873
1839
1943
1616
1490
144
1981
1988
1853
1994
42
1954
1762
1792
1896
1907
1976
1886
1971
1998
1912
1967
1857
1951
1925
1921
1518
1593
2004
1999
1571
1923
463
1897
1861
1467
1920
1504
2009
1942
1995
1947
1872
1969
1910
1955
1939
1966
1687
1827
675
1520

13
2020/01/part1.pl Normal file
View File

@ -0,0 +1,13 @@
use 5.20.0;
use warnings;
use Path::Tiny;
my @expenses = path('input')->lines;
while(my $this = shift @expenses) {
my $that = 2020 - $this;
next unless grep { $_ == $that } @expenses;
print join " ", $this, $that, $this*$that;
}

30
2020/01/part2.pl Normal file
View File

@ -0,0 +1,30 @@
use 5.20.0;
use warnings;
use Path::Tiny;
use List::AllUtils qw/ product /;
use experimental qw/ signatures /;
my @expenses = path('input')->lines;
$, = " ";
print product find_group( \@expenses, 2020, 3, [] )->@*;
sub find_group($list,$goal,$n,$so_far) {
if( $n == 1 ) {
if( grep { $_ == $goal } @$list ) {
return [ @$so_far, $goal ];
};
return;
}
my @list = grep { $_ < $goal } @$list;
while ( my $next = shift @list ) {
my $result = find_group( \@list, $goal - $next, $n-1, [ @$so_far, $next ] ) or next;
return $result;
}
}

1000
2020/02/input Normal file

File diff suppressed because it is too large Load Diff

22
2020/02/part1.pl Normal file
View File

@ -0,0 +1,22 @@
use 5.20.0;
use warnings;
use Path::Tiny;
use experimental qw/
signatures
postderef
/;
my @lines = path(shift)->lines;
print scalar grep { is_valid($_) } @lines;
sub is_valid($line) {
$line =~ /(?<min>\d+)-(?<max>\d+) (?<letter>\w): (?<password>\w+)/;
my $min = $+{min};
my $max = $+{max};
my @matches = $+{password} =~ /$+{letter}/g;
return ( @matches >= $min and @matches <= $max );
}

20
2020/02/part2.pl Normal file
View File

@ -0,0 +1,20 @@
use 5.20.0;
use warnings;
use Path::Tiny;
use experimental qw/
signatures
postderef
/;
my @lines = path(shift)->lines;
print scalar grep { is_valid($_) } @lines;
sub is_valid($line) {
$line =~ /(?<min>\d+)-(?<max>\d+) (?<letter>\w): (?<password>\w+)/;
return 1 == grep { $_ eq $+{letter} }
(split '', $+{password})[ map { $_ -1 } @+{'min','max'} ];
}

323
2020/03/input Normal file
View File

@ -0,0 +1,323 @@
.#......##..#.....#....#.#.#...
.#.#...#.##.#..........#...##..
.........#.....#.####........#.
.......#.#...#.#...............
..#....#...#.#...#.#...#.#.....
...#...........#..#.........#.#
....#..#....#..#..#.#...#..##..
#...........#..#.....#.......#.
#..#...#...#.###...#...#.#...#.
#...#.#.......#...#...#...##.##
..#..................#.#.#....#
..#.##....#........##..........
.....#....#....#.#.......#.....
##.#..##.#.....###.......#.....
......#...###....#..#.#...#....
..............#.........#.##...
#......#.............#....#...#
.#..#......#.###....#...#.....#
..#........#.....#.....#...#..#
.......#...#..............#..#.
..#...#........#...##........#.
.#........#....#......#......#.
....#..#.###.......##....#.#..#
..#..###..#....................
......#...#....#.........#.#...
....#.##................#..#...
....#......######.....#........
.#......##.......#....#..##.###
..#...##.###..#.......#....#...
....#.###...#.#.#........#.....
...###...#.......#..........#.#
..........#...#..........##.#..
..#....#........#.....#....#..#
..#...#.#....##..#...##....#...
........##...#..##.....#.......
###.......#.#...#...#.......#.#
....#.#....##.###........#.....
.....#..............#....##..##
#......#.#....#.#......#.....##
.....#....#..#......#...#......
..#.##..#.....#..#....#......#.
.....#.#.#..........##....#....
.........#..#..........#.#.....
.##..#...#......#.#..#....#....
#.#..##.......#.#......##......
..#.#....#.#.....#.............
.#.........#.......#..#.#......
##.........#..##.#......#......
#..#.....#...#.....#.........#.
..........#..##..##.#..##...###
..##.....#...#..##...##.#.#....
..#..........#.#.....##.#....#.
.##..#..#.........###.......#..
......##....#...##....##.......
.....#.#.##...............#....
#..#......#.....#..#..#.#.....#
.....##.#....#.#.....#.#.#.....
....#..#.#..##....#.....#....#.
#...#.....#....#....#.#.#......
.....#................#.......#
.......#..#.#...#.#......#..#.#
...........#....#....###...#.#.
#.##....##..###.#.#......#.##.#
..##...#.#..#..#...#.....#.#.#.
#.....###.#..#.#...#.#......#.#
..##.#...#...#.#.....#.#.......
#....#...#.##......#.#......#..
..#.....##.....#...............
.....###...##.#...........#....
...#..##.....##....#...........
.....#..#......#..........#....
....##..##.#...#...#.#.....#.##
.#.....###..###.#...#.#..#....#
.#..........#...#..#.#.#..#...#
.##.##..#..#....#....####......
....#..#.#..........#..........
###...#.#..#..#...#..###.......
####.#...#....#..#...#..#......
.....##....#.#...#....##....##.
....#.#.##....#.##..#....#.#.#.
#......#..#.###....#####.##....
..##..#.#.#..#........##.##..##
#.#...#..#..#......#..#.....#..
.###.....#.#....#.#..##.....#.#
....#......#.#...#...#.#....#.#
.....#.###.##..................
.#..........#........#.#...##.#
.##......#.#.#..#....##.###..#.
..#.##....#....#.........#.#..#
........#..#..#.#.####.....##..
#..#.##.#......#.#..##.#...#..#
..#.#.##..#.##..........#......
##.#.....#.#.##..#..##.....##.#
.##........#..#.....#...#.##.##
...#....#.#.#.........##.....#.
...#....#.#....#...#..#........
.....#...#..#...#.##......##...
##.........#......#..........##
.#......#.....##....#.#.#.....#
..#.###......#..#.#....#.....#.
.#.......#...#...#.#.#.#..##...
...#..............#...###.....#
...##......#.#..#.#........#.#.
..##.#....#..........##...#.#..
..#...#.....#.######...##...#..
#...#...#............#.....#...
.###..###.##..#.........#......
.#........##..#....#...#.#..##.
#.#.##.#.#...###...............
..#.#.#......#.#.#....#.....#.#
.#...........#.##.#..#.###.....
.###.#....#...........##.#.#...
.#...#...........#..##.........
.#...#.#...........#..###....#.
.##.......#.....#.....##....#..
#.......#........#...##.##..#.#
....#..###..#.....##.......#...
......###.#...#..#....#.#...#..
..#..#.......##...#.#.#...#....
......#..#.......#.......##.#..
#.#....###.....#...#..#...#....
#...#.##.#........#..........##
.....#.#.##.#.#..#..##.......##
.#.#.......##....#.#...........
#..##.............##...#.#..#..
#...........#.#......#.##.##..#
...#...#...........#....###.#.#
.##..#.#.#....#....#####.......
..#...#.....#.#....#...........
.#..#........#.....#.#......#..
.#.........#...#...#.#.#..#....
.##.##......#.#...#.......#...#
.##...#..#..........#...#.....#
#..........#..#...#.#......#...
....##......#...##..##..#....#.
.##.......#...#.#..##..#..#....
.#.#................#....#.....
..#..#..###.......#............
...##.....#..#......#....#.....
....#...###...#....#..##...#.#.
#.........#.......#...#....#...
.#.#...#.#....##....#.#..##.#..
...#..#..#....#..#.#..##.....##
..#..#.#.#....#...#....#..#....
......###.....#...##.#..#.#...#
.#.#.#..#.##........#.#....#...
.#..........#....#.#.......#...
#.....#........#........#....#.
.#.#..#...#...................#
....####..#..#..#..#....#..#.#.
..##.#..........#.##..#.....##.
..................##..........#
....##....###.....#..#...#.#...
.##.........#..#...............
....##..###....#.##............
#.#...###.#..##...#...........#
.....#..#......#.....#.........
..#..##...#.....#.....#.#......
......#....###.#..#.#.#....#..#
#...#.......#.##.....#.........
.#.#..#...#.............##.....
......#..............#.....#..#
......#......###....#...#......
.....#.....#...#.......###.....
#..........##......##.#.#.....#
....#.......#..#......#.......#
..#...#.###...........#..#.###.
.....#...#.#...........#.#...##
........#.#.#........#.#.....#.
....##..##.#.#..#.#....#.#.##..
..#.#.#......##.....#...#.#...#
##...#..#......#.#.#..#...#....
....#..##...........#..#..#..#.
.#..##...#...#...##.#..#.#....#
.#.....####.#..#..#....##..#.#.
.#....#..#......#.....#.#.#....
....#..#.....#......#..........
..#.#..###.....#...#...#.....##
..#.#...##..#...........####...
.#.##....##.#......#.....##.#..
#.##..#....#.###..........##...
.###...#......#.#....##........
...................#..#.....#..
#.#...#.#..#.....#...#..####.##
....#.##..##...##.##.....#.....
.#...#.##...........#.......##.
###..#.....##...#.........##...
.###....##...###...............
.#....#####........#.#.#.##....
.#.#....####.##........#.......
.....#......#..................
......###.....##......#..##.#..
....#.#...........##.#....##.#.
...................#.#.#.......
#.#.#........#..#.......##.....
..#...#...#....#......#....##.#
#..#..............#......#....#
......#.........##.............
.....#.#....##..#.......#......
......#.......#...........#....
....#....#.#..##.#....#...#....
#.#.#..#..#.#.#.#...#....#....#
.#.#....#...#.#..#......#.....#
.#...........#.#....##.....#...
........#...#....#....##.....##
#..#..........#..#..#.....#....
#.#.###..........#.##....#...##
..#................#.##.##.....
..#...#.##...##...#.........#..
#....#......#......#.........#.
##...#...##.#.........#......#.
.......#.....#.................
...#...#.....##.........#.#..#.
..#......#...#.......#......#.#
#.......#...#.##.#..##..#......
.#.#............#...###..#.....
...#.......##.......#....#..#..
.....#..#.#....#.#.............
#....#...##.##....#....##......
........#......#.......#....#..
..#..#..##......##.#..#.#..##..
....##......#.##.##......#.....
........##.#...#.....#.......#.
..##.#....#..#......#.##.......
..##.####.#...#.#....#.........
.#........#.....#..#....#...#.#
###....##......#..#..#.##..#...
..........###.#..#..#....#.....
..#.........#....#.....#....#.#
.#...#.#.....##.#...#...#.#..#.
....##......##.##.#.....#..#...
....#.##...##.......#..##......
#..........#..#....#.......#.#.
..#.....#.................#....
..........#.#.#.....#.#....#..#
.......#..........#.##....#....
#..#.....#.......#........#....
#.....##..#.........##..#..#.#.
.##.#...#..........#....#......
....#..#.#......#.##..#..#.##..
...##.####....#.....#.#...##...
..#.#....#.#........#..........
#...#.#.##.##....##..#...#...#.
...#.#.......#..#...#..#..##..#
.....#....#........###.....#...
.......#..#.##....#.#.....#....
....##....#....#.......#.....#.
.........#........###...##.....
#.#..#...##.........#.#..#....#
...##...........#.........#...#
......#.#.#.........#..#.#.#...
........##.###....#..#.......#.
....#.#...#......#..#........##
.#....##....#...#.##.........#.
####.#..#...........##.#.#.....
...#....#..#.....#..##.####.#..
.##...#...........#.#.........#
#.#..#..#...#.#.#.........#..#.
#......###............#...#....
..#.......#....#...#...#..#...#
#.#.#...##..#...#...#.......##.
......#.#.......#..........#.#.
...............#...#..#...#.#..
.#.#...##.####..##.##....#..##.
#..####.......##.#........#...#
......###....##...#.#..#.##....
.##.....###..#...#.###.###.....
..#...#.....#...#..#..##..#....
...#...##.....##........#.#.##.
.#...#..#....#....#..###....#.#
..#.#.#.#.#..........#.#..#..##
.......###.....................
##.#......#.##.....#.........#.
......................#.#.....#
#..#........##.......#..##..#.#
#.#.#.....##.#.##.##.#....##...
.#...#.....#.........#.....#...
..#.........#.##.#.###.#......#
.........#..#.##...#.......###.
.....##........#......#........
...#.#...##...#........#.##....
.........##............#.####..
#....#...#...#..#....#..#.#.#.#
..#.........#......#.##........
....#.....#........#........#.#
.##.#..#.#..#..###......###....
#.###.....#.#.#.##........#..##
#.#..#...##.....#....#...#.#...
......#....#.....#...#.........
...#........##.......#.##..####
..#..#....#....#..#..#...#.##..
.##.....#............#...#.....
......#.......#.....#...#.#.#..
.........#.....#...##..........
.....#........##...........#...
#.#..##.#...#....#....#........
#.##..#.#.......#...#......#...
...........#.#..#..#.....##.#..
#....#.##.......#......#.##..#.
.....#........#.##.#...#.....#.
.....###..#.......##...........
.........#.#.#.....#.##.......#
.......#....#......#.#.....#...
##........#...#..#.#.........#.
##...........#.##...##......#..
..#.###.#.#.#...####..#....###.
.........#...#.....##....#.#.##
.###..###.#.#.....#.##.........
#..#...#.#.................##.#
##.........#.#....#.#...#.###..
#.#....#..............#.##.#...
...#..#....##.#..#.......#..##.
.#..#.###......##..........#..#
.##....#.#....#....#.#..#......
.......#.....#..#....#.##...#..
#.#.#.........###..#..#.....#..
...##..##...##....#..#......#..
..........#....#..........#....
#..##..#...#......#.....#.#....
#..##..#....#.#.#...#..........
......##..#.........#........#.
.##..#..#......###.....#..#....
.....#..#.##..........#.#..#...

24
2020/03/part1.pl Normal file
View File

@ -0,0 +1,24 @@
use 5.20.0;
use warnings;
use experimental qw/
signatures
postderef
/;
use Path::Tiny;
my @forest = path(shift)->lines({chomp => 1 });
my $trees = 0;
my $i = 0;
for my $line ( @forest ) {
$trees++ if '#' eq substr $line, $i, 1;
$i+=3;
$i %= length $line;
}
print $trees;

46
2020/03/part2.pl Normal file
View File

@ -0,0 +1,46 @@
use 5.20.0;
use warnings;
use experimental qw/
signatures
postderef
/;
use Path::Tiny;
my @forest = path(shift)->lines({chomp => 1 });
sub go_down($forest,$right,$down=1) {
my $trees = 0;
my @forest = @$forest;
my $line = shift @forest;
my $i = 0;
use DDP;
while( $line) {
$trees++ if '#' eq substr $line, $i, 1;
$i+=$right;
$i %= length $line;
$line = shift @forest for 1..$down;
}
return $trees
}
use List::AllUtils qw/ product /;
$, = " ";
print product map { go_down([@forest],@$_) } (
[1,1],
[3,1],
[5,1],
[7,1],
[1,2],
)

11
2020/03/test Normal file
View File

@ -0,0 +1,11 @@
..##.......
#...#...#..
.#....#..#.
..#.#...#.#
.#...##..#.
..#.##.....
.#.#.#....#
.#........#
#.##...#...
#...##....#
.#..#...#.#

1029
2020/04/input Normal file

File diff suppressed because it is too large Load Diff

25
2020/04/part1.pm Normal file
View File

@ -0,0 +1,25 @@
use 5.20.0;
use warnings;
use Path::Tiny;
use List::AllUtils qw/all/;
use parent qw/ Exporter/;
use experimental qw/
signatures
postderef
/;
our @EXPORT = qw/ valid_passports /;
sub valid_passports($file) {
my $data = path($file)->slurp;
my @passports = map { +{ split /:| |\n/ } } split "\n\n", $data;
return scalar grep {
my $p = $_;
all { $p->{$_} } qw/ byr iyr eyr hgt hcl ecl pid /
} @passports;
}

47
2020/04/part2.pm Normal file
View File

@ -0,0 +1,47 @@
use 5.20.0;
no warnings;
use Path::Tiny;
use List::AllUtils qw/all/;
use parent qw/ Exporter/;
use experimental qw/
signatures
postderef
/;
our @EXPORT = qw/ valid_passports_2 validate_passport /;
my %validator = (
byr => sub($x) { $x >= 1920 and $x <= 2002 },
iyr => sub($x) { $x >= 2010 and $x <= 2020 },
eyr => sub($x) { $x >= 2020 and $x <= 2030 },
hgt => sub($x) { $x =~ /(in|cm)$/ and (
$& eq 'in' ? ( $x >= 59 and $x <= 76) :( $x >= 150 and $x <= 193)
)},
hcl => sub($x) {
!!($x =~ /^#[0-9a-f]{6}$/)
},
ecl => sub($x) { $x =~ /^(amb|blu|brn|gry|grn|hzl|oth)$/ },
pid => sub($x) { $x =~ /^\d{9}$/ },
);
use List::AllUtils qw/ pairmap /;
sub validate_passport(%passport) {
pairmap { $a => $validator{$a}->($b) } %passport;
}
sub valid_passports_2($file) {
my $data = path($file)->slurp;
my @passports = map { +{ split /:| |\n/ } } split "\n\n", $data;
return scalar grep {
my $p = $_;
all { $validator{$_}->($p->{$_}) } qw/ byr iyr eyr hgt hcl ecl pid /
} @passports;
}

13
2020/04/test Normal file
View File

@ -0,0 +1,13 @@
ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
byr:1937 iyr:2017 cid:147 hgt:183cm
iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
hcl:#cfa07d byr:1929
hcl:#ae17e1 iyr:2013
eyr:2024
ecl:brn pid:760753108 byr:1931
hgt:179cm
hcl:#cfa07d eyr:2025 pid:166559648
iyr:2011 ecl:brn hgt:59in

11
2020/04/tests.t Normal file
View File

@ -0,0 +1,11 @@
use Test::More;
BEGIN { push @INC, '.'; }
use part1;
is valid_passports('test') => 2;
is valid_passports('input') => 210;
done_testing();

19
2020/04/tests2.t Normal file
View File

@ -0,0 +1,19 @@
use Test2::V0;
BEGIN { push @INC, '.'; }
use List::AllUtils qw/ pairmap /;
use part2;
is { pairmap { $a => !!$b } validate_passport(
pid => '087499704', hgt => '74in',
ecl => 'grn', iyr => 2012, eyr => 2030, byr => 1980,
hcl => '#623a2f')
} => {
map {
$_ => 1 } qw/ pid hgt ecl iyr eyr byr hcl /
};
is valid_passports_2('input') => 131;
done_testing();

807
2020/05/input Normal file
View File

@ -0,0 +1,807 @@
FBFFFFFLLL
FFBFFFFRRR
FFFBBBBLRL
FBFFBBFLLL
FFFBFBBLLL
FBFFFFBRLR
BFFBBFBLLL
FBFBFFBLLL
BFFFBBBRLL
FBFBBFBRLR
BFBFFFBRLR
FFFBBFFRLR
FFFFFBFRRR
FBFBBBFRRL
FBFBBFBRRR
FBFBBBFLRR
BBFFFBBRLL
FBBBBBFRLL
FBFFFFBLLR
FBFFFFFLRR
FBFBFFBLRR
FBFBFBBRRL
FFFFBFFRRL
FFFFBBFLRR
BFFBBFBRLR
BBFFFFFRLR
FFBFBBBRLL
FFBFBBBLRL
FBFFFBBLLL
FFFFBBFRLR
FBFBBFFLLR
FBBFFBFRLL
BFFFBFBLLR
FBFFBBBLLL
FFFFBBBLRR
FFBFFBFLLL
BFBFBFBRRL
BFBFFFBRRL
FBFBFBFLLL
FBBBBFFRRR
FBFFBFBRRR
BBFFFFFRRL
BFFFFFFLRL
FFFFFBBLLR
FBBFBFBRRL
BFBFFBFLLL
FFFFBBBRLL
BFFFBFBRLL
FFFBBFFLLL
BFFFFFBRLR
FBFBBFFRLR
BFFBBBFRLR
BBFFBFFRRR
BFFBFFFRLL
FFFBBBFLLR
FBFBFFFRRL
FBBFFFBLLR
BFBFFBFLRR
BFFBBFBRRR
FFFBBBBRLR
BBFFBFFRLR
FBBBBBFRRR
FBFBBBFRLR
FBFFFBBLRL
FFBFBFFLRR
BFFFBFFRLL
FBFFBFBLRL
BFBBFBFLLR
BFFFBBFRLL
BFBFBF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qw/ Exporter::Tiny /;
our @EXPORT = qw/ resolve /;
sub resolve($code) {
my @row = ( 0, 127 );
my @column = ( 0, 7 );
for ( split '', $code ) {
when ('F') { $row[1] = $row[0] + int( ( $row[1] - $row[0] ) / 2 ) }
when ('B') { $row[0] = $row[0] + 1 + int( ( $row[1] - $row[0] ) / 2 ) }
when ('L') {
$column[1] = $column[0] + int( ( $column[1] - $column[0] ) / 2 )
}
when ('R') {
$column[0] = $column[0] + 1 +
int( ( $column[1] - $column[0] ) / 2 )
}
}
return 8 * $row[0] + $column[0];
}

26
2020/05/part2.pm Normal file
View File

@ -0,0 +1,26 @@
package part2;
use 5.20.0;
use warnings;
use experimental qw/
signatures
postderef
switch
/;
use part1;
sub solution(@codes) {
my @positions = sort { $a <=> $b } map { resolve($_) } @codes;
my $i = $positions[0];
for (@positions) {
return $_ - 1 if $_ != $i++;
}
}
1;

21
2020/05/tests.t Normal file
View File

@ -0,0 +1,21 @@
use Test2::V0;
BEGIN { push @INC, '.' }
use Path::Tiny;
use List::AllUtils qw/ max /;
use part1;
use part2;
subtest "part1" => sub {
is resolve('BFFFBBFRRR') => 567;
is max( map { resolve($_) } path('input')->lines ) => 813;
};
subtest part2 => sub {
is part2::solution( path('input')->lines ) => 612;
};
done_testing();

2201
2020/06/input Normal file

File diff suppressed because it is too large Load Diff

21
2020/06/part1.pm Normal file
View File

@ -0,0 +1,21 @@
package part1;
use 5.20.0;
use warnings;
use Path::Tiny;
use List::AllUtils qw/ sum /;
use experimental qw/
signatures
postderef
/;
sub solution($input) {
return sum map {
my %x = map { $_ => $_ } /(\w)/g;
scalar keys %x;
} split "\n\n", $input;
}
1;

18
2020/06/part2.pm Normal file
View File

@ -0,0 +1,18 @@
package part2;
use 5.20.0;
use warnings;
use List::AllUtils qw/ sum reduce /;
use Set::Object qw/ set /;
use experimental qw/ signatures postderef /;
sub solution($input) {