2IKHKAD4YBM4AREIQ3KS6R5MT26FO6NV6K2YI4TDRXLGDHUI3B4AC
10604480
4126658
5764801
17807724
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const lines = data.split(/\n/).map(Number);
const min = Math.min(...lines);
const max = Math.max(...lines);
let i, j, val;
for (val = 7, i = 1; val !== min; i++) {
val = (val * 7) % 20201227;
}
let key = max;
for (j = 1; j < i; j++) {
key = (key * max) % 20201227;
}
console.log(key);
swsenenwneswnewseswwseswnwsweeswnw
esweeeeneeeneeeweeeenenenee
ewewsewswnewnwnewwwwsew
nwnwnwnwnenwwnwsenwnwnwnwnwnwnw
nwswseswneswseswswneswswseneseswswsenwswse
swswswneswswswswwneseswwswsw
newnwwnwnenenenenwsweenenwnenwnenese
senwsewseneneseneenenwwneneeswnewsw
eeeeneweeeseeeeeenewneswe
wnwswwewwwsewnwnwwnwnwwwnwnwnww
nenwnwnwnesenwwnwnwwneswnwnenesweneenwnw
nwwnwwwwenwwswnwwwwwewsesew
swnwswwswswewswseswnwne
wswnewswnwwwwenewsewwwwneswe
nwnwnenenewneneneneneenenesenwneswneswse
nwewsenwnwneseswwwwwwswwswwwwe
nesenwseneswseswnwneseseseseseswnwse
wnesweseswenwnenwnweseeseseeswnwse
swswnenenenenewneneeeneneeneneenenene
seseseseeweseeesee
wwwwwwwwwnewnwwwswww
sesenwesenwseeseseseewswneseseesesw
wnewwwsewnwwnwnwewnwswnwwwwnwe
nwnwnenwnwneneenewswnwnenwswnwnesenwsw
eeswwneeneneeneeneeeeesw
seneenesewneeneswwnenenweeenenewwe
seswseswsenwswswseswswswswenwswsesesw
nwnwnenwnenwnenwnwnwnenwswnenwwwnwese
wnwwwwwnwwwnwwnwnwseneenwnwnww
ewnwnwnwnwnwnenwnwnwnenenwsenenwnwnene
neneweeeeneeneesweseswswneseswse
seswseeneswswswseseewsewnwswswwnwne
swwneneneweseswnenwneeneneeeeeeee
swwwwwwwwwwwwswswwswswnesew
eewenwseeeeeweeeeneeese
neneneneneeneswneeenee
sewnwnwwswnwseenwwnenenwwnw
swsweswswswswsewseneseswswsesweswnwsw
nenewewwwwwwwwwnewwswsesewww
enwsweneseseeesese
swneseseseneeseesenwwseneswseseseseew
nwswswneeeewneseenwnwnesewwswnwesw
nenenwneenwneneneneneneneneneswenewne
nwneneseeenwnwnwneneneswneswwnenwnwnenw
neseenenwneeneneneeeeneene
sesesewseseseswneseesesesesenewseswsese
senwnewseneneeeneeeeeenesenwnene
eeweneneeenweeeseesweeeee
esesenwswnwseewseswseeeseswenenwse
neeneeeseswseeesweneeseeesweee
swweswnwneswswwswswneswswswswswsw
wwswwwnwnwnenewnwenwswnwsesenwnwe
neseneenwneeeeeneneeeewneeene
swsenwsesesweswsewswswswsenwneseswsesw
wewwwwwnwwwwwnwwwnw
swseweeenwswneseseesenese
senwsesesesesesesewseesewe
sewnwnwnweswnwnwsenwnwnwnwsenwnwnwnwnw
swswswswswswswswswseswswswswswswwswnesw
wswnwnwsewwnwewwewwnesewwne
enenenwnewnenwnenenwwneswneseswnenwsenwnw
seseseswswseswsewnwsewswswseeseeswse
nwseswnweswnwneseweswsesweseseswne
seseswwnwswneneseneneseeseesenwswnwww
wswswwwwswwneswseswnwswswsew
senwnwwnwnwesewswnewswwsenwwnwnwwnw
swsewneswswswswwswswwswswswsw
eneseeeswneswneeseesenwewsenwewnwnw
neneneeeneweneneeswe
neeeseeenwnweewswnewneseneenenee
senewesesenweseseeesewsesesesesesee
eseeeseseseenwseeneseseeewse
nwnwseseenwenwnenwwswnwnwnwwnwnwnwnwnw
senewweseeenwsesesenesewsesesesee
enenenwswnenewswenwnwneenwwnwswnenene
eswseseneswsenwswseseseswsesesewsenwsesee
wnwneswneseneneneneeneneswenenenenewne
seswneewsenesesewnwwswnesewswesenwne
eswwesenwwenwnwnweseseeeeeese
neeneswneeswnenesenwnwneswnenwneneswsene
swswneseseswswswswwewnwsenwesweneswnwe
nwenwwwnwnwnenwnenwnwnwnwnwsweneswe
seseneneeseseeeeswsenwwwesesenwe
sweswseswwnwsesesewseseseseswseneswnene
seswseseseseseswwseswsenesesesesesesese
sesesenwswswseswswsw
senwseeeeseseeseseseenwewswesee
wwsenwewwnewwswwwwwswwwwwne
nwnwnwneswnwnwnwsenwwwnwwnwnwnwenwse
swwwswswswwwsewnenwswwswwswseww
enweenesesesenewnwnwwswswswseseese
swnenenenenenenenwnenesenewnenwnenenwnene
enenesweeeeseneeneeeneeneeew
wnweseeswnwwenwnenwnwnwwenwnwsenwwnw
neswswswseswswswwswnesw
neswseeneseswsewseseswseseswswwswswse
seeneswsesenweeeseeseswsewenesee
wewewwnenesewsenwwnenwnwseswsww
nwnwsesewnwseeeswnwnwseewseenw
nwwwwwnwwnwnwwwwnwsenwwwwsew
eenwneseeeneeneenenwseeeeeee
nwenwnwnenwswnwneesenwwwnwnwnwsenwnw
swswswswseswswswswwseswswswswswswswswne
swwwwwwwwwwnwwewwwnwwww
esweeeeeeneeenwnwenesw
eeenweeeseese
wwwnewwsewewwwwwwwwww
seseseeseseesesenwesewseeseseseswnesese
senwnwwneswwswwnenwwwewnwnwwnww
swnwsesewneenwenwseenwneeseeseewsw
eneeneneneneneneswsewswsenenenwnenenenw
wneesweseswswwsewswnweswswewswswse
neseneneeewneneenewnenenenenenenenene
wswnesewwsenewswswswswneswswswsweesw
swswsesenwseswsewseswneseseseswsesw
seswwswwwseswswswswswweswneswswnewsww
neneesenewewnenwneneneswnwweswswnese
swswswwwswswswswswwneswswwwswseww
neenenenenenenenenenwsewneneneneswnenene
eneeeeseenenwwesenesweeseeesw
swswswswswswwswnwswswwswseswswswsw
eneseseseswsesesewsesesesesenwseseswenese
nenesweenenenewneneeeneswnweenene
eneswsenwseenwenwene
swsewnenwenwwwwseseseswnwwne
seeseseseseseseswsewsesesenwseseseewse
swenewswnenwswsweswneswswswse
wnwwnwwwswwwwnwsenenwnwwwnwwww
eswswwswswnwswswwwswswsewsweeswww
nwwnwenwnwnwwnwsewnwwwnwnenwnwnwnwnw
seswwseeswswseenwneseswnewwswseswsw
enewwwswesewwnenwseswseweenwnwnew
swseswseesenwseseseseseseseswseswwsee
neneneneneneneneneneneenwnewneswe
wnwswswnewnwnwwwsenewweeswnwnenww
swenweenweeneswneeeeneneee
nesweswswseeswswsenwswsewwseneneswse
nwneswewnwnenwnwnenesenenenwnwnwneswnene
wenwswnwnwnwnwnenwnwnwenenwnwnwnwnwnwnwne
seseneesewnwnwneenwseeswswsesewnese
swnewswnwswnwnwnwwenwnwseewnwnenenww
seesesewenwneeeenwnesenenwsweseswnwsw
swnenenwnwnwnenenwnwnwnwswnenenenenwnwse
ewewnwwswesewsweswnweswswnwnwwnesw
neseneewwswwwwnwwwewwwwwsww
enwnwnwwswnesewwnwnwsewswnw
sewwwwwsweswnwswswnwwwwewsesw
neneneseweneenenwesewnenenenenenese
eeeenweeeeswseewnweewneswnew
wnwnenwnweneneswnenwenenenwnesenwne
eseseseseswsenwseseswsesesesesesesesese
eseeseeseeesesenwwseene
nenwnwnwnewnwnesenwnwsenwnwneneseesw
ewwnwnewnwwnwnwnwnwnwswswswwwnwenw
senwwneeneeeneneneenewneswenwnene
nwnenwnenwewenwnenewseeeenwswswwswe
wwewwwwnwwnwwwnw
eeeeeeseseeeeeeeeeew
wnwneeeseeneeneeneeneweseeenesw
nwwnwsweswwwseww
swswwswneswseswswswseswswseswsesweswwsw
newneneeneseenenenenenenenenenenewwne
nesewwwwswwnwwwnwwwneewwwsee
enwseseseseeseseseeeseesese
seeseseseseseeseseswneseswseseesesesenwse
nwseeseeesesewswseswwsenwseswneseesw
wneseenwnenwenwneeneneneneneeseesee
nwneesenwsweeneneneeseeneesenwww
nenenwswnwswnwnwnwnwnwnenwnenenwnenwnwnwnw
nwnwnwenwnwnwnwnwnwnwnwnewnenwnwswnwnw
wwwwnwwnwwnwewnwnwnwwnwwwswnw
neewneenewseneneeneneneneneneneene
neneneneneneneneneneswnenwnenenwnesenwnene
eeeeeeeseeeeeeeneeweee
ewwsweswsweseswswswswnwnwewnwnesw
weswswseseenweneesenenwnwnwneswswse
nwswswseswwswswswswwwswsww
seswseswwseseswswswneseswseswswswneseswswsw
eneeneewnenwneeseeneneeneneneseeee
eenwnweswenwenenwswswneeeewese
nenenenesweneswneswnenwne
enweseeseeneesweswnwsee
swnesesenenwwswnwsesenweneenenweswwew
nenwnwnwnwnwnwnwnwnwwnwnesenwswnwenwnw
nwwnenwnwnwswnwswsenwnwenwnwswnwenwnwe
swweeenwneswnwnwwswsewwswswseneew
esewnwseenwseseenweseseseesesesenwse
enweseeeeseseeneeseeeseweee
eeseeeeseseseeeewneeeseeeswe
swswwwnewswwswwswwswwswsw
eewseeenwsweenweneesewnweew
wswswsenweswnwsenwnwswswwneseweneww
nenewswnenesenenenenenwnwnenewneenenene
nwnwnwnwnwenenwnwnwwnwnwnw
sweweesweseeeswnweenwseneeenwee
ewesesenweseenwseseseeseneseeeswe
eneenenewnenenenenesenenene
eeeesesweeewseseeeneesewenesew
wswwwswswswwswswnwsweswswwswnewseswsw
swswswseswswswswswswswswswseseseswswenw
neenenwenenweseweneenesenwswneswnwswne
seswwwwwwwwwwwwwwwwnesenewne
swswswswswsweswswseswswswswswswseenwnwswsw
eneeeseeseseeseeseewseseseseee
swneswswwnewewswswsewwswwswnewse
wnwnwwwswwnwwewwwwwseewnewsw
senweeneeseeewenwsew
nwnwnwnwseswnwnwnwnwenwnwenwnwnwnwwwwsw
eeseneeeswewenwneeseeeeeee
wnwenwwnwnwnwnwe
wswwswswwwwwwsewswwneswswswsww
nwnwnwnwnenwnwnenenesw
nenewwnwnwswnwesenwneseneenenwneewne
nwneneswnwnenenwnwwsenwnenwnenenwnenenw
swwwwswswnenwsweswenwswseneswwswnese
eeeeewneweeeeswsewesweenwene
seswsewnwwnenwwsesenesewnwweeswswnwse
senweeseseswnewseseswsenesese
nwsenwnwnwnwnwnwenwnwnwnwwnwwwnwww
wseseseseseswswswswneswse
nwneneswnenenenenwnenwne
esenwseeswseseseseseseswsesenesenwswse
seswswswswnenwswenewenwneswseswwswswswse
sweswwwnwswwswwnweswww
swwswsewswwswwswwswswwnewneww
swseneswwnwweswswseswseeswwneswswswew
eseseseesesesenweeseseseweeseswese
swswnwnwnweswswswswswswswee
swseneswsesenesweewwseneswseswswnwnw
sewseeseseseeeseseesesesenese
seswnesesesesesesewseseseswsesesesesese
seseseseswseswseseseseswsesewseswsenese
enwnenwenwnenwnwswsenwnwswne
enenewnenwneneneneneneneewnenenenene
nwwsweneswwswwsewswwswwswwenwswsw
swsewseseneswswswseseswseeswseswsesese
neneseewneseneneneeneneenwnenewe
wwnwwwewswewwwwwwwswwswww
eeswneneneneneneneeneneneswswnenenwnw
nwnwnenenwnwsenwnwnenenwnenw
eeseseseesenwseseeesesesewseseseseesw
wewwwswwwswwwwwwswnwsewwnw
nwwnwnwwwnwnwewnwnwwnwswswnwwnwe
nenwnenwnwnenwnwnwswnwnwwnwnesenwnweswnenw
wwneweenenwswnesesewnewswswwwse
seswswsesesesewswseseseseseseneseswsese
swswseswseseswseswseneeswswseswsesewse
eneneenweeewnwesenenwseswseewwe
swenenweeeneeeneewseeswenwee
enesenewwwswseseswsese
eswneseweneneeneneeenweneneeee
eseseeseseeweswswenwneeeeneewne
wnwwneenwwwwsenwwwwnwwwwww
nwnweseenweewneswesweeeeeneew
swswswwnewswwswseneswwwswwwswsww
nenwswnwnwnwenwnwnwnenenwnwnenwnwnwnene
nwnwwwwnwnwwnwnewnwnwnwnwsenwwww
wswnwwseswwswwswwnwwewswsewswew
wneeweneneneseneswnewnenesesenenwnee
sesesesenwseswseswsesesesenwsewseneesese
swseswsenwsweseswsewswsweswse
nesesesweewwsweswseseswnwnwnwswsee
nenwnenwnwnenenwneswseseenw
sesenwswsenenwseswnew
sewseseseseeseseseseseesesesesenwseseswse
sewwenwnwnwwnenwnewswnwwwwnwwwnww
nwnenesewnwnwnwnwnwnenwsenwnwnwnwnwnwnwnw
nenwseneswnweseseswneweswnesenweewne
sesenwseseseewseseewseneseesesesesw
wwnwwnwnwwseswwnwenwnwwwnwnwewww
seseswsenwseswswseswwneseswsese
sweeswnenenenwneneenweeeneeeeene
seseseseswneswseswseswsenwseseseswsese
enenenenenenwnwnwnwnenesenenwnwneswnwnene
swwsweswwswwwswswswsw
wwswwnwsewswwnenwwwwwnwenwnww
eenwnwseseseseeeeeeeeeweeswswe
nwsenwnwnwnwnwnwnwnwnenwnwnenwwne
swwswswsweswswswswwesweseswswswswsww
seseesenwseweseeeseseewseseswsese
nwseeeesweeeeeseeweeenweeee
seeswneseseseseseswsesesesesesesesenw
eswenewsenwwneeeneeneeneenenee
wswenwnwenwwnenwwswesewseneweewsw
sweswenwswnwswswnwnwwnweenenwnwe
nwenweeswswwww
nwneneneswnwnenenenwnwneneswnwnwnesenenene
swseeesweeewsesenwweseenweenee
nenwneswneswneneenesenesewnwnesenewnenene
sewsesesesesesesenwseseeseneseewwsese
seswswswswwswwneswwswswswswwswwwnw
eeesenweeewseweeeswweneswnenw
eeeeeneeeweseeweeeeeeee
seswnesesewwseseeenesenewseswwnesw
eeeeeeseeewseeeeeneseeee
nwwwnwenwwswwnwenwwsenesenwwnw
wwwwwwwwwsenwwnwwnwwnwwwsew
seswswswseswseseswswswseswnwesenwseswsesw
eneeneeneneeeeweneneneseweneee
swwwwewswnwswewnwswwswwswwwswsw
eswneseeneneewneswseeweeeneenwnenw
swswnwwwseswnwnesewseswwnwswsenwswe
swswswwsewnwwwewswwneswsewwwnw
nwnwwnwnwwnwnwsenwnwnwnwnwnwseenwnwnwnw
seseseewsesesesesesenenewsesesesesesesese
nesenenenenenwnwwnwnenwnenenewneneneene
wesesesenweseseseswseseswsenwswsesewse
eseeswseeeswenweeseseeeneeee
neswwnwwwwnwwwewwnwswwenwww
nwswnwnenwnwnwnwnwnwnweswne
nwwwsenwnwnwwnwsenenwswnenwwnwnewwse
seenwseeenwweseeeweesweeeese
swswsweswswswneswswseswswwwswswswswneswne
ewwwswwwwswwwwnwwwwwswww
seswsenwseseseswsesesese
neneeswewnenwswneneseswenwseewenene
swnwnwenenenwnwnwnwseenwnwsenenwnwwnw
nwneswneneneneneneseneneswnenenwnenw
nwnwnwnwnwnwsewnwnwseenwnwnwnenwnwswnww
seswseseswseseswneswneswswseswswseswswsese
wnwnwnwnwnwnwnwnenwnwnwnwnwnwsesenwnwnwnw
seseseeesesewsenenwseweeseesesee
nwnenwwweseswnwwwnewwswseneseww
swnwseseseesesesesesewseneseseseseswsesw
seseseseesewneseseseneseeeseseeswsese
nwnwwnwnenwewwnwneseswwwwnwww
esesesesewseseseseseeseesenwsesesese
eswswnwswswneswswswseweseseswswswswne
swneenenenenenwnenenenenenwnenwnesenene
nwwswnwswswnwnenweeenenesenwwsenesw
eeeeeeeeeenweeeeenwswswee
nwnenenenwswnenenwnenenenw
nwwwnwnwenwnwnwsenwwwnwwnwwnwnwnwnw
ewneweseeseseseseese
nwnenwnwnwnewsesenwnw
nenenwnewnwnwnenwsenwswneenese
wnwwwwwnwwwwnewsewwwnwwswwnenw
enweseeeeseseeeee
wesweseneswsewnewwneewenenenwnwse
eseeswseeseeseseseseeseenweeee
wnwnweweswsesenweseseseseseswewsese
eeeneeseeenwseeeneenwseweeee
esenwseswseswswseswseseseswseseseswswse
wwseswnewwwswewwwswnewwwew
eeeneeeeeeenweeseenweeswee
sesenwneewswweneswnewsenenwenwswnw
nwnwneseenenewewnenewswneesenenene
swweswswwswswwnwwwswswwwswnwwesww
swnenenenwneneenwnwnwnenesweswnwnenenwnw
nenwnwwewwnwnwnwsewswneenwswswnwnw
nwwwsewwnwnewnesewwwwnwnwnwnww
wswwnwsenwswnweswweswswwwwenenw
neswswswneseswwswwwsewswwswnwnwneesw
newewwswwswwewwwwwwwwseswne
neenenweesweneneeneneneneneneneenese
eseseseeswseweenweseseeesesesesee
swseswseswswswseswseswswswnwsw
nenenenenenesewneewsenenenenenenenenene
eeswneseenweseeeeeeseewsewseee
nwewswswwswswwswswwswswswswswswnwse
nwnwnwnwnwnenwnwnwnenwswnwnwnw
eeeseeeeeeweenweseseseeese
swswwwswnewsewswwwnwswswsenwswsesw
seseswsesewsenesenesenw
seseswswseneswswswneswseswswnwsesesesesese
nwnwwnwnwnwenwnwnwnwnwnwnwnwnwnwnwnw
neeneseeneneneneeneenewneneneswnenew
nwsenwnwnwnwwnwsenwnwnwnwnwenwnwnw
swswswnwswswswswneswneswswswswewseswnwsw
seswneswswswswswswswseswswswswswswenwsw
wwwwnewnewnewswwswwswwwseswww
swenweswseswseneseswswsesewsese
ewswseswwsewsweswwswwswsenenenesene
swwnwnwnwseneseenenenwneswwwwwseswse
nesweneneeseneneneneneenenenenenwnwnenee
enwnwwwnwnwnwnwnwnwnwnenwsenwnwwwnwnw
wwwwwswwwwwnwwwewwnew
nenenesenenwnwswenwnwnenenwneneneneeswne
eeneeneneesweeneneneneeeeewene
eeseseenwnwsesesenwesenwesesesewese
neeeeswswneeeeeeenweeene
seseesewnesewseseeseseswseneseswnwsene
sesesewseeeneeseeseseseseeseeese
wswwnwwnewsewnwnwnwesewwnwnesene
eseeneenenewnenenwseesenwnwnesewnene
eseeneeswnwneesesewwneswewwneesw
neneswseneenwnenenenewneneneneneneseneene
sesesweseswsesesewseswsesewsesweswse
sewsesesesesewseseseneseeseneesesese
swwwenwwnwswnwnwneswwwnenwsewnwww
swwswswseseswswnwseswswswswsweseswsesw
senwenwnewweneneswswnwswwsenwenwenwnw
nenwnenenenenenenenenwneneneneneneenwwsw
wwnwwsewsewswnewsenwneesw
nenwnwseswnwnwenwesewnwneeswswnwnwswnw
nenwswnenenenenweneseneewseeneewswene
esenwwsenenenewnwnwswnwnwnwwwwnwnwnww
sesenweeeseseeeseseeseeeseswese
neneneneneenenenewsenenenenenenenenene
eeeseeeesweneneneeeeeenenwe
eswwwwnwneewwswwnwwneswwseswswwsw
wseseeeesesesesenweeneseseseseeee
esesesenweeeeeweeeswenwne
wwwwswneenwsww
seseswseneswswswseswseswswsewswswswseese
weseswseeeneseseewnweseesesesee
swswswswswswswswneswswsw
swwswswswswswswswwswswenwwswww
nweneneneeeneneeneeseneneneneene
swwswwwneneswswwswwswwseswnewswsw
eeeewenwweeeesweeeee
wnwseeewswswwwswsewwswnewnenew
ewseneeswswneswenweswnwwwwneswwe
eswseswnenwswseswwseseesesesenesesesw
senweeseseesesesesesw
nwsesesewsewnweweseseeseswsesesw
sewwwseseswswneenewenenwsenwseww
nwnenwnwneswswsenweswneneneenenenenene
eswnweeeeneeseneeeswenweneenw
wsenwnwwnwnwnwnwnwnwnwnwwnw
nwnwenesewenwnwnwwwnwwnwnwwnwew
nwsenwnenwnesenwnwnwnww
wnewneswnwwsesenwwweweseneneww
swseseseneeseswsewse
nenwsenwnwsenenwwnwwnwnenwnesenwnwnwnw
neswswswswnweewnenwswswswswswswseswswne
nwseseseseseeeseseseeeeseeeswsese
wnwnwnwwwenwsewnwnwwnwnwwnwnwnenw
wwwwwnwwewnwww
nwswswswswswswswswswswswswswneswseswneswsw
nenesweneneeneneneneneeneneenenee
swswswswswswwseswwswwswsweswswswnwwsw
nwwewswwnwwwwnewwnw
eeewenweeeseneeeseeeeeeeswe
swswenweswseseswneswswswsewsesesenenww
eeseeeeeeneswseseseeeweeeee
eeeseseeeeeeeeseenwenenweswesw
neswseswswseseseswsesw
sesenwwseneesewseneseseewneswswneswne
senenwswswwwsewwsenenwwenwewnew
neeseeweeeneeenenweeseeeee
nwswwswswswseswwswswswnewswswwswsesw
swneeneneeneswnwsesesesewnwesewsesesw
swswenwneneewneswwswswesesewsesw
nwnwsenenwnenwsenwnwnenwneneeswwnenewnwnw
swsenenewswswsewwnewwwnwsewswwsw
swenenenwseseneweenene
wswwswneswsewswswswswswswsw
wsenwsenwwwsewwnwswwnenwwnwnwnwew
nesweweeswwseseseseeeeneenwew
wseseneswnwswseseswseswswsenwwswswswesw
wwnwnwnewswenweswenwnwenwnwswnww
seswneswswseswwseswswseneswswnweswswswsesw
swwwnewswwswswwwwwsww
enwswswneeneneeneneneeneee
swswwswswswswswswswneswswswswswsw
sweseneswwseeeneeenwnenweswnenwne
eseeeeweneeseesewseswnewe
enwesweseenwseseeeesweeeenese
eswsweesenwenweeeeseeeeeenwee
eeeesenweseeeeeesweeseeee
wwseenenwnwwnwnwwwwnwswsenwwnwenw
sesenwseseseeseseswseswseswseswnwsenwsese
eeeeneeneswnenwee
seswneseswseswnwswswesesewseswswswswsenwse
nwnwwnwwenwnwnwnw
eenenenwneneeswneeneneseneneenenene
seeseseseswseseesesene
seseseswseseswnwswswwseswsweseswsesesenw
nenenenenenesenenwnenenenenenesenenenewnenw
nwenwnenenwnwenwswnwnwnwnwnwnwneneswsw
nwneswswnenenwnwnenwnenwnenwnwswnenwnwnw
eneneneeeeneeeweneeneenene
enenenenwnenenesenenenenewneenenenene
seseseseseswsesesesesesesesesesewnenesese
nwnwenwwnwenwwwenwnwnwnwwwnwwsw
eeseeesweeeseeeseeeeewnwenee
sweneneeneeeeneeewneneeneneenw
nenewnwneseseneneenwwswneneenenwwse
nwswwwwneswsewwswwneweweswnwsew
swswnwswswsweswsesw
nwwnwnwnenwnwnwswnwnwwnwnwnwnwwnwwew
swwwwwswswwwwneswwswsewwwwsw
seswsenenenewewnenenwnenewenenenenesee
wwnwwewnwnwenwwnwnwwnwswwwsww
wswswswswswswneswswseswswswswswswwswsw
sweseeeeeeeeenwneneeeenweee
eneneneeneneneswnenenenewenenenenwnesw
swseeesewsenwswsesesw
eeneneenenwneeneweswsweneneeene
swseseseseseseseseseeeenwswseesesesenese
eneweeneeneneseenenenewseeeneenew
eeswswseenenwnewe
ewenwwsesesesenwnwwesenenwnesesew
wwwwnwwwwnwenwwwnwwwwsenww
swnwsesewnenwsesesesene
sewnenenenwneenewsenwnenewneeesesw
swswswswswswswswseswnwswsww
seswswsenwwswseswnesweseseswswseseesenwse
eswswwswswnwseswswswswswsweswswswswsw
nwnweswwnesenwnwnwnweswnwnwnw
eswnewwswesewwwnwewwesenwnwwsww
eswnwneneneeeeswnesewnesweeeee
ewswwnwnwnwwwnwnw
eeneneeeneneneeenweneesweswnese
seswseseseswseneseseswweseseswswswseswsw
nwnwnwnwnenwwwenwenwnwnwesenwwnwnw
sewwnwwenwswnwnww
wseneseswseseswswenwseseswswswswswwse
seseeneseweneneswnwseenwswnenenenwnene
nenewswnwseseneeneneneseneneneewnenw
eneeeneeneeeeneeneweese
wwewwswwwwwwswswwww
seswseseseseseswseseneseswnesesesesese
neneswseswnwwseswswswwswswsweswnwwswe
newwswswswswwswswneeswnewswsewese
eseeeseeseeeeeseewe
enenewnenesesenewnwswsenesenenwneneneesw
neeseeeeesesweseseseeseseenweese
nweswswswswswseeneswwsewswswswswswe
wwwwwwsenwwwnwwenewwwnwwsww
swsesewnwswswswneweswswseeswswneswsew
swseswswswswswswswnesweeswswswsenwswswnw
eeeneseeneweneeeweeeneeneenee
nwnwnwnwnwenwnwnwnwswnwenwnwnwnewnwswswnw
nwwnenwwenwnwwwsenwnwnwswnwwneww
senewswswnenenenwneeneneneneneeenenenene
eeseseeseesesenweseeseeseewse
neswnesenenwswnenwswnenwswnwneswswnewseee
senwnwnenenwnwnwnenenwnwnenwnwnenene
wwnwwwwwwwwsenewnwww
nwnwnwnwwnwnenwnenwnwneneenwswenwnwse
wwwwnwsewswswwswenwswwswswwwww
nwwwwnwwswenwwwnwenwnwnwnwswnww
nenwesenwewneneseeseenwenewnenee
sesenwnenenewseeswwswswwnenewsewsw
neeenesenwnwwswnenewnwwsewnenwseswesw
seswneswswsenwwnwse
nwnwneseeswswnenewneswwnewseswneseene
swweswneswnenwsewnwneneseenw
eesenwseswswnenwswnwnwsewwnwsene
sewnenenenesenwsewnenwwwse
wenwwweseeeweswwwnwwe
wsweesenenewnwwnwsenewsenwwsesesenwne
neeswseenwwswnwswswnw
nenwswwsewswnenenewsenwsenwnesesenew
enewnwewneswsewnwswenweswnenwsenwsw
sweneswneswneneenwnewenewwneswswnese
swwesenesewenwneswnwwneseswwne
enesenwswwswneneswsenwnewswseenwsese
wnwnesenesenenwwnenwsewesewsesesew
nenewswnwewswnenesenwnesewesw
eneswnwswnwsenenwnwnwwseeswneewsenese
neswnwewnwnwseenwseesewsenwsweewe
wseweeenwnesenwwwswnew
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const lines = data.split(/\n/);
let flipped = new Set();
for (const line of lines) {
let px = 0;
let py = 0;
for (let i = 0; i < line.length; i++) {
switch (line[i]) {
case "e":
px++;
break;
case "w":
px--;
break;
case "n":
if (line[i + 1] === "e") {
py--;
px++;
} else {
py--;
}
i++;
break;
case "s":
if (line[i + 1] === "e") {
py++;
} else {
py++;
px--;
}
i++;
break;
}
}
const tile = px + "," + py;
if (flipped.has(tile)) flipped.delete(tile);
else flipped.add(tile);
}
function adjacent(x, y) {
return [
[x + 1, y],
[x - 1, y],
[x + 1, y - 1],
[x, y - 1],
[x, y + 1],
[x - 1, y + 1],
];
}
function play() {
const next = new Set();
const allFlipped = [...flipped].map((i) => i.split(",").map(Number));
const mnx = Math.min(...allFlipped.map(([x]) => x));
const mxx = Math.max(...allFlipped.map(([x]) => x));
const mny = Math.min(...allFlipped.map(([, y]) => y));
const mxy = Math.max(...allFlipped.map(([, y]) => y));
for (let x = mnx - 1; x <= mxx + 1; x++) {
for (let y = mny - 1; y <= mxy + 1; y++) {
const neighbors = adjacent(x, y).filter(([xx, yy]) => flipped.has(xx + "," + yy)).length;
if (neighbors === 2 || (neighbors === 1 && flipped.has(x + "," + y))) next.add("" + x + "," + y);
}
}
flipped = next;
}
console.log("day", 0, "flipped", flipped.size, "part 1 answer");
for (let i = 0; i < 100; i++) {
// if (i > 0 && (i < 10 || i % 10 === 0)) console.log("day", i, "flipped", flipped.size);
play();
}
console.log("day", 100, "flipped", flipped.size, "part 2 answer");
467528193
389125467
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const cups = [...data].map(Number);
const steps = 10000000;
for (let i = Math.max(...cups) + 1; i <= 1000000; i++) {
cups.push(i);
}
cups.forEach((v, i) => (cups[i] = { v }));
cups.forEach((v, i) => (cups[i].n = i < cups.length - 1 ? cups[i + 1] : cups[0]));
const vMap = new Map(cups.map((item) => [item.v, item]));
let head = cups[0];
for (let i = 0; i < steps; i++) {
if (i % 1000 === 0) {
process.stdout.write(" " + (i / (steps / 100)).toFixed(2) + "%\r");
}
const extract = [head.n.v, head.n.n.v, head.n.n.n.v];
const extractHead = head.n;
head.n = head.n.n.n.n;
let cur = head.v - 1;
while (true) {
while (extract.includes(cur)) cur--;
if (cur === 0) cur += cups.length;
while (extract.includes(cur)) cur--;
const pos = vMap.get(cur);
if (pos) {
extractHead.n.n.n = pos.n;
pos.n = extractHead;
break;
}
cur--;
}
head = head.n;
}
const posOne = vMap.get(1);
console.log("\n" + posOne.n.v * posOne.n.n.v);
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let cups = [...data].map(Number);
for (let i = 0; i < 100; i++) {
const extract = cups.slice(1, 4);
const remaining = [cups[0]].concat(cups.slice(4));
let cur = cups[0] - 1;
while (true) {
if (cur === 0) cur += cups.length;
const pos = remaining.indexOf(cur);
if (pos !== -1) {
cups = remaining
.slice(0, pos + 1)
.concat(extract)
.concat(remaining.slice(pos + 1));
break;
}
cur--;
}
cups.push(cups.shift());
}
let res = cups.concat(cups);
res = res.slice(res.indexOf(1) + 1, res.indexOf(1) + cups.length);
console.log(res.join(""));
Player 1:
19
5
35
6
12
22
45
39
14
42
47
38
2
26
13
30
4
34
43
40
16
8
23
50
36
Player 2:
1
21
29
41
32
28
9
37
49
20
17
27
24
3
33
44
48
31
15
25
18
46
7
10
11
Player 1:
9
2
6
3
1
Player 2:
5
8
4
7
10
Player 1:
43
19
Player 2:
2
29
14
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const groups = data.split(/\n{2,}/).map((gr) => gr.split(/\n/).slice(1));
const p1 = groups[0].map(Number);
const p2 = groups[1].map(Number);
function play(p1, p2) {
const seen = new Set();
while (p1.length && p2.length) {
const roundKey = p1.join(",") + "|" + p2.join(",");
if (seen.has(roundKey)) return [p1, 1];
else seen.add(roundKey);
const c1 = p1.shift();
const c2 = p2.shift();
if (c1 <= p1.length && c2 <= p2.length) {
const [, recursionWinner] = play(p1.slice(0, c1), p2.slice(0, c2));
if (recursionWinner === 1) p1.push(c1, c2);
else p2.push(c2, c1);
} else if (c1 > c2) p1.push(c1, c2);
else p2.push(c2, c1);
}
if (p1.length === 0) return [p2, 2];
else return [p1, 1];
}
const [winner] = play(p1, p2);
const result = winner.reduce((acc, v, idx) => acc + (winner.length - idx) * v, 0);
console.log(result);
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const groups = data.split(/\n{2,}/).map((gr) => gr.split(/\n/).slice(1));
const p1 = groups[0].map(Number);
const p2 = groups[1].map(Number);
while (p1.length && p2.length) {
const c1 = p1.shift();
const c2 = p2.shift();
if (c1 > c2) p1.push(c1, c2);
else p2.push(c2, c1);
}
const winner = p1.length ? p1 : p2;
const result = winner.reduce((acc, v, idx) => acc + (winner.length - idx) * v, 0);
console.log(result);
jnlgn xqth jtjtrd vhdt rlsr jjhfbn vvrhc hbrplx fntg dtkr fnlqrk vvbqtz prkblp ffj zkkz vmb xlvrggj qjg sfghbs srjv vphhllt fvjkp qszsz zhszc rzbncvnc mfbfsz xdjk plxs xgc gfzmpxq rmpfkv tglj rsmstv lfckh rkllz qczmsk xpbxbv zdpxfl zfsbvl mmdcl nzqx gzsdm mqv cmffmd gjlql htmb fqrm prtvmb smbdlcg zgzt zcvs qcksk trpbj jbslsbv lhtpf jgjrj tqlbk (contains shellfish)
zhszc mgrr zgdt txldvd tvz xlvrggj zvrm brvz rzbncvnc kzklp zcxq krpcn rxv xqth ztpmz trpbj hnngrhk dqspdq qmqbz qpndpm dfsnq sfghbs jgjrj gjlql dktlp prtvmb zxnjkf fvjkp prkblp jjhfbn crjpt rsmstv qthxnb tcflf lfckh fsmqv rnjlpq vvnmqt scnc mqv khmzbj xkmz hbrplx lxpqkn gzsdm nxvzp fktgv rkkgm hlhc xpbxbv kzrk pffccf ndkmq bxc vmb czzx vdjtl rkkpgs zgzt mmdcl sdggf jszqhpf jtjtrd zhbtz fntg pdst qltvp rbjdgh zdpxfl nnrctqh hprqd tcfgv vphhllt jrpm mnn tglj vvrhc mqscmlf qnc gtqfrp dtkr srjv vhr htmb ffj xrvgdh qszsz cqkprv trjqbr cqs (contains soy, wheat, fish)
xbzns trjqbr prkblp mbdbf gfzmpxq gtqfrp fntg frnmdqx rlsr zgzt qvjk cmffmd srfm qltvp brkds lkzfc qthxnb plxs tsjtr dkshp qrbbf rmpfkv sxpbg qczmsk xlvrggj nzqx rnjlpq zkkz mvmhqbpz tcflf vvrhc tvdntm qplx btttz gjlql zsd vvz sgn rkkgm vmb zhszc pdst qcksk tkv tcfgv rkkpgs vhdt smbdlcg lxpqkn pffccf krnfm lfckh khmzbj htmb tvz crbd fqrm fnpkmh fsmqv txldvd qktcqv hbrplx hzxx xqth xpbxbv jtjtrd fvt (contains peanuts, sesame, eggs)
nchjqv frnmdqx nxvzp tdszhqn jnlgn nzqx fnpkmh jszqhpf dlzb qltvp dtkr mbdbf jmvv zhbtz vhdt ltbqt ftrnplt rtjbpd vvbqtz fsmqv vmq brkds xpbxbv nltv cghkbp vrgdk fvjkp qrbbf krnfm xgc hbjmtc tcflf tftpnc zvrm flxplq qpndpm tbnlrpb qpkbc fntg zhszc vphhllt qmcdlz lnvrg srjv jtjtrd crjpt rnjlpq zbnv fnlqrk zljsv zsd xqth prpbcv vvz pffccf rkkgm gjlql khmzbj lhtpf mgrr mfbfsz kzklp zxnjkf btttz gtqfrp hxcc rlsr mbx nhldb rzbrrr vhmpqd zcxq zkkz lkzfc tkv tfn qvks zkxxnhn mvmhqbpz lzxpn dqspdq nnrctqh lxpqkn htmb crbd tvz jrpm srfm txldvd qczmsk (contains eggs, sesame)
krnfm jrpm xbzns lnvrg rzbncvnc vhr mqscmlf xqth ffj zgzt xkmz nchjqv vmq jtjtrd xzd qmcdlz mqv smbdlcg qvjk khmzbj xgc dkshp prpbcv zptr vhdt nnrctqh tqlbk zcxq mnn vhmpqd qplx crjpt zhszc jjhfbn ltbqt dktlp tftpnc hxq vphhllt gtqfrp rlsr zdpxfl flxplq plxs sgmsn cqs fqrm mmdcl qlrxfv jmvv nltv frnmdqx cghkbp jszqhpf sxpbg vdjtl tkrflnf qjg fvjkp jnlgn kzklp lfckh mgrr fntg xpbxbv hlhc tvz tdszhqn tfn srfm ztpmz sfghbs zgdt rxv trpbj qczmsk (contains shellfish)
htmb srfm qcksk ftssfh czzx fntg rbbnskn rnjlpq rxv rsmstv vrgdk gtqfrp rd flxplq hbrplx vmq xdjk vvrhc nhldb ztpmz jmvv tftpnc mfbfsz szsrnsc hprqd zptr mvmhqbpz mnn qjg srjv jtjtrd tqlbk vdjtl nltv mqscmlf rkkpgs prtvmb fvjkp hnngrhk ftrnplt lxpqkn tvdntm ffj xlvrggj bmpnrhb jrlzcv zhszc xgc vpvm zhbtz vvz mbdbf lzxpn zdpxfl qktcqv qvjk rlsr khmzbj (contains soy, fish)
rmzbr jtjtrd fvghn jjhfbn tsjtr mfbfsz tglj qthxnb cqkprv trjqbr zqnn tkrflnf lnvrg kssgts vvbqtz rzbrrr ndkmq zfsbvl qrbbf vvz dfsnq gpvcz dqspdq vhdt gzsdm phkxp rlsr prtvmb jnlgn rkllz ltbqt zljsv nchjqv fvt znhjn fsmqv cghkbp sgn nzqx fvjkp tbnlrpb fntg pffccf bxc zhszc gtqfrp cqs nxvzp mqv xpbxbv jgjrj zgdt srjv tftpnc lsnnzp lxpqkn xzd tkv qmcdlz (contains soy)
nhldb tlbtr fvghn lfckh tftpnc rlsr hxq zptr htmb lzxpn smbdlcg qplx zdpxfl hnngrhk dkshp qszsz qlrxfv plxs nxvzp xqth rd qmqbz tzc sxpbg mmdcl jnlgn nzqx rbjdgh vmb vvrhc scnc rzbncvnc prpbcv jrpm zxnjkf vhr nltv fktgv xzd fntg crbd vhmpqd pdst nnrctqh zhszc rnjlpq tsjtr krpcn rzbrrr zgzt xpbxbv jtjtrd gjlql fnpkmh cghkbp cmffmd trjqbr mqscmlf gtqfrp khmzbj dfsnq hzxx rbbnskn srjv xrvgdh fvjkp qmcdlz hbrplx xgc cqs mvmhqbpz szsrnsc hprqd qktcqv znhjn mfbfsz (contains sesame, eggs)
nzqx fktgv vmb jszqhpf ffj fvjkp qcksk xqszlhq qvks zcvs pdst rmpfkv nchjqv dtkr qplx tfn crbd zdpxfl sxpbg xpbxbv bmpnrhb zgdt zkkz rtjbpd qrbbf tvdntm xkmz zbnv sfghbs vphhllt dktlp nnrctqh pffccf xrvgdh qszsz qmcdlz gjmbv vhr qvjk rkllz rlsr xzd tzc rkkgm txldvd cqs fntg xdjk hbrplx jnlgn hxcc mgrr lfckh qnc ftrnplt vvrhc frnmdqx xgc jbslsbv gfzmpxq rzbrrr gtqfrp rbjdgh jtjtrd tdszhqn rd lzxpn srjv rsmstv ndkmq rbbnskn tsjtr fnlqrk srfm fvt vvnmqt cvnmx scnc lxpqkn tcfgv zptr zhszc vvbqtz mmdcl hnngrhk mqv prkblp brkds sgn (contains wheat, soy, peanuts)
qltvp mfbfsz rtjbpd fntg jtjtrd fvt rmzbr rzbrrr rd xqszlhq xrvgdh fvghn frnmdqx zdpxfl mbdbf rnjlpq mnn jgjrj rkllz rlsr cvnmx gzsdm lkzfc mqv nxvzp rmpfkv pffccf gpvcz zptr zkxxnhn qnc sgmsn qvjk dlzb fnpkmh txldvd trjqbr qlrxfv vhdt lfckh mvmhqbpz ftssfh krnfm hxq mbx jjhfbn fvjkp hbrplx bxc khmzbj lzxpn tqlbk lxpqkn vrgdk cqkprv zhszc jrpm trpbj hxcc prkblp mqscmlf xqth tcflf brkds tvdntm fnlqrk vvrhc vvnmqt xlvrggj qpndpm kssgts dfsnq zqnn pdst tbnlrpb qplx zhbtz mmdcl xpbxbv qpkbc (contains soy, sesame)
lnvrg ftssfh tbnlrpb zhszc xbzns hxq cmffmd cghkbp jmvv zgdt ftrnplt nxvzp xlvrggj vphhllt tglj vhr trjqbr flxplq kstd tlbtr qrbbf gtqfrp rbjdgh xpbxbv jbslsbv lxpqkn zsd fktgv vvrhc mnn brkds vrgdk nchjqv xqszlhq ndkmq hprqd czzx hlhc xgc dkshp jgjrj xqth cvnmx hbjmtc zgzt rtjbpd nhldb ltbqt zcvs qpkbc fntg xzd gzsdm fvjkp zfsbvl lzxpn fqrm plxs bmpnrhb zljsv tvz vpvm pffccf jtjtrd qlrxfv (contains sesame, fish, shellfish)
zcvs qnc zfsbvl xkmz bvdqd tzc fvjkp zxnjkf phkxp rnjlpq znhjn jgjrj vhr krnfm qcksk szsrnsc zhszc tvdntm gzsdm fntg jtjtrd vrgdk vvnmqt jrpm fnpkmh xbzns kzklp rlsr tdszhqn kssgts hbjmtc rmpfkv rkllz xdjk kzrk qczmsk nnrctqh ftrnplt tcfgv qltvp trjqbr rkkgm tcflf gjlql hbrplx srfm sgmsn qrbbf tlbtr tftpnc fvghn hprqd tqlbk gtqfrp hnngrhk fktgv ndkmq prkblp lnvrg mbx xgc gjmbv flxplq cghkbp rmzbr ftssfh nchjqv nxvzp xqth qktcqv jszqhpf jbslsbv dtkr qpndpm bmpnrhb tglj xpbxbv plxs (contains wheat, sesame)
fvghn mvmhqbpz jjhfbn zgzt krnfm xqszlhq qvks fntg kssgts jmvv dtkr xdjk nchjqv vvrhc bmpnrhb qczmsk zcxq lhtpf prkblp tbnlrpb rlsr xlvrggj xpbxbv htmb qmqbz fvjkp phkxp prpbcv mmdcl kstd zgdt hbrplx krpcn ltbqt jtjtrd jbslsbv rxjsq lxpqkn sfghbs mfbfsz xkmz tcfgv hbjmtc mbx vvz nnrctqh tkrflnf dlzb vhdt rsmstv rmpfkv brvz vmq zptr gtqfrp rnjlpq zqnn prtvmb rbbnskn qpndpm qvjk ftssfh zhbtz rbjdgh kzklp ztpmz nxvzp hzxx (contains peanuts, eggs, dairy)
xlvrggj nhldb rxjsq ltbqt fntg xgc zqnn vmb zvrm mqv jtjtrd vvz qjg mbx rkllz hxcc ftrnplt zsd jjhfbn jmvv scnc crjpt zcvs zhszc vphhllt tfn htmb mqscmlf rlsr qcksk lhtpf dtkr zkxxnhn zgdt qrbbf sgmsn srfm rd lxpqkn xqszlhq vhr gtqfrp brvz tcflf fvjkp bmpnrhb tqlbk gzsdm tcfgv qczmsk mgrr qktcqv fvghn hxq qvjk (contains fish, eggs, peanuts)
tftpnc qktcqv dlzb vhmpqd qpndpm xlvrggj bmpnrhb vrgdk hbrplx kssgts kzklp zgzt mvmhqbpz krpcn vvnmqt gjlql gfzmpxq jtjtrd zhszc xpbxbv xbzns mbx vmq crbd vpvm krnfm qmqbz txldvd bxc qrbbf kstd fvt tqlbk tdszhqn rzbrrr sgn zqnn prpbcv fvjkp rkkpgs qjg kzrk qczmsk jgjrj rd rlsr fntg lhtpf tsjtr qnc qmcdlz ftrnplt szsrnsc xgc sfghbs xkmz fnpkmh zcvs rnjlpq prtvmb xqszlhq dtkr rkkgm srjv rtjbpd mqv qplx jszqhpf tzc zxnjkf gpvcz brvz ztpmz ltbqt cvnmx tbnlrpb (contains fish)
plxs fvjkp hzxx rmzbr xbzns xlvrggj flxplq hbjmtc xpbxbv qnc sgn hxcc zhszc trjqbr qczmsk znhjn prtvmb zljsv qplx vphhllt vvnmqt zxnjkf cqs brkds gjlql rkllz zdpxfl lzxpn phkxp zsd frnmdqx hxq lsnnzp gtqfrp qltvp rsmstv hprqd fntg gfzmpxq vvbqtz mgrr tkrflnf jszqhpf vvz fvt jrlzcv prkblp kssgts nnrctqh ndkmq nltv tqlbk rnjlpq pffccf jtjtrd lkzfc rbbnskn dfsnq qvjk rtjbpd rmpfkv zbnv qcksk lnvrg qmqbz xqszlhq tvdntm zptr sgmsn txldvd (contains eggs, shellfish, fish)
xkmz qktcqv frnmdqx qpndpm tfn ftrnplt xpbxbv rsmstv gfzmpxq zhszc gpvcz jszqhpf ltbqt fvghn kssgts khmzbj krnfm ndkmq rbbnskn scnc fqrm qmcdlz zqnn qmqbz xlvrggj rlsr ftdbz jgjrj gtqfrp jrlzcv zljsv xqth mnn tlbtr vvz dktlp rkllz gzsdm fntg cqs tftpnc fnlqrk tdszhqn hzxx fvjkp qltvp fnpkmh nltv qvjk tsjtr tcfgv (contains sesame)
hbrplx xpbxbv mnn rmpfkv xdjk ftdbz fvt htmb vphhllt rtjbpd ndkmq xlvrggj xqszlhq xbzns rlsr qpkbc gzsdm krnfm srfm prtvmb fvjkp zqnn nzqx rzbncvnc tglj mqv qmqbz qmcdlz nhldb ffj nxvzp szsrnsc hnngrhk jrpm dqspdq plxs lzxpn xqth lhtpf zdpxfl sfghbs jrlzcv tcflf qltvp jjhfbn mqscmlf tkv hbjmtc tcfgv flxplq dfsnq crjpt trjqbr jnlgn ltbqt jszqhpf zgzt qszsz dktlp jmvv brkds rbbnskn lnvrg tfn prkblp tvz rkllz zcxq jtjtrd prpbcv gtqfrp vrgdk krpcn rkkgm cqs qjg zhszc zvrm rd rbjdgh tvdntm xkmz (contains fish, sesame)
vmq cqkprv rkllz mqscmlf dqspdq rxjsq nxvzp fvjkp jtjtrd xpbxbv lzxpn tcflf qthxnb kzrk gtqfrp tqlbk tcfgv vhdt fsmqv rd cvnmx vvrhc hxcc zgzt qszsz ftdbz qltvp czzx qcksk lfckh gzsdm bvdqd qczmsk rlsr brvz tdszhqn kzklp lkzfc zhszc crjpt vmb rbjdgh rtjbpd tkrflnf hzxx xrvgdh xbzns fntg vpvm mfbfsz jnlgn qjg nzqx zxnjkf tvz zptr sgn fnlqrk zqnn vrgdk rbbnskn pdst (contains wheat, dairy)
lfckh jgjrj xpbxbv lkzfc fntg mfbfsz vmq vrgdk rnjlpq tqlbk szsrnsc rkkpgs rbjdgh jrpm plxs zgdt qthxnb jtjtrd zkxxnhn bmpnrhb lzxpn mbx hbjmtc vhr lnvrg gjlql zqnn gtqfrp vvnmqt qnc qpndpm xkmz fvghn mbdbf zbnv rzbrrr qlrxfv vpvm znhjn qktcqv tsjtr qltvp rd pdst fvjkp xlvrggj rzbncvnc qvjk sxpbg czzx rlsr qczmsk (contains shellfish, soy)
zqnn fvjkp qmqbz hnngrhk vdjtl xpbxbv srfm zhszc fktgv sxpbg vvz btttz lxpqkn hzxx lnvrg vhdt lfckh vphhllt rnjlpq gtqfrp tzc qktcqv plxs zsd xlvrggj qszsz rzbncvnc rkkgm dkshp jgjrj qlrxfv ztpmz mgrr fntg jrpm trpbj jtjtrd txldvd smbdlcg pdst vrgdk rkllz bxc rmpfkv kssgts zljsv (contains soy)
cvnmx sdggf hnngrhk ltbqt srfm flxplq qthxnb prpbcv zkkz tcflf gpvcz dlzb bvdqd zvrm plxs znhjn fktgv xgc rzbrrr hzxx jgjrj rzbncvnc dkshp fsmqv fvt fvghn trpbj jnlgn qmcdlz nnrctqh brvz qpndpm kzrk xpbxbv xlvrggj nltv kzklp krnfm crbd ffj dqspdq kstd qczmsk dtkr vhdt qjg sgmsn frnmdqx rmzbr jtjtrd qlrxfv xbzns rlsr fvjkp qrbbf fntg trjqbr ftdbz sgn txldvd zptr vmq prkblp lxpqkn lkzfc rkkpgs tvdntm tkv rbjdgh krpcn mgrr srjv mbx vvrhc mbdbf qnc phkxp gtqfrp hbjmtc zsd (contains fish, sesame)
zgdt czzx rxv cghkbp tglj rkkpgs vdjtl ftdbz vhr tdszhqn tsjtr qmcdlz hprqd plxs xlvrggj mmdcl znhjn qczmsk frnmdqx jbslsbv vvbqtz tlbtr gtqfrp zkxxnhn fsmqv qmqbz zbnv smbdlcg brkds qpkbc qjg hbjmtc dqspdq zcxq rlsr nchjqv ltbqt sdggf qrbbf kzrk lkzfc ftrnplt zqnn tvz zsd fntg sfghbs srfm dtkr crjpt htmb hnngrhk nnrctqh rbbnskn rsmstv mfbfsz fvt zkkz jtjtrd zhszc pdst jjhfbn xpbxbv tkv nxvzp qcksk vvrhc fktgv dfsnq prkblp ftssfh vvz (contains shellfish, eggs, peanuts)
trjqbr ndkmq fntg trpbj vhmpqd btttz prkblp brkds tfn qthxnb lnvrg xlvrggj xpbxbv xrvgdh hxq qmcdlz hbjmtc ftrnplt tkrflnf rbbnskn phkxp dfsnq sxpbg fvjkp gfzmpxq pffccf qpndpm sdggf zhbtz ztpmz zsd sgn zhszc ftssfh rd zvrm rlsr rkllz prtvmb rmpfkv bxc cqkprv qjg zkkz fvt mqv jtjtrd qczmsk ffj dktlp nnrctqh tcfgv mbx hbrplx lsnnzp (contains peanuts, soy, sesame)
hzxx vpvm vphhllt xzd gpvcz btttz jtjtrd dqspdq sgmsn tvz xlvrggj ftdbz fnlqrk tglj zljsv rzbncvnc fsmqv xpbxbv rmpfkv qmqbz fntg pffccf zdpxfl cmffmd vvrhc rd zhszc qpndpm qszsz ztpmz lfckh fktgv zkkz xdjk nxvzp hxcc vrgdk qvks xrvgdh rxv rbbnskn qvjk nzqx vvz ndkmq zsd tkrflnf nltv mnn fnpkmh frnmdqx cqkprv vhmpqd kssgts mvmhqbpz dkshp qlrxfv tcfgv rkkgm tkv tsjtr zgzt dtkr cqs jszqhpf lkzfc hxq smbdlcg hprqd fvghn qnc prtvmb tlbtr rlsr lnvrg gzsdm tvdntm gtqfrp rzbrrr qthxnb (contains sesame, wheat, fish)
nhldb vrgdk txldvd zhszc sgmsn czzx kssgts tcflf jgjrj mqscmlf rxv jszqhpf scnc lsnnzp xdjk qvks prtvmb cvnmx jrpm hzxx jtjtrd sgn rtjbpd dktlp jbslsbv fvt zvrm lhtpf trjqbr gtqfrp rlsr tkv sxpbg prpbcv fvghn hbrplx kzklp nnrctqh gzsdm zbnv lxpqkn ftdbz srjv tzc pffccf mmdcl szsrnsc tqlbk ltbqt fvjkp tdszhqn btttz mgrr sdggf dqspdq rbjdgh xqth gfzmpxq nltv rbbnskn flxplq rnjlpq jrlzcv qnc tbnlrpb qltvp smbdlcg qpndpm xpbxbv zgdt vdjtl dtkr tlbtr xlvrggj pdst zgzt vhmpqd rzbncvnc (contains shellfish, soy)
mvmhqbpz ffj xlvrggj crbd jtjtrd dtkr hbjmtc zgdt gtqfrp szsrnsc lnvrg kzklp tftpnc khmzbj scnc lfckh rxv nzqx jrlzcv gzsdm mmdcl zcvs hzxx ndkmq sgmsn xzd txldvd mnn fnlqrk rlsr rtjbpd plxs dkshp sgn srfm nchjqv fqrm tkrflnf hxcc bxc xpbxbv tlbtr nhldb qktcqv rbbnskn ztpmz zhszc nxvzp nltv fvghn zhbtz kssgts rsmstv qvks qplx vpvm lsnnzp cqkprv qrbbf hbrplx tfn rmpfkv crjpt brvz xkmz sdggf vvz vphhllt rxjsq fntg tzc prpbcv rkkgm fktgv zcxq (contains sesame, fish)
scnc cqkprv kssgts szsrnsc cqs tkrflnf zcvs crjpt dktlp trjqbr qjg vhr lzxpn sdggf xkmz khmzbj ftrnplt rd qvjk fntg qthxnb xqth mnn jtjtrd ftdbz brkds pffccf cghkbp jgjrj dkshp vvrhc qktcqv zptr sxpbg vvbqtz sfghbs rzbrrr lfckh ffj rmpfkv lxpqkn mgrr lnvrg vmq czzx nltv qczmsk phkxp jszqhpf txldvd vvz tzc tdszhqn zgdt tvz zhszc rlsr vrgdk prpbcv znhjn fvjkp prkblp fnpkmh nhldb zxnjkf xlvrggj zvrm qpndpm ltbqt jrpm ftssfh tvdntm hxcc nnrctqh xbzns xpbxbv (contains soy)
zhszc nxvzp hbjmtc xgc gzsdm kzrk vvnmqt mqscmlf hzxx rlsr rzbrrr tcflf rmpfkv jtjtrd szsrnsc vmb zdpxfl frnmdqx gfzmpxq sgn vhdt qplx jbslsbv lsnnzp xpbxbv vmq gtqfrp crbd zvrm xdjk lkzfc zqnn bxc fvjkp tbnlrpb qczmsk zkxxnhn nzqx rxv xlvrggj tcfgv lzxpn vvrhc gjlql lhtpf fvghn tftpnc gpvcz txldvd (contains peanuts)
xlvrggj rlsr gjlql trpbj kzklp rzbncvnc nhldb xkmz hlhc fqrm rzbrrr dfsnq mvmhqbpz zkxxnhn vdjtl dlzb bmpnrhb kzrk rtjbpd xpbxbv flxplq tftpnc qmqbz krnfm fntg jszqhpf qltvp sgmsn trjqbr tsjtr dqspdq tvdntm qplx fsmqv vvnmqt qszsz cqs fvjkp nnrctqh tcfgv rnjlpq xbzns jtjtrd tzc gtqfrp xqszlhq mmdcl tbnlrpb rxjsq kstd fvt sgn zbnv fnpkmh (contains dairy, sesame)
fntg jszqhpf xrvgdh ztpmz xpbxbv qszsz hbjmtc plxs cghkbp tkv zhszc cmffmd lnvrg qjg tvz vvz qnc flxplq qpkbc rmpfkv tbnlrpb dlzb bmpnrhb hlhc rmzbr hxcc zhbtz gzsdm gtqfrp mqscmlf qvjk fvghn hbrplx bxc qltvp jrlzcv vhr tzc lhtpf zbnv sfghbs kssgts vhmpqd hnngrhk qthxnb tftpnc krpcn zgzt fvjkp rsmstv vdjtl jtjtrd mnn jbslsbv rlsr ltbqt tglj (contains wheat, dairy, sesame)
crbd krnfm jtjtrd dlzb tcfgv dfsnq ltbqt rkkpgs ffj zgzt dkshp ztpmz vdjtl crjpt smbdlcg phkxp tkrflnf kzrk tftpnc bvdqd vhr frnmdqx scnc rzbrrr sfghbs xpbxbv xzd gpvcz qpkbc pdst cqkprv rzbncvnc xlvrggj srjv ftdbz rsmstv qrbbf sxpbg prkblp hxq hlhc zgdt rlsr vvrhc pffccf vphhllt vmb hnngrhk bxc fvghn czzx nxvzp vhmpqd gtqfrp lkzfc lsnnzp prpbcv lnvrg xkmz xqth fvjkp tcflf rkkgm fnpkmh zkxxnhn jszqhpf qmqbz rbbnskn qvks tkv nltv tdszhqn kstd qplx fntg (contains sesame, eggs, peanuts)
zqnn jtjtrd rzbncvnc fqrm fvjkp zsd vhr dkshp btttz fvt fntg lnvrg rlsr xgc sgn rkllz dlzb vmb qktcqv phkxp szsrnsc txldvd rmpfkv mbx gzsdm xlvrggj tkrflnf mfbfsz xrvgdh hxcc qmcdlz tftpnc tkv rsmstv xdjk zljsv krpcn zgdt smbdlcg prpbcv gtqfrp qjg qvks vphhllt tdszhqn prtvmb zhszc cghkbp qczmsk vrgdk gfzmpxq (contains fish)
vhmpqd jjhfbn xpbxbv brvz qthxnb lkzfc xrvgdh fvt xqth tdszhqn gtqfrp tkrflnf kzrk zgdt dkshp kssgts mbx gjlql jtjtrd cvnmx gjmbv tvz zptr kstd rxv fntg prpbcv qplx zbnv jbslsbv trjqbr mfbfsz fvjkp ftdbz phkxp mgrr tvdntm dlzb crjpt vvz tsjtr xlvrggj nhldb zhszc fvghn qczmsk tftpnc htmb ndkmq rbjdgh vvrhc (contains wheat, soy)
xlvrggj tglj rzbrrr dtkr trjqbr prtvmb zvrm jnlgn xqszlhq cqkprv vphhllt fqrm qczmsk cmffmd khmzbj rbbnskn zkxxnhn xpbxbv jbslsbv fvjkp xbzns mmdcl brvz rkkpgs fnpkmh scnc gtqfrp nltv zhszc fvt rmpfkv qjg mgrr qpndpm zsd vvbqtz tftpnc ltbqt jtjtrd prpbcv dqspdq rlsr ztpmz (contains eggs)
fnpkmh hprqd kssgts czzx mnn tlbtr ltbqt bvdqd vrgdk tftpnc ftssfh hxcc tfn vhdt fntg szsrnsc bmpnrhb zljsv hbrplx lzxpn ztpmz kzrk kstd xqszlhq rtjbpd mqv qpkbc tzc zbnv qvjk rlsr sfghbs phkxp qszsz qnc txldvd nxvzp rbjdgh lkzfc xrvgdh gtqfrp gpvcz qczmsk nnrctqh tdszhqn dktlp hbjmtc rzbncvnc qrbbf zfsbvl vphhllt xlvrggj dlzb xdjk zhszc jtjtrd zkxxnhn dtkr rkllz jrlzcv vdjtl lfckh tkrflnf btttz zqnn rbbnskn fvjkp ftdbz krnfm hnngrhk rmzbr pffccf flxplq zgzt ndkmq zptr (contains wheat, eggs)
szsrnsc nnrctqh rxv prpbcv dfsnq ndkmq rxjsq qlrxfv jgjrj dkshp rkllz zdpxfl scnc rlsr qnc crjpt lsnnzp nhldb zcxq xdjk gzsdm hxq fvjkp mbdbf xpbxbv tvz tqlbk ftdbz crbd bxc zkxxnhn fntg pdst lnvrg krpcn vrgdk tsjtr fnpkmh zhszc tzc qmcdlz qpkbc kssgts gtqfrp gfzmpxq qszsz trpbj phkxp hlhc xzd xlvrggj zljsv (contains wheat)
nchjqv mgrr tvz prpbcv rlsr sgn jjhfbn gjlql zgzt nhldb vmq gtqfrp xrvgdh cghkbp nzqx vvbqtz bmpnrhb mvmhqbpz fnlqrk brkds hzxx vvz fvghn krnfm tbnlrpb zcxq gzsdm kssgts rkllz fntg tlbtr zljsv rzbncvnc kzrk rbbnskn sdggf ftdbz lnvrg zbnv lxpqkn vhr szsrnsc rxv fktgv zcvs zptr jgjrj mfbfsz cqkprv jbslsbv dqspdq xpbxbv lzxpn jtjtrd rbjdgh fvjkp rtjbpd cqs htmb gpvcz lkzfc tdszhqn hprqd zhszc sxpbg qjg fqrm qvjk tkrflnf xdjk vvrhc cvnmx zsd jszqhpf qpndpm rkkgm krpcn rxjsq vpvm mbdbf qltvp rsmstv (contains eggs)
mxmxvkd kfcds sqjhc nhms (contains dairy, fish)
trh fvjkl sbzzf mxmxvkd (contains dairy)
sqjhc fvjkl (contains soy)
sqjhc mxmxvkd sbzzf (contains fish)
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const lines = data.split(/\n/);
const products = [];
const allIngredients = new Set();
const allAllergens = new Set();
for (const line of lines) {
const p = line.split("(contains ");
const ing = p[0].trim().split(" ");
const alg = p[1].substr(0, p[1].length - 1).split(", ");
products.push([ing.sort(), alg.sort()]);
ing.forEach((i) => allIngredients.add(i));
alg.forEach((a) => allAllergens.add(a));
}
function intersect(arr1, arr2) {
return arr1.filter((a) => arr2.includes(a));
}
const found = {}; // allergen -> ingredient
function mapAllergens(usedProducts, commonIngredients, commonAllergens) {
for (const [productId, [productIng, productAlg]] of products.entries()) {
if (usedProducts.includes(productId)) return;
const nextIng = intersect(commonIngredients, productIng).filter((i) => !Object.values(found).includes(i));
const nextAlg = intersect(commonAllergens, productAlg).filter((i) => !Object.keys(found).includes(i));
if (nextIng.length === 0 || nextAlg.length === 0) continue;
if (nextIng.length === nextAlg.length) {
for (const [idx, ingredient] of nextIng.entries()) {
const allergen = nextAlg[idx];
found[allergen] = ingredient;
}
}
mapAllergens([...usedProducts, productId], nextIng, nextAlg);
}
}
while (true) {
const before = Object.keys(found).length;
mapAllergens([], [...allIngredients], [...allAllergens]);
const after = Object.keys(found).length;
if (after === allAllergens.size) {
console.log("good");
break;
}
if (before === after) {
console.log("stuck");
return;
}
}
const safeIngredients = [...allIngredients].filter((ing) => !Object.values(found).includes(ing));
const part1 = products.reduce((acc, [ingredients]) => acc + intersect(ingredients, safeIngredients).length, 0);
const part2 = Object.keys(found)
.sort()
.map((a) => found[a])
.join(",");
// console.log(found);
console.log("part 1", part1);
console.log("part 2", part2);
Tile 3457:
##.###.##.
...#..##.#
#.#..###..
##.....#..
#.#....#.#
...##.#...
##..#....#
..###..#..
#........#
#.##..#.#.
Tile 3061:
##....####
#.#.......
#.....##..
#........#
.....#....
##......##
.##..###..
........#.
...#....#.
..###.#.##
Tile 2131:
.#..#..#.#
#....#..##
#........#
#..#..#..#
.#...#..#.
##........
##.##..###
..#..##...
......##.#
##..######
Tile 2087:
.##.#.....
...#......
###.......
#.#......#
##....#.#.
..........
........##
#.....#.#.
...##.#...
..##.##..#
Tile 2593:
#.###.##.#
.#..#...#.
.........#
#..###....
....##....
##..#..#..
###.##....
#....####.
.#..##..#.
.#.....###
Tile 1277:
###.#.#...
..##......
#..#.#...#
...##.#..#
#...###.#.
..#......#
##...#....
......#.##
##.#.##..#
..#...#...
Tile 2917:
###.#....#
....##.###
#......#.#
#..#.#...#
#.#....##.
#..#..#.#.
..#####...
##.##.#.##
#.#....###
#####.#..#
Tile 1579:
#.#..#..##
..#....###
##......#.
#...#..###
#..##..#..
##.##....#
.##....#.#
#.###...#.
..#.#.#.#.
##.#.#....
Tile 3011:
....#.#.#.
##........
#.#......#
#...#..#.#
........##
#..#.....#
.....#....
#.##......
#...#..#..
....#..#..
Tile 2539:
..#.#.#.##
...#.#####
.........#
..........
.....##..#
##....##.#
#.....#...
....##.#..
..#.##.#..
#.#.#....#
Tile 1879:
##.#######
#..#....#.
........##
..#.....#.
#.#.#..#..
...##....#
#..##..#.#
..#.....#.
#.....#...
.#####.##.
Tile 2081:
..#....#.#
#.##.#.#.#
#....#.##.
##......##
....#.#.##
......#..#
##.......#
#........#
..#..#...#
..###..#..
Tile 1721:
.#.####.##
....#.#..#
#...#.#...
#...#.##..
#.#.#.####
#...#.#..#
.........#
..#..##.#.
#.#.#.##.#
#..#....#.
Tile 1237:
.....###..
.......#..
#...#....#
......#.##
###....#..
#.#..#.#..
..#......#
..#..#..#.
.#........
#.#.#.##..
Tile 3037:
..#..####.
........#.
...#.#...#
.##.##..#.
#.##.#.#..
#...#.#.##
#..###....
#......###
#.#..###.#
.##...#.##
Tile 2719:
######.##.
#...#...#.
#..##.#..#
##........
..#.##....
##........
#.###.###.
#..#....#.
##..##....
.#....#.#.
Tile 1013:
.#...#.##.
#..#.##...
##..#....#
#......#..
.#..##....
..#.......
........##
#........#
.....##...
#.#.###...
Tile 3571:
.......#.#
.#...#...#
....##....
#......#.#
.###.#..#.
#...##...#
##...#.#..
......#...
#.#....#..
##....#..#
Tile 2269:
##.#.#...#
..#.#.....
.##.###..#
.#....##.#
#.#..#.###
#.....#..#
#.#.#....#
#..##..#.#
...#....##
...##.#...
Tile 3709:
##...#..##
...#...#.#
#..#.#....
..##.####.
..#...##.#
...#...#.#
#...#.#...
.#........
..........
#..#.#.#.#
Tile 2143:
#.##.#....
####...##.
#.###...#.
....##.#.#
##.##.....
.......#.#
####..##..
.......#..
#......#.#
####....##
Tile 3677:
##.###.##.
.#.###..#.
..##...#..
..#......#
##.##.....
#.#.##.#..
..#..#.##.
##..###...
#.#......#
...###.###
Tile 2297:
.........#
..........
........##
#.#..#....
##.#..###.
#........#
.....#..#.
...#...#.#
##..#.....
.#.######.
Tile 1871:
#.#.#.....
#.#....#.#
..#...#..#
..#..##..#
#.#.##....
......#.##
##.##.#.##
#.###.####
#..#....#.
###.#....#
Tile 3449:
##..#.###.
.####.....
#..###..#.
#....#.#..
#.....#..#
#....#.#..
#.....#..#
.#..#.....
#..#.#...#
.####.####
Tile 3391:
........##
##.#.#.#.#
...##....#
..###..###
.#....#..#
.#....#.#.
..........
#...#.#.#.
.....#.#.#
#.#.......
Tile 2243:
..#...##.#
##...##...
..#......#
..#.##.#.#
.#......#.
#.#...##..
#.....###.
##..##.#.#
#.#....#.#
#.#..#..##
Tile 2153:
##.###.#.#
.#.#.#.#.#
#..#..###.
.##..#.#.#
.#.....#..
..#......#
........##
.#.....##.
.#.......#
#......###
Tile 3659:
.#.#....##
..#..#..#.
..###...##
..........
#.....#..#
##.#.#..##
#.###..#..
#..#....##
#........#
#.###..##.
Tile 2503:
##..##.#.#
#..#..#...
.....#...#
...#.....#
#.....#...
.....###.#
#..#..#...
..#...#...
#..#...##.
.###...###
Tile 2741:
#..#.#####
..#.......
...#..##..
#...#.....
.#.#.#....
..###..#..
.#.#..#..#
.##..#.##.
##.#......
.##....#.#
Tile 3371:
..###.#..#
#..#......
###...#..#
..........
.#..##...#
...#.....#
...##.#...
#.#.#..#..
#.......#.
###.#.###.
Tile 2731:
#...#.#...
#.#..#....
#...#.#...
#.###.####
.#.##....#
##..#....#
#.#.......
##..#....#
......##..
###...###.
Tile 3217:
.#..#..#.#
##...#...#
....##..#.
#...#.#...
#......###
##.#....##
#..#...##.
#...#...##
#.#.#.....
.#.#......
Tile 3911:
..###..##.
.....#.#..
##.#...#.#
#.....#..#
.......#.#
#........#
..#....#.#
#.##....##
.....#...#
##.##.#.#.
Tile 1637:
.#.#..#.##
##..#.#...
.#.#####.#
..#..#..#.
#......###
#.........
#.##...##.
#........#
#..#.....#
..#...#.#.
Tile 3989:
.#..##.##.
..........
..#.##..##
#.#..#....
#...#....#
#..#.#.#.#
##....#..#
#.#...#...
######.##.
.#..#..###
Tile 2213:
...#..####
.....###..
##....###.
#...###.##
##...####.
#.........
......#...
#.......##
###.....##
.##...###.
Tile 1061:
.#.....##.
#...#..#.#
#.......#.
.#.......#
.....#....
.#....#.##
##.#....##
#...#...#.
#...#.##..
.###.....#
Tile 2281:
..#..##.#.
..##.....#
..##.....#
..#.#....#
#.#..##.#.
#..#..#.##
#......#..
...#...#.#
..##......
#.###.###.
Tile 3803:
####.##..#
#..#..#.##
.#...##...
#..#.#.##.
#...#....#
....#....#
..#.##.#..
#..#...#..
##........
#...#.#...
Tile 3347:
.##.##...#
#..#.#....
...##.##..
#...#.....
#.....##..
#.#..#...#
.....#.#.#
#.........
#.........
##..#####.
Tile 2687:
.#####.#..
#.#.#.....
#....#....
.##.#.....
#.##....##
#....#...#
###.##...#
##..#....#
....#....#
#.##.#.##.
Tile 1097:
##....#..#
....##...#
#...#.#...
#....#....
.....#..##
#..##.#..#
#....#....
###....###
#.....#.##
#....#...#
Tile 1483:
#..#.##...
....##.#.#
...##....#
#..##..#.#
.#...##...
..........
#..#..##..
....##.#.#
######....
####....#.
Tile 2207:
.#.###.##.
.##..#....
....#....#
#....#....
#....##..#
#.#.....##
...#....#.
#.#..#...#
.#.......#
.#####.##.
Tile 1559:
.####..##.
##..##.#.#
......##..
##.#..#..#
.#.#.#....
#....#..#.
#..#..#.#.
#.#..#.#.#
#...##.#..
.#...#....
Tile 3019:
...#.###.#
.##..#..##
...##..#..
..#...##.#
#......#..
#....#.###
##..#....#
#.#....#..
#..##..#.#
#.#####..#
Tile 2441:
...####.#.
#..#.#...#
...##.#..#
#.#......#
#..#.#.#..
#..##....#
.####.#...
.#.#...#..
..##..#..#
.#..#.#...
Tile 1997:
.##.###...
......#..#
....#.#..#
..#.##...#
.....##..#
###.#.#...
##........
#.....#...
##....#.##
######..##
Tile 1481:
####.#####
##.#.....#
#.#....#.#
.......#..
#........#
#....##...
...#..#..#
.#......##
....##...#
.#########
Tile 1811:
..#..#.##.
.....#.#..
..#...#...
##.....#..
.#.#.....#
...#####.#
#...#.##.#
....#.#..#
....#.#...
#..#.##...
Tile 3701:
####.###.#
###.....##
#...##.###
....###.#.
#.#.#..#.#
..###....#
.#...#...#
#.##..#...
####....##
.#####..##
Tile 1451:
###.##.#..
#...##.#.#
.#.......#
#.....#...
.#........
#.......##
...##.#.#.
.#..##..##
#.#.#.....
....#....#
Tile 3319:
....####.#
.#..#...##
..##.###..
#...#..#.#
.#........
......#...
........##
#.....#...
#.........
..##.##..#
Tile 2659:
.##..#.#..
#.#...##..
.####..##.
.....#####
##........
.#........
#.#.#.....
.....##...
........##
..#.......
Tile 1433:
#.##.##.##
.#.....#..
....#.#...
.#..#.####
....#.#..#
####...#.#
.#.#..#.#.
..#......#
.#.#.#.#..
#.###.#.#.
Tile 1409:
#..###....
###.......
#...#..##.
#.##....##
..#...#..#
.#..##..##
..#..#...#
##..#.####
#....#####
##..####..
Tile 1747:
...##.###.
##...##.#.
......#..#
#.#.....##
#..#....##
###.##.#.#
.......#.#
#...#....#
......#..#
##...####.
Tile 2011:
.#.#..##..
.......###
#.#.#...##
#...#.###.
......###.
....#.#...
....#.##..
.##......#
##....###.
###.####..
Tile 1009:
.#.#...###
#.#.##..#.
..........
.....#...#
.#...#..##
.#..#.#.##
#..####.##
#.##.#.#.#
..###....#
.##..#....
Tile 1759:
#.#######.
#..#....##
..........
..###..#.#
#..###....
#.######..
...##.##.#
#.........
##.......#
#...#..###
Tile 1223:
###..#.##.
##..##....
...##.....
#..#.#..#.
#..##.#...
.#.......#
...#..#.#.
##.......#
##........
.###.#...#
Tile 2467:
.#.##.#.#.
#.........
##.....#..
.##...####
#..#..#..#
#.#...#...
........#.
##.......#
..#....###
##....#...
Tile 1571:
...##.#.##
..#.......
.#.#..#..#
..........
#.......#.
..#....#.#
#.###.....
...#..##.#
..##.#..##
####.....#
Tile 1931:
###..#.##.
##.#..##..
...##.##.#
........#.
.####...##
..........
#.....#..#
#.....#..#
.#..###..#
.......##.
Tile 2711:
#..#.#...#
#....####.
.#.#..##.#
#.#.#..###
......##..
###...##.#
##..##....
.....#..#.
##....##.#
.#...#....
Tile 3331:
...#.#.##.
.#......#.
##.#.....#
#..##....#
.........#
##....#.#.
#.#......#
#.......#.
##......##
..##..####
Tile 1979:
..##.#.##.
...#..###.
......#.#.
..#..#...#
#.........
#.........
..#.#...#.
#..#..####
#...#....#
##.######.
Tile 1229:
##.###.###
#....#.#..
#....##...
#.....#...
#.#......#
##...#....
.#...###.#
#..#.#..##
...#.#....
.##...#.##
Tile 1217:
#..#.#....
.#....#..#
.#.....###
..#.#....#
##....#...
.#...##.##
.#..#.#.#.
.##..##...
.#....#..#
.#.#.#.#.#
Tile 2521:
.....####.
#.#....#..
..#..#...#
..#...#...
......#...
#.##..#..#
..#..##..#
.#..#....#
#..##..###
#.###.##.#
Tile 2251:
#...#..###
...##.#.#.
#..#..##..
##........
#.........
......#.##
##.....#..
..#.#...#.
###.#.....
.###..#.#.
Tile 1093:
#####.#...
###.....#.
#.#.###..#
....##....
###.....##
.#......#.
#.........
..#.......
....#.....
#.#.#.#...
Tile 2293:
##..#.##.#
#...#....#
#..##.....
..#......#
#....#....
.......#..
##.....###
#....#....
#...#..##.
########..
Tile 1279:
#.###.##..
..........
#...#....#
.....#...#
#....#####
#...#.#.#.
#..#..#..#
.......#..
#.#...##.#
#####..#..
Tile 1213:
#...##....
##.#.....#
#.....#...
#.......#.
#.........
#.#.......
#........#
#....#....
.#..#....#
.##...##..
Tile 3851:
#.#...##.#
.........#
#.......#.
.#.#.#..#.
.##.....##
...##...#.
#.#...#..#
#.....#..#
.#.#......
.#.#.##..#
Tile 1531:
..##..#...
#....#....
#...#.#..#
....##..#.
#..#..##..
.##.###.##
#..#####.#
##.#.##...
#.#.##..#.
#..##.####
Tile 1321:
#.##.....#
###.#.....
#.........
.......#.#
#...##...#
.....###.#
..##...#..
..#.#.##.#
####....##
.##...##.#
Tile 1619:
.###..####
#..##....#
#.....#...
......#...
#.......##
#....#....
##..#..#..
....#...#.
.#.....#..
.#.#.##.##
Tile 2803:
#.#.#..#..
#...#..#..
#####.#.#.
.##....#.#
......#..#
##..#.#..#
..#..#..#.
##......##
..#.##...#
.#.#....##
Tile 2383:
.####.#..#
#..#..##..
#..##.#..#
..##...#.#
##..#.##..
.#........
#.##..#...
#......#..
#...#....#
##.##..#.#
Tile 1291:
...#.#..##
##.#......
....#.#.##
#.#.#...##
.#.##.#..#
##.#...#..
#..#......
#.#..#....
#..####..#
##.....###
Tile 1129:
#.#....##.
...#.#.#..
.#.#.#...#
.#..#....#
.#.##....#
........#.
.##......#
...#.#.#..
#.....##..
.###..#...
Tile 2857:
#.#.#.####
...#.....#
..#.....#.
###.....#.
###...##.#
#..#.#...#
#.##.###..
.####..###
#.##......
..#..#.###
Tile 2411:
......##.#
##..#....#
#.....#..#
#..#......
.#...##..#
#.....##..
###.#..###
#.#.#####.
#...#.#..#
.#.##.#.##
Tile 3923:
..#####..#
#...#.#...
#...##.#.#
....#.....
..........
#.##....#.
.........#
##.......#
#...#...##
###..##.##
Tile 3343:
#..#.###.#
..#...##.#
..#...#...
#...#.....
..#.......
##.#..#...
...###..#.
#.#.#.#..#
...#..##.#
#..#...##.
Tile 2017:
.#...###..
.........#
.##....##.
....#...##
..###.....
##..##..#.
#..#.##..#
#.#..####.
##........
..#.##....
Tile 3889:
#.##.##..#
.#....#.#.
.##...##.#
#..#.###..
#..##.#...
#...##.#..
.#....#.##
###.#.#..#
#..#...#.#
.#.#..##..
Tile 1823:
....##.##.
#...#...#.
..#......#
..........
....###..#
####....#.
.##......#
...###.###
##....#...
#.#.##....
Tile 3769:
.#..#.....
...#.....#
#...#....#
..#..##...
.....#...#
....#.....
#...####.#
#..#.##..#
#..#....##
#######.#.
Tile 1523:
.#.##....#
...#...#.#
#.........
.....##.#.
##.##..#..
..#.##...#
#...#..##.
#....#....
.#.#...#..
#.#.###...
Tile 2843:
...#....#.
......###.
..##....##
#.###.#..#
#..##.#...
#.##....#.
.....##...
.#.......#
##.#..#..#
#.##....#.
Tile 2423:
#.##.#####
..#.#...#.
#.....#.#.
#..#.....#
..##..#..#
##....#..#
#......#.#
#.#..#.##.
#.....#...
.##.##.#..
Tile 1999:
.#..#.####
.#.#..#...
..........
...#.#.#..
..#....#.#
##.#...#..
.#..####..
.....#.#.#
..#..#..##
##..#..#..
Tile 2341:
#....#.#.#
##.##....#
#..##.#...
#..#.#....
...#..#.#.
##..##.###
#.#.....##
.......#.#
##.##.....
....#.####
Tile 3359:
#..###.##.
#.........
.####.###.
#.##....#.
.#..#.##..
#.........
.#.#.#....
..#...#..#
###......#
...#......
Tile 3863:
..##.##.#.
#.##..#.##
.###......
.#.......#
..##......
#..##..###
.##..##...
....#.#...
#.#.#.##.#
...##..##.
Tile 3187:
#.#.#.#...
......###.
#.....####
..#.#...#.
#....#..#.
#......#..
#...##..#.
#........#
#.##.....#
.##.#...#.
Tile 3119:
##.....##.
....#....#
#..#..#..#
#....##..#
........#.
...#.#....
...##..#..
.....#....
#.####....
...#..#.##
Tile 1063:
.#.#.#....
##........
#..#.##...
#..#.....#
....##...#
.#......#.
..##...##.
#........#
..........
.#..#..#..
Tile 1657:
.##.#.#...
##.....#.#
....#.#.#.
#....#####
###......#
.#....#..#
#.#..#.#..
#.#.##....
##.#......
#..##.#...
Tile 3257:
##.####..#
#.#.#####.
##.#..##..
.##.#..###
..#.......
#...#.#..#
#..#.#.#.#
...#....##
##.....##.
...###..##
Tile 1987:
.#.#..###.
.#.......#
...#....##
#...##....
.......#.#
.#.##.####
...#...#..
.##...#...
.........#
.#.##..#..
Tile 1459:
#.....####
......#..#
........#.
##..#..#..
###.##.#.#
##..#...#.
##..#.###.
.##..###.#
#..####...
.#.#####..
Tile 3533:
#.##...#..
.#.....#..
#.##......
..#.....##
....#..#..
##..#....#
#....##..#
..#....#..
........##
.####.##.#
Tile 2789:
..####...#
#....###..
#..#..##.#
#.#..#....
#....##...
....#.....
#.........
#..#......
.......#.#
...####.#.
Tile 2137:
#..####.##
....##...#
.#.....#..
#.#..#####
...#..#...
.#.....#.#
.....#..#.
##..#...##
..#.#.....
#..######.
Tile 1181:
.#####.#..
..#.##...#
#....#....
#...#.#...
##.......#
.....#...#
##..#...#.
.##.##....
#...##....
..#.##....
Tile 1117:
#####.####
.......#..
##.#..#..#
#....#.#..
..........
..#...#.#.
......#...
##...#...#
....#...#.
#.....##..
Tile 3739:
..####.#.#
#.#.#.#...
#.......##
.##...#.#.
#....#.#..
#...#....#
#.....##.#
.......##.
##...###.#
....##..##
Tile 2909:
.##..###..
#...#.....
.....#...#
..##......
#.##.###..
##.....#.#
#..#...###
....##....
#......#..
#.#...####
Tile 1609:
##.###.#..
....#.#...
#.#....##.
#..##.#...
.####..#.#
..........
##..#....#
...#..#...
#.........
....#.###.
Tile 1753:
....#.###.
##.##.....
....##....
#.....##..
#.##..#...
..........
#..#.#..#.
#.....#...
.#........
.#.#...#.#
Tile 2003:
#.#.####.#
#.##.#...#
####..#...
###..##...
###.......
#.....#...
..##......
#....#..#.
#.###...#.
.#..#.###.
Tile 1399:
#.#..##..#
....#.##.#
#..#.....#
#..#....##
#...#..#..
#.#.#....#
......##..
.##.......
.####.####
...#...#..
Tile 1249:
..#..####.
#.##.....#
..........
..#.....##
#.#..#...#
#..#...###
.....#.#.#
..###..#.#
.#...#..#.
.#...##.#.
Tile 1289:
#########.
...#......
.....##.#.
...#.#...#
#..#..#...
#....###.#
....#..#..
.....##..#
.....#...#
.#.#####.#
Tile 3373:
#...##..##
#..#....##
#..#...###
#......#..
..#......#
.....#....
#.#.......
.....#.##.
...#.#..##
..##.##...
Tile 1613:
####...#..
#.#.......
..........
#....#####
#..#....##
...#..#...
.....#...#
.#......##
##....#..#
....#..###
Tile 2029:
#..###.#.#
#.#..#...#
##...#....
.#..#..#..
...#...##.
##.....##.
..##...#.#
...##.#..#
#.........
.#.####.##
Tile 2203:
..####.###
..##....##
...##.....
....#..#.#
..#...#.##
#.#.......
...###....
#.....#..#
.........#
.###....#.
Tile 1877:
##.....###
.....#..#.
....#...#.
##.#.....#
.#..##...#
##.#..##..
..#...#...
#...##....
#.#.#.....
.##..#....
Tile 3847:
...##.#...
.##.....##
#.#.#..##.
#.##..###.
.........#
..#...##.#
#...##..##
##..#.##.#
#..#.....#
#.##.#..#.
Tile 1499:
..#.######
#....##..#
##...#...#
...#.##.#.
##...#...#
....#....#
##.....#.#
#.....#...
.#....#..#
#.#.#..#..
Tile 3251:
.###.#.#.#
##....####
##..#.....
#.#....#..
...#..#.##
...#......
#.#.##....
......##..
......#...
..#.##...#
Tile 3323:
...#.#....
........##
...#......
#.......##
###.##..##
##.##....#
...#..#...
...###.###
##.....#..
.###.##..#
Tile 3109:
.#.#.#.###
######.#..
......#...
##.#.#...#
.#...#..##
###...#.#.
....#.....
#....#..##
#...#.#...
.#....####
Tile 1889:
#..#.####.
#..##.##..
...#....##
........##
#.#..#####
#.........
#.#.#.....
...###.#..
#....#..#.
..###.#...
Tile 2027:
#....##...
.##....#..
#...#...##
#........#
#.....##.#
.#...#..##
#..#...###
....#.....
#..#...##.
##.#.#####
Tile 2677:
#..###.#.#
##.#....#.
.##.###.##
#.........
#........#
.#.##.##.#
##...##..#
##......##
...#......
#..####...
Tile 1663:
.####.#.#.
#...#....#
###....##.
#..##.#.##
#.....#..#
.#..##....
#....#.#..
##........
#..#......
.##.##..##
Tile 3559:
..###...#.
##........
..#..#..#.
#.........
.#.#..##.#
##.#.....#
..#.......
#..##.#..#
###.#....#
.#..#..#..
Tile 3049:
.#.##...#.
#.......#.
#.##....#.
...#...#.#
..........
####..#.#.
.##.##...#
...#..#.#.
....#....#
###.#.#.#.
Tile 2777:
..#.#..##.
##..#...#.
.....##...
#.###...##
##...#..#.
.##......#
....#....#
##....#...
##.....#..
###.##...#
Tile 2551:
#.####.##.
#.........
#..##...##
..#......#
..........
##...#..##
.........#
#.#......#
..#.....#.
...#.###.#
Tile 3491:
#.##...###
#.#.#.#...
#.....#..#
#.....#...
##..#..##.
###......#
#......#..
....#.##.#
#.##....##
####.#.#.#
Tile 3947:
#.##.#.#..
....#.#.##
...##....#
###......#
##.#..##.#
..#.#..#..
#....#..#.
#...#....#
...#..#.##
###.##.#..
Tile 1361:
..#.#.####
#..#..#.##
.#...#...#
..........
..#......#
##........
#.##.....#
.#.......#
#.#..#...#
#..##...#.
Tile 2851:
.###.##...
#.....##..
....##...#
........#.
#.#.###..#
#...#.#..#
##...#..##
...#..#...
##.......#
#####.#.##
Tile 2381:
.#.#######
.#..#..##.
...#......
#......###
#.#..#...#
..###..#..
...#.#.#..
#......#..
..##.....#
..#.#.##..
Tile 1069:
.#.#...###
##..#.##.#
#.#..###..
###...##..
.#.#....#.
.........#
#..#...#..
..#....##.
.#.#....##
#.....##.#
Tile 2311:
..##.#..#.
##..#.....
#...##..#.
####.#...#
##.##.###.
##...#.###
.#.#.#..##
..#....#..
###...#.#.
..###..###
Tile 1951:
#.##...##.
#.####...#
.....#..##
#...######
.##.#....#
.###.#####
###.##.##.
.###....#.
..#.#..#.#
#...##.#..
Tile 1171:
####...##.
#..##.#..#
##.#..#.#.
.###.####.
..###.####
.##....##.
.#...####.
#.##.####.
####..#...
.....##...
Tile 1427:
###.##.#..
.#..#.##..
.#.##.#..#
#.#.#.##.#
....#...##
...##..##.
...#.#####
.#.####.#.
..#..###.#
..##.#..#.
Tile 1489:
##.#.#....
..##...#..
.##..##...
..#...#...
#####...#.
#..#.#.#.#
...#.#.#..
##.#...##.
..##.##.##
###.##.#..
Tile 2473:
#....####.
#..#.##...
#.##..#...
######.#.#
.#...#.#.#
.#########
.###.#..#.
########.#
##...##.#.
..###.#.#.
Tile 2971:
..#.#....#
#...###...
#.#.###...
##.##..#..
.#####..##
.#..####.#
#..#.#..#.
..####.###
..#.#.###.
...#.#.#.#
Tile 2729:
...#.#.#.#
####.#....
..#.#.....
....#..#.#
.##..##.#.
.#.####...
####.#.#..
##.####...
##..#.##..
#.##...##.
Tile 3079:
#.#.#####.
.#..######
..#.......
######....
####.#..#.
.#...#.##.
#.#####.##
..#.###...
..#.......
..#.###...
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const groups = data.split(/\n{2,}/);
const tiles = {};
const edgeCandidates = {};
// find edge candidates per tile
for (const tileLines of groups) {
const lines = tileLines.split(/\n/);
const head = lines.shift();
const id = /Tile (\d+):/.exec(head)[1];
tiles[id] = { lines };
tiles[id].possibleEdges = [];
tiles[id].possibleEdges[0] = lines[0];
tiles[id].possibleEdges[1] = lines.map((l) => l[0]).join("");
tiles[id].possibleEdges[2] = lines.map((l) => l[l.length - 1]).join("");
tiles[id].possibleEdges[3] = lines[lines.length - 1];
for (let i = 0; i < 4; i++) {
tiles[id].possibleEdges.push([...tiles[id].possibleEdges[i]].reverse().join(""));
}
for (const edge of tiles[id].possibleEdges) {
edgeCandidates[edge] = edgeCandidates[edge] || [];
edgeCandidates[edge].push(id);
}
tiles[id].id = id;
tiles[id].adjacent = [];
}
// count possible connections
// collect adjacency data
for (const [edge, ids] of Object.entries(edgeCandidates)) {
if (ids.length === 1) {
continue;
}
for (const id of ids) {
tiles[id].connections = tiles[id].connections || 0;
tiles[id].connections++;
}
tiles[ids[0]].adjacent.push({ t: tiles[ids[1]], e: edge });
tiles[ids[1]].adjacent.push({ t: tiles[ids[0]], e: edge });
}
// collect edge tiles ids
const edgeTiles = Object.values(tiles)
.filter(({ id, connections }) => connections === 4)
.map(({ id }) => id);
// helpers
function flipLines(lines) {
for (const [k, line] of lines.entries()) {
lines[k] = [...line].reverse().join("");
}
}
function rotateLines(lines) {
const oldLines = lines.map((l) => [...l]);
const newLines = Array.from({ length: oldLines.length }, () => Array.from({ length: oldLines.length }, () => ""));
for (let j = oldLines.length - 1; j >= 0; j--) {
for (let i = 0; i < oldLines.length; i++) {
newLines[j][i] = oldLines[i][oldLines.length - j - 1];
}
}
newLines.forEach((l, idx) => {
lines[idx] = l.join("");
});
}
// make map of tile ids
const map = [];
const availableIds = new Set(Object.keys(tiles));
// place first edge tile
{
// based on the order of generated possible edges
const flipIfEdge = [1, 3, 4, 6];
// rotate to make connecting edge on top
// all rotations are counter-clockwise
const rotateIfEdge = [0, 1, 1, 2, 0, 3, 3, 2];
map[0] = [edgeTiles[0]];
const connectingEdgeString = tiles[map[0][0]].adjacent[0].e;
const edgeStringNo = tiles[map[0][0]].possibleEdges.indexOf(connectingEdgeString);
if (flipIfEdge.includes(edgeStringNo)) {
flipLines(tiles[map[0][0]].lines);
}
// 3 extra rotations to make connecting edge on the right
for (let r = 0; r < rotateIfEdge[edgeStringNo] + 3; r++) {
rotateLines(tiles[map[0][0]].lines);
}
}
availableIds.delete(map[0][0]);
// last placed tile, py - line no, px - tile in line
let px = 0;
let py = 0;
// place all remaining tiles
{
let isFirstLine = true;
do {
const rightEdgeString = tiles[map[py][px]].lines.map((l) => l[l.length - 1]).join("");
const adj = tiles[map[py][px]].adjacent.find(({ t: tileCandidate }) => {
if (!availableIds.has(tileCandidate.id)) return false;
for (let i = 0; i < 4; i++) {
const leftEdgeString = tileCandidate.lines.map((l) => l[0]).join("");
if (rightEdgeString === leftEdgeString) return true;
rotateLines(tileCandidate.lines);
}
flipLines(tileCandidate.lines);
for (let i = 0; i < 4; i++) {
const leftEdgeString = tileCandidate.lines.map((l) => l[0]).join("");
if (rightEdgeString === leftEdgeString) return true;
rotateLines(tileCandidate.lines);
}
});
// if (!adj) return console.log("bad left step");
availableIds.delete(adj.t.id);
map[py][px + 1] = adj.t.id;
// first line ends on edge tile
// other lines end at first line length
if ((isFirstLine && !edgeTiles.includes(adj.t.id)) || map[py].length !== map[0].length) {
// not the end of the line
px++;
continue;
}
if (availableIds.size === 0) {
// no more tiles
break;
}
// line has ended, must place first tile on the next line
{
let bottomEdgeString = tiles[map[py][0]].lines[tiles[map[py][0]].lines.length - 1];
let adj = tiles[map[py][0]].adjacent.find(({ t: tileCandidate }) => {
if (!availableIds.has(tileCandidate.id)) return false;
for (let i = 0; i < 4; i++) {
const topEdgeString = tileCandidate.lines[0];
if (bottomEdgeString === topEdgeString) return true;
rotateLines(tileCandidate.lines);
}
flipLines(tileCandidate.lines);
for (let i = 0; i < 4; i++) {
const topEdgeString = tileCandidate.lines[0];
if (bottomEdgeString === topEdgeString) return true;
rotateLines(tileCandidate.lines);
}
});
// first line may need to be entirely flipped for this to work
if (!adj && isFirstLine) {
map[0].forEach((id) => {
tiles[id].lines.reverse();
});
bottomEdgeString = tiles[map[py][0]].lines[tiles[map[py][0]].lines.length - 1];
adj = tiles[map[py][0]].adjacent.find(({ t: tileCandidate }) => {
if (!availableIds.has(tileCandidate.id)) return false;
for (let i = 0; i < 4; i++) {
const topEdgeString = tileCandidate.lines[0];
if (bottomEdgeString === topEdgeString) return true;
rotateLines(tileCandidate.lines);
}
flipLines(tileCandidate.lines);
for (let i = 0; i < 4; i++) {
const topEdgeString = tileCandidate.lines[0];
if (bottomEdgeString === topEdgeString) return true;
rotateLines(tileCandidate.lines);
}
});
}
// if (!adj) return console.log("bad line step");
availableIds.delete(adj.t.id);
map[py + 1] = [adj.t.id];
px = 0;
py++;
isFirstLine = false;
}
} while (true);
}
// make final image
const image = [];
const tileSizeForImage = tiles[map[0][0]].lines.length - 2;
for (let i = 0; i < map.length; i++) {
for (let j = 0; j < map[0].length; j++) {
for (let k = 1; k <= tileSizeForImage; k++) {
const line = tiles[map[i][j]].lines[k].substr(1, tiles[map[i][j]].lines[k].length - 2);
image[i * tileSizeForImage + (k - 1)] = image[i * tileSizeForImage + (k - 1)] || "";
image[i * tileSizeForImage + (k - 1)] = image[i * tileSizeForImage + (k - 1)] + line;
}
}
}
const pattern = [
` # `, //
`# ## ## ###`, //
` # # # # # # `, //
];
// offsets relative to first hash on second line in pattern
const requiredHashesOffset = [];
for (let i = 0; i < pattern.length; i++) {
for (let j = 0; j < pattern[0].length; j++) {
if (pattern[i][j] === "#") {
requiredHashesOffset.push([i - 1, j]);
}
}
}
const imageSize = image.length;
function countPatterns() {
let res = 0;
for (let i = 1; i < imageSize - 1; i++) {
for (let j = 0; j < imageSize - pattern[0].length; j++) {
res += requiredHashesOffset.every((shift) => image[i + shift[0]][j + shift[1]] === "#");
}
}
return res;
}
// only one flip/rotate combo has patterns!
let foundPatterns = 0;
search: do {
for (let i = 0; i < 4; i++) {
if ((foundPatterns = countPatterns())) break search;
rotateLines(image);
}
flipLines(image);
for (let i = 0; i < 4; i++) {
if ((foundPatterns = countPatterns())) break search;
rotateLines(image);
}
} while (false);
// result is number of hashes that don't belong to a pattern
const hashesInPattern = [...pattern.join("")].filter((char) => char === "#").length;
const hashesInImage = [...image.join("")].filter((char) => char === "#").length;
console.log(hashesInImage - hashesInPattern * foundPatterns);
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const groups = data.split(/\n{2,}/);
const tiles = {}
const edgeCandidates = {}
for (const tileLines of groups) {
const lines = tileLines.split(/\n/)
const head = lines.shift();
const id = /Tile (\d+):/.exec(head)[1];
tiles[id] = { lines }
tiles[id].possibleEdges = [];
tiles[id].possibleEdges[0] = lines[0]
tiles[id].possibleEdges[1] = lines.map(l => l[0]).join('')
tiles[id].possibleEdges[2] = lines.map(l => l[l.length-1]).join('')
tiles[id].possibleEdges[3] = lines[lines.length-1];
for (let i = 0; i < 4; i++) {
tiles[id].possibleEdges.push([...tiles[id].possibleEdges[i]].reverse().join(''))
}
for (const edge of tiles[id].possibleEdges) {
edgeCandidates[edge] = edgeCandidates[edge] || [];
edgeCandidates[edge].push(id)
}
}
for (const tileGroup of Object.values(edgeCandidates)) {
if (tileGroup.length ===1) {
continue;
}
for (const id of tileGroup) {
tiles[id].connections = tiles[id].connections || 0
tiles[id].connections ++;
}
}
let result = 1;
for (const [id, {connections}] of Object.entries(tiles)) {
if (connections === 4) {
result *= id
}
}
console.log(result);
3: 97 29 | 2 104
45: 97 10 | 2 73
114: 44 97 | 90 2
78: 2 95 | 97 32
7: 97 64 | 2 119
118: 97 81 | 2 58
64: 97 29 | 2 14
106: 53 121
4: 2 103 | 97 55
54: 2 53 | 97 44
58: 33 97 | 130 2
91: 104 97
102: 104 97 | 83 2
128: 2 59 | 97 3
79: 98 2 | 124 97
117: 2 65 | 97 92
1: 75 2 | 115 97
40: 2 96 | 97 119
8: 42
92: 102 97 | 57 2
97: "a"
93: 2 66 | 97 103
36: 2 104 | 97 32
2: "b"
108: 43 2 | 68 97
46: 44 2 | 90 97
31: 97 5 | 2 132
110: 14 2 | 90 97
61: 38 2 | 9 97
10: 63 2 | 34 97
32: 2 2 | 97 121
11: 42 31
103: 121 121
131: 75 97 | 60 2
74: 2 112 | 97 47
20: 93 2 | 69 97
53: 97 2 | 97 97
23: 125 121
9: 97 66 | 2 25
101: 83 97 | 95 2
35: 25 2 | 104 97
76: 97 55 | 2 104
125: 83 2 | 32 97
22: 59 97 | 76 2
127: 6 97 | 55 2
126: 97 119 | 2 17
113: 59 97 | 35 2
81: 46 2 | 72 97
104: 2 2 | 97 2
100: 25 2 | 95 97
95: 97 2
132: 97 27 | 2 45
107: 97 90 | 2 32
34: 98 97 | 50 2
33: 2 95 | 97 83
119: 32 97 | 66 2
90: 2 2 | 97 97
77: 126 2 | 22 97
6: 2 97
14: 97 2 | 2 121
94: 2 110 | 97 129
21: 56 97 | 105 2
65: 2 96 | 97 98
122: 2 71 | 97 86
87: 101 97 | 91 2
15: 107 97 | 120 2
120: 103 2 | 66 97
56: 128 2 | 20 97
129: 2 66 | 97 83
41: 97 48 | 2 122
13: 39 97 | 26 2
30: 97 88 | 2 54
84: 55 97 | 53 2
86: 84 2 | 59 97
96: 55 2 | 104 97
83: 97 121 | 2 97
50: 53 97 | 95 2
19: 2 70 | 97 78
121: 2 | 97
57: 53 2 | 83 97
37: 6 97 | 6 2
68: 97 53 | 2 83
112: 97 23 | 2 19
66: 2 97 | 2 2
49: 97 90 | 2 103
80: 2 97 | 97 97
85: 83 97 | 55 2
12: 2 35 | 97 51
116: 97 67 | 2 77
123: 4 2 | 85 97
82: 21 2 | 111 97
105: 30 97 | 87 2
72: 25 97 | 95 2
115: 104 2 | 29 97
63: 97 37 | 2 36
42: 24 2 | 82 97
0: 8 11
70: 2 80 | 97 25
5: 2 74 | 97 116
52: 16 97 | 94 2
62: 35 97 | 114 2
18: 123 2 | 61 97
25: 97 97
88: 83 97 | 66 2
124: 2 6 | 97 80
89: 114 97 | 100 2
44: 97 2 | 2 97
71: 49 97 | 106 2
38: 2 104 | 97 90
75: 53 2 | 104 97
98: 53 2 | 25 97
69: 97 95 | 2 95
73: 2 1 | 97 7
24: 41 97 | 109 2
48: 2 40 | 97 113
39: 103 2 | 104 97
67: 2 15 | 97 62
55: 2 2
47: 2 79 | 97 108
51: 6 2 | 95 97
17: 95 2 | 90 97
59: 53 97 | 66 2
28: 2 12 | 97 131
27: 2 52 | 97 28
29: 97 97 | 2 121
16: 4 2 | 127 97
109: 2 117 | 97 18
43: 104 97 | 6 2
99: 97 89 | 2 13
130: 83 121
111: 99 2 | 118 97
60: 97 44 | 2 25
26: 121 44
abbbbababababbaabbbbbbab
bababababaabbbaaaabaabaaaaabaabaaabbbbab
baaaabbbabbbbababbbbaabababaaababbaaaabbbbabbbbb
abbababaaabbabbaabaaaaaaaaaabaabaaabaabb
aabbaababaabbabbaaabaababaaaabab
baabaaaaabbabaabaaabaaabbaaabbabbaaabbbbbabbbaba
babaabaaabaabaababaabbab
bbbbbababbbaaaababaaaaabbaabaaba
bbaabaaaaaaabbabbababaabbabbaaaa
aabbababaaaabababbbbaabbaaabbaba
bbaaababbbbaababbbbabababbaaabaaaaababba
bbbbababaabbbabaabbaabbaaaaabbbabbbbbbbbbaaaabaabbbaaababbaaaaababbbabbabbabaaab
bbbabbbabbaaabaaabaababbbaabaabaaabbbbba
abbbbbabbaabbbbbbaaaabbbbaaaaabb
aabbababbabbababbbbbaaabaababbaabbaabbaa
bbbbbabaaabbaaaaabaaabbbabbaaaba
baaabbbbbaabbaaabbbaabaaaaaabbbbaabaaaab
bbabbbaaaabaabbaabbbabab
bbbbbabbbabbbababbabaabaabbbbaab
aaaabbabbbababbabbaabaaaaabbbaaaabbabbababbbaabbbbbbaaaa
bbaabbabbaaabbabababbbbbbbbbabbbaabaaaaaabbababbbbbaaaba
bbbaabbbaaabbaabbbbbbaaa
bbabbabbbababbbbababbbaa
baabbbabaabaaabaabbbbbbbaaabbaaaabbababa
aabbaabaabaabbbabbbbabaaabbabbbbabbabaabbbabbbaababbbbba
aaabababbbbaaabbbaaaaaabaaaaabaabaabababbbbabaaaabaaaaabbbbbbbba
babaaabaaabbbabaabaaabbbababbabbbabbabaaaaabbaba
aabbaaaabbbbbabbbbaaabbbaabaabbbbbaaabbbabaabbbbbbbababaabbaaabbabbaaaba
aaaabababbaabaaaaaaaaaba
babbbbaababaaaabbbabbbabaaababaaabababaaaaabbaababaaaaba
abbbabaababababbabbaaaab
babaabbbbabababaabaaaabbbababababbaaaabbaabbabba
bbabbababbbababbabbaaabb
bbabababbbbababbbbbbaaaa
bbaaababaaaababbbabbbaba
aabbbabababbababbababaaaababbaabbbabbaabaabbabbbbaaaaabb
bbbbbababbaabbababaabbbbababbbaabbbabbba
abbbbaabbbaaababaaababaaababbbbbbbaaaaaabbbaababaabababb
baaaaabbbaabaaabbbbbbaaaaabbaabaaabbaaaabbbbbbbbbbaaaaabbabbbababbabbbba
abaabbbaaabaabbbbaaabbababaabbab
abbbbababbbbaaababbbbbabbababbaaababbabaabbaabbb
babbababaabbbaaabaaabbabbbbaabaabaaaabbbabaabbaaabbbbbba
babbabaabaababbabbaabbbbbaabaaabbaabaabbbbaaabbaaabababb
babaaaaababbbaaabbabbabb
baabaaabbbbababbbabababbabbabaabbbaabababbbbbbabaabaaaab
aaaaabbbaababaababbbbababbbabbaaabbbabbbabbaaabbababaabbbaaabbaaaaaabbaa
bababaaaabbbbbbbababbbababbbbbaabaabbaab
baaabbbbaaaaabbabbababaaabbabbab
aaaaabbbaabbbaaabaaaaaabbabbbbbb
aababbaabbbabbaaabbbbabbaaaabbbb
aabbababbbbbbaabbaaaaaaaabbbbaabbbabaabb
bbbbbaabbbbbabaaabbbbbaa
babababaabaaaaaabbaaabbaaaaabbbaabbbbbababaaababbbabaaabbaabbabb
bababababbaaabbbababaabb
bbabaababbaaaaabbabbbaaabbbaaaababaaaaaaaabbbbab
bbabbbabbbbbabaabbbabaaa
aaabbbaabbaaaaabbbabbabababababbabbababb
aabbaaaabaabaabbbbbbaabaaaaabaaabaabbaab
aaaabbbabbbbaaababbabbab
abbaaaaabaabbbaaaaabbbbbbbababaabbbbaabbabbbababbaaaabaa
aaaabbbababababbbaaababaabbabbbabbabbbbb
baaaaaabbaababbbabbaabaa
aaaabbbaabaaabbbbaaaabbababaaabaaaabbaaabbababaa
bbaaaaabbabbaabbbabbbaba
aaaabbbababababbababbaababaabaabaaabbaab
baaaaaababaaabbabbabbaabaaaabbbb
bbbbaaabaaabaabaaabababaabbabaabbbbaaabb
aaabbababbbbaabbbbaababbaaababba
aabaabaaaaaababbbabbaaaabaaaaabaabbabaaabbabaaabaaabbbababaaabaa
aabaaabbabbabbbaaaabbbab
bbaaaaaabaabaaaababbaaaaaabaababbbbbbabbbabbbaaabbbabbbbbabbbaab
bbbbabaabbabbaaabaaaaaaabbbaaaabaaaabbababbaabbbbbabaabaaaabbbbaaaababaa
aaababaabaababbabbaabbbbbbbabaabaaaabaaabaaabbabaaaabaab
ababababbbbbbabaababbbabbbbaaabbabbababaaaabbbba
babbbbabbaabaababbabbbaabbbaabbbbaabbaab
aabaaababbbbaaabbabaabbaababaababbbabaab
aabaaabbbbaabbbbbbbaabbababbabaabbaaabaa
abbbbbbbaabbbaabbbabbbabbababbaabbababbb
aabababababaaaaabbbababbbaabbbba
aaaababbabaaaabbaabaabbaaaabaaaa
bbbbbabbababbaaaabbbbbabbaabaababbbbbaaa
aabbaaaababbbaaaaaaabbaa
aaaaaaabaabaaabbabbaaaaa
babaaababbaaabbabaabbbbbbaaaababbbaabaab
abbabbbaaaababbbababbbabaabaababbbababab
baabbbaabbabbbabaabbbaaabbaaaabbbbaaabaaabbaabbb
babaabaaaaababababbbbabbbabaabaaaabaaabaababababbbaabbbabbaaaaaababaaaab
aabaaabbaababbaaabbbbbaa
aaababaaaaaaabbabbbbbbba
ababbbabbabaabbabbabbbbababbaabbaabababb
baabaaabbaaaaaabababbaababaaabaaabbbbbbbbaabababbbbabbba
bbababbababbababbbaabbbbbbbababbabbaaabbbbbbaabbaababbba
ababbaaaaaabbbaaababbbaa
ababbaabababbaabbaabbaba
aaaaabbabbabbbabbbaaabbbababababaaababbabababbabaaabbbabbbaaaaba
aabaabaaabbbbabbababbaababaabaaabaababab
bbabbaaaaabbbabababababbababbbaaabbbaaaababbbabbbbbbbbabaababaaa
aabaaabbbbbbababaaabaaaaaababbaaabaaabaaaabaabaabababaabbbbaaaaabbbabaaa
aaabaabaabaabbbabbbbabba
aaabbbaabaabbbabbbababbb
bbbbbaababbbbaabbbabbaabbbbaaaaa
baaaabbbbbabbbababaaaaababbbabab
bbaaaaabbaabaabbaabbaaaaabaaabaaaaababbbabaababa
babaabbaabaaabbabaababbaababaaaa
abbbaababaaabbababbbbaabaaababbbbbbbbbab
abbbbbbbbbaaabbbaabbabaa
baababbabaaababaababbabababbbbabaababbbaaaabaabbabbaaabb
bbababaabbaabbbbbabaabaababbabba
bbbaabaaababababbaabaaba
aaabaaaaaaaaabaabbabaaabbbaabbab
aaaaabbaababbabababaabaabbbaaaaa
ababbabaaaaaaaaabaabbbaaaaaaaaabaaaaaaaababbaaaa
aabaabababbaababaababbabbaabbaabbbaaaabbababbabbbaaabbba
babaaaaababbaabbbbbbabaabaaababababbbabbaabbaaab
bbabbbabbbbaaaabaaaabbaaabbaabaabaaaabaa
baababbabbabbbaabaabbaab
babaabbbabaabbbaabaaabaaabaaabab
abaababbbababbbaaaaaabbababaaabbbaaabbbb
aaaababbaabaabbabbaaaaaa
baabbbbaabababababbbbaaababbaaaabbbbaaababaabbaaaaabbbbbaabbabbbbbaaaaaa
bbbbaaabbabbbaaaaabbbbba
aaabbbaaaabababaababbaabbbbabaaa
baabbbbbbaabaabbbababbaabbbabbabaabbbbab
baaababbaabaaabbbbbaaaaaaabbabbaaaaabaab
ababbabbabbbbbbbabababbaaaabababbaaabbaa
baaabbbababaabbbbaaaaabb
bbaabbbbababaabaaaaaaaba
aabbbabbbbabbbabbbbbabba
abbabbbbaabaaabaaabaabab
aaaaaaaaaaabaababbaaaabbaabbbaabbbbabbaabbabbabbababbbaabbaababbaaaaaaba
abaabbbbaabbbabbabbbbabaabbabbab
bbaabbabbbabbbbaabbbbaabababbbbaaaaaabbabbabbbbb
bababaaabaabbbbbbbaabbbaaaabbbab
abbbabaabaabaabbbaabbababbbababababbbabb
ababaabababababaababbbabbababaabbabbbaababababbb
baabbbbbabaabbbbabbbabab
ababbabbbabababbbbabbaaaaabbabbb
baabbabbbbaabaaabbabbaabbbabaabb
babababbbabaabbaabbbbbba
abaaaaabbbababaaaabaabbbaaaabaab
baaaaaabbabbababbaababbbbaabbabbaabbbbab
abbbabaabbaaababaabbbaabaababaabbababbabaababbba
bbabababaabbbbaaaabaabaaabaababbaabaaaaababbbbabbbaaaaabbabababaaabababababbaabb
aaababaaababababbbbbbababaabbabbabbbbabababbbaba
aabaabbbaaaaaabbbbbaababbabbbbba
bbabbbabbbaaabbbabaabbbababbababbbbaaabaaaaaabaabaaabaabaabbbbaaabbbabab
bbaabbbbbbaabbbbbaaababaaababbabbaaaabba
ababbbbbabbbbaabaabaabbaabaabbab
bbabbbaaaabbbaabbbababbaaaabbbba
baabbbbbababbabababbbaababbabbbaaaaaaaba
abbabbbaaabbbaaabbabaabababbabaaabbaaaaaaaaabaabbbabbbbb
aaabaaabbaabaabbbaababaabababbbbaabaaaab
baabbbaabaabaabbaababaabbbaaabba
abaaabbbbbbbabaababaabaaababbbbaaababbaaaabbbabaabaaaabababbbbbbabbaabab
abaaaabbaaaaaaabbbbbabaaababbabbabaaabaabbaabbba
bbaabbabbbbaabaabbaabbaa
abbbbababaabbbaabbbbbabaababbbaabbbbbaaa
babaaaaabbbbbbbbbbbbbababbbaabaabaaaaaabbbabaaabaabbabaa
bbaaababbabaabbabaabbbbbbababaabaabababbbabbbbba
baaaaaababbabaabaaaababaababbaabaaaaabab
aabaaaaabababaababaaababaaaabbabaabaaabaabbababbbaaabaaabaababaa
babababbababababaaababbb
aaabaaabbbababaaaabaabbabaaabbbabaaaabab
abbabbbaaaabbbaabbaaaabbbabbbabbabaabbaa
bbbbbabbabaaabaabbababaabaabbabbbabbaabbbbbbabbbabbaaaaa
bbbbbabaaabbbabaababbbbbabaabbbbbbaaaabbbbbaabbbabaaabab
bbabababbababaabababbbbbbbbaaabbabbaabbb
aaaaaabbbbbaababbbaaabaabbbaaaaa
aaababbabbabbbaababbabbaabbabaabaaabaababbbabbabbbbbbbbbaabaaaab
abbbbbbbbaaabababaaaaaabbbabbabb
babaabaabaaabababaabbabbbabaabaabbbaabaabbabbbaabbbabaaa
bbaabbabbbabaaabaaaaaabbbbabaaab
baaababbababbaaaabbbbbba
baaababbaaaabaaaaababbaabaabbbbbabaaaaababbaabaaaabbbbaaaaabaaaa
aabaabbbbababaaababbabaabaabbaaabbaaabbbbbbbbbbbabbababb
aabbbaaababaabbabaabaaaaaabaaabbbabbaaabbababbbbabaababb
baaabbabbaaaabaaaabaaababbbbabaaaaabaaba
ababbaabbaabbbabbabbababaaaabbbbaabbabba
abaabbbbbababaaabaababab
baabaaaaabaaabbbaabbaabbaaabbbbb
bbbbbbaaaaabbaababbabbabbbbbbbaa
abaaabaabaabbbbbbabababbbabbbaaaabaabbbaabbbabbbaabaaaaa
bababbaabaaabbababaababb
bbbabaabbababbaabbbabbaababbbbbbbbbbbbab
bbbbbbbbaabaabbaaaabaaabbbaaabbbbbabbbbb
abbabbbabbbbbaabbbaaabbbbaabbbaaabaabbbbbabbabbb
baaabaaababaaaaaaabbbabbbaabbaaababbbbbbbaaaabba
abaaabbaabaabbbabbaaabbbabaaabbbaababaaa
aaaaabbbaabaabbabaabbbbbbbaabbaa
aaaabbbaabbbbabaabbabaaaaaabaabb
aaabaaabaaabaaabbaabbaaababbbbabbabaaaab
aabaaabaaabababaabaaabaaababbaaa
bbbabbaabbabaababaaabbbabbbbaabb
bbaabbbbbaaabaaaaaaaabbaaaabbbbb
abbbabbaababbbbbbbbabaaa
bbbababbababbbabaabaabba
babbbaaababaabbbbbababababbbabaaabbbbaaa
abaaaaabbaaaaaabbabbabbb
ababaababbbbbabaaababbab
abbbabbbaaaaaaababbbaaaa
babaaaaabbaaabbbabbabbbbaabbaaaaabaabbabaaabbabb
babbaabbbbbbabaaabaaabbaabaabaaabababbba
ababbbbbaaabababbbbabbaaabaaaaaa
bbaaaabbbaabbbaababbbbbb
abaabbbaabbbbbbbaaabababbbbbababaaaabbaa
abaaabaaabbabbbbbabbababbabbbaabaaaaaabaaaaaabaabaababab
abaabaabbaaabbbbbbbbbabbaaabababbbaabaaaaaaaabab
aaabbbaabaabbbbbbabaabbabbbbaabb
bababaaabaabbbaabbaaabbababbbaabbbbabaababaabbaababaaaab
aaabaabaaababababbabbbbb
bbbababbaabbbaaaaabbbaabbababbba
baabbbaaabbabbbbbbbbabaaabbbbaabbababbbb
baabaaaaaaabababaaabbbab
babababbaabbbabaabbbbaaa
babaaababbaabbbbbababaaaabbbaababbaaabaa
aabbbabbbabbababaaaabababbbaabba
aabbbaaabbabaabbbbbbabbabbbbbbaaaababaaaabbbaaabbaabbabaabbbabaaababaaaa
ababaabaaaaababbbaaaaaba
bbabbbbaababaababbabbaabbbabbaaaaaaaaaababbbbbbabbabaaababbbbaaabbabbbbb
bbaabbabbaaabaaaaaabbbaabaababbbbaababbabababbababaabaaa
bbbbbaabbababaabbbabbaabbbababaabababbab
baaabbabaababbaaaaabbbaabbbbbaabbabbbaaaabbaaaabaabbbbaa
aababababababbaaabaaaaababbabaabaaaabbbaabaaabaaabbaababbbbabbbbbbbaaaaababbbbab
aaabababaabaaabbaabaaabbaaabbabbaabbaaab
baaabaaabbbbbbbbaaaaaaba
abbbabbbbbbbaababbbabaaa
babababbbbbbbabbaabaabbababbbbba
aaaaabbaaabbbaababaaabbbaabbbbab
bbbaaaaaabbabababaabbbaaaaaabbaaaababbbaaaaabababbabaaaaaaaaababbbbbbaabbbabaaab
aabaabbabababbbaabbaabbbbbabaabbbbabaabb
aaaaaaababbbabbbbababaaababababbaabbbaaabbbabbba
babbabaababbaabbbaabaaaabbaaaaababaaabaabaabbaab
abbbbbbbabbbbabbaabbbaaaabbbbbaa
bbaaaabbbaaabbbbbbbbabbb
aaababaababaabbbababbabbabaabbbabaabbaaabbbbbaaa
bbbababbbaabbaaabbabaaaababbbaaabbabbaba
abbabbbbbbbbbaabaabbaabaababbbaa
baababbabaaaaaaaaabbbbaa
baaabbabaabbbbbbaaaabbabbbbaaabb
bababbaabaabbaaabaabbabbabababbb
bbbbbababbbabbaabaababab
aaaabbababbabbbabbbbbbbbaaabbaab
bbababbaaababbaabbbbbbbbaaaaaababaaaaaba
ababbababaabbabbaaabaaaa
bbabbbaaaaaabbabaaaaaaabbbabaababbbbbbaababbbaba
aaaaabaaababbbaabbbbabba
ababbbbaaabbbbbbbaaaabbbbbaaabbbbbbbbbaa
babbaaaaabbbabbbaabbbababaaaaabaaaabaababababbab
baabaaabbabababbbbbaabbabbbbbbabbbbbbbaa
bbabbabaaaaababbaabaabaaaabbabbabbaaaaaa
aabbbababaabbabbbabaaabaabbaaababbbbaabb
aabbbaabaabaabaaaaaababbbbbababa
abaaaaaaabababbbaaabbaabaaabaabb
abbbbabbaaaaabbbababbabbbabbbaaaabaabbbbabaabbbabbbaaaba
aabbbaaaaaabbbaaaaaaabbbbababaabbbaababaaaabbaaaababaabb
aaababaaababbaaaabbbabaaabbababb
baaabbbabaaaaaababbbabbbbbbbababbbaabaabbabbabbababbbbabbbabaaab
bbabbabaaabbababbaabbbabaabbabab
abaabbbabbbbabaabbbaabba
babaabbbababaababaabbbbbaababbba
abaabbbbabbbabaabbababbb
baaabaaaaaaabaaabbbbbaabaaaabbbb
bbaaabaaababbaabbbaaababaaaabbbbabbaaabaaaaaababbabaaaaa
babbabaaaabbababaabbbaaaabaabbbbbbbaabab
bbabaabaaababaababaababb
aabbaaaabaabbbaabaaababaabbbbbabbbabbabaaaabaabb
baabbbabbaabaabbabaabaabbaabbbbbabababaa
abaabbbaabbaabbaaaabbbbababaaabb
bbbbaaabbbbbbabaaaaabaaabbbabbab
ababbbbaabbbabaabababbbabbababbaaaabaaabaaabaaaabbaaababaaaabbaabbbbaaaa
bbaabbababababbaaabbabbb
babaaababbaaaabbaabbbbab
bbabbbaabaabbabbaabbaaaaaabbbaabaaabbbab
abaabbbbabaaaabbaabbababaaaababaabaabbbabbaababbbbbaaaba
abbbbaabbbaaababbbabbbaaaaaaabaabababaaababbaabb
aabbbabbaaabaaabaabbabba
ababbabbababbaababbbbabaabbbaaab
ababbbbaabaaaaabaabbaaab
babbbaababababbaaaabaaabbaabaaaabbaabaaabbaaabbaaabaabababbaaaba
bbbbbbbbbaabbbababbaabba
aabbababbaabaaaaababbbaa
aabbbbbbababaabaaabaaabbbbabbabaaaaaababaaabbbba
aabaabbaaabaabaabbbaabaaaaaabbbb
abaaaabbbbbbaaabaaaaabaa
baaabbbbbabbabaaababbbaa
baaababaababaaababbaaabbabaabbba
ababaababbabbbabababbababbaababb
baaaaabbbaaababbbabaaaabbabbbababaaababbaaaababbbbaaababbaabababaababaab
baabaaaabaaababbbbabbbabababbabababbabba
aabbbabbababbabbaabbaaaaaabbbbaa
aaaaaaabbbbbaaaabbbabbabbaabababbbaaaaba
aabbbbbbaaaabbbabbbabaaa
aaaabaaaabbbbbbbbbaabbaa
baaaabbbabbbbabbbbbababa
ababaabaaabbaaaaabaabaabbbbbaabb
babaabbbbabbababbbbbabaaaabbaaabbbbaababaabbaaabbbabaabb
baabbbbbbbabbbbabaabbbba
aaababaaababaababbaaababbbababbaabbbbbabbbbaabbabbbbbbab
baaababbbbaabbbbbbaabaaabbbaabbb
baabaabbaaaaabbabaaabbababbaabbb
bbabaaaabbbababbaabbbababaaabbabbbaabbabaababbabbaaaabab
baabaaaabaaabbabbabbabaabbabbbababbbbbababaabaababbbaaaababaabab
abaaabbabaaabaabbbaaaabababbbbaabaaaabba
aaaaaabaaabaaabbaaabbaaaaabbbaabaabbaaaaaaababaa
bbbbabaaaababbaabaaabbaa
ababababbaaaaaaaaaaaaabb
aabbaabaaaabbaababaaaabaabaabbabaaaaabaabbbabbba
aaaababababbababababbbaa
abaaaaaababbbaabaaababbaababbaabbabbabababbbabbabbabbaab
bbabaabaabbbabaabaaabaaababaabbbabaaaabababbaabaaabbabaa
baabaaaabababaaabbbababa
aaaababaabbabaababaaabab
baaaaaaaaabbbabababbabba
abaababbbabbbaaaaaaaabbbbaaabababaababaaabbbbabaabbbaaaaabbaaaababbaaabb
ababbabbaabaabbbababbabaaabaabab
aaaaaaabbbabaaaababaabbaabbababa
bbbabaabbbbbabaaaaaaaaabbbbaabaabbabaaabaabbaaab
ababbabbaabaaabaababababaaaabbbb
aaabaaabaabaabaaaabaaabaaabaabab
abaaabbbaabbbbbbaaaaabaa
bbababababaabbbbbbbbbbbbababaaabaaabbaba
babbabaababababbabbbbbbbbaabbabbaaabbaab
aaabbbbabbbbbbbababaababbabbaaaaaaababbb
bbaaababbbaaabbbababbabbbbbbbbbbaabbabba
babaaabaaabbbabbaaaabbabbaaabaab
babaaaaaaabaabbbabaaabab
baaabbbbababbbbbbabbbaabbabaaaab
abababbbababbaaabbaaabababababaaaabaaabb
babaabbbababaabaabaabbbb
baabbaaaaaabbbaaaabababaaabbbaabbbbaabbababbbbab
bbababaaabaaaaabbabbbaaaaaababbb
bababbaababababbbbbbaabb
babbbaaababbbaaababababababbaaabbbaabaab
aaaabbbabbaaabbbbaabbbbbbbaabaaabaaabaab
baaaabbbababbaaaaabbbabbbabbbabbbabbbbab
bbabbbabaaaaabbbbabaabbbabbabbaa
abbbbaababaababbbaaabababbbbaabababaaaaabbabbbaaaaaabbaaabbbbaab
ababbbbabbabbbaaaabbbaaababaabaabaababbaaaaabbbbaaaabbbbbabaaaab
bababababaaababaababbabbabaabbaaaaabaabb
bbaaaabbabbabbbabbaabaaaaaaaabbbaaaabbababbabbabbabbbabaabbbaaabaabaaaab
bbaaabbbbaaaabbbbabaaaaaabbbaabb
babaabbaaaabbbaaaaabaaababbbabbaabbbbbabaaabbababbaaaababbbaaaaa
ababbabbbaabbbaabaaaabaa
aabaaabaaaaaaaaabbbbbaaa
baabaaabbabaabbbababbabbbababbab
abaaabbaaaaaabbabbaababa
babbabaabaaaabbbbababbab
aaabbbaaaabbbabbababbaaababababbabbbaabbabaababb
aabaaabaaabbbabaabbaaabb
abaaaabbbaaabbbaababbbbabaababab
bbababaabbbbaaabaabbbabbabbbaababbabaaab
abababbabbabbabbaabbabaabbaabbaa
abaaabbbababbbabbbaababa
ababbbabababbabaaaaabbbaabbababa
baababbabaababaabbaaaaaa
bbbbbaabaaababababaabaaa
babbaabbaabbbaaaabbbabbaabbabaaabbabbabaaaaaaaaababbbbaaaabaabab
aabababaababaabababbbaaabbaabaaabaaaabab
bbabaabababababbbabbbaba
aaababbbaabaabaabbaaaabbbbabaaabbbaababb
baaaabbbbababaabbabababaaabbbbbbaaabaaaa
abbbbabbaabbbabbabababaa
aabbbaaabbbababbbbaaaabaabbbaabb
ababbbabaababababaaaabab
bbaaabbabbabbbaaabbbaaaa
bbaabbbbabaaabbaabababbb
abbbaababbaabaaaaabbaaaaaaaaabaa
baabbabbabaaaaabaaabaaaa
aaabababababbbbabbbbbabaabababaa
aaaaabbbaabaaabbbbbabaabaaaabbaa
aaaaabbbababbbabbababbba
ababbbabababbaabbbaaaaabbbbbbbaa
bbbaaaabaababaabbaababbaabababaa
baaaaaabbbbaaaababbabbaa
baabbabbbbababaaabbabaababbbabbaabaaaaababababbb
abaaaaabbbbaaaababbabbaa
abbabaabbaabbbaaaabbaabbaabaabaaaaababbabaabbabababaabaabbbbbbbbbaaaaabbababbbba
aaabaaabbbbabaabbaababaaabbbbbabbaaaaaaaaababaaaaaababbabaaabbaa
aaaaaaabbaabbaaababbbaababaabaaababbbbaa
bababababbbbbabbaabababbbaaabaaaaaaaaaaaaabbbaaa
babababaaaaabaaabbaaabaa
abbbbabbbababbaababbbaabbababbbb
bbabbbabaabaaabaabbabbbbabbaaaaabbbabbba
aabbaaaabaaabaaaabbbbabaaaaaaaba
baabbbbbbaaabaabababaabaababaaaaaabbaaaabbbbaabbabbabbaa
bbaaaabbbbaaabbabaaabaab
bbbbbababaabbaaabbbbbaba
bbabbababaabbabbaaaababbbbbbbabaaaaaabaa
aaabababaabaabbbabbbabbaaaababaabbbabaaabbabbbbbabaaabab
bbbabbaababbababaaaaaaba
bbbbbababbabbaabbbbaaaba
aabaabbbbbabaaaabbaaababababababbabaaaab
baaabbbabbbababbabababaa
bbaaababbabaaaaaabababbb
bbabbaababbbabbaaaababbb
bbabbbbaabababbababaaaab
42: 9 14 | 10 1
9: 14 27 | 1 26
10: 23 14 | 28 1
1: "a"
11: 42 31
5: 1 14 | 15 1
19: 14 1 | 14 14
12: 24 14 | 19 1
16: 15 1 | 14 14
31: 14 17 | 1 13
6: 14 14 | 1 14
2: 1 24 | 14 4
0: 8 11
13: 14 3 | 1 12
15: 1 | 14
17: 14 2 | 1 7
23: 25 1 | 22 14
28: 16 1
4: 1 1
20: 14 14 | 1 15
3: 5 14 | 16 1
27: 1 6 | 14 18
14: "b"
21: 14 1 | 1 14
25: 1 1 | 1 14
22: 14 14
8: 42
26: 14 22 | 1 20
18: 15 15
7: 14 5 | 1 21
24: 14 1
abbbbbabbbaaaababbaabbbbabababbbabbbbbbabaaaa
bbabbbbaabaabba
babbbbaabbbbbabbbbbbaabaaabaaa
aaabbbbbbaaaabaababaabababbabaaabbababababaaa
bbbbbbbaaaabbbbaaabbabaaa
bbbababbbbaaaaaaaabbababaaababaabab
ababaaaaaabaaab
ababaaaaabbbaba
baabbaaaabbaaaababbaababb
abbbbabbbbaaaababbbbbbaaaababb
aaaaabbaabaaaaababaa
aaaabbaaaabbaaa
aaaabbaabbaaaaaaabbbabbbaaabbaabaaa
babaaabbbaaabaababbaabababaaab
aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba
0: 4 1 5
1: 2 3 | 3 2
2: 4 4 | 5 5
3: 4 5 | 5 4
4: "a"
5: "b"
ababbb
bababa
abbbab
aaabbb
aaaabbb
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const groups = data.split(/\n{2,}/);
const rules = Array.from({ length: 1024 }, () => false);
for (const r of groups[0].split(/\n/)) {
let [key, variants] = r.split(": ");
key = +key;
if (variants[0] === '"') {
rules[key] = variants[1];
} else {
rules[key] = variants.split(" | ").map((variantRules) => variantRules.split(" ").map(Number));
}
}
rules[8] = [[42], [42, 8]];
rules[11] = [
[42, 31],
[42, 11, 31],
];
function test(line, pos, rule) {
if (pos >= line.length) {
return false;
}
if (typeof rules[rule] === "string") {
return line[pos] === rules[rule] ? [pos + 1] : false;
}
const possibleNextPositions = [];
for (const variants of rules[rule]) {
let testPositions = [pos];
let good = true;
for (const testRule of variants) {
testPositions = testPositions
.map((testPos) => test(line, testPos, testRule))
.filter((res) => res !== false)
.flat();
if (testPositions.length === 0) {
good = false;
break;
}
}
if (good) {
possibleNextPositions.push(...testPositions);
}
}
if (possibleNextPositions.length > 0) {
return possibleNextPositions;
}
return false;
}
const result = groups[1].split(/\n/).filter((line) => {
const matchSizes = test(line, 0, 0);
return matchSizes !== false && matchSizes.some(matchLength => matchLength === line.length);
}).length;
console.log(result);
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const groups = data.split(/\n{2,}/);
const rules = Array.from({ length: 1024 }, () => false);
for (const r of groups[0].split(/\n/)) {
let [key, variants] = r.split(": ");
key = +key;
if (variants[0] === '"') {
rules[key] = variants[1];
} else {
rules[key] = variants.split(" | ").map((variantRules) => variantRules.split(" ").map(Number));
}
}
function test(line, pos, rule) {
if (typeof rules[rule] === "string") {
return line[pos] === rules[rule] ? pos + 1 : false;
}
for (const variant of rules[rule]) {
let testPos = pos;
let good = true;
for (const testRule of variant) {
testPos = test(line, testPos, testRule);
if (testPos === false) {
good = false;
break;
}
}
if (good) {
return testPos;
}
}
return false;
}
const result = groups[1].split(/\n/).filter((line) => test(line, 0, 0) === line.length).length;
console.log(result);
7 * (7 + (4 + 5) + 4)
2 * 6 + 7 * 3
5 * 5 + 8 * ((7 * 4 + 7 * 5 * 4) * 8 + 2 + 2 + 6 + 9) + 8 + 2
8 * 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) + (6 * 3 * 7 + (3 + 6) * 3) * (6 + 7) + 7
5 + 3 + 6 * ((9 + 6 + 8 + 6 * 5) + 6 * 6 + 5 + 3 + (5 * 9))
9 + (5 + (8 * 8 * 8 * 5 + 8 * 9) * 5) * 7 + 8
(7 + 2 * 7 * 6) + 6 + 9 + 7
7 + 8 + ((5 * 6 * 2) * (4 * 5 * 7 + 8 * 8)) * (9 * 5 + 8 * (5 * 3 * 3 * 5 + 3 * 3) * 9 * 9) * 9 * 6
((8 * 5 + 6 * 6) + 2 + (4 + 2 * 2 * 9 * 7 * 7)) * (7 + 9) + (9 + 3 + 7 * 8 + 4) * 5
5 + (8 * 3 + 9 + 3 * 4 * 3)
let data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let lines = data.split(/\n/);
const re = /\([^()]+\)/;
function calculate(line) {
const parts = line.split(" ");
let res = +parts[0];
for (let i = 1; i < parts.length; i += 2) {
switch (parts[i]) {
case "+":
res += +parts[i + 1];
break;
case "*":
res *= +parts[i + 1];
break;
}
}
return res;
}
const re2 = /\d+\s\+\s\d+/;
function calculate2(line) {
let matches;
while ((matches = re2.exec(line))) {
const partialValue = calculate(matches[0]);
line = line.substr(0, matches.index) + partialValue + line.substr(matches.index + matches[0].length);
}
return calculate(line);
}
let result = 0;
for (let line of lines) {
let matches;
while ((matches = re.exec(line))) {
const partialValue = calculate2(matches[0].substr(1, matches[0].length - 2));
line = line.substr(0, matches.index) + partialValue + line.substr(matches.index + matches[0].length);
}
result += calculate2(line);
}
console.log(result);
let data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let lines = data.split(/\n/);
const re = /\([^()]+\)/;
function calculate(line) {
const parts = line.split(" ");
let res = +parts[0];
for (let i = 1; i < parts.length; i += 2) {
switch (parts[i]) {
case "+":
res += +parts[i + 1];
break;
case "*":
res *= +parts[i + 1];
break;
}
}
return res;
}
let result = 0;
for (let line of lines) {
let matches;
while ((matches = re.exec(line))) {
const partialValue = calculate(matches[0].substr(1, matches[0].length - 2));
line = line.substr(0, matches.index) + partialValue + line.substr(matches.index + matches[0].length);
}
result += calculate(line);
}
console.log(result);
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const lines = data.split(/\n/);
const map = lines.map((line) => [...line]);
function range(start, end) {
return Array.from({ length: end - start + 1 }, (_, i) => start + i);
}
function nestedIterate(bounds, level, coordsBase, source, result) {
if (level < bounds.length) {
for (const i of range(...bounds[level])) {
nestedIterate(bounds, level + 1, [...coordsBase, i], source, result);
}
} else {
const active = source.has(coordsBase.join(","));
const neighbors = nestedNeighbors(0, coordsBase, [], source);
if (neighbors === 3 || (neighbors === 2 && source.has(coordsBase.join(",")))) {
result.add(coordsBase.join(","));
}
}
}
function nestedNeighbors(level, coords, shiftsBase, source) {
if (level === coords.length) {
return !shiftsBase.every((x) => x === 0) && source.has(coords.map((v, i) => v + shiftsBase[i]).join(",")) ? 1 : 0;
} else {
return range(-1, 1).reduce((acc, i) => acc + nestedNeighbors(level + 1, coords, [...shiftsBase, i], source), 0);
}
}
function run(dimensions, iterations) {
let active = new Set(
map
.map((line, x) =>
line.map((v, y) =>
v === "#" ? `${x},${y},${Array.from({ length: dimensions - 2 }, () => 0).join(",")}` : null
)
)
.flat()
.filter(Boolean)
);
const bounds = [[-1, map.length], [-1, map[0].length], ...Array.from({ length: dimensions - 2 }, () => [-1, 1])];
while (iterations > 0) {
iterations--;
const next = new Set();
nestedIterate(bounds, 0, [], active, next);
bounds.forEach((b) => {
b[0]--;
b[1]++;
});
active = next;
}
return active.size;
}
console.log("part 1", run(3, 6));
console.log("part 2", run(4, 6));
...#...#
..##.#.#
###..#..
........
...##.#.
.#.####.
...####.
..##...#
.#.
..#
###
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const lines = data.split(/\n/);
const map = lines.map((line) => [...line]);
// TypeError: Cannot read property '-1' of undefined => increase size!
const size = 11;
const mapSize = size * 2 + map[0].length;
const emptyPlane = Array.from({ length: mapSize }, () =>
Array.from({ length: mapSize }, () =>
Array.from({ length: mapSize }, () =>
"."))
);
let space = [];
let nextSpace = [];
for (let i = 0; i <= mapSize; i++) {
space[i] = JSON.parse(JSON.stringify(emptyPlane));
nextSpace[i] = JSON.parse(JSON.stringify(emptyPlane));
}
for (let i = 0; i < map.length; i++) {
for (let j = 0; j < map[i].length; j++) {
space[size][size][size + i][size + j] = map[i][j];
}
}
function runIteration() {
const bounds = { x: [mapSize, 0], y: [mapSize, 0], z: [mapSize, 0], w: [mapSize, 0] };
for (let i = 0; i < space.length; i++) {
for (let j = 0; j < space[i].length; j++) {
for (let k = 0; k < space[i][j].length; k++) {
let [f, l] = [space[i][j][k].indexOf("#"), space[i][j][k].lastIndexOf("#")];
if (f !== -1) {
bounds.x = [Math.min(bounds.x[0], i), Math.max(bounds.x[1], i)];
bounds.y = [Math.min(bounds.y[0], j), Math.max(bounds.y[1], j)];
bounds.z = [Math.min(bounds.z[0], k), Math.max(bounds.z[1], k)];
bounds.w = [Math.min(bounds.w[0], f), Math.max(bounds.w[1], f)];
}
}
}
}
console.log("bounds >", bounds);
const extra = 5;
for (let x = bounds.x[0] - extra; x < bounds.x[1] + extra; x++) {
for (let y = bounds.y[0] - extra; y < bounds.y[1] + extra; y++) {
for (let z = bounds.z[0] - extra; z < bounds.z[1] + extra; z++) {
for (let w = bounds.w[0] - extra; w < bounds.w[1] + extra; w++) {
let neighbors = 0;
for (const a of [-1, 0, 1]) {
for (const b of [-1, 0, 1]) {
for (const c of [-1, 0, 1]) {
for (const d of [-1, 0, 1]) {
if (a === 0 && b === 0 && c === 0 && d === 0) {
continue;
}
if (space[x + a][y + b][z + c][w + d] === "#") {
neighbors++;
}
}
}
}
}
nextSpace[x][y][z][w] = neighbors === 3 || (neighbors === 2 && space[x][y][z][w] === "#") ? "#" : ".";
}
}
}
}
let t = space;
space = nextSpace;
nextSpace = t;
}
for (let i = 0; i < 6; i++) {
console.log("iteration >", i + 1);
runIteration();
}
const result = space.flat(Infinity).filter((v) => v === "#").length;
console.log(result);
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const lines = data.split(/\n/);
const map = lines.map((line) => [...line]);
const size = 6;
const mapSize = size * 2 + map[0].length;
const emptyPlane = Array.from({ length: mapSize }, () => Array.from({ length: mapSize }, () => "."));
let space = [];
let nextSpace = [];
for (let i = 0; i <= mapSize; i++) {
space[i] = JSON.parse(JSON.stringify(emptyPlane));
nextSpace[i] = JSON.parse(JSON.stringify(emptyPlane));
}
for (let i = 0; i < map.length; i++) {
for (let j = 0; j < map[i].length; j++) {
space[size][size + i][size + j] = map[i][j];
}
}
function runIteration() {
for (let x = 1; x < space.length - 1; x++) {
for (let y = 1; y < space[x].length - 1; y++) {
for (let z = 1; z < space[x][y].length - 1; z++) {
let neighbors = 0;
for (const a of [-1, 0, 1]) {
for (const b of [-1, 0, 1]) {
for (const c of [-1, 0, 1]) {
if (a === 0 && b === 0 && c === 0) {
continue;
}
if (space[x + a][y + b][z + c] === "#") {
neighbors++;
}
}
}
}
nextSpace[x][y][z] = neighbors === 3 || (neighbors === 2 && space[x][y][z] === "#") ? "#" : ".";
}
}
}
let t = space;
space = nextSpace;
nextSpace = t;
}
for (let i = 0; i < 6; i++) {
console.log("iteration >", i + 1);
runIteration();
}
const result = space.flat(Infinity).filter((v) => v === "#").length;
console.log(result);
departure location: 31-221 or 241-952
departure station: 27-780 or 787-957
departure platform: 34-405 or 411-970
departure track: 41-672 or 689-963
departure date: 26-827 or 843-970
departure time: 38-283 or 297-963
arrival location: 50-250 or 259-970
arrival station: 35-878 or 884-950
arrival platform: 49-746 or 772-955
arrival track: 37-457 or 481-954
class: 28-418 or 443-970
duration: 32-722 or 728-970
price: 41-519 or 525-966
route: 50-606 or 628-974
row: 46-92 or 111-967
seat: 41-112 or 135-972
train: 25-540 or 556-957
type: 39-574 or 585-954
wagon: 32-699 or 719-957
zone: 49-71 or 83-951
your ticket:
61,151,137,191,59,163,89,83,71,179,67,149,197,167,181,173,53,139,193,157
nearby tickets:
854,509,243,913,926,411,308,322,69,875,779,371,51,514,367,873,524,645,934,322
358,885,814,800,197,363,388,50,138,820,854,793,89,738,733,306,796,334,387,8
194,897,151,634,178,597,173,791,251,344,306,568,804,145,142,136,573,173,242,508
793,667,856,328,284,596,215,70,873,507,777,948,851,922,694,153,743,250,926,142
219,870,66,945,803,485,325,670,788,186,822,365,451,512,906,443,678,404,312,173
329,572,654,409,804,563,847,330,265,148,875,904,173,411,927,259,945,536,148,920
788,867,405,249,51,454,819,512,306,850,384,337,71,587,316,649,724,389,645,318
271,143,266,447,322,187,650,254,497,155,860,405,655,946,635,862,517,937,729,721
211,856,566,262,156,201,804,735,172,809,870,56,313,801,447,508,622,517,91,807
312,334,928,657,776,276,319,893,163,162,244,206,446,719,568,856,391,831,722,931
250,68,900,183,785,790,270,922,312,914,269,664,305,337,350,904,778,896,68,371
516,650,391,333,604,730,406,779,341,354,447,162,884,53,803,327,861,721,321,328
654,169,947,825,395,4,374,569,518,885,315,563,67,900,195,511,789,739,345,863
909,871,876,874,194,141,151,54,805,381,943,413,556,553,268,305,629,774,179,540
325,299,721,195,772,376,255,699,737,911,567,274,859,186,780,605,556,568,220,162
482,799,304,784,495,136,949,938,140,58,773,152,855,342,884,393,276,445,557,821
534,807,455,221,832,89,658,734,947,945,672,259,456,137,558,557,902,744,382,315
274,775,797,928,940,299,821,653,216,918,163,814,162,63,929,640,321,456,362,257
889,188,454,309,488,457,775,183,166,382,916,262,322,307,716,204,664,411,790,354
366,894,820,567,180,641,146,859,517,497,735,186,310,362,203,381,824,885,718,513
60,813,630,672,88,947,663,405,515,376,51,182,910,380,903,847,318,843,542,572
447,300,897,602,55,918,664,272,623,245,368,411,699,157,735,587,722,641,574,356
890,804,648,369,731,848,394,866,249,884,3,652,212,876,742,892,517,844,667,932
89,524,529,628,324,944,860,449,887,392,112,805,592,181,905,929,323,787,140,54
301,885,646,353,657,820,572,629,666,891,195,378,274,849,729,24,196,875,515,212
709,197,454,827,733,742,91,175,366,572,508,314,170,282,744,316,164,69,178,801
218,457,484,161,800,860,911,492,250,898,455,888,252,54,932,745,393,856,363,519
207,923,189,314,182,483,179,730,174,186,324,481,658,494,294,167,492,854,803,778
800,87,644,61,586,517,645,905,190,573,316,855,150,170,304,389,218,979,388,741
846,482,84,326,798,745,926,725,362,176,340,197,165,572,268,912,481,558,335,632
184,773,536,594,945,494,738,401,649,949,404,135,274,467,817,299,853,740,603,926
843,855,551,798,443,586,481,721,809,340,142,570,774,938,150,485,154,299,822,857
272,782,366,666,658,917,731,509,733,371,639,245,585,312,336,805,111,868,642,511
447,888,511,822,822,940,527,909,274,938,867,984,193,274,527,449,487,888,515,560
304,174,393,1,170,444,568,634,395,481,260,586,729,634,694,55,305,531,501,162
629,585,932,813,572,945,598,369,743,375,178,411,397,648,221,805,648,72,817,698
631,554,698,861,906,380,484,70,739,606,359,519,418,111,728,564,935,208,90,383
90,500,825,163,899,532,392,641,571,484,220,877,530,351,368,918,229,337,367,50
171,341,914,323,737,256,647,939,745,138,908,648,690,857,145,774,855,919,745,605
179,906,324,91,365,322,843,512,857,324,139,69,902,823,332,313,776,254,653,457
668,237,456,573,913,503,140,200,283,449,241,148,148,323,635,734,694,143,815,924
84,195,63,216,356,730,457,67,923,654,269,173,646,400,65,664,641,455,400,294
401,373,418,600,848,659,740,59,400,796,418,449,721,993,644,163,875,444,949,87
628,934,497,657,336,325,398,62,384,150,672,335,785,170,305,241,167,361,502,571
458,858,501,491,271,217,569,162,168,205,335,325,744,380,54,303,884,794,916,646
280,498,728,358,587,171,891,525,935,819,843,398,515,671,729,418,257,512,871,591
288,891,658,311,853,166,510,84,502,937,633,360,143,692,374,92,515,393,60,277
447,153,383,332,260,447,694,299,531,490,636,534,166,137,892,858,817,498,654,784
252,799,885,852,856,774,89,154,333,590,338,504,165,378,696,606,53,728,349,537
221,281,278,179,737,813,522,798,355,283,193,570,921,928,264,745,585,241,351,808
556,244,60,858,452,221,655,595,204,603,899,329,417,449,503,894,192,56,980,587
875,780,350,728,889,527,671,790,589,857,520,936,180,942,818,448,558,664,920,819
355,858,531,976,530,135,55,336,894,150,194,905,379,496,338,299,262,247,511,574
182,637,184,865,7,933,55,826,733,738,820,245,566,655,632,564,529,900,538,342
905,509,943,814,798,819,417,485,327,61,160,168,616,210,788,936,788,365,908,497
50,946,380,527,894,203,267,810,906,198,569,803,888,170,555,694,659,70,371,590
591,815,364,401,766,815,275,596,176,634,370,561,505,181,890,138,452,735,518,147
827,683,52,534,656,510,328,323,52,278,815,930,743,137,53,190,903,741,660,875
167,859,260,725,923,917,922,142,339,388,363,508,914,667,790,862,515,282,212,350
161,882,443,265,517,483,776,650,661,499,887,794,302,516,150,412,485,698,820,185
345,487,810,868,871,190,209,507,327,534,86,856,305,877,931,210,121,886,903,567
843,875,362,560,320,17,869,64,948,561,896,248,778,174,54,947,792,386,630,366
916,904,884,91,867,796,862,153,453,449,397,908,485,264,53,848,141,936,889,551
569,740,646,200,792,649,213,719,787,456,933,414,361,526,340,732,63,135,469,865
359,384,221,87,650,396,241,197,281,947,19,418,527,738,172,486,857,282,262,525
854,603,494,532,160,329,162,537,358,887,415,913,487,531,172,177,393,521,940,698
403,535,738,334,827,530,527,495,229,526,512,340,248,170,866,188,691,820,398,822
654,241,630,740,920,485,532,722,479,348,90,51,87,158,241,389,301,531,496,350
547,143,492,534,871,939,303,306,88,247,268,55,363,312,564,344,740,560,277,150
915,823,90,651,852,416,668,207,905,563,249,308,84,338,216,67,346,112,523,924
825,734,211,581,454,811,340,347,207,532,506,400,660,412,328,573,319,146,735,519
540,875,176,220,355,184,885,854,780,572,83,142,181,387,371,603,925,514,654,9
398,402,561,151,608,565,528,850,136,497,939,386,943,919,938,86,946,329,380,367
390,912,651,811,563,63,20,368,146,187,173,538,658,364,938,264,869,194,573,845
154,331,321,244,189,445,88,873,208,650,312,368,744,932,243,345,792,58,995,637
172,813,638,66,859,161,915,921,928,383,587,644,388,183,868,358,319,681,602,567
399,866,603,207,557,172,366,349,707,812,664,806,454,299,593,779,772,651,502,170
310,777,312,917,406,670,874,187,559,945,58,505,393,393,418,666,158,297,811,664
66,936,270,595,515,844,546,491,638,314,381,177,791,805,264,640,342,693,172,160
521,270,906,822,273,269,448,905,456,304,176,330,249,211,492,780,515,539,802,640
135,790,271,772,935,492,300,875,827,896,282,260,891,915,657,879,505,88,283,303
443,275,414,237,888,596,729,938,161,514,147,275,854,497,652,629,366,910,264,922
370,146,402,649,328,859,789,787,794,665,321,810,174,777,889,396,649,389,494,410
642,629,221,538,400,591,84,983,815,692,267,267,266,179,667,564,566,359,689,159
499,806,219,663,690,536,535,664,83,370,531,640,589,988,654,511,260,666,173,531
670,733,900,881,635,313,281,449,179,695,513,397,915,774,532,209,343,375,889,661
654,300,195,921,434,564,143,861,720,893,875,208,860,777,557,305,62,774,71,139
342,916,201,899,741,357,645,363,146,317,630,380,287,370,773,649,174,358,876,667
875,736,866,60,867,308,159,152,296,872,354,241,56,586,656,513,491,933,213,323
564,632,648,503,190,728,270,272,850,666,348,663,263,201,406,206,697,249,504,164
568,592,738,518,277,456,780,635,883,70,218,411,722,403,175,910,334,413,484,175
827,198,282,832,53,111,414,411,329,388,909,208,602,531,745,734,195,52,502,938
493,324,779,691,882,746,335,891,937,594,527,145,167,729,848,315,54,556,731,746
163,153,806,795,246,398,312,505,52,897,880,780,590,519,70,487,533,53,498,896
220,339,843,212,524,596,151,412,853,865,860,496,360,810,559,357,201,746,491,734
137,822,270,870,852,53,730,761,648,165,481,801,414,370,399,519,944,305,343,814
455,303,137,919,166,336,448,532,531,211,504,773,593,698,905,455,171,995,500,603
851,631,742,789,332,205,818,350,386,495,528,544,361,210,693,827,305,870,689,506
111,163,207,780,595,393,874,692,368,300,10,485,220,450,499,860,398,190,593,211
631,871,733,921,864,599,170,653,361,362,211,746,219,258,313,370,193,321,207,188
897,831,929,868,843,342,901,791,450,537,280,445,511,667,719,389,197,360,398,945
375,906,876,211,457,361,373,557,65,164,170,184,794,728,692,22,503,325,395,142
812,360,395,735,69,825,445,904,356,804,336,858,542,366,171,642,504,903,917,939
156,309,731,695,723,450,940,632,793,262,62,638,728,378,186,446,919,263,247,821
534,215,60,854,730,867,163,927,799,994,932,865,670,269,791,857,347,53,744,664
507,373,844,729,451,264,455,283,923,366,514,212,272,378,307,814,410,662,557,531
606,87,594,289,893,772,511,926,111,939,165,314,413,53,650,936,498,263,309,179
788,153,740,318,856,444,337,183,178,632,50,180,245,490,792,443,163,723,489,510
301,140,324,571,884,508,868,872,301,730,798,484,593,147,259,350,700,810,852,692
416,943,853,178,827,565,279,566,317,892,251,857,817,217,538,271,348,63,264,140
378,346,699,393,903,943,534,880,151,302,414,397,819,933,689,150,893,397,598,58
277,311,645,525,904,141,112,697,347,151,877,376,149,643,358,793,929,773,881,310
855,488,659,250,513,918,64,484,889,488,360,91,51,274,932,735,880,54,737,369
732,89,976,659,299,772,494,185,268,369,891,513,305,342,188,264,86,945,657,732
417,155,392,689,171,186,53,982,931,85,803,147,376,825,499,945,158,719,193,904
206,397,910,722,591,359,315,268,194,356,606,948,728,822,805,198,63,292,791,140
719,664,490,521,562,938,592,404,401,276,316,313,637,803,177,937,453,794,851,282
587,530,400,165,944,873,350,696,389,930,636,260,780,879,383,825,660,655,305,656
890,914,67,299,824,914,360,211,68,186,206,899,705,443,246,361,734,568,846,909
379,976,403,160,939,737,817,777,263,742,416,506,325,111,597,213,887,405,330,507
211,641,930,320,790,719,362,90,792,323,696,519,925,599,92,173,466,592,923,142
495,529,164,911,505,668,357,390,88,731,628,630,170,519,910,416,69,335,667,473
616,746,332,354,905,730,83,59,903,525,313,571,304,925,56,844,643,383,793,909
556,668,601,848,397,175,260,152,727,672,787,664,788,281,369,199,453,573,574,149
216,174,851,71,790,366,785,213,594,640,746,216,656,729,207,157,86,570,176,731
384,606,204,809,199,303,285,779,509,493,52,217,391,451,596,69,885,629,69,929
844,157,61,571,186,184,728,831,646,898,146,902,661,54,391,219,928,62,204,218
271,391,809,504,852,157,986,853,889,413,940,791,137,271,628,221,493,813,932,365
482,190,329,886,921,162,802,914,787,532,452,790,873,210,657,810,595,235,395,323
821,339,199,325,414,150,16,259,566,730,496,799,445,371,249,177,936,511,88,135
903,147,384,485,70,300,268,345,830,631,318,269,787,174,937,500,360,511,90,910
84,322,277,178,280,153,915,191,92,571,327,822,646,65,413,638,540,715,886,245
455,465,316,696,515,112,265,788,533,367,205,193,641,144,282,651,530,190,601,604
218,802,398,351,142,886,357,932,210,638,152,734,90,53,787,343,531,873,17,737
339,90,808,176,322,316,157,598,302,590,327,775,218,151,806,372,165,478,184,299
900,527,921,413,884,573,380,221,482,942,566,778,879,668,144,161,567,208,659,326
365,854,372,112,176,457,416,569,152,871,740,809,652,371,147,90,784,735,851,788
386,388,573,919,277,69,608,803,813,933,905,855,862,337,326,719,733,563,667,450
593,187,825,503,142,187,559,719,175,193,495,849,564,61,524,511,593,737,867,605
199,395,635,487,910,822,944,864,415,661,988,55,153,375,248,187,196,641,819,160
389,878,304,196,904,395,716,628,925,135,145,593,632,495,649,598,209,86,812,859
653,406,798,497,806,556,84,320,202,278,363,787,594,824,305,585,208,192,213,395
55,691,789,88,876,910,594,331,274,862,51,563,875,370,614,900,569,947,172,666
149,736,926,525,16,929,263,52,444,645,935,83,452,347,815,509,806,454,152,868
307,605,265,638,578,797,864,855,414,895,372,495,849,65,318,926,888,528,372,646
189,941,53,531,699,415,342,635,633,244,805,193,794,180,976,339,54,456,196,316
369,322,332,874,468,52,197,518,507,356,489,694,268,796,351,655,206,655,907,244
347,382,161,675,628,745,689,349,662,776,893,787,210,854,411,376,855,510,111,155
322,597,266,874,448,774,306,916,905,416,550,820,249,483,663,378,931,65,793,281
357,149,598,734,873,344,802,943,745,850,218,61,479,873,58,203,268,371,279,348
261,154,947,178,866,360,733,484,195,806,342,312,942,334,252,189,804,221,556,912
245,338,858,532,804,565,892,445,491,889,329,190,264,599,347,567,901,879,321,929
452,1,213,593,847,850,372,898,660,414,738,947,497,485,795,390,245,632,887,814
152,362,445,694,860,272,848,363,2,944,334,926,450,823,943,249,142,318,190,907
188,919,70,513,56,501,148,164,600,401,211,353,219,321,449,521,897,71,792,303
989,592,493,60,369,655,86,263,772,779,181,537,263,180,450,173,370,84,596,344
491,671,934,539,513,163,830,111,314,647,266,798,667,179,325,849,921,356,864,204
331,491,181,921,193,925,644,178,411,532,643,874,68,87,601,555,788,343,890,217
218,945,341,669,802,143,571,140,188,154,899,777,573,88,302,257,444,587,411,908
559,572,365,448,179,930,668,636,58,354,142,7,403,318,387,382,157,388,188,447
302,365,799,547,211,872,729,55,585,904,799,189,922,152,645,925,561,273,313,446
892,213,531,257,539,855,316,242,349,886,242,248,153,822,670,176,586,670,386,310
556,215,50,270,668,484,140,333,867,55,326,944,70,414,454,83,510,626,569,283
179,455,501,670,902,185,536,574,376,900,195,919,982,629,148,884,662,487,845,331
65,794,491,211,322,388,888,343,782,644,135,558,564,263,488,666,335,275,672,206
281,252,887,594,52,203,194,587,606,155,777,843,451,412,851,56,196,194,794,498
812,640,850,777,175,450,918,160,418,165,507,304,532,445,385,373,504,492,499,712
451,153,209,486,153,500,645,328,324,912,979,691,657,490,381,572,199,931,86,336
796,603,908,792,228,525,58,807,363,572,657,66,350,55,331,515,484,775,456,137
280,265,910,174,128,343,356,775,200,372,112,598,447,56,154,516,859,268,265,938
318,628,356,396,452,266,742,906,180,273,797,661,309,327,310,201,888,872,622,320
84,50,311,898,363,320,208,341,358,672,354,995,818,731,199,791,176,810,740,327
494,454,931,721,394,918,507,553,656,167,210,662,730,530,807,695,647,917,863,356
737,193,215,937,53,347,54,381,793,271,632,389,69,526,162,374,699,324,7,333
160,716,746,199,306,629,873,628,163,903,249,585,695,281,403,322,630,261,528,150
327,797,533,660,669,638,924,532,307,53,495,24,396,691,908,185,516,283,720,845
574,216,58,458,202,221,793,164,454,906,457,182,62,696,943,376,300,312,741,919
344,358,691,566,794,316,592,298,361,654,731,189,819,573,493,250,296,894,194,744
385,873,483,249,699,808,736,166,899,789,486,900,777,646,345,148,739,762,658,63
662,923,853,888,256,259,242,87,589,332,821,876,143,516,367,213,91,935,330,794
311,532,802,374,355,526,337,795,662,161,475,646,631,147,561,63,452,194,871,55
216,165,263,561,268,896,283,699,327,495,869,332,527,701,260,729,245,145,698,742
880,731,453,593,334,919,564,639,335,924,905,65,363,942,780,247,733,411,921,719
373,908,601,315,914,656,825,928,351,902,859,734,986,537,639,823,816,634,181,859
500,137,378,918,515,923,411,735,415,819,599,346,146,400,459,899,906,798,859,518
670,622,590,346,793,518,396,571,810,790,168,866,486,948,602,91,221,283,337,849
277,452,731,532,61,266,391,575,503,397,569,825,562,71,298,911,364,175,635,312
265,322,849,816,501,821,910,928,909,15,512,539,205,396,564,516,538,851,851,642
271,55,901,353,313,386,498,408,383,58,412,337,211,572,217,65,804,917,449,518
283,364,187,806,153,891,279,372,350,502,195,338,454,412,538,446,854,864,721,609
778,366,398,596,892,867,412,195,274,812,535,883,921,51,353,340,933,83,61,598
788,404,934,21,246,888,654,539,145,418,150,658,510,91,281,930,788,932,910,282
634,156,798,159,565,487,592,633,390,910,139,854,277,140,585,2,332,513,492,932
380,198,209,696,417,385,50,329,804,745,935,516,591,735,719,694,768,731,508,111
174,734,268,301,854,745,518,615,345,312,244,565,633,506,599,789,773,352,886,178
891,216,324,184,527,449,572,535,378,911,339,659,979,928,560,823,773,318,814,386
565,58,253,415,177,402,86,206,201,192,948,395,648,694,628,899,865,561,401,323
863,340,557,324,136,986,245,167,482,354,596,56,89,374,178,690,242,849,637,346
341,601,416,697,308,777,188,785,150,526,263,903,915,661,897,734,164,497,510,137
92,599,932,895,325,499,199,139,561,191,668,697,511,329,315,815,833,887,813,443
402,396,495,852,386,453,148,84,826,800,263,564,52,606,659,871,698,185,266,522
645,878,352,812,865,776,881,902,262,917,810,205,165,314,606,368,739,644,853,559
517,527,452,807,306,68,181,523,216,628,874,719,605,269,266,155,897,496,817,369
507,927,927,220,378,775,865,380,339,631,366,917,491,643,156,574,391,543,51,515
906,244,787,280,194,806,813,213,523,890,745,671,665,377,336,449,169,565,630,909
259,791,87,329,191,275,540,71,155,176,362,874,217,320,827,517,774,782,398,70
496,820,812,332,706,370,417,857,649,500,308,559,794,394,181,58,777,92,413,383
651,368,357,324,153,244,385,868,70,667,280,372,742,314,556,800,298,578,492,561
160,159,324,902,340,158,455,205,370,875,986,787,193,85,507,650,333,663,843,319
744,391,514,399,936,65,928,197,678,450,586,662,732,632,654,359,640,203,272,443
170,362,136,567,303,596,186,287,183,663,199,811,742,603,338,360,275,918,169,808
402,330,894,481,802,218,199,906,147,492,364,315,697,821,842,150,665,720,728,455
56,184,204,629,586,197,354,519,318,697,694,742,176,338,664,900,140,518,71,880
483,932,861,559,212,503,663,394,863,918,560,887,745,322,881,940,896,60,167,344
629,590,176,650,719,374,152,518,409,930,902,643,266,922,205,375,196,387,875,948
556,63,800,148,78,886,169,697,516,663,158,185,341,889,499,802,167,851,342,871
399,402,946,386,175,640,886,682,633,493,507,371,670,145,892,162,166,198,632,214
560,915,526,498,923,305,667,216,602,864,519,186,924,326,241,905,329,407,824,163
417,0,138,596,495,797,189,64,404,799,670,381,658,912,482,161,651,537,270,354
139,815,530,914,592,318,337,447,449,911,809,184,263,264,781,826,328,731,538,338
302,448,272,163,505,313,691,940,392,878,817,258,800,905,642,738,349,856,264,932
493,307,64,283,86,925,153,815,600,850,511,698,280,520,305,904,493,179,531,367
357,817,648,386,513,806,592,701,735,372,573,564,855,214,366,848,353,816,136,264
201,631,313,145,538,912,447,363,194,796,561,668,777,306,780,488,323,646,251,451
934,66,490,826,314,168,821,603,539,417,735,864,902,895,358,197,998,777,307,525
170,60,858,249,557,197,476,396,416,810,932,737,396,929,602,198,529,657,450,871
68,390,153,452,377,907,231,587,187,332,778,385,112,690,513,874,906,357,380,393
492,822,261,729,548,138,655,283,485,640,497,920,482,897,320,810,183,175,488,698
902,286,366,890,405,603,911,259,499,940,374,271,376,515,694,904,948,653,516,743
595,506,741,630,948,401,915,884,549,386,847,166,914,694,690,569,368,371,777,388
445,245,145,821,633,141,417,948,327,204,147,149,325,507,857,890,73,537,191,380
506,734,638,342,534,55,719,473,369,322,945,894,365,803,889,404,405,179,663,145
383,857,774,404,674,338,350,495,187,884,304,507,862,948,155,207,259,61,651,362
147,338,892,348,629,210,488,243,299,451,162,161,689,657,280,365,581,302,518,137
721,274,947,627,570,892,489,328,221,318,443,557,50,648,250,166,532,186,629,944
539,532,191,984,112,282,801,200,913,336,948,739,815,777,161,50,742,804,159,212
67,343,887,712,273,500,661,141,57,172,567,356,65,515,788,631,693,922,897,373
196,512,803,383,864,802,694,348,417,826,591,8,797,194,191,794,206,862,159,739
489,519,484,399,276,774,270,944,176,173,263,908,522,377,744,593,196,162,416,655
269,384,55,177,142,699,741,225,807,497,908,314,744,586,221,778,395,276,390,151
694,211,643,822,773,348,329,174,269,866,276,242,565,856,167,919,555,343,776,243
class: 0-1 or 4-19
row: 0-5 or 8-19
seat: 0-13 or 16-19
your ticket:
11,12,13
nearby tickets:
3,9,18
15,1,5
5,14,9
class: 1-3 or 5-7
row: 6-11 or 33-44
seat: 13-40 or 45-50
your ticket:
7,1,14
nearby tickets:
7,3,47
40,4,50
55,2,20
38,6,12
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const groups = data.split(/\n{2,}/);
const rules = {};
groups[0].split(/\n/).forEach((rule) => {
let [name, ranges] = rule.split(":");
[name, ranges] = [name.trim(), ranges.split(/ or /)];
rules[name] = rules[name] || [];
ranges.forEach((range) => {
rules[name].push(range.split("-").map((x) => +x.trim()));
});
});
const rulesAll = Object.values(rules);
const tickets = groups[2]
.split(/\n/)
.map((raw, i) => {
if (i === 0) return;
const values = raw.split(",").map(Number);
const good = values.every((value) =>
rulesAll.some((ranges) => ranges.some(([low, high]) => value >= low && value <= high))
);
return good ? values : null;
})
.filter(Boolean);
const mine = groups[1].split(/\n/)[1].split(",").map(Number);
tickets.unshift(mine);
const allFieldNames = Object.keys(rules);
let candidates = Array.from({ length: tickets[0].length }, () => [...allFieldNames]);
tickets.forEach((values) =>
values.forEach((v, ind) => {
candidates[ind] = candidates[ind].filter((name) => rules[name].some(([low, high]) => v >= low && v <= high));
})
);
do {
const found = candidates.filter(options => options.length === 1).map(options => options[0]);
candidates = candidates.map(options => (options.length === 1 ? options : options.filter(name => !found.includes(name))))
if (found.length === allFieldNames.length) break;
} while (true);
const result = candidates.reduce((acc, [name], ind) => name.startsWith("departure") ? acc * mine[ind] : acc, 1)
console.log(result);
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const groups = data.split(/\n{2,}/);
const rules = {};
groups[0].split(/\n/).forEach((rule) => {
let [name, ranges] = rule.split(":");
[name, ranges] = [name.trim(), ranges.split(/ or /)];
rules[name] = rules[name] || [];
ranges.forEach((range) => {
rules[name].push(range.split("-").map((x) => +x.trim()));
});
});
const rulesAll = Object.values(rules);
const tickets = groups[2].split(/\n/);
let sum = 0;
for (let i = 1; i < tickets.length; i++) {
const values = tickets[i].split(",").map(Number);
values.forEach((value) => {
if (!rulesAll.some((ranges) => ranges.some(([low, high]) => value >= low && value <= high))) {
sum += value;
}
});
}
console.log(sum);
6,4,12,1,20,0,16
0,3,6
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const numbers = data.split(/,/).map(Number);
const spokenLast = Array.from({ length: 30000001 }, () => false);
const spokenBeforeLast = Array.from({ length: 30000001 }, () => false);
numbers.forEach((n, i) => (spokenLast[n] = i + 1));
let last = numbers[numbers.length - 1];
for (let turn = numbers.length + 1; turn <= 30000000; turn++) {
let next;
if (last !== 0 && spokenBeforeLast[last] === false) {
next = 0;
} else {
next = spokenLast[last] - spokenBeforeLast[last];
}
spokenBeforeLast[next] = spokenLast[next];
spokenLast[next] = turn;
last = next;
if (turn === 2020) {
console.log("part 1", last);
}
}
console.log("part 2", last)
mask = X11001110001101XX01111X1001X01101111
mem[32163] = 23587
mem[59015] = 3487205
mem[25831] = 33360
mem[62711] = 224797
mem[41307] = 1818
mask = 1010001X010111X00101X1X101X1X01010X0
mem[45083] = 11122937
mem[3480] = 10
mem[46489] = 4658914
mem[10554] = 14018239
mem[46503] = 702809
mem[40599] = 21908484
mask = 1X0X0111001X1X1000X11X11000110011000
mem[27073] = 1598154
mem[56277] = 895
mem[64440] = 121221812
mem[36973] = 803170
mask = 01X0101101011X110X11XX0111111010X011
mem[56954] = 862350849
mem[56448] = 732
mem[57698] = 10805529
mem[9948] = 743476
mem[54082] = 27464
mem[26950] = 13890763
mask = 1010001101XX11X0X10X000X00001X11X00X
mem[4270] = 361512
mem[8603] = 140991
mem[11543] = 11280669
mem[48952] = 13983
mem[23994] = 160573183
mem[21654] = 16471299
mask = 1X0011X0XX10001000X1011XX1X110X10000
mem[54082] = 204797
mem[2442] = 88978843
mem[43594] = 10538
mem[50284] = 1009918861
mem[44229] = 496323
mem[12926] = 20879
mem[49547] = 4018180
mask = 1010X0X1X10111X0X10X0X0000XX10011110
mem[21387] = 1595920
mem[49543] = 426267846
mem[33458] = 232911215
mem[12713] = 36660
mem[25009] = 1531450
mem[160] = 41645
mem[62607] = 29094926
mask = 10X1X1010011X0100X0X0X10X1X0X0111000
mem[41099] = 556
mem[35924] = 165390
mem[4217] = 95434
mem[29377] = 256242448
mem[65298] = 219301
mem[2150] = 513838120
mask = 101000X1X1X1110011XXX000110001X01000
mem[40639] = 152100
mem[47089] = 234875
mem[21980] = 108670
mem[13822] = 351059
mask = 1X1011110111X11100010X100001X00110XX
mem[48992] = 3047
mem[56444] = 201961239
mem[21371] = 204
mem[24671] = 3709
mask = 101X10010X01111011010101000X0001X010
mem[391] = 1771
mem[9761] = 167201870
mem[26810] = 35048
mask = X1100111X001001110X1XX1X1101X110001X
mem[58134] = 62107560
mem[1977] = 431050
mask = XX1101110001X01XX0110111X11011X0X100
mem[61811] = 3322
mem[45400] = 126787711
mem[11959] = 231430790
mem[6529] = 50711275
mask = 1010011100X110X10X010X011X10X001X101
mem[35664] = 4018
mem[51789] = 1147
mem[9164] = 2673
mem[3887] = 6903395
mask = 1XX01101001XX0X10001X100X10X00011011
mem[45588] = 44392
mem[45672] = 130449
mem[10651] = 199
mem[13830] = 609557
mem[16601] = 9139
mem[39047] = 7390
mem[15735] = 2200
mask = X1100111X0011001001X10010100XX0X1100
mem[47001] = 12904
mem[60088] = 78
mem[16541] = 35014846
mem[36988] = 274445
mem[64869] = 721
mask = 111001101001001X1XX1010011X0111X1000
mem[47089] = 484293694
mem[32833] = 1324010
mem[573] = 621230513
mem[30223] = 4408118
mem[21631] = 108617
mask = 101X0101001XX0XX00011X10101X0111010X
mem[818] = 847
mem[7536] = 12876
mem[61097] = 637
mask = X11X01110X0110X01011011X1011XX000101
mem[1160] = 2769715
mem[11521] = 389
mask = 1X0X1X11X0X110110X011101100111001011
mem[18913] = 2463
mem[60014] = 22803235
mem[37134] = 6832
mem[62311] = 85539171
mem[35150] = 1323288
mem[48099] = 1648075
mask = 10001X11X11110100X0101X01001X0001011
mem[48089] = 20
mem[4229] = 1868
mem[51778] = 69531
mem[6163] = 803954017
mask = 10X000110011X0100XX1110X011001X00000
mem[44294] = 12646
mem[17281] = 484
mem[19939] = 492
mask = 0XX0X11100XX1X1100111110X1100X001100
mem[47104] = 5349940
mem[12968] = 633
mem[27118] = 388686386
mem[22054] = 1418
mem[26460] = 3963
mem[27686] = 324058
mem[8678] = 406066094
mask = X1001X1011X0001000X1X0001101XX111X11
mem[34728] = 4733
mem[19944] = 3955289
mem[73] = 2844
mem[5056] = 3114323
mem[61113] = 3346
mask = 0XX011100001101010X1010X101X11XX1000
mem[13529] = 4870075
mem[32746] = 30227
mem[16882] = 5182
mem[58506] = 3864
mask = 101011X1001X100101X10X01000000001101
mem[16135] = 1425313
mem[59176] = 2841231
mem[26460] = 54607
mem[7136] = 12152
mask = 1010X11X001X10X1000X100X000101X1010X
mem[23809] = 464
mem[41790] = 25173055
mem[19793] = 119
mask = XX00101011000010001100000X11001XX00X
mem[34368] = 338852
mem[1953] = 158
mem[33469] = 240238
mem[26651] = 39001013
mem[52523] = 39414
mem[43956] = 4612
mask = 10110X11XX11101100001010101X00000110
mem[50811] = 5113517
mem[53419] = 58853
mem[23534] = 234
mem[27568] = 164916174
mem[16184] = 967
mem[56977] = 14248978
mem[9076] = 338687637
mask = 100011010010000XX0011001X1X110000100
mem[49329] = 7872
mem[62711] = 917801821
mem[20767] = 9510
mem[41836] = 9669
mask = 011001X000X110110X111X01101X0X1110X0
mem[58112] = 8759
mem[59015] = 249132
mem[2696] = 6617538
mem[4055] = 322572
mem[35039] = 14480645
mem[33920] = 1480
mem[24136] = 1072057057
mask = 101011X1001XX0100001X00001X1001X0000
mem[23619] = 1830
mem[23927] = 29452
mem[64905] = 150741701
mem[60932] = 18507
mask = 10X0011X011X10110X0XX100101X00010X01
mem[54685] = 201370
mem[18104] = 2839230
mem[62384] = 7435156
mem[63305] = 444204
mask = 01101X01X0011011001111XX110X000X0XX1
mem[23354] = 50190934
mem[33372] = 2936904
mem[51383] = 965780683
mask = X11001X1000110X100110X011X101XXX0X00
mem[22184] = 43654247
mem[45672] = 88907038
mask = XXX001110011X0XX1001XX01X01010010010
mem[8280] = 44185
mem[53900] = 276378856
mask = 1010011101X1X0110X01001100X01X1100X1
mem[31239] = 200025883
mem[19233] = 22660998
mem[54966] = 459709
mem[21900] = 128456203
mem[27568] = 45525987
mem[18207] = 1317041
mem[4755] = 1465553
mask = 101XX111X01110X10X01X11100010000110X
mem[9761] = 6212379
mem[6490] = 15160
mem[32338] = 454253
mem[21371] = 528675530
mem[57305] = 149
mask = 111X011110011001001X00110X01X1000001
mem[5685] = 876
mem[38670] = 90390560
mask = 10100111X011X0110001001XX01100001XX0
mem[19086] = 153283033
mem[22316] = 982
mem[9660] = 648
mem[38272] = 7464642
mem[23530] = 1073526128
mask = 1X0011X0101X0010001111000100XX1110X0
mem[61800] = 1612
mem[25746] = 12896802
mem[59222] = 402335
mask = 10110111001110XX010101X11000X101X110
mem[5330] = 38096565
mem[48438] = 3312971
mem[50454] = 213
mem[51532] = 35683154
mem[2857] = 162001059
mask = X110X1X0001110110XX1XX01X00X10111010
mem[35384] = 487
mem[8386] = 4875
mem[818] = 25314
mem[9902] = 809
mask = 01101X1000010010X01100X0X00111000101
mem[11465] = 6937
mem[9166] = 8060
mem[30630] = 88490
mem[35039] = 58041908
mask = 1010X11001011X11010XX0X100X11X110101
mem[31189] = 12546611
mem[61841] = 10859
mem[18402] = 3088
mem[46169] = 298
mem[42469] = 10635847
mask = 111X1101X011X01100X11XX101X00X0X1111
mem[9917] = 2696
mem[8987] = 613809199
mem[29213] = 462633736
mem[3210] = 5696
mask = 100010110111101001010100100XX00010XX
mem[22919] = 1049
mem[32274] = 1304246
mem[50722] = 3730781
mem[25729] = 473131
mem[33167] = 255409
mem[954] = 847404
mask = XX1011X0000100100X11011110110XX01010
mem[64019] = 453
mem[33921] = 68992034
mem[11994] = 5228
mask = 0110XX1000010X101011100X11000XX0X101
mem[35244] = 747081
mem[2508] = 46321
mask = 100011110111101001010110X001X0X00X01
mem[33072] = 189542868
mem[22582] = 495965
mem[40368] = 152283413
mem[12558] = 12822
mem[28400] = 130947363
mem[5692] = 50965428
mask = 1X10X11100010011101111000111X10001X0
mem[52617] = 3163
mem[28750] = 3075
mem[11316] = 18721092
mask = 011X1011X101X11X00X110000X1001111011
mem[36035] = 1783926
mem[18174] = 89261
mem[6538] = 434889
mask = 011011100X011010101101X0111001X0100X
mem[25969] = 10970
mem[2186] = 132591
mask = 10101X0X01111110000111X000010101X01X
mem[7956] = 20198
mem[32632] = 9868915
mem[17009] = 616154170
mem[33337] = 1948
mem[28455] = 314
mem[19300] = 437925314
mem[53760] = 9859
mask = X01X0X11010111X0010110111X1X0011X00X
mem[54194] = 60308
mem[55677] = 10602
mem[47982] = 6803
mask = 1010011XX0X110111101111X11101X1X0000
mem[12226] = 26775502
mem[7654] = 1776936
mem[25032] = 9029
mem[63355] = 2515
mem[44393] = 51402
mem[19754] = 538701
mask = 101001X1001110110011001100XXX0001XX1
mem[17878] = 2952
mem[28744] = 1204082
mem[44294] = 167
mem[54229] = 1360071
mem[58603] = 5499
mask = 1010011100X110X11X011XX01110101110XX
mem[19454] = 484695
mem[51120] = 2797
mem[24926] = 2203
mem[62232] = 2795361
mem[4928] = 135948629
mask = 101011X10111XX1X0001011X0000010XX00X
mem[51586] = 51038500
mem[16550] = 10911116
mem[39368] = 31165
mem[49995] = 2240467
mem[20935] = 58885075
mask = 01X00110X0X1101X10111XX1000011000001
mem[60395] = 14487
mem[45597] = 58180
mem[4169] = 20594
mem[28774] = 3668360
mem[46407] = 161563088
mask = 10101X0101011X000100X0000X0010010110
mem[21371] = 8802
mem[32905] = 123119533
mem[4770] = 106677838
mask = 11X0X10100111011X0010011111000X111X0
mem[43143] = 7717
mem[9164] = 377145
mem[39883] = 57
mask = 1011X101001000100001001X10100X0100X1
mem[43124] = 5241585
mem[22122] = 960211786
mem[31235] = 4256719
mem[32461] = 560355
mem[62468] = 18038
mask = 1010011001X1X0X101X101010000X1010001
mem[48307] = 186177048
mem[11940] = 218581
mem[44812] = 72594882
mem[32461] = 794715
mem[40357] = 142382
mem[9612] = 7990
mem[32943] = 2523
mask = X110X11X0001X01X1011XXX011X011001000
mem[4569] = 390383592
mem[8258] = 223605244
mem[14022] = 27470197
mem[44813] = 1232213
mem[15480] = 364141654
mask = 1X1011X100X100110001X001001010101011
mem[21024] = 32037758
mem[38961] = 4442700
mem[60415] = 478809
mem[9366] = 1425318
mem[18104] = 4027612
mem[48952] = 1698
mem[9164] = 3844
mask = 1X10011X100XX001001XX0110110000X01X1
mem[63362] = 961021193
mem[61648] = 10624
mem[8540] = 1240358
mem[22072] = 180594
mem[45028] = 48614278
mem[51941] = 437953
mask = X010001X011X10100101XX0X011101XX0100
mem[28400] = 20048177
mem[38442] = 42972
mem[19202] = 137
mask = 1110X10X0011001X00110000X00X101X101X
mem[45776] = 29115
mem[46228] = 82002990
mask = 0110011100X1X011101101X10100110X11X0
mem[2178] = 1415
mem[7573] = 59211
mem[63355] = 14666328
mask = 111111011X11001100010X1XX100X000111X
mem[36973] = 251101
mem[45549] = 49149
mem[11185] = 11173
mem[36931] = 9105286
mem[34000] = 191861
mem[4112] = 5803908
mem[46851] = 898742
mask = 101010X10101X10011000X0000000001111X
mem[21952] = 58087941
mem[7811] = 310568
mem[12683] = 7296
mem[40986] = 1593
mem[4484] = 217102381
mask = 111X01X00X011011101111001X0011000010
mem[34000] = 42900698
mem[29787] = 486803
mem[16456] = 314970629
mem[2178] = 127921
mem[5330] = 3477920
mem[41836] = 507753704
mem[19939] = 1233
mask = 10X11X1110X1X011010111X0000101011110
mem[42088] = 43182
mem[55372] = 7107
mem[20352] = 707842
mem[38160] = 4365
mask = 10X101XX1011X0X1X0010101X0010100X011
mem[57996] = 825
mem[9164] = 38731
mem[10590] = 1024
mask = 0110XXXX0X011011001111X11010XX0X1000
mem[43004] = 23865126
mem[26521] = 62786105
mem[58508] = 16251607
mem[44915] = 6296
mem[50928] = 15905704
mem[28304] = 6883261
mask = 10000X1X0111101000010001X01110X0110X
mem[38961] = 892
mem[21387] = 654
mem[40691] = 70505975
mask = 011X10110001101XX0111011111XX0X00000
mem[26664] = 190634
mem[41638] = 58433745
mem[33818] = 31913
mask = 1110110000111X110101000X00X0X010001X
mem[21371] = 827
mem[48330] = 554110094
mem[4159] = 13842042
mem[28294] = 10751539
mem[4122] = 3155
mem[56641] = 143543
mask = 10X0110XX010X0XX0X01010010000001100X
mem[42088] = 28605
mem[26003] = 2052146
mem[2810] = 12539132
mem[19177] = 873302110
mem[45682] = 198549
mem[53419] = 12015
mask = 01101100000X0XX00001X110110000111X00
mem[13216] = 42793
mem[32720] = 1691682
mem[61256] = 2824
mask = 10100111XX111X0X01010001001XX1010101
mem[9076] = 33
mem[35540] = 2369998
mem[56213] = 472
mask = 0X0010X011000010X0111000X10100001001
mem[33599] = 292
mem[48557] = 63
mem[61148] = 84252
mem[21382] = 4805
mem[21707] = 599022397
mask = 0110X1110X01X011101100X0110101000001
mem[2445] = 15421
mem[22230] = 421726
mem[31424] = 179041731
mem[64905] = 287710
mem[46793] = 19157238
mask = 10100110X10X00X10101111X11X10100X101
mem[388] = 231948622
mem[21332] = 55144051
mem[25129] = 24447
mem[2442] = 458
mask = 11101100000X001X000101X01010X1011010
mem[19300] = 1121636
mem[48626] = 4127847
mem[37338] = 2796197
mem[22754] = 385623
mem[3467] = 12303468
mask = X11011X0000X0010X0X100010X00111100X0
mem[20168] = 46314
mem[30633] = 7925538
mem[32746] = 7822
mem[37513] = 22922
mem[9366] = 8809
mask = 11100X1100010011101100X0101000011XX1
mem[21371] = 544068236
mem[65001] = 127152183
mem[9112] = 4281720
mem[33376] = 54760474
mem[27066] = 47706947
mem[10567] = 20664563
mask = 10X00X11X01110010X010X11011001010100
mem[41952] = 16538323
mem[44409] = 127
mem[32732] = 88470340
mem[39136] = 1209
mem[52852] = 4841355
mem[57307] = 18767970
mask = 10100X110X111X100101X1X010010X0000X0
mem[60932] = 43059
mem[38522] = 266295
mem[14489] = 257072
mem[56504] = 4614424
mem[47257] = 103706
mem[51586] = 11495785
mask = 101XXXX100111011000X10100011X101010X
mem[954] = 515172677
mem[53419] = 2673
mem[34982] = 737
mem[4945] = 23383
mask = 001001X1001X111100X110X011X0X0000100
mem[55053] = 1024580
mem[55436] = 18571176
mem[22582] = 1874
mem[39435] = 78890341
mem[31752] = 4058
mem[4134] = 1478
mask = 10X0X1110X11101X0X01X10110X01X001X01
mem[24668] = 15910647
mem[35266] = 766999241
mem[57305] = 145297
mem[7722] = 249220230
mem[11092] = 35301
mem[47089] = 5070
mask = 0110011000011011X011XXX0X0001100X0X0
mem[43956] = 78016
mem[3712] = 87083821
mem[36931] = 3887
mem[50618] = 38029
mask = 101001X0010110110101X11X0X01X101010X
mem[4168] = 66691
mem[51120] = 276061
mem[7259] = 8999648
mask = 11000XX1000X001X1X111010010X00000X0X
mem[26947] = 6243
mem[14746] = 166248
mem[59885] = 723042
mem[45400] = 53392
mem[44876] = 749
mem[59029] = 1815
mask = X0101X010011X01X0001X1100011111011X0
mem[6490] = 1443315
mem[9164] = 900
mem[29237] = 868260102
mem[53419] = 893281
mem[61685] = 1369185
mem[4228] = 739257
mem[45110] = 4469052
mask = 11X0011XX0X100111011100X1X0XX1001001
mem[19944] = 33579152
mem[9221] = 53082
mem[12164] = 85657
mem[18757] = 6173
mem[9612] = 38383098
mem[41658] = 441286882
mask = XX10011100X11011X0X111X1XX1X10011000
mem[15544] = 380788
mem[19086] = 141583
mem[34269] = 9666
mem[22877] = 1051665868
mem[32360] = 7
mask = 1X1011110011X011000X1010X0111X1010X1
mem[13883] = 5817
mem[4217] = 15681
mem[8703] = 171924
mask = 000000000000000000000000000000X1001X
mem[42] = 100
mask = 00000000000000000000000000000000X0XX
mem[26] = 1
mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
mem[8] = 11
mem[7] = 101
mem[8] = 0
let data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let lines = data.split(/\n/);
const re1 = /^mask.=.(\w+)$/;
const re2 = /^mem\[(\d+)\].=.(\d+)$/;
let memory = {};
let mask;
function shiftify(values) {
return values.map((v) => v << 1n);
}
function oneify(values) {
return values.map((v) => v | 1n);
}
lines.forEach((line) => {
let m1 = re1.exec(line);
if (m1) {
mask = m1[1];
} else {
let m2 = re2.exec(line);
let base = Number(m2[1]).toString(2).padStart(36, "0");
let v = BigInt(m2[2]);
let addresses = [0n];
[...mask].forEach((digit, index) => {
addresses = shiftify(addresses);
if (digit === "X") {
addresses = [...addresses, ...oneify(addresses)];
} else if (digit === "1" || base[index] === "1") {
addresses = oneify(addresses);
}
});
addresses.forEach((a) => {
memory[a] = v;
});
}
});
const sum = Object.values(memory).reduce((a, v) => a + v, 0n);
console.log(sum.toString());
let data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let lines = data.split(/\n/);
const re1 = /^mask.=.(\w+)$/;
const re2 = /^mem\[(\d+)\].=.(\d+)$/;
let memory = {};
let maskAnd, maskOr;
lines.forEach((line) => {
let m1 = re1.exec(line);
if (m1) {
maskAnd = BigInt(parseInt([...m1[1]].map((x) => (x === "X" || x === "1" ? "1" : "0")).join(""), 2));
maskOr = BigInt(parseInt([...m1[1]].map((x) => (x === "X" || x === "0" ? "0" : "1")).join(""), 2));
} else {
let m2 = re2.exec(line);
let addr = m2[1];
let v = BigInt(m2[2]);
memory[addr] = (v & maskAnd) | maskOr;
}
});
const sum = Object.values(memory).reduce((a, v) => a + v, 0n);
console.log(sum.toString());
1000340
13,x,x,x,x,x,x,37,x,x,x,x,x,401,x,x,x,x,x,x,x,x,x,x,x,x,x,17,x,x,x,x,19,x,x,x,23,x,x,x,x,x,29,x,613,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,41
939
1789,37,47,1889
939
7,13,x,x,59,x,31,19
let data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let lines = data.split(/\n/);
let requirements = lines[1]
.split(",")
.map((v, i) => (v === "x" ? false : { modulo: +v, remainder: (v - (i % v)) % v }))
.filter(Boolean);
// bigger steps first
requirements.sort(({ modulo: a }, { modulo: b }) => b - a);
console.log(requirements);
let val = 0;
let step = 1;
for (let pos = 0; pos < requirements.length; pos++) {
while (val % requirements[pos].modulo !== requirements[pos].remainder) val += step;
step *= requirements[pos].modulo;
}
console.log(val);
let data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let lines = data.split(/\n/);
const wait = +lines[0];
const buses = lines[1]
.split(",")
.map((x) => (x === "x" ? false : +x))
.filter(Boolean);
let bus;
let minWait = wait;
buses.forEach((busInterval) => {
const busWait = busInterval - (wait % busInterval);
if (busWait < minWait) {
bus = busInterval;
minWait = busWait;
}
});
console.log(minWait * bus);
F41
N2
L270
S3
F85
R90
E4
R180
E4
L90
F78
R270
F63
W2
R90
F40
R90
E3
S4
F44
W3
F6
S3
F21
N1
F47
L180
F96
S5
F7
S4
E4
S2
F46
L90
R180
W4
N4
F11
N3
W1
F51
S4
L90
W4
F93
R90
N3
R180
F66
W3
F93
W4
F20
W5
S4
E4
S4
E2
S3
L90
N5
F93
E5
N2
F50
L270
F10
W4
L180
N4
E2
S5
F17
E1
N5
F99
R90
F47
R180
F43
W3
L90
E3
N3
E5
S1
F89
W5
F73
R180
S3
L90
F81
N4
F17
L180
W2
F56
W5
N1
F81
S1
F7
S3
E4
F26
S2
W2
F71
W5
F10
L180
F3
E1
L90
F54
E5
N4
R90
F81
W3
F73
N5
F38
S1
L90
N1
L270
F51
R90
N2
E1
L90
F12
L90
E2
F69
S5
L90
F17
L90
W4
S4
L90
R90
F80
W5
N1
W2
F16
S5
F66
E3
F39
W4
F89
N5
W1
F37
N4
E4
R270
E2
L90
W2
F99
N3
E5
N2
F38
W4
S5
L180
F9
S4
W1
F8
W5
L90
W3
F60
W2
N5
F41
W2
L90
F75
N4
L90
N4
F5
W3
S2
F22
R90
S2
W4
F61
S1
L90
N1
L90
W4
S1
W3
S2
F94
E3
N4
F41
N1
W3
N4
R180
E4
F90
W1
S1
E5
N5
R90
W3
S1
F42
R90
F18
S4
E2
R180
E5
N2
F70
W5
F39
N3
W1
N5
W2
L90
N5
L90
S4
W2
L180
F62
S1
E4
F89
S2
W5
W4
S1
F86
F12
N5
F76
S2
W5
F32
R90
W2
F81
R90
W5
F6
S3
W5
F21
E4
F11
R90
S5
N5
W3
L180
W4
N4
L180
E2
F71
L90
E3
N5
R90
W3
R90
F1
W3
F67
R90
N5
F64
R90
N4
F2
E3
N4
R90
S2
F73
W4
R180
S5
L90
W4
F60
R90
W1
N5
F44
R90
S5
E3
F74
N5
F92
W3
R90
F65
N3
E3
N2
R90
F43
R90
F53
N5
L90
F75
W2
R90
F66
N4
F25
R180
N2
W5
F57
E4
F77
E5
R90
S5
F99
N3
F54
N5
F37
E5
F48
S1
F17
F49
L180
S2
R180
N3
L180
F100
E4
R90
E3
R90
F49
L180
W4
S3
E2
L90
N4
S3
F60
S5
F86
L90
E5
L180
F96
L90
W4
F30
S1
F31
S4
F78
E3
F51
S2
E5
S4
F5
S1
F45
R90
W2
S3
E5
F46
E4
R180
F9
W1
S5
W4
S1
R90
N1
W5
F87
N3
W2
F10
W1
L90
F34
S1
E2
L270
F98
N2
R90
F48
S4
F54
R90
N3
W3
R90
E4
S4
F93
N1
E2
F42
W4
L90
F29
E2
F51
S2
L90
F60
S4
R90
L90
S1
F58
S4
F81
N2
R90
S1
F28
S3
W5
F50
L180
S4
E4
F3
E2
R90
W4
F21
E2
S4
F99
N2
W1
F42
R180
S1
F9
L90
S4
W3
L90
F61
L90
F80
E2
N4
E1
R90
F62
W1
F59
R90
W4
N3
W1
L180
E2
R90
S1
F24
N1
R180
W5
F26
E4
N4
R90
E1
F19
W3
S2
L180
F18
L90
W2
F91
R90
E3
F88
N4
W4
F13
W4
F66
R90
E3
F33
L90
F24
L90
F17
S2
E1
F47
S4
F61
S3
R270
W1
L180
N2
E1
L90
F42
E3
R180
F58
W3
R90
W4
S3
F54
N3
L90
F49
L90
F49
E2
S3
F76
W2
N2
R90
F20
N4
R180
F34
N2
F44
W5
N3
F50
R180
F13
L90
F76
R270
F18
N2
F12
L90
W1
S5
L180
F72
N3
E3
W4
F36
E4
F74
S5
R90
F86
L90
F63
L90
S2
W4
F63
N3
E3
E3
S3
R90
W1
S3
L90
N1
E4
F4
E4
R90
F82
N3
F58
S5
R180
N3
F98
R90
R90
F29
S2
R180
W5
N1
F61
N3
E5
S3
E2
F30
N2
F66
W2
N2
F32
W4
R90
F2
E5
F90
R90
E2
R90
F7
R180
N5
E1
R90
S2
L90
F68
W3
F84
S4
E4
S4
E2
L90
S3
F83
R90
E4
R180
S2
L90
F92
F6
W5
R90
F5
R270
F85
E1
F9
L180
N5
L90
W1
N3
L90
E5
F10
R180
S3
W1
W1
L90
E1
F24
E5
F63
E4
F10
E3
F73
W3
F68
N5
W3
F90
R90
W2
F79
N5
R90
F71
E4
F51
E4
F11
W4
R90
N5
F41
L180
S4
L90
F18
R90
N3
W5
F38
S5
F24
S2
F25
W4
N2
E2
F36
N2
L90
F30
W1
F56
L90
W5
S2
E3
R90
F63
W2
F63
S4
W3
F81
R90
S1
L270
N5
L90
W2
F6
W4
L180
E2
L180
W3
R90
S3
R90
F49
N4
F23
R90
W4
N5
L90
F8
R90
F12
E2
L180
F95
F10
N3
F7
R90
F11
let data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let lines = data.split(/\n/);
let pos = [0, 0];
let wp = [-1, 10];
for (let i = 0; i < lines.length; i++) {
let a = lines[i][0];
let v = +lines[i].substr(1);
if (a === "R") {
a = "L";
v = 360 - v;
}
switch (a) {
case "F":
pos[0] += wp[0] * v;
pos[1] += wp[1] * v;
break;
case "N":
wp[0] -= v;
break;
case "S":
wp[0] += v;
break;
case "E":
wp[1] += v;
break;
case "W":
wp[1] -= v;
break;
case "L":
do {
wp = [-wp[1], wp[0]];
} while ((v -= 90));
break;
}
}
console.log(Math.abs(pos[0]) + Math.abs(pos[1]));
/*
+
2,-1 +
+
+ 1,2
+
+++++++++++++++++++++++++
+
-1,-2 +
+
+
+
*/
let data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let lines = data.split(/\n/);
const dirs = "ESWN";
let pos = [0, 0];
let dir = 0;
for (let i = 0; i < lines.length; i++) {
let a = lines[i][0];
const v = +lines[i].substr(1);
if (a === "F") {
a = dirs[dir];
}
switch (a) {
case "N":
pos[0] -= v;
break;
case "S":
pos[0] += v;
break;
case "E":
pos[1] += v;
break;
case "W":
pos[1] -= v;
break;
case "L":
dir = (dir - v / 90 + 4) % 4;
break;
case "R":
dir = (dir + v / 90) % 4;
break;
}
}
console.log(Math.abs(pos[0]) + Math.abs(pos[1]));
LL.LL.LLLLLL.LLLLLLLLLLLLLLLLLL.LLLLL..LLLLLLL.LLLLLLLLLLLL.LLLL.LLLLL.LL.LLLLLL.LLLL.LLLLL
LLLLL.LLLLLL.LLLLLLLLLLLLL.LLLL.LL.LLLLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLL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LLLLLLL.LLLLLL.LLLLLLL.LLLLL.LLLLL..LLLL.LLLLLLLLLLLLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLL.LLLLL.LLLLLL.LLLL.LLLLLLLL.LLLLLL.LLLL.LLLLL
L.LL.LL.LL
LLLLLLL.LL
L.L.L..L..
LLLL.LL.LL
L.LL.LL.LL
L.LLLLL.LL
..L.L.....
LLLLLLLLLL
L.LLLLLL.L
L.LLLLL.LL
let data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let state = data.split(/\n/);
function get(row, col) {
return state[row] && state[row][col];
}
function replace(line, pos, char) {
return line.slice(0, pos) + char + line.slice(pos + 1);
}
function seatingRound() {
let changed = false;
let nextState = [...state];
for (let i = 0; i < state.length; i++) {
for (let j = 0; j < state[i].length; j++) {
if (state[i][j] === ".") continue;
let occupied = 0;
for (let a of [0, 1, -1]) {
for (let b of [0, 1, -1]) {
if (a === 0 && b === 0) continue;
let aa = a;
let bb = b;
while (get(i + aa, j + bb) === ".") {
aa += a;
bb += b;
}
occupied += get(i + aa, j + bb) === "#";
}
}
if (state[i][j] === "#" && occupied >= 5) {
nextState[i] = replace(nextState[i], j, "L");
changed = true;
}
if (state[i][j] === "L" && occupied === 0) {
nextState[i] = replace(nextState[i], j, "#");
changed = true;
}
}
}
state = nextState;
return changed;
}
while (seatingRound());
const result = state.reduce((acc, row) => acc + [...row].filter((seat) => seat === "#").length, 0);
console.log(result);
let data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let state = data.split(/\n/);
function get(row, col) {
return state[row] && state[row][col];
}
function replace(line, pos, char) {
return line.slice(0, pos) + char + line.slice(pos + 1);
}
function seatingRound() {
let changed = false;
let nextState = [...state];
for (let i = 0; i < state.length; i++) {
for (let j = 0; j < state[i].length; j++) {
if (state[i][j] === ".") continue;
let occupied = 0;
for (let a of [0, 1, -1]) {
for (let b of [0, 1, -1]) {
if (a === 0 && b === 0) continue;
occupied += get(i + a, j + b) === "#";
}
}
if (state[i][j] === "#" && occupied >= 4) {
nextState[i] = replace(nextState[i], j, "L");
changed = true;
}
if (state[i][j] === "L" && occupied === 0) {
nextState[i] = replace(nextState[i], j, "#");
changed = true;
}
}
}
state = nextState;
return changed;
}
while (seatingRound());
const result = state.reduce((acc, row) => acc + [...row].filter((seat) => seat === "#").length, 0);
console.log(result);
8
40
45
93
147
64
90
125
149
145
111
126
9
146
38
97
103
6
122
34
18
35
96
86
116
29
59
118
102
26
66
17
74
94
5
114
128
1
75
47
141
58
65
100
63
12
53
25
106
136
15
82
22
117
2
80
79
139
7
81
129
19
52
87
115
132
140
88
109
62
73
46
24
69
101
110
16
95
148
76
135
142
89
50
72
41
39
42
56
51
57
127
83
121
33
32
23
28
33
18
42
31
14
46
20
48
47
24
23
49
45
19
38
39
11
1
32
25
35
8
17
7
9
4
2
34
10
3
16
10
15
5
1
11
7
19
6
12
4
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const lines = data
.split(/\n/)
.map(Number)
.sort((a, b) => a - b);
// inputs only have differences of 1 and 3
const input = [0, ...lines, lines[lines.length - 1] + 3];
// lengths of found contiguous blocks of values
const contiguous = [];
for (let i = 0; i < input.length - 1; i++) {
if (input[i + 1] - input[i] === 1) {
const start = i;
while (input[i + 1] - input[i] === 1) {
i++;
}
contiguous.push(i - start + 1);
}
}
// variations[i] = 1 + 1 + 2 + ... + (contiguous[i] - 2)
const variations = contiguous.map((v) => Array.from({ length: v - 1 }).reduce((acc, _, i) => acc + i, 1));
// answer is all numbers of possible variations multiplied
console.log(variations.reduce((a, v) => a * v, 1));
let data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let lines = data
.split(/\n/)
.map(Number)
.sort((a, b) => a - b);
let input = [0, ...lines, lines[lines.length - 1] + 3];
let diffs = [0, 0, 0, 0];
for (let i = 0; i < input.length - 1; i++) {
diffs[input[i + 1] - input[i]]++;
}
console.log(diffs[1] * diffs[3]);
17
42
18
39
1
16
13
31
35
32
47
11
40
23
29
30
3
38
43
27
41
9
19
14
46
44
4
20
5
6
10
7
12
17
8
13
25
11
37
49
15
16
22
21
18
23
24
32
19
9
14
26
27
20
76
28
29
36
30
31
33
38
42
34
57
25
58
40
37
44
50
82
109
47
23
71
45
81
75
55
48
54
70
53
61
56
60
69
85
84
94
105
87
67
141
107
123
101
83
76
216
142
103
130
121
109
165
143
136
116
224
187
160
151
150
154
183
226
159
330
177
184
185
192
179
295
212
282
225
230
328
339
266
252
267
362
301
304
305
329
414
429
549
336
363
356
369
391
371
404
641
494
905
455
572
518
621
785
519
705
1424
605
665
734
685
909
888
727
692
973
760
740
1118
974
922
1099
949
1027
1258
1184
2398
1211
1224
1124
2006
1270
1290
1419
2335
1377
1432
1452
1649
2297
1500
1864
2426
2160
1871
2021
2283
2414
2809
3885
2308
2348
2394
2494
3430
3398
2709
2667
2796
5385
3797
4840
3101
4167
3364
3371
3735
6379
3892
5079
9750
4842
4656
4702
4742
5015
7902
4888
5203
5505
8486
5376
5463
5897
14281
8594
6993
6465
8252
6735
7263
10785
8548
8634
9358
16886
9544
9444
16351
9630
9903
11273
10091
13837
18725
10839
20688
11360
18138
13200
17182
26772
13728
15515
22558
15811
19333
17906
17992
18902
20383
29352
35907
37870
19721
46105
59833
20930
22199
24039
25088
24560
32533
26928
80216
40500
29243
39716
38369
48254
33717
37627
36808
41920
38623
53391
40651
43129
43760
44281
44969
46759
47858
46238
48599
51488
53803
70160
56171
69743
62960
83780
73433
95311
82596
85680
75431
109198
115353
79274
84411
121648
89250
155840
90519
91207
104770
158271
130649
100087
105291
152756
210898
277488
132703
136393
152707
148864
218383
154705
181726
159842
169793
163685
226939
173661
179769
180457
230736
457257
232790
314429
451173
252843
205378
237994
347291
269096
333164
285257
467136
620966
303569
314547
318390
386781
455050
449553
390624
360226
353430
556384
385835
733126
474474
618421
798464
443372
458221
687547
906223
554353
572665
663795
1021489
618116
678616
621959
1309506
671820
713656
739265
744054
907783
746061
827904
1865890
1478888
1706247
1579603
1145768
901593
1122016
1012574
2614030
1127018
1172469
1285754
1281911
1647048
1459717
1293779
1483319
2360704
1415874
1567169
1916523
1490115
1573965
1758635
1729497
1914167
2023609
2028611
2294485
3196078
2973434
2694187
3595780
2739638
2775869
2454380
2928959
2575690
2709653
2943036
2899193
3057284
2905989
2983043
3064080
3219612
3248750
5543235
3488132
3643664
4208652
4052220
4323096
4870175
5682674
6193046
5285343
5030070
5164033
5766937
5842229
5474883
5558733
5608846
5805182
5882236
7229085
5889032
6468362
6283692
12661408
12082078
7131796
8673734
9891326
11357079
12725954
11694214
9900245
11317112
10194103
13703804
21217357
26984294
11033616
11083729
11363915
11167579
11414028
12350598
11771268
12172724
12357394
12752054
20846458
17023122
23764626
15805530
18565060
19791571
21314273
23256453
22581607
20094348
21361682
21608131
32268864
26973109
22117345
22497757
23536639
22531494
22938847
36814693
23943992
34710115
31317114
25109448
39725163
37869580
32828652
46475486
37922875
38356631
58290223
41408621
41456030
41702479
45203796
44615102
43725476
44648839
45029251
47640942
56365291
79304138
62256657
46882839
82571714
49053440
62979028
68834924
57938100
93668542
81648351
71185283
80059110
76279506
79765252
82864651
83111100
83158509
85427955
88374315
88340578
91531678
107627867
162503466
138536163
151319606
160952489
95936279
104820939
141049200
106991540
137997210
126773024
129123383
147464789
151244393
159525861
156044758
229389778
162876352
165975751
166269609
168586464
173768533
176714893
179872256
333294394
236751250
200757218
255896407
211812479
202927819
222709303
231593963
342984502
233764564
264770234
318921110
276588172
315570619
307289151
322020509
322314367
399740315
328852103
522856758
397863572
342354997
350483426
356587149
498793366
434521782
403685037
532484579
933315148
414740298
436692383
665298869
685339499
587084601
498534798
541358406
598902539
583877323
622859770
707029466
644334876
672797793
1065039184
763373885
692838423
834555955
698942146
707070575
1197735512
1256675116
871214165
818425335
1578243631
1433458494
851432681
935227181
1039893204
1082412121
1097437337
1121394568
1248387872
1228212199
1462316031
1267194646
1317132669
1365636216
1038347917
1391780569
1803267089
1525495910
1753652516
1558503256
1578284740
1689639500
1858318539
2188346834
1669858016
2135785254
2827952247
4406236987
1975120385
2078241121
2120760038
2286735789
2487030784
2515582518
2266560116
2305542563
3387954684
6381357372
2792000433
2841615006
2917276479
3533623641
3312155772
3136787996
3636744377
3248142756
3359497516
3528176555
4773766573
4053361506
4280662948
4095880423
6305231163
4261856174
4199001159
4387320154
4553295905
5357197524
5147157569
6165419235
6607640272
6887880856
5633615439
10024668852
8440681660
6054064475
7920943795
7412859022
9534477723
6996241893
6776319311
10441384629
7581538061
8294881582
8149241929
9637860472
8940616059
8460857333
8752297064
11800179176
12241255711
11522616759
12035038425
14460300817
12409934750
15145483822
11687679914
15936857952
12830383786
13050306368
13466923497
15291123475
19269217975
13772561204
18578476531
14357857372
15730779990
15876419643
16444123511
16901538993
17213154397
23322795935
24989540256
34515334483
26147980731
24572923127
23557655184
23722718339
24097614664
35010475849
27564099557
24737986282
25880690154
26297307283
26517229865
27239484701
30985715601
43510461680
28130418576
51121754741
30088637362
55969327516
34114693390
44008223068
42202694653
40535950332
46880451119
47280373523
85713156333
47655269848
48130578311
47820333003
49603408493
48835600946
50618676436
96483859612
51035293565
76317388043
53536791984
54647648441
55369903277
72291332015
64203330752
97545015052
112333909063
81935026393
80995144509
74650643722
82738644985
87416401451
87816323855
103190236280
179222504597
125152988989
95475602851
184961416503
96655933949
110017551718
99454277382
104572085549
191959462463
153286476524
108184440425
135642792950
136365047786
119573234029
136494662767
146138357145
155645788231
194223877751
168811468364
157389288707
162067045173
170155046436
287435065314
183291926706
192131536800
194929880233
196110211331
204026362931
201228019498
324457256595
207638717807
255100065613
272007840736
227757674454
243827233375
305797839386
255216026979
326200757071
256067896796
292140450998
360943005164
319456333880
338966514800
358617308205
327544335143
425371073415
451210276944
375423463506
559845327703
387061417033
560897904999
499895130171
405254382429
408866737305
527107906349
462854744786
471584907829
678073642085
482973701433
563283567255
1011055604647
511283923775
810551422629
767351820571
611596784878
792315799462
702967798649
666510849943
686161643348
946906744736
762484880539
875318593677
780677845935
795928154338
814121119734
1071765232372
868109127215
871721482091
1470319619220
934439652615
1406024560444
1238936728400
1197445567123
1046257268688
1174880352133
1495283598111
1635460947786
1739830609306
1667634393139
1278107634821
1352672493291
2250997465155
1428995730482
1808742149227
1630594007754
1543162726474
1939874359587
1576606000273
1610049274072
1682230246949
1917978750779
3304025747338
1806161134706
2212547287436
2109320004748
2541540866799
2221137620821
2626441297605
2398929761979
3794160191629
3084268769527
2854713635094
2630780128112
3614903283933
2707103365303
2781668223773
3111225977431
3368870090069
3119768726747
4880631747611
3549923633659
6575828415402
3186655274345
3292279521021
4459519617578
5910410956868
4890988228521
3915481139454
4321867292184
4330457625569
6230994704178
4620067382800
5029709890091
5892894201204
5974482361841
10851062086978
5337883493415
5412448351885
5488771589076
7912346903821
5901436950520
6297881251776
10594549744641
6412048247768
7751799138599
10232278249052
6478934795366
7102136413799
10223351826773
9889963501295
8237348431638
10394415934820
8941934674984
8652324917753
8950525008369
18875676744526
9649777272891
16263510438863
15138548861967
16404124056352
10750331845300
11313885302405
12776816047142
11390208539596
12199318202296
12313485198288
14535229683414
12890983043134
13514184661567
13581071209165
15420869470350
15339484845437
25354649064721
16889673349391
17179283106622
20436666633934
28049414344981
27794332595948
17602849926122
19700856853669
20400109118191
22540760316025
23641314888434
33950851295501
22064217147705
28920556054602
47895409380746
33213482681076
24512803400584
29378601308918
25204468241422
26405167704701
33291092161325
27095255870732
42957498990843
51759816769422
59618650385777
34068956456013
34492523275513
38002959044313
42241617169694
37303706779791
39667067073827
88997251694695
40100965971860
42464326265896
44604977463730
52561870943036
46577020548289
49159473018437
79868112709614
86023818090478
49717271642006
135574272242984
51609635946123
60386348032057
let data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let lines = data.split(/\n/).map(Number);
const range = 25;
let f;
for (let x = range; x < lines.length; x++) {
const test = lines.slice(x - range, x).sort((a, b) => a - b);
while (test.length >= 2) {
if (test[0] + test[test.length - 1] === lines[x]) break;
if (test[0] + test[test.length - 1] < lines[x]) test.shift();
if (test[0] + test[test.length - 1] > lines[x]) test.pop();
}
if (test.length < 2) {
f = lines[x];
break;
}
}
const window = [0, 1];
while (window[1] < lines.length) {
const slice = lines.slice(...window);
const sum = slice.reduce((a, v) => a + v, 0);
if (sum === f) return console.log(Math.min(...slice) + Math.max(...slice));
if (sum < f) window[1]++;
if (sum > f) window[0]++;
if (window[1] === window[0]) window[1]++;
}
let data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let lines = data.split(/\n/).map(Number);
const range = 25;
for (let x = range; x < lines.length; x++) {
const test = lines.slice(x - range, x).sort((a, b) => a - b);
while (test.length >= 2) {
if (test[0] + test[test.length - 1] === lines[x]) break;
if (test[0] + test[test.length - 1] < lines[x]) test.shift();
if (test[0] + test[test.length - 1] > lines[x]) test.pop();
}
if (test.length < 2) return console.log(lines[x]);
}
let data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let lines = data.split(/\n/);
const vm = {
nop: (acc, pos) => [acc, pos + 1],
jmp: (acc, pos, val) => [acc, pos + Number(val)],
acc: (acc, pos, val) => [acc + Number(val), pos + 1],
brk: () => {
throw false;
},
ret: (acc) => {
throw acc;
},
};
function run(prog) {
let pos = 0;
let acc = 0;
prog.push("ret");
do {
if (pos >= prog.length) throw false;
const prev = pos;
const [ins, val] = prog[pos].split(" ");
[acc, pos] = vm[ins](acc, pos, val);
prog[prev] = "brk";
} while (true);
}
lines.forEach((line, i) => {
const t = [...lines];
const [ins, val] = line.split(" ");
if (!["jmp", "nop"].includes(ins)) return;
t[i] = ["jmp", "nop"][+(ins === "jmp")] + " " + val;
try {
run(t);
} catch (e) {
if (e !== false) return console.log(e);
}
});
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const lines = data.split(/\n/);
let pos = 0;
let acc = 0;
const vm = {
nop: (acc, pos) => [acc, pos + 1],
jmp: (acc, pos, val) => [acc, pos + Number(val)],
acc: (acc, pos, val) => [acc + Number(val), pos + 1],
brk: () => {
throw false;
},
};
try {
do {
const [ins, val] = lines[pos].split(" ");
const prev = pos;
[acc, pos] = vm[ins](acc, pos, val);
lines[prev] = "brk";
} while (true);
} catch (e) {
console.log(acc);
}
acc +8
acc +37
jmp +328
jmp +574
nop +321
acc +17
jmp +450
acc +46
acc -15
nop -5
acc +48
jmp +358
jmp +29
acc +23
jmp +11
acc -14
jmp +561
acc +9
acc +17
jmp +136
jmp +394
acc +24
acc +37
acc +19
jmp +241
acc +38
acc +44
acc -5
jmp -8
acc +50
acc -9
acc +5
jmp +424
acc -15
nop +93
acc -1
jmp +414
jmp +548
jmp +454
acc +39
jmp +490
jmp +103
jmp +214
acc +37
jmp +164
acc +34
jmp +362
acc +24
acc +32
jmp +375
jmp +500
acc +23
nop -1
nop +463
jmp +108
acc +14
jmp +106
acc +20
nop +298
nop -39
jmp +321
jmp +1
jmp +515
nop +6
acc +3
acc +18
acc -10
jmp +353
jmp -43
jmp +1
acc +0
acc +7
jmp +507
nop +396
jmp -62
acc +30
acc -13
jmp +466
jmp +137
acc +6
jmp +211
acc +33
acc +4
jmp +269
acc +50
nop -65
acc +18
jmp -54
jmp -68
nop +38
acc -6
jmp +165
nop +342
acc +31
acc +30
nop +465
jmp +273
acc +35
jmp +201
acc +13
acc +18
acc +28
acc +40
jmp +244
nop -63
acc +25
acc +16
jmp -32
acc -6
acc +17
jmp +298
jmp +358
acc +28
jmp +1
acc +27
jmp +204
jmp +4
acc +17
acc +47
jmp +83
acc -14
jmp -42
acc +0
acc +14
acc -9
acc +13
jmp +108
acc +1
acc -8
acc +44
jmp +420
acc -1
acc +24
jmp +101
acc -10
nop +493
nop +140
acc -12
jmp -134
acc +21
nop +385
acc +38
acc +4
jmp +349
jmp +225
nop +432
jmp +421
acc +33
acc +11
jmp +462
acc +21
acc +11
acc +5
acc +15
jmp +260
nop +308
acc -6
acc -14
acc -3
jmp +178
nop -33
jmp +80
acc +33
acc -11
acc +39
jmp +145
jmp +64
acc +49
acc +47
acc +13
jmp +331
acc +1
jmp -10
acc +37
nop +276
jmp +259
acc +16
acc +38
jmp +121
acc +11
nop +301
acc +2
jmp +94
nop +186
nop +255
jmp -106
nop -171
acc +35
acc -1
acc +44
jmp +129
acc +27
acc -6
jmp -150
acc +12
acc +19
acc +15
jmp +247
nop +309
nop +429
nop -131
jmp +410
jmp +187
acc -4
acc +45
acc +3
acc -16
jmp -166
acc +41
jmp +276
acc -2
nop +23
acc +11
acc +19
jmp +271
acc +35
jmp +136
acc +46
acc -9
nop +189
jmp +1
jmp -201
acc -11
nop -190
acc +9
jmp +175
acc +25
acc +10
acc -12
jmp -50
acc +44
jmp +132
acc -14
jmp -71
acc +47
acc -9
jmp -125
jmp +1
acc -5
acc +47
jmp +184
nop -26
jmp -48
acc +24
acc +33
acc +38
jmp +246
acc +38
nop -114
nop +42
nop +131
jmp +256
acc +48
nop -126
acc +20
jmp +189
acc +39
nop +206
acc +2
acc +8
jmp +279
acc +31
acc +8
acc -14
jmp +221
acc -14
acc +4
jmp +161
jmp +188
acc +13
acc +50
acc -10
acc +42
jmp -169
acc +25
jmp +292
acc +40
jmp +53
acc -1
acc +29
acc +20
jmp -240
jmp +4
acc +28
acc -9
jmp -158
jmp +305
acc +47
nop -250
nop -155
jmp +321
acc +24
acc +48
acc +41
acc -2
jmp -61
acc +40
jmp +1
jmp -209
jmp +231
acc +28
acc +13
jmp +45
nop +147
nop -35
jmp -36
acc +33
acc +12
acc +7
jmp -62
nop +1
acc +3
acc +18
jmp +320
acc +9
acc -19
acc -3
acc +11
jmp -151
acc +11
acc +31
jmp -296
acc -10
acc +21
jmp +104
acc +46
acc +22
jmp +29
jmp +1
jmp +187
acc -7
acc +28
acc +1
acc +8
jmp +74
acc +45
jmp +114
acc +21
nop -204
jmp -327
acc +5
acc +36
jmp -148
jmp +285
acc +2
jmp +1
jmp +197
jmp +271
nop +137
nop +279
acc +41
jmp +1
acc +43
jmp +214
nop -307
jmp +245
acc -13
nop -210
jmp +56
acc -7
acc +18
acc +12
jmp +88
acc -18
acc +32
jmp +1
jmp -199
acc -9
jmp -317
acc -17
acc +2
nop +202
acc +20
jmp +227
jmp -44
jmp -28
acc -9
acc +12
acc -10
acc +3
jmp -115
acc +19
acc +22
jmp -340
acc -7
acc +7
acc +32
acc -11
jmp -19
acc +7
jmp +1
acc +14
jmp -89
acc +39
jmp +75
acc +32
nop +215
acc +40
jmp +83
jmp +204
acc +1
acc +29
acc -2
jmp +70
acc -15
acc -1
nop -381
jmp +27
nop +65
acc +40
jmp -299
acc +16
acc +13
jmp -24
acc +26
jmp -20
acc +36
acc +10
nop -274
jmp -394
jmp +165
acc +33
acc -7
jmp -419
jmp -386
nop -298
nop -406
jmp -108
acc +10
acc +46
acc +0
nop +50
jmp -343
jmp -5
acc -8
jmp -233
acc +13
acc +43
jmp +87
jmp +24
acc +35
nop -421
acc +46
jmp -35
jmp -55
acc +24
acc +17
acc -16
acc +26
jmp +128
nop -11
jmp +167
acc +25
acc +14
nop -59
jmp -108
acc +50
acc -18
acc +45
jmp -390
acc -2
acc +16
jmp +123
acc +41
jmp -242
nop -338
acc -15
acc +44
jmp -227
nop +159
acc +10
jmp -298
jmp -338
acc +10
acc +9
acc +24
nop -173
jmp -330
nop -453
acc +2
jmp +1
jmp -138
acc +21
acc +50
jmp -451
acc +19
acc -7
nop -454
jmp +85
acc -11
acc +19
jmp -394
acc +27
acc +4
acc +42
jmp -491
acc +36
acc +33
acc -5
acc +39
jmp -425
acc +46
acc +10
jmp -452
acc -1
acc +36
jmp -339
acc +26
acc +24
acc -8
jmp -376
acc +35
jmp +1
acc -4
acc +24
jmp -71
acc +46
acc -4
acc -8
jmp -289
acc +11
acc +32
acc +32
acc +26
jmp -214
acc +46
nop -485
acc +16
jmp -287
jmp -95
acc +36
nop -376
acc -13
jmp -406
nop -278
acc +22
acc +21
acc +33
jmp -463
jmp +11
nop -346
acc +33
jmp -86
acc -17
nop -350
nop +83
jmp -299
acc +31
acc +28
jmp -516
acc -13
acc +15
acc -19
jmp -338
acc +21
acc +10
jmp -309
jmp -473
nop -150
jmp +44
acc +45
acc +41
acc +41
nop -139
jmp -448
jmp +1
jmp -103
nop -433
acc +1
acc -1
acc +0
jmp -289
jmp -531
jmp -134
acc +21
acc +14
jmp -51
jmp -520
jmp -275
acc +6
acc +42
jmp -256
acc +26
acc +36
jmp -17
acc +11
acc +32
nop -244
acc +42
jmp -546
jmp -565
acc +31
acc -12
nop -496
jmp -531
acc +25
nop -196
acc -18
acc +10
jmp -22
nop -231
jmp -41
jmp -555
acc +37
acc -14
acc +43
jmp -462
acc -11
acc +43
acc +15
jmp -229
acc +0
acc +20
acc -18
nop -3
jmp -240
acc +37
jmp -520
nop -424
jmp +1
jmp +1
nop -158
jmp -19
acc +0
nop -591
acc +29
nop -192
jmp -24
nop -55
jmp -364
acc +5
acc +33
jmp -176
acc +25
acc +6
acc +21
acc +16
jmp +1
let data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
let lines = data.split(/\n/);
const vm = {
nop: (acc, pos) => [acc, pos + 1],
jmp: (acc, pos, val) => [acc, pos + Number(val)],
acc: (acc, pos, val) => [acc + Number(val), pos + 1],
};
function test(testLines) {
let pos = 0;
let acc = 0;
let was = Array.from({ length: testLines.length }, () => false);
do {
if (pos === testLines.length) return acc;
if (pos > testLines.length || was[pos]) return false;
was[pos] = true;
const [ins, val] = testLines[pos].split(" ");
[acc, pos] = vm[ins](acc, pos, val);
} while (true);
}
lines.forEach((line, i) => {
const t = [...lines];
const [ins, val] = line.split(" ");
switch (ins) {
case "jmp":
t[i] = "nop";
break;
case "nop":
t[i] = "jmp " + val;
break;
default:
return;
}
let result = test(t);
if (result !== false) return console.log(result);
});
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const lines = data.split(/\n/);
let pos = 0;
let acc = 0;
let was = Array.from({ length: lines.length }, () => false);
const vm = {
nop: (acc, pos) => [acc, pos + 1],
jmp: (acc, pos, val) => [acc, pos + Number(val)],
acc: (acc, pos, val) => [acc + Number(val), pos + 1],
};
do {
if (was[pos]) return console.log(acc);
was[pos] = true;
const [ins, val] = lines[pos].split(" ");
[acc, pos] = vm[ins](acc, pos, val);
} while (true);
wavy bronze bags contain 5 striped gold bags, 5 light tomato bags.
drab indigo bags contain 4 pale bronze bags, 2 mirrored lavender bags.
pale olive bags contain 3 faded bronze bags, 5 wavy orange bags, 3 clear black bags, 1 striped purple bag.
faded white bags contain 5 vibrant violet bags, 4 light teal bags.
mirrored magenta bags contain 2 muted cyan bags, 3 vibrant crimson bags.
dull purple bags contain 1 striped fuchsia bag.
dull lime bags contain 2 posh green bags, 2 muted gold bags, 1 light bronze bag, 2 pale teal bags.
pale indigo bags contain 5 drab blue bags, 3 posh fuchsia bags.
dull lavender bags contain 5 plaid orange bags.
pale teal bags contain 2 dark silver bags, 1 faded silver bag, 1 dotted brown bag.
clear lime bags contain 5 bright crimson bags, 2 dim chartreuse bags.
faded coral bags contain 5 muted silver bags, 5 plaid gold bags.
dull blue bags contain 4 mirrored turquoise bags.
muted salmon bags contain 2 dim chartreuse bags, 2 mirrored tan bags, 2 plaid tomato bags, 3 clear cyan bags.
dim orange bags contain 5 light purple bags.
posh chartreuse bags contain 5 pale red bags, 2 pale gold bags, 3 dotted brown bags.
pale red bags contain 4 mirrored green bags.
dotted turquoise bags contain 2 posh maroon bags, 1 striped silver bag, 2 pale blue bags, 4 drab lime bags.
light blue bags contain 4 muted fuchsia bags.
shiny teal bags contain 5 faded brown bags.
drab gold bags contain 1 dull purple bag, 2 wavy magenta bags, 1 faded red bag, 1 wavy silver bag.
plaid maroon bags contain 3 dark gold bags, 2 dim silver bags, 1 vibrant plum bag.
shiny beige bags contain 3 mirrored bronze bags.
wavy chartreuse bags contain 1 muted bronze bag.
posh teal bags contain 5 dark cyan bags, 5 posh green bags.
faded chartreuse bags contain 3 muted yellow bags.
clear crimson bags contain 2 striped gold bags, 4 bright crimson bags, 1 dull red bag.
plaid turquoise bags contain 3 wavy crimson bags, 5 light gold bags, 2 mirrored olive bags, 1 posh white bag.
dotted gray bags contain 4 posh teal bags, 5 dotted lime bags, 4 clear fuchsia bags.
drab purple bags contain 2 shiny blue bags.
dim black bags contain 3 vibrant white bags.
muted cyan bags contain 2 light bronze bags.
dim aqua bags contain 5 striped brown bags, 3 bright white bags, 1 dark purple bag, 3 wavy aqua bags.
light violet bags contain 4 wavy lavender bags.
light tan bags contain 4 dim cyan bags.
muted chartreuse bags contain 4 drab blue bags, 4 dim yellow bags, 4 vibrant red bags, 2 faded violet bags.
faded purple bags contain 4 clear salmon bags, 4 pale white bags, 3 dim indigo bags, 2 bright fuchsia bags.
shiny violet bags contain 1 dim aqua bag, 3 shiny coral bags.
dim green bags contain 1 pale cyan bag, 2 faded purple bags, 1 light gold bag, 5 shiny fuchsia bags.
dotted teal bags contain 4 muted lavender bags.
drab green bags contain 3 pale aqua bags, 5 striped chartreuse bags, 5 mirrored gray bags, 2 mirrored salmon bags.
pale orange bags contain 3 bright teal bags, 2 dark green bags.
wavy lavender bags contain 3 wavy aqua bags, 5 dull purple bags.
shiny gray bags contain 1 light blue bag, 3 drab beige bags, 1 vibrant blue bag.
dull yellow bags contain 5 dark teal bags, 1 dull teal bag.
muted lime bags contain 3 shiny aqua bags.
pale yellow bags contain 3 dull silver bags, 1 shiny green bag, 5 muted silver bags.
dark salmon bags contain 3 mirrored fuchsia bags, 1 light blue bag, 4 mirrored green bags.
faded fuchsia bags contain 5 dotted lavender bags, 4 clear bronze bags, 3 muted white bags.
dark blue bags contain 3 mirrored orange bags.
striped red bags contain 3 dotted lime bags, 4 mirrored orange bags, 2 dim yellow bags, 1 dull silver bag.
faded lime bags contain 2 faded beige bags, 5 dark coral bags, 5 dark maroon bags.
dim salmon bags contain 5 dark indigo bags, 4 dull aqua bags.
light plum bags contain 2 dotted tan bags, 5 mirrored plum bags.
pale tomato bags contain 1 posh violet bag.
light olive bags contain 1 clear blue bag, 5 clear purple bags.
faded bronze bags contain 1 mirrored lime bag.
mirrored orange bags contain 3 shiny green bags, 2 vibrant white bags, 1 dull black bag.
vibrant purple bags contain 2 dull gray bags, 2 dark magenta bags, 4 wavy green bags.
dull green bags contain 5 shiny tomato bags.
plaid magenta bags contain 4 dim plum bags, 2 dull tomato bags, 2 drab violet bags.
bright magenta bags contain 5 dim plum bags, 3 mirrored teal bags, 5 dim red bags, 2 plaid maroon bags.
dark beige bags contain 4 shiny aqua bags.
dark orange bags contain 1 dark violet bag, 4 mirrored green bags.
dim violet bags contain 5 shiny yellow bags, 1 dark lime bag, 2 vibrant coral bags, 3 mirrored turquoise bags.
light cyan bags contain 2 mirrored gold bags.
striped turquoise bags contain 3 mirrored aqua bags, 3 faded violet bags, 1 plaid maroon bag.
dull plum bags contain 4 posh gold bags, 3 light salmon bags, 4 dull silver bags, 1 dark salmon bag.
posh green bags contain 3 clear blue bags, 3 dull silver bags, 2 drab turquoise bags, 2 light silver bags.
faded salmon bags contain 2 faded black bags.
dull violet bags contain 2 plaid lavender bags, 4 plaid crimson bags, 1 bright crimson bag, 4 striped bronze bags.
posh coral bags contain 4 plaid gold bags.
shiny green bags contain no other bags.
mirrored turquoise bags contain 3 vibrant crimson bags, 2 faded turquoise bags, 4 muted aqua bags, 4 drab lavender bags.
dim yellow bags contain 1 dark tomato bag, 4 mirrored orange bags, 1 bright blue bag, 1 wavy red bag.
vibrant orange bags contain 1 drab turquoise bag.
muted black bags contain 3 dotted purple bags.
faded brown bags contain 2 vibrant white bags, 1 dim silver bag.
posh gold bags contain 5 bright green bags.
pale salmon bags contain 3 faded gray bags, 2 posh tan bags, 5 pale cyan bags.
dull brown bags contain 5 drab lime bags, 1 plaid lavender bag.
dull fuchsia bags contain 4 dim silver bags, 1 shiny gold bag, 1 faded violet bag.
mirrored chartreuse bags contain 3 dark gray bags, 3 muted teal bags, 2 mirrored black bags.
dotted gold bags contain 1 mirrored red bag, 4 dim indigo bags, 4 faded cyan bags.
striped tomato bags contain 5 dull gray bags, 4 light tomato bags.
clear lavender bags contain 1 clear coral bag, 4 wavy turquoise bags, 5 dark maroon bags.
dark chartreuse bags contain 2 clear beige bags.
dark brown bags contain 4 bright white bags, 4 faded turquoise bags, 1 clear black bag, 1 wavy lavender bag.
clear gold bags contain 5 vibrant gray bags, 5 wavy white bags.
plaid cyan bags contain 5 dotted salmon bags, 5 vibrant cyan bags, 3 dark black bags, 4 shiny aqua bags.
dark tomato bags contain 2 muted white bags, 5 bright silver bags, 5 posh red bags, 3 dull black bags.
pale bronze bags contain 2 wavy coral bags, 2 drab blue bags, 5 clear purple bags, 4 vibrant blue bags.
clear tan bags contain 1 dull black bag, 2 drab fuchsia bags.
dotted aqua bags contain 5 striped brown bags, 3 vibrant bronze bags, 1 wavy brown bag, 2 plaid red bags.
wavy blue bags contain 1 dark aqua bag, 2 striped purple bags, 2 dark coral bags, 5 plaid red bags.
clear indigo bags contain 4 shiny gold bags, 4 bright blue bags.
mirrored plum bags contain 3 striped gold bags, 5 dim fuchsia bags.
faded tomato bags contain 2 wavy green bags.
dark cyan bags contain 1 dim yellow bag, 4 dark silver bags, 5 drab aqua bags.
striped blue bags contain 4 dull magenta bags, 5 plaid maroon bags, 5 plaid crimson bags.
posh turquoise bags contain 2 pale silver bags.
vibrant lavender bags contain 3 faded plum bags, 1 dark tomato bag.
mirrored lime bags contain 1 faded lavender bag, 5 light silver bags.
drab fuchsia bags contain 5 faded lavender bags, 2 muted silver bags, 3 pale indigo bags.
clear olive bags contain 1 dotted green bag.
dim gray bags contain 4 pale tan bags.
light aqua bags contain 5 mirrored lime bags, 2 dim white bags, 1 dark gold bag, 5 faded black bags.
striped lavender bags contain 4 faded green bags.
plaid brown bags contain 4 vibrant turquoise bags, 1 posh violet bag.
bright lavender bags contain 1 faded black bag, 2 posh tomato bags.
pale purple bags contain 4 light silver bags, 4 plaid gold bags.
posh gray bags contain 1 drab lime bag, 2 dark chartreuse bags, 3 dim fuchsia bags, 3 vibrant red bags.
dull turquoise bags contain 5 vibrant fuchsia bags.
shiny plum bags contain 2 striped fuchsia bags, 5 dark red bags.
posh purple bags contain 4 vibrant gray bags, 1 plaid turquoise bag.
muted teal bags contain 3 mirrored lime bags, 5 shiny tomato bags.
shiny silver bags contain 2 clear cyan bags.
bright green bags contain 4 plaid gray bags, 4 dull black bags, 1 clear blue bag, 1 dull red bag.
clear orange bags contain 5 bright plum bags, 2 shiny red bags, 2 vibrant lavender bags.
muted coral bags contain 5 dark brown bags.
posh lime bags contain 2 dim silver bags.
clear maroon bags contain 4 dotted chartreuse bags.
dim red bags contain 5 muted yellow bags, 3 dark violet bags, 3 light tomato bags.
faded red bags contain 1 striped lavender bag, 3 mirrored gray bags.
bright maroon bags contain 2 posh crimson bags.
muted gold bags contain 5 vibrant tan bags.
dotted lavender bags contain 3 shiny green bags, 2 muted fuchsia bags.
shiny magenta bags contain 4 shiny red bags.
clear salmon bags contain 2 faded fuchsia bags, 4 posh crimson bags, 2 wavy fuchsia bags.
dim lavender bags contain 1 posh magenta bag, 1 drab silver bag.
vibrant aqua bags contain 5 dim teal bags, 5 bright blue bags.
dim maroon bags contain 4 light white bags.
striped tan bags contain 1 light aqua bag, 4 dim chartreuse bags.
drab lime bags contain 2 dim blue bags.
mirrored purple bags contain 5 striped tomato bags, 3 wavy tomato bags.
dark violet bags contain 2 vibrant red bags, 1 dim silver bag.
wavy beige bags contain 2 muted violet bags, 1 bright white bag, 5 vibrant red bags, 1 faded lavender bag.
dim gold bags contain 1 wavy turquoise bag, 5 dim plum bags, 3 shiny silver bags.
dotted magenta bags contain 2 vibrant white bags, 4 vibrant tan bags, 2 muted orange bags.
plaid coral bags contain 5 dark brown bags, 2 posh coral bags, 2 dull crimson bags, 4 vibrant violet bags.
wavy silver bags contain 2 dim chartreuse bags, 2 bright crimson bags, 4 mirrored green bags, 5 striped turquoise bags.
mirrored olive bags contain 1 light purple bag, 4 muted silver bags.
muted violet bags contain no other bags.
bright red bags contain 1 muted red bag, 2 posh indigo bags, 3 shiny purple bags, 4 clear salmon bags.
dotted fuchsia bags contain 3 muted gold bags, 3 mirrored yellow bags, 1 plaid maroon bag, 1 dull purple bag.
mirrored cyan bags contain 1 muted fuchsia bag, 2 pale lavender bags.
plaid beige bags contain 4 dotted violet bags, 1 mirrored salmon bag, 5 mirrored plum bags.
pale magenta bags contain 3 vibrant indigo bags, 4 drab blue bags, 1 wavy violet bag.
dim olive bags contain 2 drab indigo bags, 4 clear turquoise bags, 2 plaid tan bags.
wavy fuchsia bags contain 1 muted silver bag, 3 striped red bags.
drab olive bags contain 3 striped turquoise bags, 5 dim brown bags, 4 vibrant crimson bags.
dull crimson bags contain 1 dotted tomato bag, 5 light silver bags, 1 dull black bag, 1 mirrored orange bag.
faded beige bags contain 4 mirrored aqua bags, 2 faded plum bags, 3 posh aqua bags, 2 muted violet bags.
posh black bags contain 1 muted chartreuse bag, 2 faded salmon bags.
shiny turquoise bags contain 3 striped plum bags, 4 dull purple bags, 3 pale red bags, 4 dim brown bags.
bright beige bags contain 3 drab white bags, 2 plaid olive bags.
dim silver bags contain 5 mirrored yellow bags, 5 dark gray bags.
muted bronze bags contain 3 pale black bags.
clear black bags contain 4 dark gray bags, 2 drab magenta bags.
posh violet bags contain 1 muted gray bag, 4 dark blue bags.
light gold bags contain 1 mirrored silver bag.
faded magenta bags contain 3 light gray bags.
dotted crimson bags contain 3 clear crimson bags, 4 bright white bags, 5 bright green bags.
striped coral bags contain 1 pale beige bag.
drab brown bags contain 3 mirrored white bags, 4 clear crimson bags.
clear tomato bags contain 5 dim magenta bags, 3 dull magenta bags, 4 dim turquoise bags.
pale maroon bags contain 5 dark aqua bags.
dark silver bags contain 2 bright blue bags, 2 pale yellow bags, 3 mirrored lime bags.
striped purple bags contain 2 wavy red bags.
wavy violet bags contain 2 dark gold bags, 1 plaid red bag.
clear coral bags contain 5 clear violet bags, 2 clear crimson bags, 4 vibrant white bags.
striped brown bags contain 2 posh red bags.
pale brown bags contain 5 posh cyan bags, 3 clear salmon bags.
dotted red bags contain 3 wavy aqua bags, 1 mirrored bronze bag, 2 dark silver bags, 1 pale tan bag.
faded plum bags contain 2 striped brown bags.
posh olive bags contain 5 muted white bags, 3 mirrored tomato bags, 4 dull olive bags.
faded violet bags contain 1 mirrored yellow bag, 1 vibrant white bag, 3 mirrored orange bags.
light silver bags contain no other bags.
striped aqua bags contain 4 dull gray bags, 5 dark lavender bags, 4 shiny cyan bags.
vibrant fuchsia bags contain 3 drab beige bags, 2 dim beige bags.
shiny white bags contain 2 posh aqua bags, 4 faded gray bags.
muted green bags contain 4 dim coral bags, 4 wavy turquoise bags, 3 clear lime bags, 1 striped black bag.
dim tan bags contain 5 pale chartreuse bags, 1 mirrored cyan bag, 1 light maroon bag, 5 muted chartreuse bags.
faded olive bags contain 1 light salmon bag, 2 wavy blue bags, 3 drab lavender bags.
drab cyan bags contain 1 faded cyan bag.
muted magenta bags contain 3 clear purple bags, 4 pale aqua bags.
wavy maroon bags contain 1 wavy bronze bag.
faded green bags contain 2 mirrored gray bags, 4 wavy gray bags, 3 dark salmon bags.
wavy purple bags contain 2 posh red bags, 5 bright white bags.
vibrant black bags contain 4 plaid silver bags.
wavy white bags contain 3 dim chartreuse bags.
dark magenta bags contain 2 dim lime bags.
dull tan bags contain 1 posh red bag, 2 shiny green bags, 3 pale yellow bags, 2 faded salmon bags.
pale lavender bags contain 4 dim red bags.
mirrored black bags contain 1 plaid gray bag.
posh silver bags contain 4 wavy purple bags, 4 vibrant blue bags, 1 dull fuchsia bag, 5 faded brown bags.
plaid blue bags contain 5 pale yellow bags, 5 vibrant salmon bags, 4 wavy cyan bags.
plaid purple bags contain 1 bright bronze bag, 2 vibrant blue bags, 1 shiny salmon bag, 5 faded magenta bags.
striped orange bags contain 5 mirrored black bags, 2 clear cyan bags, 2 wavy yellow bags, 5 dim aqua bags.
pale chartreuse bags contain 1 shiny blue bag, 4 shiny tomato bags, 1 bright lime bag, 5 dim blue bags.
mirrored lavender bags contain 4 shiny gold bags, 3 dull crimson bags.
bright blue bags contain 5 mirrored yellow bags, 5 light silver bags.
dull teal bags contain 1 drab aqua bag, 4 dim coral bags, 3 muted yellow bags.
mirrored indigo bags contain 3 dim brown bags.
dotted coral bags contain 1 light lime bag, 5 mirrored indigo bags, 5 wavy indigo bags.
light white bags contain 1 vibrant coral bag.
faded yellow bags contain 3 light white bags.
plaid black bags contain 5 dim indigo bags, 2 dull olive bags.
dim cyan bags contain 5 shiny blue bags, 5 drab black bags.
plaid tomato bags contain 4 dull crimson bags.
bright yellow bags contain 5 mirrored green bags, 2 dim yellow bags.
clear magenta bags contain 4 dim cyan bags, 4 bright orange bags.
vibrant olive bags contain 4 pale turquoise bags.
dull orange bags contain 1 mirrored yellow bag, 2 clear purple bags.
drab tan bags contain 5 dotted salmon bags.
dark black bags contain 4 bright magenta bags, 3 striped lime bags.
faded teal bags contain 2 dark red bags, 3 plaid teal bags, 2 vibrant red bags.
posh magenta bags contain 3 dark tan bags.
dim indigo bags contain 2 dotted brown bags, 2 dull tan bags, 1 dark indigo bag, 3 dim fuchsia bags.
vibrant red bags contain 2 muted fuchsia bags, 5 bright blue bags.
mirrored tomato bags contain 4 shiny tomato bags, 1 dull orange bag.
dark lime bags contain 3 plaid tan bags.
vibrant silver bags contain 5 pale yellow bags, 2 faded lime bags.
faded tan bags contain 4 pale violet bags, 3 muted gold bags, 3 vibrant red bags.
pale beige bags contain 5 dark blue bags, 1 drab white bag, 3 faded crimson bags, 3 dull gray bags.
wavy teal bags contain 1 posh maroon bag, 2 clear violet bags.
bright turquoise bags contain 2 pale aqua bags.
striped chartreuse bags contain 2 striped tomato bags, 2 dark red bags, 3 posh coral bags, 4 mirrored fuchsia bags.
wavy yellow bags contain 5 striped gold bags, 1 striped maroon bag, 4 dull fuchsia bags, 3 shiny gold bags.
dull salmon bags contain 5 plaid cyan bags.
shiny bronze bags contain 5 pale indigo bags, 1 mirrored orange bag, 1 vibrant bronze bag.
dull red bags contain 5 wavy beige bags.
dotted green bags contain 2 clear indigo bags.
plaid fuchsia bags contain 2 vibrant salmon bags, 1 light silver bag.
striped crimson bags contain 3 dotted bronze bags, 2 shiny coral bags.
mirrored teal bags contain 2 clear purple bags, 5 muted yellow bags.
plaid gray bags contain 1 muted silver bag, 2 pale yellow bags.
pale gray bags contain 5 drab lavender bags, 4 mirrored aqua bags.
clear plum bags contain 3 dull blue bags, 5 clear chartreuse bags.
light salmon bags contain 3 bright silver bags, 3 clear black bags, 1 bright crimson bag, 4 bright white bags.
dark tan bags contain 4 shiny bronze bags, 1 mirrored chartreuse bag, 5 bright silver bags, 4 clear black bags.
vibrant bronze bags contain 4 vibrant teal bags, 3 dark silver bags, 2 mirrored green bags.
light teal bags contain 5 drab blue bags, 4 clear red bags, 1 drab aqua bag.
plaid plum bags contain 2 faded yellow bags, 5 striped maroon bags.
dull silver bags contain no other bags.
mirrored beige bags contain 4 dotted blue bags, 3 clear indigo bags.
pale aqua bags contain 2 shiny blue bags, 1 dim red bag, 1 posh teal bag.
wavy orange bags contain 5 pale red bags, 3 wavy purple bags, 5 shiny aqua bags.
dotted silver bags contain 3 dim beige bags, 5 striped silver bags, 2 pale brown bags, 1 muted white bag.
dotted orange bags contain 3 plaid violet bags, 1 pale salmon bag, 4 dull bronze bags.
vibrant turquoise bags contain 2 drab silver bags.
clear cyan bags contain 5 shiny green bags, 4 dark chartreuse bags.
dotted tan bags contain 4 vibrant blue bags.
mirrored brown bags contain 3 faded olive bags.
bright bronze bags contain 4 light yellow bags, 1 mirrored orange bag, 3 light silver bags.
plaid lavender bags contain 1 posh violet bag, 4 muted yellow bags, 3 bright gold bags.
bright coral bags contain 3 posh teal bags, 5 wavy purple bags.
faded aqua bags contain 1 faded black bag.
posh yellow bags contain 1 vibrant violet bag, 4 drab blue bags.
plaid red bags contain 3 mirrored orange bags, 2 muted gold bags, 5 faded black bags.
muted silver bags contain no other bags.
bright black bags contain 4 plaid teal bags, 2 wavy lavender bags, 5 posh tan bags.
dim white bags contain 1 mirrored orange bag, 1 dotted lavender bag, 4 muted yellow bags.
posh brown bags contain 2 dark purple bags, 3 plaid lavender bags.
dotted plum bags contain 4 bright teal bags.
plaid silver bags contain 1 dark coral bag, 5 shiny coral bags.
vibrant chartreuse bags contain 1 shiny magenta bag, 4 muted crimson bags, 2 dull tan bags, 2 striped cyan bags.
drab red bags contain 3 drab aqua bags, 1 dark yellow bag, 2 mirrored gray bags.
dull gold bags contain 5 dark coral bags, 2 dark blue bags, 5 bright orange bags, 5 muted lavender bags.
dull cyan bags contain 3 faded tan bags, 3 muted teal bags, 1 muted orange bag, 4 striped bronze bags.
drab lavender bags contain 4 faded lavender bags, 2 light blue bags, 3 posh fuchsia bags.
bright tan bags contain 1 faded tan bag, 4 vibrant coral bags.
shiny indigo bags contain 2 dark silver bags.
dark turquoise bags contain 3 dark purple bags.
drab magenta bags contain 2 bright white bags, 5 muted silver bags, 5 posh red bags.
vibrant coral bags contain 5 plaid orange bags, 5 pale gold bags, 1 dark yellow bag, 4 dim yellow bags.
clear yellow bags contain 5 plaid lavender bags, 1 vibrant coral bag, 1 posh coral bag, 4 vibrant brown bags.
bright indigo bags contain 5 bright black bags, 4 plaid crimson bags, 2 dim fuchsia bags.
plaid violet bags contain 1 drab crimson bag, 4 dotted cyan bags, 4 shiny green bags.
dim blue bags contain 1 dotted lavender bag, 5 clear purple bags.
vibrant plum bags contain no other bags.
clear bronze bags contain 5 dull tan bags.
striped green bags contain 1 wavy bronze bag, 4 light silver bags, 3 posh aqua bags.
mirrored gold bags contain 1 pale tan bag, 1 shiny bronze bag, 5 dim beige bags.
plaid lime bags contain 1 mirrored fuchsia bag.
posh salmon bags contain 3 dim brown bags, 4 mirrored silver bags.
wavy coral bags contain 4 light orange bags, 4 shiny orange bags, 4 dark blue bags, 1 bright yellow bag.
clear teal bags contain 2 posh white bags.
mirrored aqua bags contain no other bags.
light green bags contain 3 posh chartreuse bags, 3 shiny red bags, 1 dim silver bag, 4 faded crimson bags.
muted aqua bags contain 1 shiny green bag, 3 shiny gold bags, 5 light blue bags.
posh maroon bags contain 5 pale yellow bags, 2 dim red bags, 5 wavy beige bags, 1 bright blue bag.
faded gray bags contain 3 faded orange bags.
plaid orange bags contain 1 dark brown bag, 4 dotted salmon bags, 4 clear violet bags, 1 clear indigo bag.
striped indigo bags contain 2 muted gray bags, 4 dim brown bags, 4 clear black bags.
bright salmon bags contain 3 dark tomato bags, 5 pale tomato bags, 2 dim magenta bags, 3 dotted cyan bags.
wavy aqua bags contain 5 dark violet bags, 4 dim yellow bags, 2 dark blue bags.
plaid olive bags contain 2 dull red bags.
bright teal bags contain 2 shiny green bags.
vibrant beige bags contain 5 dark teal bags, 3 plaid turquoise bags.
dull chartreuse bags contain 4 pale blue bags, 2 drab violet bags, 2 dotted beige bags.
dotted brown bags contain 5 posh lime bags, 5 muted gray bags.
muted plum bags contain 4 clear violet bags, 2 shiny green bags, 1 dotted fuchsia bag.
muted blue bags contain 5 drab tomato bags.
dull bronze bags contain 3 bright magenta bags, 3 muted purple bags, 2 striped red bags, 1 clear gray bag.
shiny red bags contain 1 shiny green bag, 2 muted white bags.
shiny purple bags contain 1 wavy red bag, 1 drab magenta bag.
plaid tan bags contain 4 wavy bronze bags, 3 clear fuchsia bags.
drab orange bags contain 4 shiny salmon bags.
faded gold bags contain 2 pale bronze bags, 5 striped plum bags, 2 muted violet bags.
light magenta bags contain 5 bright tomato bags.
light yellow bags contain 5 posh gold bags, 5 faded lime bags.
mirrored maroon bags contain 5 posh plum bags, 5 pale gold bags, 5 vibrant maroon bags.
dark coral bags contain 3 shiny red bags, 3 posh fuchsia bags, 1 striped gold bag.
dark teal bags contain 2 striped red bags, 2 striped turquoise bags.
dark purple bags contain 1 clear blue bag.
plaid gold bags contain 2 posh teal bags, 4 dim yellow bags, 3 pale red bags.
dim coral bags contain 4 dull plum bags, 5 faded violet bags.
vibrant salmon bags contain 4 plaid silver bags, 5 faded green bags, 5 clear indigo bags.
bright brown bags contain 1 shiny plum bag, 1 dim magenta bag, 5 shiny turquoise bags, 4 dim yellow bags.
vibrant crimson bags contain 4 pale red bags.
posh crimson bags contain 4 plaid olive bags, 3 plaid orange bags.
faded indigo bags contain 1 clear red bag.
wavy red bags contain 1 vibrant plum bag, 5 dotted lime bags.
faded lavender bags contain 1 mirrored yellow bag, 4 vibrant plum bags.
drab silver bags contain 3 dark gray bags, 3 muted fuchsia bags.
pale black bags contain 4 posh white bags, 3 pale blue bags, 5 shiny plum bags, 1 posh salmon bag.
posh tan bags contain 2 mirrored yellow bags, 3 striped bronze bags.
drab aqua bags contain 1 dull silver bag, 1 dark tomato bag.
wavy plum bags contain 3 clear violet bags.
shiny crimson bags contain 5 drab lime bags.
shiny lime bags contain 5 vibrant teal bags, 5 faded black bags, 1 dull black bag, 5 clear purple bags.
dark maroon bags contain 3 dull black bags.
faded blue bags contain 4 bright blue bags, 1 mirrored lime bag, 5 shiny green bags.
clear turquoise bags contain 2 dim silver bags, 4 muted coral bags, 3 clear bronze bags, 4 light orange bags.
striped yellow bags contain 1 dotted brown bag, 2 plaid coral bags.
pale coral bags contain 5 faded crimson bags, 3 drab tan bags, 2 dotted olive bags, 3 shiny blue bags.
wavy black bags contain 1 mirrored yellow bag.
muted indigo bags contain 3 dim coral bags, 1 shiny lavender bag, 1 drab aqua bag, 5 faded blue bags.
dull aqua bags contain 4 dark gray bags, 3 mirrored orange bags, 3 pale red bags, 4 drab turquoise bags.
striped violet bags contain 4 posh red bags, 3 wavy violet bags, 1 pale aqua bag.
bright crimson bags contain 4 bright silver bags, 4 wavy beige bags, 5 striped fuchsia bags.
wavy tomato bags contain 4 dim turquoise bags, 2 mirrored chartreuse bags.
pale fuchsia bags contain 3 pale violet bags, 4 shiny turquoise bags, 1 drab white bag, 3 mirrored green bags.
mirrored gray bags contain 4 dim chartreuse bags, 4 bright chartreuse bags.
mirrored bronze bags contain 4 drab olive bags, 5 drab white bags, 2 clear crimson bags, 1 dim aqua bag.
light crimson bags contain 5 plaid teal bags.
light lime bags contain 2 faded salmon bags, 5 dim indigo bags, 1 dotted lime bag, 5 striped green bags.
clear silver bags contain 4 vibrant cyan bags, 2 dotted olive bags.
striped magenta bags contain 5 faded aqua bags.
dark gray bags contain 2 bright white bags, 2 posh red bags.
pale crimson bags contain 4 dark teal bags.
dotted cyan bags contain 1 striped brown bag, 3 shiny green bags, 1 dull crimson bag, 1 bright crimson bag.
clear violet bags contain 5 drab magenta bags, 2 striped brown bags, 2 striped fuchsia bags, 5 mirrored aqua bags.
drab white bags contain 3 bright blue bags, 3 wavy purple bags, 4 mirrored lime bags, 4 dotted salmon bags.
plaid yellow bags contain 3 dull violet bags, 1 striped turquoise bag.
clear gray bags contain 1 dim chartreuse bag, 2 dotted chartreuse bags, 5 dull plum bags.
pale cyan bags contain 2 striped tomato bags.
pale turquoise bags contain 1 faded coral bag.
shiny aqua bags contain 3 dotted magenta bags.
dull tomato bags contain 5 vibrant indigo bags.
light orange bags contain 1 posh lime bag, 5 bright yellow bags, 5 faded magenta bags, 2 pale beige bags.
dull white bags contain 1 dotted lavender bag, 1 pale beige bag, 5 posh black bags, 3 light silver bags.
drab yellow bags contain 2 shiny orange bags, 4 faded green bags.
bright gray bags contain 3 muted red bags, 4 dull orange bags, 5 mirrored yellow bags.
dim crimson bags contain 2 bright white bags.
dim fuchsia bags contain 1 light silver bag.
dim bronze bags contain 4 light blue bags, 1 light gray bag, 3 faded crimson bags, 2 posh tan bags.
muted tan bags contain 1 dark blue bag, 5 clear crimson bags, 1 striped silver bag.
dark gold bags contain 4 posh red bags, 5 drab blue bags.
light tomato bags contain 3 wavy olive bags, 3 dark maroon bags, 5 shiny gold bags, 3 muted yellow bags.
shiny fuchsia bags contain 2 faded lime bags, 5 drab beige bags.
striped gold bags contain 1 dim blue bag.
light lavender bags contain 3 wavy fuchsia bags, 2 shiny salmon bags.
shiny tomato bags contain 1 striped turquoise bag, 5 light gray bags, 2 dark tomato bags, 1 dull aqua bag.
dotted indigo bags contain 2 dark indigo bags.
shiny blue bags contain 2 shiny red bags, 2 posh salmon bags, 5 dotted tomato bags.
vibrant blue bags contain 2 plaid teal bags, 3 dim silver bags.
pale blue bags contain 1 striped tomato bag.
dull magenta bags contain 1 striped chartreuse bag, 2 dark silver bags.
drab blue bags contain 2 dark gray bags, 4 dotted lime bags, 3 shiny green bags, 3 wavy olive bags.
light bronze bags contain 3 wavy silver bags, 1 wavy coral bag, 4 faded green bags.
muted beige bags contain 4 dull coral bags, 3 dim chartreuse bags, 3 pale blue bags, 2 plaid lavender bags.
bright plum bags contain 1 plaid indigo bag, 2 dark purple bags, 5 dark indigo bags, 5 vibrant crimson bags.
plaid salmon bags contain 3 dark gold bags, 1 dotted lavender bag, 5 wavy red bags, 1 bright olive bag.
dim lime bags contain 4 wavy brown bags, 5 wavy fuchsia bags, 1 dark tomato bag.
dark aqua bags contain 5 wavy beige bags, 3 pale yellow bags, 2 bright white bags, 2 muted violet bags.
light coral bags contain 4 dotted coral bags, 1 pale indigo bag, 3 dull brown bags, 4 plaid white bags.
clear purple bags contain 4 dark aqua bags, 5 vibrant white bags.
striped plum bags contain 2 plaid gold bags, 1 dim silver bag.
mirrored yellow bags contain no other bags.
shiny olive bags contain 5 dotted lavender bags.
pale gold bags contain 2 plaid orange bags, 5 bright yellow bags.
dotted violet bags contain 3 dim orange bags.
mirrored blue bags contain 2 mirrored coral bags, 5 posh green bags, 1 wavy teal bag.
plaid green bags contain 3 wavy red bags.
wavy cyan bags contain 4 dull crimson bags, 2 dim chartreuse bags.
dull beige bags contain 1 shiny black bag, 5 posh green bags, 2 pale gray bags, 3 posh gray bags.
dark indigo bags contain 3 drab plum bags.
striped black bags contain 1 bright green bag, 4 muted silver bags, 1 plaid crimson bag.
plaid indigo bags contain 2 drab lime bags, 1 faded plum bag, 5 bright yellow bags.
shiny maroon bags contain 3 dark cyan bags, 1 dotted chartreuse bag.
dotted lime bags contain 5 light silver bags, 1 shiny green bag, 1 mirrored aqua bag.
posh beige bags contain 4 mirrored aqua bags, 2 mirrored black bags, 3 wavy blue bags, 1 plaid cyan bag.
bright cyan bags contain 4 mirrored aqua bags, 5 dotted fuchsia bags, 1 wavy plum bag.
plaid white bags contain 5 vibrant lime bags, 5 dull magenta bags, 2 pale blue bags, 5 plaid cyan bags.
drab maroon bags contain 1 clear violet bag, 5 posh green bags, 3 dotted bronze bags, 2 dark silver bags.
plaid bronze bags contain 4 shiny plum bags, 5 dim brown bags.
dim magenta bags contain 2 muted chartreuse bags, 4 wavy lavender bags.
clear blue bags contain 1 muted yellow bag, 5 muted fuchsia bags.
dotted salmon bags contain 3 muted silver bags, 4 mirrored yellow bags, 1 vibrant red bag.
posh orange bags contain 2 pale violet bags, 3 posh maroon bags.
mirrored red bags contain 5 posh crimson bags, 1 light green bag, 1 striped black bag, 2 dark black bags.
vibrant green bags contain 5 faded fuchsia bags, 4 faded orange bags, 3 clear turquoise bags.
pale violet bags contain 2 bright teal bags, 5 faded crimson bags.
clear brown bags contain 3 posh coral bags, 2 vibrant maroon bags, 1 drab olive bag, 5 mirrored cyan bags.
vibrant violet bags contain 4 dark purple bags, 4 striped olive bags, 5 faded fuchsia bags.
pale green bags contain 4 posh green bags, 2 striped lime bags.
light maroon bags contain 3 dull cyan bags, 4 dim red bags.
wavy salmon bags contain 4 drab lavender bags, 5 bright gray bags.
dotted yellow bags contain 4 mirrored black bags, 1 dim plum bag.
drab crimson bags contain 5 striped fuchsia bags, 1 pale indigo bag.
vibrant tomato bags contain 1 dotted lime bag, 1 dotted green bag, 5 light teal bags, 2 light indigo bags.
wavy olive bags contain 4 muted white bags, 5 muted silver bags.
wavy lime bags contain 2 vibrant bronze bags, 3 vibrant gray bags.
striped lime bags contain 1 faded brown bag, 3 vibrant red bags, 4 mirrored gray bags.
wavy crimson bags contain 1 striped silver bag, 5 pale magenta bags, 1 wavy gray bag, 5 vibrant plum bags.
wavy indigo bags contain 3 shiny cyan bags, 5 light orange bags.
posh fuchsia bags contain 5 dark aqua bags, 1 muted white bag, 2 shiny green bags, 5 dull black bags.
striped maroon bags contain 5 striped fuchsia bags, 5 muted chartreuse bags, 5 dark purple bags, 4 shiny gold bags.
dull gray bags contain 5 dark tomato bags, 3 shiny purple bags, 5 faded violet bags, 1 dull silver bag.
dotted bronze bags contain 4 dark blue bags.
muted olive bags contain 4 mirrored lavender bags.
dark plum bags contain 2 faded lime bags.
drab tomato bags contain 2 posh chartreuse bags, 4 vibrant indigo bags.
plaid teal bags contain 5 dark gray bags, 4 light silver bags.
drab teal bags contain 3 pale salmon bags.
wavy brown bags contain 5 plaid red bags.
mirrored violet bags contain 4 vibrant brown bags, 4 dull crimson bags, 4 shiny violet bags, 1 dim magenta bag.
faded silver bags contain 2 bright teal bags, 2 shiny green bags.
dark bronze bags contain 3 muted violet bags, 5 plaid cyan bags.
dim tomato bags contain 3 dotted black bags.
muted tomato bags contain 3 posh crimson bags, 2 muted yellow bags.
bright orange bags contain 3 pale silver bags.
dotted tomato bags contain 5 posh tan bags, 3 dotted lavender bags.
bright white bags contain no other bags.
dotted white bags contain 1 dim yellow bag, 5 plaid orange bags, 1 bright chartreuse bag.
vibrant teal bags contain 2 vibrant red bags.
light beige bags contain 5 wavy crimson bags, 5 mirrored aqua bags, 5 light yellow bags.
drab black bags contain 2 dotted lime bags, 2 mirrored fuchsia bags.
drab salmon bags contain 5 pale indigo bags.
bright silver bags contain 4 wavy red bags.
pale lime bags contain 1 dark indigo bag.
dark red bags contain 4 vibrant white bags, 1 dark violet bag.
dull coral bags contain 3 dark indigo bags, 3 bright plum bags, 2 wavy silver bags, 4 clear bronze bags.
vibrant white bags contain 1 dotted lime bag, 3 mirrored aqua bags.
posh red bags contain no other bags.
muted fuchsia bags contain 1 bright blue bag.
bright aqua bags contain 1 shiny blue bag, 4 dark red bags, 2 wavy fuchsia bags, 4 pale gold bags.
vibrant magenta bags contain 5 clear red bags.
light indigo bags contain 4 dark red bags, 3 vibrant salmon bags.
mirrored tan bags contain 5 muted teal bags.
dim teal bags contain 1 drab lime bag, 2 drab bronze bags, 4 bright lavender bags, 5 posh salmon bags.
shiny black bags contain 2 faded yellow bags, 1 shiny blue bag, 5 dark teal bags, 2 light crimson bags.
drab plum bags contain 2 muted fuchsia bags.
muted turquoise bags contain 1 faded plum bag, 3 plaid red bags, 3 dotted lavender bags.
muted brown bags contain 1 dotted magenta bag, 4 pale red bags, 4 posh violet bags, 3 muted yellow bags.
dull olive bags contain 2 drab magenta bags, 2 plaid crimson bags.
drab coral bags contain 1 dull blue bag, 2 striped white bags, 1 plaid indigo bag, 2 shiny violet bags.
mirrored white bags contain 1 dull fuchsia bag, 3 muted white bags, 5 faded lime bags.
shiny gold bags contain 1 pale indigo bag, 3 pale yellow bags.
vibrant tan bags contain 2 dull fuchsia bags, 1 faded bronze bag, 5 shiny orange bags.
dark olive bags contain 3 bright green bags, 5 wavy beige bags, 4 muted tan bags.
light chartreuse bags contain 4 dark turquoise bags, 2 striped gold bags.
mirrored salmon bags contain 1 plaid lavender bag, 5 dim white bags.
mirrored crimson bags contain 3 dark teal bags, 1 striped silver bag, 3 clear blue bags.
wavy gray bags contain 3 plaid maroon bags, 5 clear crimson bags, 1 dull purple bag, 2 drab brown bags.
mirrored green bags contain 4 vibrant white bags, 3 shiny cyan bags.
vibrant gray bags contain 2 dotted salmon bags, 5 drab black bags, 4 shiny red bags.
dull black bags contain 1 dark gray bag, 1 mirrored yellow bag, 4 dark aqua bags.
dim plum bags contain 2 clear blue bags, 3 shiny turquoise bags.
posh aqua bags contain 4 bright white bags, 2 pale yellow bags.
muted yellow bags contain 4 dark aqua bags, 3 muted silver bags, 3 bright white bags, 3 mirrored orange bags.
dark crimson bags contain 5 wavy salmon bags.
bright gold bags contain 3 drab lavender bags, 2 dotted magenta bags, 5 dim chartreuse bags, 1 plaid gray bag.
dim purple bags contain 4 clear silver bags, 1 faded purple bag, 2 faded blue bags.
light gray bags contain 4 dotted bronze bags.
bright chartreuse bags contain 3 vibrant white bags, 1 wavy red bag, 1 faded violet bag, 5 dull fuchsia bags.
shiny tan bags contain 3 dim red bags, 1 shiny orange bag, 4 clear violet bags.
shiny coral bags contain 1 dull black bag.
dull indigo bags contain 3 drab blue bags, 2 light gray bags, 3 dim turquoise bags.
dim brown bags contain 1 drab turquoise bag, 5 dull black bags, 1 posh aqua bag.
bright fuchsia bags contain 3 bright olive bags.
light brown bags contain 2 muted tan bags.
posh plum bags contain 5 striped fuchsia bags, 5 shiny cyan bags, 5 shiny violet bags, 1 shiny green bag.
drab bronze bags contain 4 dotted aqua bags, 5 shiny orange bags, 3 dull aqua bags.
dim beige bags contain 3 striped bronze bags.
dark lavender bags contain 1 posh salmon bag, 5 dotted teal bags, 5 dim blue bags, 4 pale beige bags.
light black bags contain 1 clear orange bag.
clear white bags contain 3 vibrant aqua bags, 2 pale aqua bags.
pale white bags contain 5 faded magenta bags.
vibrant cyan bags contain 5 light lime bags, 4 bright purple bags, 4 clear black bags.
bright lime bags contain 5 dim silver bags.
bright olive bags contain 5 striped magenta bags, 4 dark turquoise bags, 2 dark chartreuse bags.
vibrant lime bags contain 3 mirrored coral bags.
faded turquoise bags contain 2 dark gray bags, 1 dull black bag.
muted red bags contain 3 muted coral bags.
vibrant indigo bags contain 3 posh tomato bags.
striped olive bags contain 4 plaid orange bags.
posh blue bags contain 5 plaid teal bags.
striped gray bags contain 1 mirrored purple bag.
posh lavender bags contain 5 plaid maroon bags, 2 dim lavender bags, 1 bright maroon bag, 4 dark coral bags.
dim turquoise bags contain 2 posh tomato bags.
light purple bags contain 1 shiny green bag.
vibrant yellow bags contain 5 pale brown bags, 5 vibrant crimson bags, 2 plaid aqua bags.
pale silver bags contain 3 pale tan bags, 1 vibrant lavender bag.
posh bronze bags contain 5 pale lavender bags, 3 dotted indigo bags, 1 striped olive bag, 5 mirrored green bags.
striped white bags contain 5 faded plum bags, 5 striped indigo bags, 4 pale gold bags, 4 plaid gold bags.
striped cyan bags contain 4 faded salmon bags, 5 dull coral bags, 1 drab bronze bag, 1 mirrored bronze bag.
shiny yellow bags contain 2 faded aqua bags, 1 striped black bag, 4 pale cyan bags, 3 clear red bags.
muted white bags contain 5 mirrored aqua bags, 2 muted fuchsia bags.
bright violet bags contain 4 dark turquoise bags, 5 plaid crimson bags, 2 clear lavender bags, 2 dim red bags.
light red bags contain 4 dim lime bags, 3 vibrant red bags.
drab gray bags contain 2 drab tomato bags, 1 shiny blue bag, 2 vibrant tan bags, 1 striped fuchsia bag.
pale tan bags contain 2 striped green bags, 2 dark maroon bags, 4 drab turquoise bags, 3 posh lime bags.
faded crimson bags contain 4 clear crimson bags, 5 dull purple bags, 1 clear violet bag, 4 wavy beige bags.
shiny orange bags contain 3 dark gray bags, 5 dim silver bags, 3 bright green bags.
clear fuchsia bags contain 4 pale indigo bags.
shiny salmon bags contain 4 dull coral bags, 2 muted crimson bags.
dotted black bags contain 1 vibrant cyan bag.
drab turquoise bags contain 1 shiny green bag.
shiny chartreuse bags contain 5 faded violet bags.
wavy magenta bags contain 5 plaid lime bags, 4 bright chartreuse bags, 2 clear lime bags, 3 plaid orange bags.
wavy tan bags contain 4 dark brown bags, 3 clear turquoise bags, 4 muted fuchsia bags, 5 clear gold bags.
dotted maroon bags contain 2 dim gold bags, 4 posh tan bags.
striped silver bags contain 3 dark coral bags, 4 dark turquoise bags, 1 pale beige bag, 1 bright silver bag.
dotted blue bags contain 3 drab blue bags.
striped bronze bags contain 1 light blue bag, 3 wavy olive bags, 5 dark tomato bags, 4 dark blue bags.
dotted chartreuse bags contain 2 dark salmon bags, 2 striped magenta bags.
muted orange bags contain 2 clear crimson bags, 3 mirrored fuchsia bags, 2 drab blue bags.
light fuchsia bags contain 2 dim cyan bags, 4 pale lavender bags, 1 dark teal bag.
wavy green bags contain 5 faded turquoise bags, 1 faded lavender bag, 3 faded silver bags, 2 dark tomato bags.
muted maroon bags contain 5 vibrant red bags.
drab beige bags contain 2 clear red bags, 4 faded blue bags, 1 dim beige bag.
light turquoise bags contain 3 dim violet bags, 3 light teal bags.
striped beige bags contain 4 vibrant brown bags, 3 dull red bags.
drab violet bags contain 4 dotted gray bags, 4 striped chartreuse bags.
clear red bags contain 3 posh crimson bags, 4 wavy green bags, 3 dotted brown bags, 3 wavy violet bags.
clear green bags contain 3 vibrant gray bags, 5 dim orange bags, 4 posh magenta bags, 4 dim tan bags.
posh indigo bags contain 4 shiny coral bags, 2 bright green bags.
dotted olive bags contain 1 striped bronze bag, 1 dim silver bag.
striped fuchsia bags contain 4 light silver bags, 4 dark blue bags, 1 bright green bag.
dark fuchsia bags contain 5 shiny turquoise bags, 5 shiny maroon bags, 3 dim gray bags, 1 dim cyan bag.
faded cyan bags contain 3 pale gold bags, 3 wavy fuchsia bags, 2 wavy orange bags, 2 drab violet bags.
drab chartreuse bags contain 5 muted blue bags, 5 wavy orange bags, 2 mirrored beige bags, 5 wavy tan bags.
mirrored silver bags contain 3 drab lavender bags.
faded black bags contain 3 drab turquoise bags, 3 muted yellow bags.
muted lavender bags contain 5 light crimson bags, 5 bright gold bags, 4 dull orange bags, 2 striped crimson bags.
shiny cyan bags contain 5 drab plum bags, 4 drab aqua bags.
dark white bags contain 4 mirrored fuchsia bags.
plaid aqua bags contain 1 dark cyan bag, 4 drab tan bags, 3 drab blue bags.
muted purple bags contain 4 dim turquoise bags.
clear chartreuse bags contain 2 vibrant gray bags, 3 striped teal bags, 3 dim tan bags.
clear beige bags contain 4 plaid tan bags, 1 dark teal bag, 4 dark cyan bags, 2 posh brown bags.
posh white bags contain 3 plaid red bags.
posh cyan bags contain 2 dull teal bags, 3 posh indigo bags, 1 dotted aqua bag.
mirrored fuchsia bags contain 4 mirrored aqua bags, 3 striped fuchsia bags, 1 faded violet bag, 5 wavy red bags.
striped teal bags contain 4 dark purple bags, 1 pale teal bag, 3 clear violet bags, 2 shiny yellow bags.
dull maroon bags contain 1 dull beige bag, 3 dim crimson bags.
shiny brown bags contain 5 striped red bags, 5 dotted magenta bags.
vibrant gold bags contain 4 bright lime bags.
wavy gold bags contain 5 vibrant white bags, 3 dim orange bags, 1 dark gold bag, 5 bright tan bags.
muted crimson bags contain 1 plaid chartreuse bag.
mirrored coral bags contain 5 mirrored teal bags, 5 shiny cyan bags, 2 dull purple bags.
dark green bags contain 2 dark gray bags.
dotted beige bags contain 5 shiny gold bags, 1 drab turquoise bag, 2 plaid lavender bags.
plaid chartreuse bags contain 2 clear cyan bags, 1 bright blue bag, 2 dark violet bags, 1 dark chartreuse bag.
dotted purple bags contain 3 bright crimson bags, 1 striped black bag.
bright tomato bags contain 5 pale lime bags, 2 shiny aqua bags.
plaid crimson bags contain 5 dull orange bags, 3 dim chartreuse bags, 4 wavy aqua bags, 5 muted gold bags.
muted gray bags contain 3 posh aqua bags, 1 faded blue bag, 4 striped brown bags.
vibrant brown bags contain 5 shiny crimson bags, 4 mirrored orange bags.
clear aqua bags contain 3 drab magenta bags, 1 drab crimson bag, 3 dull plum bags, 4 faded magenta bags.
posh tomato bags contain 2 clear black bags.
dim chartreuse bags contain 5 bright green bags, 3 shiny gold bags, 4 vibrant red bags.
striped salmon bags contain 1 faded purple bag, 4 wavy fuchsia bags, 5 vibrant chartreuse bags, 5 posh tomato bags.
faded orange bags contain 4 pale beige bags, 4 dim blue bags, 2 faded silver bags.
shiny lavender bags contain 3 dotted olive bags, 3 dotted gray bags, 4 shiny yellow bags, 1 dim cyan bag.
wavy turquoise bags contain 5 wavy lavender bags, 4 striped red bags, 2 drab aqua bags, 3 shiny aqua bags.
pale plum bags contain 4 drab silver bags.
faded maroon bags contain 3 posh fuchsia bags, 5 vibrant teal bags, 1 dull violet bag.
dark yellow bags contain 3 faded black bags, 2 dark salmon bags, 2 vibrant lavender bags.
bright purple bags contain 5 light lime bags, 1 pale gray bag, 1 faded turquoise bag, 2 faded magenta bags.
vibrant maroon bags contain 5 vibrant lavender bags, 3 wavy black bags, 2 striped magenta bags, 2 pale green bags.
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const lines = data.split(/\n/);
const rules = {};
lines.forEach((line) => {
const re1 = /(\w+ \w+) bags contain/;
const re2 = /(\d+) (\w+ \w+) bags?/g;
let match = re1.exec(line);
const current = match[1];
rules[current] = [];
const children = line.substr(match[0].length);
while ((match = re2.exec(children))) {
rules[current].push([match[2], +match[1]]);
}
});
function getFor(type) {
let count = 0;
if (rules[type] && rules[type].length > 0) {
rules[type].forEach(([t, num]) => {
count += num + getFor(t) * num;
});
}
return count;
}
console.log(getFor("shiny gold"));
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const lines = data.split(/\n/);
const rules = {};
lines.forEach((line) => {
const re1 = /(\w+ \w+) bags contain/;
const re2 = /\d+ (\w+ \w+) bags?/g;
let match = re1.exec(line);
const current = match[1];
rules[current] = [];
const children = line.substr(match[0].length);
while ((match = re2.exec(children))) {
rules[current].push(match[1]);
}
});
let lookup = ["shiny gold"];
let result = new Set();
let lookupNext = [];
do {
lookupNext = [];
for (const y of lookup) {
for (const x of Object.keys(rules)) {
if (x !== y && rules[x].includes(y)) {
lookupNext.push(x);
result.add(x);
}
}
}
lookup = lookupNext;
} while (lookupNext.length > 0);
console.log(result.size);
fekdcbayqxnwvh
fycwqktvxandeb
kqbafvcxyewrdn
akwqcvenxfydbs
ewbaxdcvnkyfq
timjneyhbvxkfagdpzrous
gsumijvxoheptbafnkyzrd
yxtbnupramvdezhkfojsig
soaruhxnpiemjvytzbfdkg
vfanlgjoiskzmubtxhceyprd
dhgabzfspkltq
pflzsbtaxhqdkg
kzpbfgasthldq
xeu
uoe
tnpeox
e
vrdzwglecbk
nucwl
hnmx
fqv
kfubtzpovrdlw
vdjmblrztpkosfg
kavpdbgfzreol
qpdzfrvokibcy
yhknrqpubeolzixtvsj
tlysdjzovxhnuqreimk
bclpmatw
btqmcw
cvwtbm
bmwct
ctmwb
qmo
oqm
su
s
s
s
s
ztfmocgiesxdq
fpjmthksidlbo
smzbn
bmnzes
skzmnb
mbszn
kibmrznqcyladupv
umnbkdpievlqcyar
idavpbmnrklqucy
favynhqocijkmtbzsrulp
ycbzrmkuvlhnpfqsitjao
ujbomprktafvliqhycnzs
nymjkczihqbpfvutosalr
tdev
vh
wva
va
gzv
d
d
d
ejrmqwg
merjguw
jmreugw
mjrgwtie
wxiqgpu
guxqiwp
puigxqw
pugqwxi
ealugrzsvhpxfmjdbqknoy
doyhvplkjqarnbeutxsgfmz
uhvxjaklmzoyqdbegrpfsn
iv
os
o
amtle
n
npz
vbfxystq
knsxyqubtvf
t
p
p
o
xtz
ptz
ftx
ujt
tp
rs
qdfan
mkpz
idewynukmzac
yacfmdwuizke
ieuamdczkywf
iczwymuekad
adwekumyciz
agnq
gn
gno
gni
vkmnxug
ftlyhuvaj
xsribwknlgmt
a
nay
a
a
leq
q
qj
sxrwi
isrwx
wrsix
iwsvxjr
rixwbs
p
p
p
p
p
unvlyxripzbmaedwjsfqth
uvefyibspxrzjdlwtqhnam
hnbapqzflsvxreiutmydwj
nwdefhtzrxuqpsvljabyim
razbwymsdfpnlutqxveijh
zfihqcvwdbsm
sufwpahczlbvd
tqjanyicszeodpmk
ljmtwvkrcfghdqbu
ydxnthpazbskufcq
txymsjdfhwuqbz
vhyuqsfjbxdrtzg
smyvegtwiu
imyqtuesv
idrluzhjatkvpc
pzacglju
pzulcagj
jcalgupz
rgzbvefacsw
vafbrezcw
wegjvrczfqba
zwrvabpfce
rlhekwzyfbacovm
hfqu
fq
kywvrsxgiojp
xosvigpkwyjr
irwkjfvmxpsyog
pvxyrwiksjgo
ynebghqmrkcjlpiuftdoaz
reaqjoyngdbiltkmuphcf
ynobfdgluriphskejcqtam
uac
ca
fmxawgkrin
xfrnbigok
sfighjeckrux
girxkfl
gaxirnfk
smoyaxbku
uobkxysam
kyszxumojba
uocvgjr
hjponwcuzg
fobhkeascqluwrzm
hzcolfipysnrjaguwkeq
ezwlhkcfsoxqrua
blnosjgezuqcrvxwm
cmeznoglqxubwjrsv
zxnqvwoubpremsjcgl
umxrlsgqoczwbvnej
cuxanesjkivzrmlboqgw
dewtyuqjlv
ucvazfm
kbm
imltbj
ydqnxlmbouvaztcg
vhrkwxjzfnpisye
jqeadkcibtgflsz
ltbxqifjedsawkzcg
zdfqgkijestcl
jczfqdektlsig
scdgufyjeizlkqt
w
w
w
w
s
wygptc
ygctpw
gcptyw
tpycgw
xaqicwhtdpvk
aixdcpkzhvqwt
qkcdhxpwaivt
wt
xtrowm
wt
wt
tw
sncq
cus
zehxb
txe
exuma
exz
epjgfknhvuwmr
nkwrmfhjegp
rjkpynefgmwh
ehfprjkgndmw
mewkfdnrgjhp
hgyc
kgc
ghc
cgxjzl
evsloum
leosvmu
mejvuzoxdsl
evmolsu
fugckqhymrxbtvdpnose
beyorulcqxgdkzafh
s
s
sq
wtjfgezdhsxckibrqyunvpo
uaonrpkmidbgftwlsjz
mrylewxsgvfodhu
sfdxoyghwlrvmu
dungfohvlwrxsym
ulmsoghvxfrwdy
uoifgdlwrsvymhx
tbg
btdg
tbg
tgb
btg
pukht
huk
fhkqu
hykcfu
hedvmgubsk
dxycvosnr
xcsdyrgmapf
qoyrsxdc
uedsxtyrc
ucdrsbxy
m
xz
m
gcjsybuhrotm
dojcsubhprt
opmgsudhej
mjceogdsuhp
djpgmoushe
jgeptsluhfomakdvyq
jugocetyrzwfbhp
ipvqwcozxbsdu
gybprkmznowultcaj
ipcau
n
juzmidp
iudjp
digjups
pajiud
zxnugrosjvlcphwmqbdyt
bvtlmqnudzrjwysxcohagp
tdxhyuwemcvbrpzgnoqfjls
hoefmguvxyiazwcpbrjk
umlbagzxeowthjfpik
hmxeziglfbwjup
jgxbspifzwqhneum
mgvupsk
ezwcui
adczjnguyq
ygnujdacqz
ohricgqjfu
rqgucfhoji
vygwkszidxqa
onxkejczsguywqv
stvzbqypwmxkg
ydjm
fpbustykx
yrq
ry
vjphn
npvhj
phvnj
bryndzmekui
oathqpcv
yczewurklaxnfdhoqbt
rlyhawcdunqeofxkzbt
lhbsqfkxctyonwrdzuea
zltnhdkqybaxufoerwc
cjwarkog
joawgrkc
wcjgkrao
wrcjogak
coerwgsajk
umwjqsetdg
sjwmet
jbteyhownvsaxm
dmuspcztjrew
xtswpc
eahncvzqxkgmo
lcixybdrsuft
pcrfwszodmqnj
vrcylgb
iruc
bqigzouxryndpa
jaixybnro
oabixhnjry
pbznr
xrb
bdntx
qecbyi
zbvhxyfm
vxmbyfpz
vbxzmyfh
nfcqwuhsrxojk
jrqvokfscnxuh
nxqiaulkrojszchyf
dkwqfb
wd
hwd
nhwd
dnw
vjtpxorsdyzbwhqi
kirdlmofpnectxqwuz
ynzxtvqogrdhwl
yhdjomktn
hqwn
hnwq
hnqw
hwnq
gosxz
xog
gfomxa
ogxd
wctesuhxonyl
oxwhtecynusl
cslwxehupyton
pr
spr
pr
pr
maqfseovdhzj
sqodparevimfzjl
dxosqmafejvz
dqzojehfasvm
awsicurgfmxeqjylnvktbd
dywmreaitvjgcnbklxs
wmvbnqtxuriz
hbuwefypzlkadq
asjcpwml
lcasmjpw
ajspcmwl
cmslwjap
unkrl
n
ny
yan
nv
zrjwsxduie
jswxrziunde
xrujwhsidze
qnl
unc
xhtdjbvf
omauis
wxvoqihatseg
setwqgi
ewgstqci
fetwqgis
wqtfgkiesd
vmpikgfsarbnxqudwjtoh
bdovpatjgnxkqufsihmrw
bjhnrtaokxudmfqpigwvsc
kaqbvihwmsnxjpgrtoufd
fmabtdgkuhxpwrivsoqnj
eazsitkjronml
otmrenjakzsi
samrojenitzfk
tkzenmrjoais
tszkioaejrnm
r
rbq
r
r
lwbrfsuahoq
yjawifugdtrvs
rfbaswu
cfsarlknupw
ist
ay
kc
cu
kd
mbku
bkva
sxktwmyfaldbn
ymkbnfpdltx
xbyftnmkdl
dlkfetbimxycn
cjru
rcju
rjucl
kcjrum
auzcjrtn
vkinfzqbrled
rinldvbqfze
rqizebfvldn
aciqrfbsnelvxdz
ig
ig
gi
gi
rskzxocuq
kcovqsnztur
skzocrnyuq
vourxysqzkc
opescqukrhjz
i
u
xqfviycpuzjbwkn
lnxbfkpcyqdawm
xofypnwkbcqv
wbvxcfkqtnpry
bnoixpfqgkcwy
ziwlofkdgpc
qzayrwjvks
krybec
ryk
yrk
kyr
yrk
xkhdreqfbyipmzalco
wiepqtyhxflvcomabjdsz
jpgankzcvbtw
kxzugtvnbjp
gknqpjxzvtb
kbtjpvzgmn
bptzvmjkng
hdaxwiypslz
ndbylw
xdkwtflpyqsz
wlrvcdyjg
mlfewsqodyu
c
c
o
c
mah
a
gwa
heczudoqwmvtyab
acevwozyqtdumhb
v
e
rom
mor
romi
rom
uxdj
d
p
p
m
db
t
dtpzeykh
pkdhryzetu
zdkhtpyac
qanetkhrc
ndlhkceqof
khbfjlnacvz
cmavfjlkn
aynljofvqkgc
tlkjcnavfm
ejcbnl
mbgcoiuhsfl
qblyc
blyjevc
vgqlcfhnx
xwgonuc
pystigbca
cnqlgmdk
rlfcwg
nazyhitgcjr
nytgizahwprjc
zjcgrinmahyt
nrcdhzgjyati
xtljebqpg
bpjewtgn
gjtpebx
gmoipkebtcsj
ptwejlbng
e
exa
h
nohegc
h
ivbgpd
isfglyvbdo
dgvbi
bdivug
gvikbd
wyjmpxghiqfeoctdnbuar
qetnaimxlgsfcbrpj
kbcrhxgjnqpadefzimwt
kindbwqlusyh
tpzryjgehaucfmov
wzgou
ugo
guo
voug
ndwhzsrugpjmltxiqofvkbyc
lgirqyotwjbmvuspfnxhdzck
jbqzgwcvhxofkrmsdlytpuni
xrqzfjolsywtcghdbmukpivn
oqryngdmhljvctxwkbfusipz
saw
as
sa
msajv
sfa
oxtrnhvfqyswldb
tmzwgrakc
coqyrbzjhsmwivanep
xkshzgft
hsz
slzh
z
glh
dtusogw
fmpkzvbxnjwh
eaqdciyw
bgcyqhrztvdxwn
vqtanbyurxczowdg
kmjxyvnbqztfgcrwd
vospejybinm
fiosvkbnjep
johqpznbeisv
iysbokmjvepn
nxsrfohagwb
agblosrxwnhf
xgircuhsaobfw
hfxpgosarnbw
bgqurk
eumkrnvxqg
gkrqhspafuoc
qtogubkr
bxlapnm
nptix
oqxpn
npx
rytbpswaezlufdqxo
imazhtjqnglc
encpqudzigamorv
vamkeznqirdcgp
opvrglqsmcindzae
mpvncrisdezaqg
ikxqemun
zadbkqjtxney
kenmpxuoq
vjdqxfyhckrpton
hmngcfpytkdxqvo
ohdvuywpstzkcaqf
tepj
te
ecvty
jqotiphkmsexvfugd
gwpyfuhlevkdiotjqx
tjkfvghibocaqxeudp
onexjzpgthuidfkvqs
ltfq
lqts
oqtl
nqsyglepwzhmtiojbuvxf
wihkgaoydpzvfxclsenqjmt
fqxmt
bsgtmxqyrjfdv
tfqmx
itmhqwfx
qtmxf
rgv
vjwo
nlekpa
ldytkguwhazeqpb
pqzaytglhbmfuedki
dqbatkpyezhglu
ztgyqjebhkdvpual
kpalzeytqghudb
xsynhr
hsnury
qyjukdtmnwhrczvolsb
ymsutqrchdblznowvj
mpw
wmq
tdwm
wmd
n
n
n
no
vnutqbxrygmjwhks
rhoalixstfyuq
jeyfhsotc
setchyoj
hcyoejst
ylhpvfiawoekjbq
pkroabqvljiyefhw
akqbyjpziglmfedw
wjdbyeaqpzligmkf
lfikyqwzbmadjegp
aswgkzdyfrqpmnlibje
fqpmyedjklgzibaw
qe
eqo
jbxoe
qoikde
c
n
j
j
j
rfh
rhf
rfyh
rhbf
qfrh
hokvgpxyunam
bmpyogvhunlw
morevjuznhydgit
ohns
nhos
ohns
hons
hsno
kxclzyqpan
aexnyqzkpc
pakcqnxzy
gkytw
mgtw
gptmw
fixsozjwykhupqmvtbrc
syimxhzbpwcktrofuvjq
xuiwfjvzcpykqhbrosmt
mwrbvqjtkcsipxfolyhzu
bzhxpyfmk
yfzxmakphb
mkzpxbhyof
hbmzfkxpwyu
pxzhkoybmf
osdyp
dbsroy
sydoj
yterzphvxdm
vtxrmyhzedp
vymperdhxtz
mpxrvyhedzt
esakn
cseak
hxasge
enksta
u
gfzua
jsymd
dmxjy
jmdy
xymjd
sezfhlvxmaqtd
ajvtmqsecyghfixzwl
ksbhxzvafqpmuet
zfeqytxhadmsvc
nextsvazhmyfq
rucla
auclyr
uticrapl
akizsuwdmnhpxbgyceft
gwxpfeoyihcklbndasz
zwhsbigdynkpxceaf
zag
vmisa
yphkcant
jdma
bia
nplydbkoq
oasptkqgldnbey
doypnqklbc
yblkodncpuq
lqkynpdob
hmj
jm
gniearxpdbjlkfm
qdvjlute
omsihqlnwzbt
blzmhisnqoftw
onqlmwsetzbphi
jzoxcwdf
wdcjzifxq
ykdshgzwjfecimnp
jhipmsaftezkoc
ziaspcjfmkhve
t
t
t
f
zmevcjhbsainxoquwpftkydlr
cygwbtvxemnzfjhrqkdspaolu
efdtnrlwczymxqvpsoukjbah
oujkhnlzydsirva
dxgzjsuptaohqvnkic
aoiujdlnkzehvs
uriadhksjyoznv
iydmovnzakhfusj
ycajzrtie
zctyriesap
pxiacrztehby
qaenyxtzirc
saecrytzi
xrnjkgdpuzqvcm
ndqkvuxczjpgrm
ucgmzjpqrnxkvd
npqxkumdcezvgrj
thymlxwaoz
ylhowtmazx
nwaisrejbtqfmh
mbwhqnrfjesa
hfnrqebjasmw
jecwhfgrsqodanmb
qasbhnjwferm
ny
ny
yne
lgkmfbthwaouscxpznvyrdi
nhlmtpwyrojfvbuaczxkgds
askbuvdozmnxhfygrlwctp
fytznqhlbmxgrwcdoupavks
wcplxyvsrdjnfgkmuzbtaho
fklceui
kclfiue
klefiuc
clfekiu
iklcufe
yavcmhwbp
capvymhbw
whypmabcv
pbzmcywvhja
lbevjz
gnvefbu
webvd
ewzcqndmjhvy
jevrqnym
guqpiotaevsbmynlj
vqmekjynf
nefqmjxvy
akgwyjfi
giwfyljak
pdejr
jerd
redj
liwtk
kiwl
wikl
rbwvox
bxvnor
vbwxro
vkrxob
xbvirwo
ntsbkwqefjphro
nqdvgxihopwc
dn
nd
nd
j
f
g
k
j
tfsul
usftl
ov
v
w
tj
sl
gdlufaesv
uagvd
vudag
cbegxmuiwkzo
okrmgbfwvnecp
uybxehawmgqkoc
yloqmbwgtczke
jms
ymsfjo
lmsuiwhe
ydsmk
wgckujsd
irp
zgeulsjvimptdaxrqnk
zbxtefdmvganulqprikjs
ptslznrjqkxemagiudv
fqtb
qp
aq
q
q
hrkzci
bhwkpidxtflcue
hkic
chki
kcjhiv
gi
s
rakewmostbfvjzgi
begtioavfrkzjm
zoeikjtbfagrvm
xnbhdlctm
bgfhwlxsaqnkov
pelmnhuxryb
e
qr
jh
vhtwuokdqpa
jfaniksczbeymr
ngedtljsvybxkmhfuzw
tbzedwsjgknvhlmfu
lzbgdsuhkjtvermwfn
smizqluwdetfavbnhjg
blwtngusvdjzhefm
lxaiqvkoh
feioxvwbsrl
fy
yfbqlm
fy
yf
yf
cuygpzd
kv
k
v
antp
nat
uk
ku
uk
tdjbri
rdwezgjtlck
stvfhapyx
psu
spy
ps
pksy
bpsq
db
o
o
yi
iq
pmxi
i
oxt
atox
txo
wn
sgzth
b
m
ynq
ayxvhzu
vhyzxu
hvzuyx
cxoygklt
toky
ovkpyt
voystpk
yqtjwifbvsn
vstyfbxjqwin
vsjtinqfwby
qxysnitjwfvb
bjfynsthqiwv
zobny
zynob
ozbyn
noybz
onyzb
inpdmtkblgqrvaowzxu
zhrbpuwiqdomgvlnt
topveguwzrcbndmqli
eapmtqrski
islukrmpe
sevcbzfngx
pcbl
vxqwe
ky
t
p
qzfo
bkhdlpnrxezivu
lztsfxpgknho
knwlxmzjhpy
t
ita
oqt
sbt
omwk
eowm
wmo
wmo
osbtmxwd
dwgpvjemitbcnuhr
vyjlitenkbpmuhqwxd
iedvbwjczstunpmhg
yfakujntsriwgxm
rfatigyjkxusnm
uyxitmkagnjfs
isjafytxumgnek
tiknjmugxsyaf
pahkyfojrv
enxmd
sehnkcr
shkrc
hcwxilkru
skgchrfpjt
zdcvpant
nizclpmtgbv
jtcpnzv
phtnscvza
azcntrowvpd
ativhgmyedozw
nvztmiahewg
uhaimgzventw
txiqfmzglphvwae
ehmgiwtzav
qdpreikohtyjc
ihtydekrocpqj
djkoticqhpery
jcorkdepqyiht
kgwunqm
qgjunwk
oinqruwzyk
wtkqceimludr
mkhpwdcqleurzt
mqweldutkcr
kdtmwceulrq
rqlutcidwmke
k
h
k
k
k
irb
arbi
bri
irb
fbxvri
umpkng
qmnugpk
sbdxmlzacj
sbzlcamjxd
cajmslzxdb
fwndcxr
xbmusn
t
t
gh
p
t
zovqiwdhuaslkjxrbcnt
flhnkoxvadiqrwpzbjs
gqkisrxodznabjwvlhp
koqlswdahnzjvbrmyxie
apecofvgshiyqbj
icegjhasytobfpvq
ocsheqagjfpyivb
pewjncobqiysgzrfahv
wzomnlgyxj
thazprgi
rywgaemsubhvkqcozpnxl
avehbwolxnzmqyprgu
qyrgpxhazluvenobmw
jhtrzywlnmbeoxvgpiaqu
gavmwzrponyxhduqble
tw
wt
tw
qpzxrctf
iqpunlsawtcykmxbdvgfzjr
vnwdruyptakbgqxjimlzcfs
fgizdmcblparnsvtuqwxkjy
pxwylavndgqtjbicfksmzru
xtpdfrbkcglzvqjuminaysw
xkyvhtdwpjnulig
hvegnyitdwxjz
vthsnxjaywdig
whdagyqvxjtni
wjvgytdaxnhi
ygduev
clqoa
qxc
xaz
fc
rzeqvofasyhjgxwkmtcudn
vkuogexmwhznrycdqft
zupwcondeklthrbvxgmyfqi
mtredzn
xcnozebtrmd
elzrmwtund
emtdnrz
tedmzorn
tlbunpqygz
xmehasrifvwj
hoskgitlw
owrailhtfkg
wigbjvhtolk
tbhivwgsuklo
fxnachtsdmiwvuzkg
hacwldskfgvuixmtzn
xghufdizawvnmsctk
gnauvfizjdortq
rinjautyqdzvg
giunqazvtdrjmc
wndhjzuqviatgr
vtpsy
sptvy
svpty
ptksyv
yaskce
xdtvyjnqma
faoyb
psyfa
lbxounj
lijrmoxnb
mioybjnx
afbjnvopxsch
bjlzoknx
vqmsgwjfkzdbthal
jszvlwthkmqfgdba
akmfjzgldswvqth
tuswfahjmdqkgvlcz
jvatqgfmnwzhdksl
uqyfkzdwta
hctzeiywabpgvlqonmuf
zyurtaqwsxf
wyruzjaqft
rwltyhqdecxagbov
azthexlkoqmvrdngcwfs
corjvwqhutexadlg
lecogwrhavqdtx
qpdvrgctyaohwlex
egsilhd
hxmijg
tzdmnvsyiwjrhakbgp
wmzhsctpdrbnagvyei
bvwtaylgdnzhsmipr
rhmlswzvpandgtybi
qriopbacexhnlwfvsmdk
wblaondrszhcfpei
pdnahlrjseiwfcob
cerwaoshjldbfnipzu
oalsrdienwcfhpb
xcpe
pcx
cxpl
nbpyzixc
lpecx
xyfcgdaew
jdlcopnaixqbv
ehkcdrax
dcytarmuhgxews
bqozpsd
pqzosd
zgqdop
ocqzdfp
uxy
szj
jzl
fhvk
muz
m
omycvi
im
t
u
xslkmbzarnfeo
axmndjpsqzelrbkfo
eykroszbaxlmhfn
rsz
rzq
kzrit
hkmqiydpzlosuanvwj
czsjklbvwaidhnxpu
ejvwqmatlkziundhps
udgjnfoepkwilrhsvaz
czlnqtdy
bcv
cvga
hvcb
ac
lcmytwdeqifzakjhuon
mdqxhfgpzykvteajn
emfpxqnhbykzdatj
rtgmujlen
eguclrkmtnj
npjgemtrlu
untmegrjl
olykiz
orxyswdtka
qelnh
yijmfxtvbs
gweh
wrc
vjcediawtnrmoh
lvnhmabrxcjwet
ajmkbntrvchlegw
yicrxeztbdpjuqlfgnvksmah
rayjtgdsfhexiqvpcznlkubm
crxijflabsgkhtqmdeunpvyz
gpbklvxy
pybxg
ypwgxbd
gpxyb
vos
sv
vs
hqiktnmezpvacby
uekhv
egskvh
kvehog
myhoetiwlqrpdk
pgfkbqleywmhtic
tezpslhymwkiq
t
vxh
g
t
gjimn
ijugmn
njmgi
drojlynvs
nrysdjvlo
lydosnjvr
sjylnrodv
nyjrdvols
vjrclek
vuljbckqfteds
cihklevgj
rqbvni
flxuv
gpywjntefcm
cnoaetmyjpgd
mpeynjcg
rbnpymcgexzhqji
cjumnegpwy
h
c
h
h
h
hzrqoybi
wynqkcmlduae
zqybh
itnoq
rtinoq
tqhlin
imtbq
moetialxhyqkznjwscgdpv
qwcagyzjvtoednmixlsphk
kxqajsiotvnlhcgwdzympe
ynejvlhsopakcmzdtxgiqw
yaxdpiqktjsozmgvncewlh
qyrlgevbzsutwmxjhindcaokp
vtdjrqaocngwehspylbukmz
aev
ve
a
byqg
ycfvpamkhliot
wmckyrthxusfqiedjlaz
atcmhkboiylf
sfqkmlhdc
mlhkscqdf
fcqsdhmlk
kqfhcdmsl
kqslzfdmhoc
dgveoupsmhabyfkrztclj
vedwkmptusfhzaygqolcr
tfoaevgbi
yfu
sfwqh
kpfxlj
dufl
mlwhb
jvgtzp
jzp
szwipyj
larkxcqsbpeuiv
fharycntpzi
lsympnqboj
nlpjmobqys
njoslbqpym
qsnodjtlmbyp
lnosbmpjyq
jpovmflgikracyqunwthe
hawgrlcyvpnmkjeofuit
pltojwgrcfkhaneuivmy
klaoumwtfgejnhcripvy
hmvxakwrtundglz
mkacvnhwrlxbzdug
asvoizlprxjefycmthugnqw
zohmwpxdaiyvrfnulecgjtq
natmhjdg
zctmdalg
vbiamufq
vhxbajdokyn
dkvxonyhmab
hnexvbdaoyk
gyjfnm
gmfnyj
jfygmn
bjqn
bnqj
nqbj
qbnj
hawjpsxeolr
rwlqenjhpsobgamx
tovhgbwjdckpqn
ifzl
mleysuzrax
sky
ky
mgfpwk
zx
h
ict
gz
zsjitm
lijor
jmwabyit
nbzmj
abvfwrdn
csnbm
hdqyski
ywvclhdsq
hsqbyxd
jmt
mtsuhxjzkla
fijlt
psjbtfieg
zqcohan
gwnfpqb
pnwf
wpnf
wfnp
nwpf
irgkabh
khgibar
akgirhb
emonkbuycsz
noyzscmuk
ejsqzftblax
scomdrxgibw
afdjtiyvgqorsmnhubweplkxzc
fmznscjliqbyevhxwoktdugrap
cgyxhiubmptdokesrjzlafq
pmdqvjuygbeslzatokxfr
hyawt
wh
wh
wh
vojux
ei
nq
pvnjgmxksluctq
zfrdoa
d
z
x
xd
d
dwpscgknx
kwxc
xcwk
wxkci
qipb
ildp
ziacpr
pbdi
x
xb
x
x
x
fenqcuwi
niczkhxeq
mcejqnxit
iycrngpqel
uyj
yju
yuj
ujy
b
bd
e
e
e
e
fei
tncbizahupsdwlog
oclbqdskwnaymx
atloswndebjcriv
msojaeqnphzylgdbc
ebmzlphcgyjoadq
apehlz
tozlmeba
ekyflaz
qpnhfgjdzymlctkrb
slmbhkqpfyngzj
mlpqjyzbghnkf
nmzghjyblkfpq
bngqfhymkzpjl
apgvczsfuybdiklq
gmhxdubftesavzlpjcqyi
aswyzugkicpfvqldb
oylsvgbcnuqzdafpi
ncrkh
nhkrc
kncrh
hkrnc
hcknr
nvrjtzamfuhqxp
ebdigavktsywflmco
evrabhcmxkonl
vlcxmbnkrheo
cxloknrmeb
pkclmerbonx
lbkoryunexmc
zdmhgatfpqcwrsu
beravdksgly
wfo
fw
bfwh
kpzlhbtjfiw
fjwpzhkbli
bfhpkjzwil
pjwoikhzlbf
yworad
adsyr
atqhenzlswmufgkojrb
lfoanzusbhgtjkyeqwm
nsgajlhqeobkfztwmu
mlcisaozwkhetnqfjgbdu
xhqkmdutfzasylbw
hqubgdwxlztkmsyfae
pfhuacyitsqxmbwlzkd
tqbpnosumlj
jdtpqbyoli
ulobptqjn
tfqlvwzopbajc
jxpeobqtulis
awg
wag
awgk
czbledy
avgwqu
kf
f
bh
gm
tj
l
dm
lspg
zfeauxn
qt
zwep
pwze
wpze
ewzp
jptngbzhk
tgnkrpzxdjh
ghjznktp
ofrbuieszcakqt
snomauqcerdpbt
nbjxhyvtpl
tbxzgovhjy
yhbtxjovizk
bytvxhj
pibogfjn
fogbinjl
bonqgfji
banjisugcmwfvoe
iobghfjn
tz
t
ta
qnraf
qrxf
qfr
ezroqf
iachtzfemxwbs
gzsfycehaqwkm
twmhzcsbrafe
zmafhcewxs
gqoznmrlxvudwehf
uvzrohmlgdnwqxef
frgvqedxohmlnuwz
fqledmnvwghruzxo
rxcvnyjbqgm
cjygxmrvbqn
vuybxmkcrnqg
ipgrxvnobcmeyq
yvqnbmrgcx
ay
ay
ay
ya
ay
np
xa
ba
ibrcmtxqvyaed
vycdaeitmbxqr
dvqiytmcxabre
dvbaicqeyxrtm
hgzd
zdlho
zhd
zdh
zdh
hcipn
zchnipb
rwptzv
ymoedzaltsc
ubdwmjecyqxltipzfn
mvfulhydqewjtzpnci
najhotpuyrsxdlqbk
wxetrjaobduqpznklsyc
jwcgbxoipeyfmkvhr
cmblwpoudxteyfvnhkrg
qzseparbjxvykfocghwm
eqvwroycibpxmfghk
xwedaqgiznj
khubyeatir
avgncxeljzmsoif
zf
f
f
htbcr
st
kmr
rm
tvebzs
cig
gdij
gvi
jhgies
fduipkhlz
izdplfu
pdculaojmwsqebvgh
zmhjsdwlefgoucrpvy
bzwagcde
uhsqpmloni
mf
f
ltfn
xlhmpdyieob
mlxpyhideo
mixkldhpoye
lwthjcvgnmxuypos
vixqojmy
evrxmoyj
ymkajoxv
zfvjdymaxo
voh
h
onqdyf
qmnf
wiktfqsajgn
poaheifqcl
plqcoifaeh
paegritwhnvlofzucjd
ipeohaflc
oielhpafcs
tzvenpcqxisbjhmgkrw
xvnckipbhszegfwm
pkchgoxbavsmewizn
csvzekmhyngipxbaw
wgim
ixaw
wixka
iyownrps
iwk
caofbkuznsiqrtvpjyg
pyroglzcjtfub
pcfjryzgtubmo
junoecpfwmhtxkayziqvgrl
zqigynpcvufwohjlemtkxar
oeavkrhizljumtgfpxwcqny
tyizfjnoqcbgxarepklvwsudmh
itvqcxburwo
idtvacoqbex
btvifjxcqyo
ojikvqcltbx
bromkxwdfq
dkfrbwqamxo
korxywiqfdmb
smyfvkg
xmkgvsf
kgnsfvem
mkfvgs
pdxa
mqgx
lxsezkbjic
xy
wfprx
ynhepftgslro
wytlefgosarn
ysgtndocwlrf
lrgnfoswtya
zlibfutmrkxsvjnqgyo
kht
tkh
htk
hkt
pcdxhjnovlusitq
dbtrjizv
bjhnkitaegvrsx
nxghvbestra
bwetgsarvhxdn
oleswygxbnfmtzkjuar
xuaezbtcwlgmnrofsjy
hdrgyowbfktavjuqlzm
gtkvfdulwqjzhymabro
rzojgmltbyhafvwdqku
uxpwqbyr
xpquwyrb
rwxyqubp
rwbyquxp
qxrbyuwp
kqlwz
rkve
klnf
ucqk
irqgpjmdk
ctqmvnkfbgj
dv
dv
dv
fariyqplzoetb
zykjphxcg
pytmwqvx
txvpqmdwy
xtyqvwmp
wvqmxypt
oekfrmuatwl
axsvpcjkgqdzhiby
fnyuqsihvmatgwxlr
ufjmioapebxnqydhtk
tpskxdqc
kxsqcdtp
ytqsdkxcp
cxpqdtks
tcxpsdqk
soivtnhezljymw
mhcyptneuvob
nfetymhgdavo
vnbhmxetaoy
sqruavzncixgbpof
vioanzfgreuxqc
acetqngfrxoziuv
gqcfmxvrnzaoliju
earxh
gmizfq
tejlcvwgxpdbhsorufmiz
oftmijdscxlvzbuwpehgry
cvnksdzamhgbporwtufiljxe
wdmgbxyihk
khmxyidwg
hikxwdlpygm
nzcf
cz
vhfecblgmowtqxpaskyi
xwgztblrjiacpfmheksvy
pemi
e
e
ze
e
fxwy
xyfw
yzxfw
kshfqrlmyea
xsqboukan
vknp
levn
pknv
vqsdyhzwei
poijeyhscazl
ryf
ofit
txw
jqvlhmbgeuznps
qhzycdugf
cuhqdzfg
fghuqzcd
emqngdv
meaqh
ezqmax
exqm
qmaze
jgrnahfyvotupkxziqsdmceblw
ntughqlksexifdraozvmbcpwy
imt
tim
pthzw
tpnwhz
piztlw
tzpw
xpuh
xbqrvys
lxw
cpidsmqk
rkpcdmisq
pcdkqsmi
pmskqdic
thxqby
bqxohty
qybhxt
yqtbxh
yqbxth
qkplixrshe
jndbsraivm
zrgelsyit
lfsri
zqr
zrtc
rz
deabt
ueatgs
hwiqknj
ulxb
tdm
sfpwq
phsqw
kpsqw
guhmbl
gmuhb
mhndpub
yuihmgcb
uismhby
qioblnp
olnqbip
loqbinp
rqc
qcr
crqay
rqc
z
z
z
z
zp
ljo
lcbajeorg
jlox
oljx
loasmqxdy
mqld
lvmdqb
iq
qi
filjwt
fwitlj
fliwtj
wtljif
tjwfil
dx
xd
dx
xnd
xd
vzo
zov
ogbwntefukpch
ebwnsfkgupocht
noctepwgfhkub
wfqkugnpodjthbce
genbzqkvspy
brkwjevpqsczn
fdxnvtzsobqiekau
nxwb
wnj
imfvncxbhlrdzgok
vbfdakgnhlcrixmo
cnzbholrkvdifmxg
ucoklqmbdxnvigrhf
blndpvmhkirgcxfo
hquykcmexvza
evnayxkchmzq
jfyxamhqpiwzeokgcvs
ekzdruqamhlbtvxyc
nk
knwct
pbykwan
dzsegnfqrom
linuwk
tbc
tqbe
tcub
lzxybkftrhis
ylrxhdasutjzncipgbfw
xktyhfizlrobqsmv
sjb
pdkaowvu
bnhcaqjprkx
ncdrqxbolaijkt
zaxrnksqchybj
cbnaxejqrk
bteqziwsumofxpvchr
choiepzjxuwtvfrsm
irtuwcsemlpvfzhox
twhximepcsfzorlvgu
ta
at
xjdybasehgpm
edaosjpgxhmby
xybgpdjemsha
dmexjpbaslhywg
xpmedyahjbsg
cbjxvynghstrfluoempdk
idhbtapleufcsrgywnvmox
xohdljfecvupmsgrbytkn
rvleksucfbdymxgotqpnh
klfewtsaihpxnmogudy
seqdufxypnlikwtogah
ewpohdiknstxugayfl
xwenydkuhfasotlgpij
fignpyousdtkwexalh
oudzygfimh
xvj
qbpviwoadmfr
dimbswlpqnh
yzgxbqidwuj
ismkdvnyzajbuowlpqfr
vjqwufylscopgmkrdabi
rhbwefvqiykupsajolmd
msdqtukoipvfxlyjrabw
lho
hol
jfolhv
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const groups = data.split(/\n{2,}/);
const answers = groups.map((g) => g.split(/\n/));
const alphabet = "abcdefghijklmnopqrstuvwxyz";
let sum = 0;
answers.forEach((lines) => {
[...alphabet].forEach((char) => {
sum += lines.every((line) => line.indexOf(char) !== -1);
});
});
console.log(sum);
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const groups = data.split(/\n{2,}/).map((d) => d.replace(/[^a-z]/gs, ""));
const answers = groups.map((g) => new Set([...g]));
const sum = answers.reduce((acc, a) => (acc += a.size), 0);
console.log(sum);
FFBFFFBLLL
BFBFBBFRLR
FFFBFFBLLL
FFBFBBBRRL
BFFFBBFLRR
B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
BBFBFFFRRR
FFFBBFBLRL
BFFBBBFRLL
FFFFFFBRRR
BFBFFBBLRR
BBFFBBFLRL
FFFBBBFLLR
BFBBBFBLRR
FBBFFBBRRL
FFBFFBFLLR
BBFBBFBLRL
FFFBFFFRLL
BFBFBBBLLR
FFFBFFFLRL
BFFFFBBRLR
BBFFBFFRRR
BFBBFBFRRL
BBFBBFFLRL
FFBBBBFRLL
FBFFBBBLLL
FBFBBFFLRL
BFFFBBBRRR
BFBBBBBRRL
FBBBFFFLLR
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const lines = data.split(/\n/);
let found = Array.from({ length: 881 }, () => "0");
for (let line of lines) {
const id = parseInt(line.replace(/B|R/g, "1").replace(/F|L/g, "0"), 2);
found[id] = "1";
}
console.log(found.join("").indexOf("101") + 1);
const data = require("fs").readFileSync("input.txt", { encoding: "utf-8" }).trim();
const lines = data.split(/\n/);
let max = 0;
for (let line of lines) {
const id = parseInt(line.replace(/B|R/g, "1").replace(/F|L/g, "0"), 2);
max = Math.max(max, id);
}
console.log(max);
ecl:#eef340 eyr:2023 hcl:#c0946f pid:244684338 iyr:2020 cid:57 byr:1969 hgt:152cm
pid:303807545 cid:213 ecl:gry hcl:#fffffd
eyr:2038 byr:1951
hgt:171cm iyr:2011
hcl:#c0946f byr:1933 eyr:2025 pid:517067213 hgt:173cm
ecl:hzl
iyr:2018
pid:5253256652 byr:2009 hgt:152cm iyr:1989 eyr:1968 hcl:64cb63 ecl:hzl
iyr:2013
pid:862607211 eyr:2020
hgt:174cm
byr:1990
ecl:blu hcl:#888785
ecl:grn byr:1955
pid:608098408 eyr:2027 iyr:2020 hcl:#b6652a cid:264
hgt:181cm
byr:1998 ecl:hzl eyr:2021
hcl:#866857 hgt:189cm iyr:2030
pid:013735467
pid:075417314 hcl:#b6652a byr:1957
iyr:2011
hgt:154cm
eyr:2025
ecl:amb
iyr:1993 hgt:74cm eyr:1960
byr:2029
hcl:293244 ecl:#3cb5e5 pid:4861232363
hgt:153cm hcl:#6b5442 pid:065240897 byr:1932
cid:196 ecl:blu eyr:2028 iyr:2019
eyr:2024 ecl:amb
hcl:#866857 byr:1922 pid:496904942 hgt:164cm iyr:2020
pid:847705161 byr:1951 cid:124 iyr:1991
eyr:2028 ecl:dne
hcl:6b2d28 hgt:172cm
byr:2007 iyr:2029 ecl:hzl eyr:2026 hgt:168in
hcl:z
pid:63151612
iyr:2027 hgt:172in
cid:174 byr:2014 hcl:z eyr:1921
ecl:grt pid:#cebdc2
ecl:amb hcl:#d09c0f
iyr:2015 hgt:156cm eyr:2026 byr:1962
pid:086120872
cid:125
pid:837849996
byr:1958 ecl:brn hgt:166cm hcl:#ceb3a1 eyr:2028 iyr:2012
ecl:gry hgt:180cm
pid:939059935 eyr:2023 byr:1977 hcl:#b6652a
hgt:190in byr:2029 eyr:1984
ecl:gry hcl:z pid:055092916 iyr:2010
hgt:63in ecl:blu byr:1940 iyr:2012 eyr:2029 hcl:#7d3b0c
pid:163033394
eyr:2040 pid:181cm
iyr:1928 hgt:76cm hcl:d8aafb byr:1949 cid:275 ecl:xry
hcl:#cfa07d ecl:oth byr:1948 eyr:2021
pid:719690182 hgt:179cm iyr:2020
byr:1939 cid:266
eyr:2026 iyr:2017 hcl:#f116d2
ecl:hzl pid:522421825
hgt:68in
hcl:z hgt:61in
cid:115 pid:180cm iyr:2030 byr:2014 eyr:2032 ecl:hzl
ecl:xry
eyr:2028 pid:191cm iyr:2015 hgt:150cm byr:2029
eyr:2027
hcl:#a97842 pid:997937480 hgt:61in iyr:2019
byr:1921
ecl:grn
hgt:163cm
pid:912318455 iyr:2016 byr:1988 ecl:brn hcl:#a97842 cid:221 eyr:2029
cid:333 hcl:#c0946f
hgt:163cm iyr:2018 eyr:2027 ecl:oth
cid:70 hcl:#c0946f
pid:961507902 byr:1949 ecl:grn iyr:2017 eyr:2029 hgt:69in
hgt:169cm ecl:amb
iyr:2013 pid:496169901
byr:1943 eyr:2028 hcl:#ceb3a1
cid:249
ecl:blu cid:343
iyr:1998 hgt:154in hcl:#efcc98 byr:1972
pid:508213120 iyr:2012 eyr:2025 hcl:z hgt:70cm byr:1976
ecl:brn
iyr:1924
eyr:2005
hcl:z
hgt:167 pid:154cm
byr:2007
pid:761333244 hgt:180cm iyr:2017 hcl:#18171d eyr:2021
byr:1983
cid:67 ecl:oth
eyr:1993
byr:2003
hcl:#602927
ecl:grt
cid:84 hgt:178
pid:1847086637 iyr:2026
hcl:#866857 hgt:162cm pid:483774485 iyr:2010
byr:1946 eyr:2028 ecl:gry
pid:726639691 eyr:2028
hgt:171cm hcl:#ff65a6
iyr:2011 byr:1989
hcl:z iyr:2026 ecl:xry
eyr:2037 byr:2005 pid:#f09a0f
hgt:68 cid:156
hgt:71in ecl:blu eyr:2026 hcl:#18171d
byr:1981 iyr:2017
pid:698636544
eyr:2021
byr:1957 ecl:brn pid:365378126 cid:93 iyr:2019 hcl:#18171d hgt:179cm
byr:1996 iyr:2014 hgt:64cm
eyr:2034
hcl:z
pid:629486472 cid:140
hgt:192cm eyr:2020 hcl:#b6652a iyr:1988 byr:2021 ecl:brn
byr:1955 iyr:2015 eyr:2030
ecl:gry hcl:z pid:6550198754
hgt:158cm cid:305
ecl:gry hcl:#a97842
hgt:176cm eyr:2022 pid:810146585 iyr:2020
byr:2027 hcl:#cfa07d
iyr:2011 ecl:#f07598
cid:293
hgt:150cm pid:#fa948d eyr:2029
eyr:2028 iyr:2013 hgt:69in ecl:gry pid:317170371
cid:147 hcl:#bfe1f1
byr:1976
pid:059341891 hgt:174cm
ecl:oth
eyr:2029 iyr:2017 hcl:#733820
iyr:2018 hcl:#ceb3a1 hgt:188cm cid:308
pid:792826885 byr:1948 ecl:blu eyr:2028
iyr:2017 cid:94 hcl:#95c7dc
pid:231757803 eyr:2022
byr:1992 hgt:153cm ecl:amb
eyr:2027
iyr:2011 hgt:186cm
ecl:brn pid:996347346 hcl:#866857
byr:1960
eyr:2025 byr:2001
ecl:blu pid:755715478 iyr:2019 hgt:61in
ecl:gry
eyr:2038
hgt:81 hcl:z iyr:2028
cid:214 byr:1965
pid:412744447 byr:1979 hcl:#cfa07d ecl:blu
eyr:2029 cid:157
hgt:180in iyr:1948
hgt:170cm
pid:623557081 byr:1924 eyr:2024 hcl:98d623 iyr:2012 ecl:amb
cid:311 ecl:grn
iyr:2011 byr:1982
eyr:2002 hcl:#ef318a
pid:0548169957
hgt:87
eyr:2030 hcl:#733820 iyr:2016 pid:558470391
byr:1936 ecl:oth hgt:185cm
iyr:2019
ecl:amb byr:1949
pid:376468392
hgt:178cm
pid:019195245
ecl:grn hgt:171cm
byr:1978 iyr:2011 eyr:2022 hcl:#733820
cid:134
hcl:#623a2f hgt:192cm eyr:2026 byr:1977
ecl:grn cid:308
ecl:hzl pid:715816358 hgt:69in iyr:2014 hcl:#623a2f
byr:1996
eyr:2027
iyr:1947
ecl:#39a697
hgt:183cm byr:2029
eyr:2022 pid:7951883913
hcl:z
ecl:gry byr:1950
hcl:#18171d hgt:168cm iyr:2020 pid:677187333 eyr:2027
byr:1969 ecl:blu hcl:#18171d iyr:2011
hgt:162cm
pid:701349891
cid:269 byr:1966
iyr:2011
pid:905940527 eyr:2023 hgt:190cm
ecl:brn hcl:#ceb3a1
eyr:2027 pid:454627395 ecl:brn
hcl:#ceb3a1 cid:302 hgt:184cm
byr:1959
iyr:2015
iyr:2011
eyr:2028
hgt:166cm
hcl:#733820 byr:1938 ecl:blu pid:857984986
hcl:#c0946f ecl:brn pid:226877822
hgt:182cm byr:1998
cid:160
hgt:186in pid:26499164 byr:2017
hcl:z
iyr:1998 eyr:2026
cid:331 ecl:#236556
pid:328866543
hgt:165cm eyr:2039 iyr:1987 ecl:amb byr:2018 hcl:z
iyr:2016 eyr:2036 hcl:#888785 byr:1976 pid:160402352 hgt:76cm ecl:blu
ecl:blu
hcl:#fffffd eyr:2025 hgt:66in pid:979788527
byr:1957 iyr:2013
ecl:grn pid:279357265 iyr:2019 eyr:2021 byr:1953
hgt:177cm hcl:#c0946f
ecl:oth hcl:z eyr:2025 byr:1949 hgt:189cm iyr:2020 pid:901383503
byr:2019 hcl:#733820
pid:31022828 eyr:1929
hgt:75cm iyr:2012 ecl:grn
pid:080462937
ecl:blu hcl:#866857
cid:102
iyr:2013 eyr:2025 byr:1975 hgt:64in
iyr:2016
eyr:2028
cid:125
byr:1979 hcl:#866857
ecl:brn hgt:173cm pid:814947616
hcl:z byr:2020 pid:#c3b54b hgt:174in eyr:2038
iyr:2016
ecl:gmt
cid:132
iyr:1958
pid:61543452 hcl:z
ecl:zzz eyr:2039 byr:2006
cid:55 eyr:2022 byr:1954 iyr:2015
hgt:188cm hcl:#a97842 pid:49143631 ecl:amb
hgt:152cm
byr:1982
iyr:2013 ecl:blu
hcl:#341e13
eyr:2026 pid:440841976
iyr:2019 ecl:blu pid:553456616 hcl:#733820 hgt:160cm byr:1932 eyr:2030
byr:1980 hgt:169cm hcl:#7d3b0c cid:312 iyr:2010
eyr:2026 pid:028550304 ecl:grn
ecl:amb eyr:2021 iyr:2014 hgt:71in pid:986053283 byr:1981
ecl:oth
eyr:2023 hcl:#888785
byr:1949
iyr:2016 pid:699325656
hgt:63cm cid:297 eyr:2020 pid:990390922
hcl:#602927 ecl:lzr
iyr:2012 byr:2016
hcl:9ea2fa eyr:2023 pid:088680493
byr:1998 iyr:2017 ecl:utc hgt:170cm cid:175
cid:316 iyr:2016 eyr:2026 hcl:#79ff1d hgt:65in
byr:1997 pid:215466710 ecl:oth
cid:213 byr:1983 hcl:#888785 iyr:2016 pid:767747981 eyr:2025
ecl:hzl hgt:168cm
eyr:2030 byr:1972
cid:282
ecl:gry hgt:178cm
hcl:#a97842
iyr:2018
hcl:#6b5442 ecl:amb
eyr:2028 cid:104 hgt:159cm pid:446429120 iyr:2012
byr:1938
byr:1940 hgt:178cm ecl:oth
hcl:#ceb3a1
pid:845683663 iyr:2015 eyr:2024
byr:1940 pid:496262233
hgt:184cm hcl:#b6652a
ecl:grn cid:152 iyr:2012 eyr:2029
hgt:185cm pid:455744229 byr:1954 eyr:2022 ecl:gry hcl:#6b5442 iyr:2012
hgt:182cm byr:1966 eyr:2028 ecl:#a5b7fc
iyr:2029
pid:343591896
cid:58
ecl:hzl
eyr:2022 hgt:180in byr:2021
hcl:#6b5442
ecl:utc hcl:#b6652a
pid:635147657 byr:2020
eyr:2022 hgt:157cm iyr:2018
ecl:grt cid:312 iyr:1959 pid:154262836
hgt:171cm
hcl:#fffffd
eyr:2024
byr:1982
hcl:#7a12b4 pid:223424149 ecl:hzl hgt:175cm
byr:1930 iyr:2010 eyr:2028
hcl:#c0946f pid:633476454 eyr:2026 iyr:2011
byr:1934
hgt:186cm
cid:289 ecl:gry
hcl:#fffffd pid:376300524 hgt:155cm byr:1964 iyr:2017 eyr:2021 ecl:grn
hcl:a5d4dc byr:2006 cid:165 ecl:#db800f iyr:2029 pid:0199789970 eyr:1961 hgt:61cm
eyr:2027 hgt:170cm iyr:2010
hcl:#c0946f
ecl:grn pid:415726530
byr:1985
cid:197 byr:1957 hgt:192in hcl:#a97842 ecl:hzl eyr:2029 pid:958973455 iyr:2011
iyr:2015 pid:933689314 hgt:162cm ecl:amb
cid:122 eyr:2021
hcl:#6b5442 byr:1973
eyr:2026 hgt:172cm
iyr:2012
ecl:brn hcl:#733820 pid:004474632
byr:2000
hgt:191cm eyr:2030 byr:1999 pid:9155071477 iyr:2026 hcl:#602927 cid:315
ecl:grn
iyr:2010 pid:182884251 hcl:#18171d hgt:154cm
eyr:2020
byr:1926 ecl:oth
iyr:2019 eyr:1920 pid:132839546
cid:283 hgt:188in hcl:#efcc98 byr:2027
iyr:2011 hgt:177cm
cid:117 byr:1976
ecl:gry
hcl:#623a2f eyr:2030 pid:134592046
byr:1968 hgt:146
iyr:2013 hcl:eefdc4 eyr:2028
ecl:xry pid:722120008
iyr:2016 byr:1941 hgt:67cm cid:51 hcl:#b6652a ecl:hzl eyr:2034 pid:994005715
hcl:#cfa07d ecl:oth
hgt:182cm eyr:2021 pid:612583941
byr:1983
iyr:2019
byr:1922
hcl:#602927 hgt:161cm ecl:gry eyr:2020 pid:190170808 iyr:2013
hgt:63cm cid:136
iyr:1999
pid:8235748647 hcl:z
byr:2022 eyr:1933
ecl:#304383
cid:273 ecl:blu hcl:z
iyr:2011 byr:2007
eyr:2020
pid:942473857 hgt:178in
ecl:grt byr:2029 hgt:187in eyr:2030 cid:160
hcl:#efcc98 pid:#39f22b
iyr:1966
byr:1978 ecl:oth iyr:2011 hgt:164cm eyr:2027 hcl:#cfa07d
hgt:75cm hcl:#1e8137 byr:1986 ecl:blu eyr:2022 pid:796688423
iyr:2012
eyr:2026
ecl:#3013af hcl:z pid:#e8597f hgt:123 iyr:2025 byr:1942
hcl:z hgt:177in
iyr:1993 pid:#4c9348 byr:2008 eyr:1989
pid:123524366 byr:1935
hgt:156cm hcl:#7d3b0c
iyr:2020 ecl:brn eyr:2020
hcl:z eyr:2038 pid:7663741757 ecl:gmt hgt:174
byr:2008 iyr:1939
cid:225
hcl:#888785 hgt:172cm
ecl:oth pid:500711541 eyr:2027
byr:1931 iyr:2012
pid:575447108 ecl:amb byr:1943
hcl:#888785 hgt:173cm eyr:2024
eyr:2021 iyr:2010 pid:178773264 hgt:157cm byr:1965 hcl:#bb7bcf ecl:amb
iyr:2023 ecl:#35bd84 byr:2020
hgt:72in
eyr:2037
hcl:#6b5442
pid:421311669
byr:1921 iyr:2011
pid:146088688
eyr:2023 hcl:#15ed24 hgt:183cm
ecl:brn
hcl:#b6652a cid:243
byr:1993 eyr:2024
iyr:2014 hgt:172cm
pid:771275594
eyr:2024
hcl:#cfa07d pid:858807920 cid:293 hgt:157cm ecl:hzl iyr:2013 byr:1984
ecl:blu hgt:193cm cid:73 hcl:#18171d eyr:2026
iyr:2016 pid:124151812 byr:1945
ecl:amb iyr:2018
pid:214555737 hgt:157cm
eyr:2028
byr:1925 hcl:#866857
pid:5633250409
hcl:4ef7d8
byr:2004 iyr:1958
hgt:96
eyr:2038 ecl:xry cid:274
byr:1972 pid:401239851 hgt:184in hcl:z iyr:2017
eyr:2030 ecl:#cb289a cid:140
hgt:175cm
byr:1926 hcl:#cfa07d eyr:2029 ecl:gry pid:325039730 iyr:2017
cid:101 hgt:166cm byr:1986 ecl:amb
hcl:#7d3b0c iyr:2013
pid:413769688 eyr:2024
hgt:159cm cid:311
byr:1993 eyr:2028 pid:188cm ecl:oth hcl:#602927 iyr:2013
pid:565831038
ecl:amb
hgt:155cm hcl:#fffffd cid:335 iyr:2016
eyr:2029 byr:1997
hgt:122
byr:2022
eyr:2028 ecl:blu iyr:2017 pid:269710626 hcl:#b6652a
cid:196
byr:1953 hcl:#6b5442 iyr:2010
pid:216121215 hgt:188cm ecl:blu
iyr:2011 hcl:98166c hgt:62cm
byr:2028
eyr:2024
pid:792478385 ecl:grn
hcl:#efcc98 iyr:2012 pid:020039675 eyr:2021 byr:1974 hgt:156cm
ecl:hzl
cid:123 hcl:#7d3b0c
byr:2026 eyr:2004 iyr:2012 ecl:oth pid:349203133 hgt:160cm
pid:085461475
byr:1962 iyr:2020 hcl:#623a2f
eyr:2024
cid:80 ecl:brn
hgt:154cm
ecl:oth hgt:156cm iyr:2016
hcl:#6b5442
byr:1973
eyr:2021 pid:539898580
iyr:2026 hgt:191cm
hcl:z
byr:1930 pid:#abc2f0 ecl:blu cid:242 eyr:2024
cid:167
hgt:179cm
iyr:2017 eyr:2021 pid:756797571 byr:1949 ecl:brn hcl:#a97842
byr:1975 eyr:2030
ecl:oth hgt:169in pid:4031206183 hcl:#733820 iyr:2017 cid:244
ecl:#54cfeb hgt:152cm
iyr:2026 hcl:36b4b9
byr:2030
pid:#fa1cb9 eyr:1964
byr:1974 cid:99 hcl:9e3296
eyr:2032
pid:686747414
iyr:1995
ecl:amb
iyr:2030 ecl:oth hcl:z byr:1979
pid:114661006 hgt:191cm eyr:1941
hcl:#341e13 iyr:2014 byr:1953
pid:188326193 ecl:gry hgt:189cm cid:283
eyr:2030
byr:1975
pid:092061576 hgt:73in eyr:2023
ecl:brn cid:227 hcl:#5e9d91
iyr:2011
hcl:#7d3b0c hgt:167cm cid:141
eyr:1957 byr:2012 ecl:gmt iyr:2019 pid:#1b7c8a
hgt:168cm hcl:#c0946f pid:599500784 byr:1930 eyr:2023 ecl:hzl cid:113
iyr:2013
eyr:2030 hcl:#b4cb4f
hgt:68in
ecl:brn byr:1923 pid:699162086
iyr:2013
ecl:dne hcl:z eyr:1971
pid:#580add byr:2020
hgt:190cm
hcl:#ceb3a1
byr:1976 eyr:2020
cid:162 iyr:2016
hgt:168cm
ecl:hzl
pid:050478613 hgt:59cm
iyr:2017
ecl:grn byr:2030 hcl:#cfa07d eyr:2025
pid:352943968 eyr:2025 byr:1980 iyr:2014 ecl:gry hcl:#c0946f
hgt:193cm
pid:328621931 cid:310 hgt:170cm
hcl:#733820 byr:1955
iyr:2016
eyr:2028 ecl:hzl
hcl:#866857
pid:095858739 byr:1956
iyr:2018 hgt:193cm
ecl:hzl
eyr:2029
pid:70973661 eyr:2039 ecl:gry
iyr:2016
cid:291
hcl:#623a2f hgt:97
hcl:4d51a8
eyr:1978
ecl:gmt
byr:2029 iyr:2022
pid:34507041 hgt:61cm
byr:1989 ecl:brn pid:769582914
eyr:2026 cid:218
iyr:2020 hcl:#866857 hgt:184cm
ecl:brn
iyr:1998 cid:227
hgt:162in
byr:2026
hcl:#602927 eyr:2027 pid:236998728
ecl:gry byr:1984 hgt:157 cid:295
eyr:2020
iyr:2018 hcl:#733820
pid:037871534
hgt:166cm hcl:#c0946f pid:412146401
iyr:2011
eyr:2022
byr:1938
ecl:brn
ecl:brn cid:95 byr:1981 eyr:2030 hcl:#efcc98 pid:777041035 hgt:152cm iyr:2011
eyr:2024 hgt:89 pid:3761913749 iyr:1939 byr:1967 hcl:a222f6 cid:165 ecl:#7fe574
cid:339 hgt:156cm
ecl:brn iyr:2013 byr:1951 hcl:#efcc98 eyr:2026
pid:863566946
ecl:brn hcl:#6b5442 eyr:2023
pid:787129723 byr:1949 iyr:2015
pid:#7f615a
cid:202 hcl:#6b5442 eyr:2028
ecl:#a5419c
hgt:75cm
iyr:2011
byr:2001
pid:864001133
cid:236
byr:1943 hcl:#733820 ecl:dne eyr:2025 hgt:171cm iyr:1989
pid:193073684 ecl:grn byr:1962 iyr:2014
hcl:#cfa07d hgt:189cm
cid:321 eyr:2029
byr:1959
hcl:#b6652a
eyr:2026
hgt:159cm pid:815014918 iyr:2011 ecl:amb
iyr:2017 hgt:182cm
hcl:#a97842 eyr:2023 ecl:grn pid:656177536
byr:1973
eyr:1923 ecl:grn
cid:138 iyr:2020
hgt:164cm byr:1958 hcl:#c0946f pid:783366277
iyr:1932 hgt:172 ecl:blu
hcl:#733820 byr:1962 pid:554221464
cid:169 pid:922622614
byr:1942 hcl:#ceb3a1 hgt:169cm eyr:2024
ecl:gry iyr:2017
cid:219 ecl:grn
hgt:156cm byr:1998 eyr:2021
iyr:2017 hcl:#ceb3a1 pid:450186263
ecl:amb hgt:179cm pid:768428582 iyr:2010 eyr:2023 byr:1952 hcl:#fffffd
eyr:2024
hgt:193cm
iyr:2017 pid:469033795 byr:1979 hcl:#18171d cid:67 ecl:amb
iyr:2016 byr:1937 pid:798267514 hgt:155cm hcl:#866857 eyr:2026
ecl:oth
hgt:172cm hcl:#866857 iyr:2018 pid:662186551
byr:1996
eyr:2025 ecl:amb
pid:2854521962
iyr:2021
ecl:zzz
hcl:12f1ba eyr:2037 hgt:159cm
byr:1937
ecl:oth pid:488050418 byr:1927 hcl:#a97842 hgt:153cm iyr:2013 eyr:2024
pid:119536312 ecl:#2036ad
hcl:543178 iyr:2020
byr:2013
hgt:177cm
eyr:2022
pid:788908662 hcl:#602927 eyr:2029
ecl:oth byr:1930
iyr:2020
hgt:179cm
byr:1972
pid:053386972 iyr:2014 ecl:grn hgt:65in hcl:#cfa07d
pid:9828921035 ecl:blu
hcl:z hgt:152in
eyr:1949 byr:2010
cid:157 pid:097910554 byr:1999
hgt:159cm hcl:#6b5442 ecl:blu eyr:2024
iyr:2010
hcl:#a97842
eyr:2040 ecl:#f8ad77
hgt:173cm
byr:2019 iyr:2010
pid:#d16a6e
ecl:dne hgt:191cm iyr:2020 hcl:#b6652a
eyr:2021 pid:571971509 byr:1983
hcl:#18171d iyr:2016 pid:159074622
eyr:2027 hgt:163cm byr:1954
cid:257
pid:243560302 cid:58
hcl:53a4cf byr:2012
ecl:#fdbfb8 eyr:1920 hgt:179 iyr:2026
pid:040606106 eyr:2030 hgt:188cm
byr:1969
iyr:2012 hcl:#ceb3a1 ecl:amb
eyr:2022
hgt:175cm hcl:#b6652a byr:1967 pid:269969031
iyr:2018
hcl:#18171d cid:278 byr:1931
pid:134809791
eyr:2035 ecl:#44e6cd iyr:1993
hgt:177in
ecl:utc cid:289
iyr:1923
hcl:13a67a pid:3045345984 byr:2030 eyr:1944
pid:839901650 eyr:2030
ecl:grn
byr:2015 iyr:2017 hgt:168 hcl:131f4e
iyr:2015 pid:529736732 ecl:brn hgt:176cm
eyr:2026 byr:1952 hcl:#6b5442
hcl:#c0946f
cid:323 pid:303966428 iyr:2019
eyr:2027 hgt:170cm
byr:2001
ecl:brn
pid:193678728 hgt:72in eyr:2027 iyr:2015 byr:1951 ecl:gry hcl:#18171d
eyr:2026 cid:283
iyr:1938 pid:687430885
hgt:186cm
byr:1949 ecl:#521638 hcl:d13b2f
eyr:2024 hcl:#ceb3a1 iyr:2013 ecl:brn
hgt:168cm pid:792088241
hcl:#888785 ecl:amb
byr:2009 iyr:2015
hgt:151cm
eyr:2020 pid:223927808
byr:1926
pid:717704850
hcl:#623a2f eyr:2022 hgt:64in iyr:2018 ecl:gry
eyr:2023 byr:1954
hgt:169cm
ecl:hzl
iyr:2010 pid:116868997 hcl:#18171d
ecl:hzl byr:1965 hcl:#a97842 iyr:2011 pid:506354451 hgt:172cm eyr:2029
eyr:2022 pid:994565705
iyr:2013 ecl:brn hcl:#623a2f
byr:1979
iyr:2011
byr:1931 hgt:183cm hcl:#284f26 cid:306
ecl:amb eyr:2021
pid:977533079
eyr:2027
iyr:2011 ecl:gry
byr:1993
pid:272334781 hgt:161cm hcl:#9a35b6
eyr:2026
hcl:#602927 ecl:blu
pid:212300161 byr:1946
cid:193 iyr:2020 hgt:157cm
pid:538594567 byr:1976 eyr:2027 hcl:#efcc98 iyr:2011 hgt:154cm ecl:oth
byr:1949
hcl:z ecl:#ce67aa
eyr:1942 pid:7978941589 iyr:2025 hgt:161in
hcl:#c0946f
cid:55
byr:1963 ecl:blu hgt:161cm
pid:547120453 iyr:2015 eyr:2021
hgt:173cm eyr:2022
iyr:2016 byr:2001
ecl:hzl pid:239803460
hcl:#b6652a ecl:oth eyr:2021 hgt:167cm pid:401266644 iyr:1969 byr:1974
eyr:2030 pid:581963885
hcl:#64cb23
ecl:blu
byr:1928 hgt:181cm iyr:2018
pid:186338247
ecl:hzl hgt:193cm hcl:#ceb3a1
eyr:2022 iyr:2010
iyr:2015 ecl:gry hgt:159cm eyr:2027 hcl:#ceb3a1
byr:1925 pid:715902111 cid:149
iyr:2018 hcl:#623a2f eyr:2020 hgt:162cm ecl:grn cid:135
byr:1922
pid:373216777
eyr:2020 pid:749899012 hcl:#888785 ecl:brn
iyr:2010 cid:225 hgt:172cm
byr:1972
iyr:2020 hgt:178cm ecl:grn hcl:#18171d pid:613792489 cid:240
eyr:2028
byr:1972
iyr:2015 byr:1938 eyr:2026
cid:113 ecl:grn
pid:846231640 hgt:161cm
hcl:#b6652a
ecl:gry
hcl:#ceb3a1
byr:1956 cid:338 pid:936012518
hgt:62in
eyr:2029 iyr:2016
pid:730866353 ecl:brn byr:1986
iyr:2014
hgt:190cm
eyr:2021 hcl:#a97842 cid:126
eyr:2021
cid:180 pid:958310635 ecl:brn iyr:2015 hgt:189cm hcl:#efcc98
hgt:188cm ecl:hzl pid:179001863 iyr:2016 eyr:2029 hcl:#341e13 byr:1932
cid:77 eyr:2027 hcl:#623a2f iyr:2016 ecl:brn hgt:170cm
byr:1947
hgt:66in pid:617518313 iyr:2013 byr:1977 hcl:#b6652a ecl:brn eyr:2025
pid:787861420
iyr:2014 hcl:#623a2f hgt:61in
ecl:oth cid:78
eyr:2022 byr:1975
ecl:hzl
iyr:2017 eyr:2028 hcl:#602927
byr:1958 pid:985208714
hgt:160cm
byr:2002
iyr:2013
hcl:#341e13 pid:188110633 ecl:gry hgt:169cm
eyr:2025
byr:1981
eyr:2028
hcl:#341e13 ecl:amb hgt:160cm cid:121
iyr:2015 pid:963848397
iyr:2013 hcl:#866857 pid:#db8648 eyr:2021 ecl:gry
byr:1975
hgt:153cm cid:114
hgt:109
cid:287 hcl:#6b5442
iyr:2028 byr:1926 eyr:2036 pid:2378208387
ecl:#245a62
pid:857722366
byr:1975 eyr:2027
ecl:grn iyr:2019 hcl:#0afad1
hgt:66in
byr:1935 hcl:#cfa07d hgt:173cm ecl:brn eyr:2021 iyr:2019
cid:66 eyr:2024 hcl:#efcc98 byr:2002 iyr:2010
hgt:176cm pid:697153153 ecl:amb
iyr:2019
hcl:#cfa07d ecl:blu
pid:695914972
eyr:2024
hgt:158cm
byr:1943
ecl:xry hgt:62in
pid:14733148 cid:148
iyr:2016 byr:1925 hcl:#6b5442
eyr:2028
iyr:2025
cid:53 hgt:132 ecl:gmt hcl:159b19
pid:156cm
byr:2025 eyr:2001
hcl:#623a2f ecl:oth byr:1974 iyr:2018 hgt:161cm eyr:2029 pid:6826285172
ecl:gry
byr:1956 hcl:#7d3b0c hgt:170cm iyr:2020
eyr:2020
pid:#946a88 hgt:186cm hcl:#733820 byr:1946 ecl:#016645 iyr:2015
hgt:181cm hcl:#888785 iyr:2013 pid:634152817
byr:1982 cid:245 ecl:grn eyr:2021
ecl:brn
pid:737531770 iyr:2010
eyr:2020
byr:1929 hgt:189cm hcl:#c0946f
cid:158 iyr:2019 hcl:#341e13 eyr:2027 ecl:amb
byr:1986 pid:834976623
pid:976934668 cid:61 eyr:2020 iyr:2020
hgt:76in byr:1927 ecl:amb
hcl:#e05ee3
pid:526042518 iyr:2019 eyr:2027 hcl:#623a2f byr:1976 ecl:amb
pid:279367290 hcl:#a97842 hgt:158cm
eyr:2027
byr:1959
iyr:2020
ecl:xry byr:2028
pid:357216861 hcl:#a97842 eyr:2024 hgt:66cm
iyr:2012
hgt:188in
ecl:lzr cid:64 eyr:1958 byr:2014 hcl:z pid:285207570 iyr:2026
eyr:1973 iyr:2017 ecl:oth cid:282 pid:695814158
hcl:z
iyr:2010 pid:661168409
hcl:#53c696
hgt:186cm ecl:amb
byr:1960
eyr:2029
eyr:1982 hgt:169cm
iyr:2002 byr:2025 hcl:327f93 pid:831648100
byr:1967 ecl:oth
eyr:2021
hcl:#602927 iyr:2014
pid:274974402 hgt:183cm
### fix off by one, I mutated the input to make code simpler
const fs = require("fs");
const readline = require("readline");
(async function () {
const rl = readline.createInterface({ input: fs.createReadStream("input.txt") });
const fields = ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid", "cid"];
let lines = [];
let found = {};
let result = 0;
const re = /(\w{3}):\s*([^\s]+)/g;
for await (let line of rl) {
line = line.trim();
if (line.length > 0) {
lines.push(line);
} else {
if (lines.length > 0) {
const combo = lines.join(" ");
let match;
while ((match = re.exec(combo))) {
found[match[1]] = match[2];
}
const foundKeys = Object.keys(found);
if (
foundKeys.length === fields.length ||
(foundKeys.length === fields.length - 1 && !foundKeys.includes("cid"))
) {
if (/^\d{4}$/.exec(found.byr) && Number(found.byr) >= 1920 && Number(found.byr) <= 2002) {
if (/^\d{4}$/.exec(found.iyr) && Number(found.iyr) >= 2010 && Number(found.iyr) <= 2020) {
if (/^\d{4}$/.exec(found.eyr) && Number(found.eyr) >= 2020 && Number(found.eyr) <= 2030) {
const h = /^(\d{1,3})(cm|in)$/.exec(found.hgt);
if (
h &&
((h[2] === "cm" && Number(h[1]) >= 150 && Number(h[1]) <= 193) ||
(h[2] === "in" && Number(h[1]) >= 59 && Number(h[1]) <= 76))
) {
if (/^#[0-9a-f]{6}$/.exec(found.hcl)) {
if (["amb", "blu", "brn", "gry", "grn", "hzl", "oth"].includes(found.ecl)) {
if (/^\d{9}$/.exec(found.pid)) {
result++;
} else console.log("bad pid", found.pid);
} else console.log("bad ecl", found.ecl);
} else console.log("bad hcl", found.hcl);
} else console.log("bad hgt", found.hgt);
} else console.log("bad eyr", found.eyr);
} else console.log("bad iyr", found.iyr);
} else console.log("bad byr", found.byr);
}
}
lines = [];
found = {};
}
}
console.log(result);
})();
const fs = require("fs");
const readline = require("readline");
(async function () {
const rl = readline.createInterface({ input: fs.createReadStream("input.txt") });
const fields = ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid", "cid"];
let lines = [];
let foundFields = [];
let result = 0;
const re = /(\w{3}):\s*[^\s]+/g;
for await (let line of rl) {
line = line.trim();
if (line.length > 0) {
lines.push(line);
} else {
if (lines.length > 0) {
const combo = lines.join(" ");
let match;
while ((match = re.exec(combo))) {
foundFields.push(match[1]);
}
if (
foundFields.length === fields.length ||
(foundFields.length === fields.length - 1 && !foundFields.includes("cid"))
) {
result++;
}
}
lines = [];
foundFields = [];
}
}
console.log(result);
})();
......#..##..#...#...#.###.....
#..#............#..........#...
..........#....#..........#....
....#..#.#..........#..#.....#.
#.......#...#......#........###
#####........#.#....##..##..#..
......#.#..#..#..##.#..#.##....
.#..#.#..............##....##..
..##......#....#........#...###
...#....#.#....#.#..#......#..#
..................#.....#.....#
#.#...#...#....#............#.#
.#...#.....#...##........#.....
...#....#........#..#....#..###
#...##.....##.#.#...........#.#
.###........#.#.#.........#....
...#.............###.....#.#..#
.####.#..#....#.....#.........#
.#.#........#.#.....#.....#....
.#.......#................##.##
...#.#..#...###.....#....#..##.
...#....##..#............##...#
#...#............######...#.##.
.........#........#.#...#..##..
.....###..#.#.....##.#.#......#
..#.#...#.#..#.#.##..#.....#.#.
..#......#.#....#...#..........
..#...#.....#.#...##.....#.....
.##...........####........##...
....#............#.#...........
.....####.........#.##....###..
#..#..#.#..............#.#.....
...#.#........#.........#......
......#.#.#...#.....#....#.....
........#.#...#####..#..#......
.....#.#....#....#...........##
.#...#.........#.......##......
.#.##..##......#...............
...#.....#.......#.#.#.........
.........#..#...#...#.#.##....#
.#......##....#..#.........#...
....#.....#........#.........##
......#...........##...........
.....#..............###.#....#.
........#..#...#..#..#..#..#.#.
.#.....#.##.#..#..#.#.....#....
...#....#...#.#.....##.#...#..#
#..#......#..#.###...........#.
.##...##.#........#.#......#.#.
...#.#..#.#.......#..###...##..
#.......#.#....#..........#....
.#.....#..#.#.#..#..#........#.
.#...#......#.#...#.##.....#.##
...######..#.#....#.........##.
#.#.......................#....
..#..##...#...#.#..##.......#..
.##..#.......##......##.#..#...
#.#....##.......#..#...........
..#...#............#..#........
........#.#.........#...#..#..#
.#...###...............##...#..
...........#.....#....#....###.
#..#....##..#................##
...#.#..#..##......#....##....#
...#.##...#....#..#....#.......
#...##..##.#.........#...#....#
.##........###.#..........#....
..#..#..#...#.##..#.#......#...
.......##..#....###.##.....#..#
#....#...#.#.....#..###....##..
.#.......#.........#....#.#..#.
.........#.......#.#.......#...
..........#...##..#...#....#.##
..#........#.......#...........
#....#.....##......#....#.#...#
......#.....#....#.....#..#....
.#....##...#...##..............
..#....#......#...#....#...#...
#....###...##..#.#....##......#
..#.......#.........#..#......#
...#...#.##.......#....##..#...
..#.#...#.##..#..#..#...#.#...#
.#.........###....#....#.....#.
.#.##.#..##..#...........#....#
....##..#..##.#.......#....#..#
....#..#.........##..#......#.#
..........#.#.#....##.#......##
.##...#....###...#..........#..
#..#.....#..#.#.#.#..#......#.#
......#....#......##.#......#.#
...#.....#.......#....#.......#
.#.#................#..........
......#..#..#...............##.
##......#...#.####....#.#.#....
...#..##............#....#.....
..#..#.#...#..................#
.##.#.#..##.###.....#..#.......
..#...#.#...#......#..#........
.###..........##...###..##..#..
#.#...#........#.......##......
..##...#........#....##...##...
.......#.##.....#.#.##..#..##..
........#............#....##...
...#.#.#..#.........#.#.......#
..#..##.##...#.##...#....#...#.
.....##.#...##............##...
.#...#.###....#.......#...#...#
.......#######.#....#.....#.#..
......#.......#............##..
.....#...........#......#.....#
........#....#.##.#............
.#........#.......##.#.#....#..
#.....#..####.#................
.....#.......................##
.#.....#..##.#..##........#.#.#
#...##....#..##................
......##.###..........#.....#..
.#........#...#..............##
..#..........###.........#.....
....#.....##....#..#..#.#.#....
....#.......#.##...#.####.#....
#........#............#.##.....
..#......##.....#..#...#.......
..#......###...#.##......#..#..
#..#..#............#..#.###....
...##.........#..##...#..#.#...
..#.###..#.##.#........#..#....
......#..###.#........#........
.#....#.#..#.....#..#..#.......
#.....##.##...#...###.#.#..#.#.
.#....#..#.........#..#....###.
......##.####...#....#........#
##..#........#..#..##...#......
#.........#.........#...#..#.#.
..........#...................#
###....#....#....#......###...#
#....##........#..###.#..#.....
.#......#.....#.#.........#..#.
...#.......##.....#.........###
..............#........#.....##
....#.#..#.....###.#....##.....
.........#..##.#....#.#........
...#....#.......#.#.#..#.#....#
...........#...#..........#.#..
#.................##........###
####..#.#..#...#.....###.......
..#.#......##.#.......#........
.......##........#..#.....#..#.
...#..#......#..#.#.......###..
#....#...##..#.#.#.#.........#.
....#....#....#.#..#..........#
...###........#.#.###......##..
................#.....#.#...##.
..#..#.###...........#...###.#.
.........................#..#.#
#...#..#..##.###.....##.##.#...
...#..................#.#....#.
......#..##.#.......#.......#..
.##....#.#................#....
.#...#..#.#.#....##....#.......
.##......#.....#..........#....
..#...........#..##.........#..
....#.#...........#..........##
....#.#.#...........#.#........
......#.....#..#....##....##...
............##...##......#.#.##
#.#.....#..#....#..#...#.#...#.
.#...###..#..#.......#.......#.
.....#..#.##.....#....#...#....
##.....#..##.......##..#.#.#..#
....#.#......##....#.....#..###
.#...#.#......#.##...#..##.....
.#...#...#......##..#..#...#.#.
.#.........#....##...###...##..
###.....#......####.....#.#....
.....#..##.##................#.
.#.................#...#..##.#.
....#....#..#.......#.....#....
.##....#..#..#.....###.#..#..#.
#.#.......#.....##...#.....#...
#.#........#.#.###...#....#....
.#.....#.....##.#...#..#.......
..###.#............#...##.###..
.....#.....#..#..##............
.#.#..#.#..##..#....#...##.....
.#...........#..#.......#...#.#
#.#.#.#.....##....#............
...#.................#.#......#
.....##.............#...#.#....
.##......#.#....#..........#.#.
.#.##.......##...#...#.....#.#.
#...#.#........#......##....#.#
#....##....#....#...#..#..#.#.#
......#..........#...#.....#..#
#..#....#....#..##.#..#.#...#..
......#..#.#....#.....#.#..#..#
...#.#...###........#.#......##
..#............................
...#.#..##...##...#...#......##
...#.####......#.........#....#
.#...#.#...##....#......#.#....
.#.....##..##.#................
.#...............#.............
......#.....#...#..##..##......
...#..##.......#.......#..#.#.#
......##.....#..#.....#...#.#.#
........##........#.#........##
.#....#.....###..#.......#...#.
#...#....#.........#.......#...
...##..#........#####.#........
###..#....#.#..#...#.####......
..#..........#.#.............#.
#......#.#....#.#.#....#.##....
.#.#.#.............#....#...#..
......#.....#.#...#..###.#..#..
.....#..#............#...#...##
..#......###..#........#.#.....
#..##......#.#.#.#...........#.
#..#...##.##.....#....#..#.....
...##.#..........#.#....#...#..
.#.#.#.#..#.#...#......#.......
....#......###.#...............
.........#...#....#...#.#....#.
##.#.........#...##............
........#..........#.#...#.....
..#........#....#.......#......
#..#...............#..#...##.#.
#........#.....##.#..#....#...#
..##....#....#.#...........##..
....#.#.........#..#.....#..#..
.......##....#.#.#....###.#....
......#....#.#...#..#.........#
.....##..#....#.#......#.#.#...
#.##..##.#.......#..#...##.#.##
........#.#..#...##.#.#..#.....
#..#......#......#...#.#..#....
.....#......#.#....##....##....
....#.##...##..#..........##.#.
.#....#.......#.........#......
.#.......#.#...#...............
....#.##.......#.##..#.##..#...
#..#.......#.....#..#..........
..#.##.......#....#.#..##..#...
.#.....#...##.#.#..#...#.......
.......#.........#......#.#....
#.##.....##.......#....#.......
##.#.#.........##..#.....#....#
....#.#.#.#....#..#..##.......#
#...#...........#.#............
...#...#.#..#..##..............
......#.......#.........#..#.#.
#.....##.#....#...#..#.........
#...#..###.##..###...##.....#..
#....#.#.#...#.#..........#....
................#.#....#.....##
#.##..............####.....#.##
................#.....#........
#...#..#......#.....#......#...
.........##...........#...#...#
#.#....#...##.....#.....#..#..#
.....#...##..##.............#..
....###.#.......#.........#...#
..#.......#......#..#...#.#....
#.#....#......#.##....#.##.#...
.#.#...#.......#.#...#.##..#...
..........#......#.....#.......
........#...#.....#...##...#.#.
.....##....#.##..#........#.##.
..........##.....#..#........#.
.#....#..#.......#.##..........
.#..#..#...#...#........#.##...
.#...#.##.......#...#........#.
.....#....#.............#..#...
...#....##...#...#.....##......
#.#####.........##...#.....#...
......#.......#....#.....#..#..
..#..............#.#..#..#.....
....#.................#...#....
###.#..##.#....#...#.#......#.#
..##......#.#........#.#...##..
.....#...#...#..#.#..#..##..#..
.##...#......#...#...##.#...#..
.......###.#...........##.##...
.#.##..#.#.###.......#..##...#.
..#....#.......#..##......#....
.#....#.#..#..#.#.#....#...#...
..........##....#....#.#.......
.....#.......#.#..###.#.###....
.#.#....#.##..#.#..#.....#.#.#.
....#.....#.#.#............#...
.###....#...##......##..###..#.
...#.#..#.....#...#....##..#...
.#.#....#..........#...##.....#
#.....##...#........#.#..##..#.
.......#....#.#..........#...#.
.........#..#.#.###.........##.
..................#.#....#....#
....#....#.#..#.......###.##.##
....#...#.................#....
...#..#####.......#.#..##.##...
##.#....#...............#..#...
....#..........#...........#.#.
..##.#.##.#..#.#....#..........
.....#....#....##.#....#....#.#
.......#..##.....###...#....#.#
.#.......#..#.#.#...........#..
.#...........##.#.##....#.#....
....#.#....#.#.#......##.......
.........##......#.#.....###...
........#.#...#.##.....#.##.##.
##.#..##.#.........#....#......
.#.#.#....#..........#.#....#..
....###.........#.#.#..........
#..#....##.....#...............
#.##....#.#...#.....#......#.#.
............#.##........#......
.....#.#.....##..##............
.##..........#.......#......#..
...##..##......#.....#..#....##
.##.##...#.................##..
#....#.#........#..#....#..##.#
....##..##......#....###.#.#..#
.....#....#..#..#...##...#...#.
const fs = require("fs");
const readline = require("readline");
(async function () {
const rl = readline.createInterface({
input: fs.createReadStream("input.txt"),
});
const map = [];
const slopes = [1, 3, 5, 7, 1];
const result = [0, 0, 0, 0, 0];
const pos = [0, 0, 0, 0, 0];
let even = true;
for await (let line of rl) {
line = line.trim();
if (line.length > 0) {
result.forEach((v, idx) => {
if (idx === 4 && !even) return;
if (line[pos[idx] % line.length] === "#") {
result[idx]++;
}
});
pos.forEach((v, idx) => {
if (idx === 4 && !even) return;
pos[idx] += slopes[idx];
});
even = !even;
}
}
console.log(
result,
result.reduce((acc, v) => acc * v, 1)
);
})();
const fs = require("fs");
const readline = require("readline");
(async function () {
const rl = readline.createInterface({
input: fs.createReadStream("input.txt"),
});
const map = [];
let result = 0;
let pos = 0;
for await (let line of rl) {
line = line.trim();
if (line.length > 0) {
if (line.charAt(pos % line.length) === "#") {
result++;
}
pos += 3;
}
}
console.log(result);
})();
6-10 s: snkscgszxsssscss
6-7 b: bbbbbxkb
2-4 n: nnnjn
1-2 j: jjjj
5-9 z: jgzzzqhbj
4-11 m: mfmmmpmjmkdr
12-15 t: twqrxttwttthtkxbz
8-9 z: ftzjzzzzr
17-18 h: cpkhssvpphzvprfnft
7-8 b: bjbbbbbb
4-5 p: pppppppppgppps
16-18 r: rrrrrrrrrrrrrrrrrr
9-16 v: vvvrpvbvvvvvvvvvwvvh
11-15 d: ddddddddddddddjd
9-14 g: ggbggghggggggggw
1-5 d: ddddbd
1-4 x: xxxwxxx
1-2 l: bdjjddlqg
1-4 b: lbbxb
15-16 f: ffffffffffffffmz
10-16 m: mmlmmmvmmmbhmmmq
4-15 v: vlfvvqphhjfvlgt
5-12 m: mmmmjmwmmmmcmmm
7-8 q: qqqqqqxkq
4-9 h: hhzhhhhhhhhhsh
3-7 t: thltdtjtstzrtwtt
6-7 k: kkkkkkk
1-5 q: jqwqd
4-13 x: xxxxxxxxxxxxxxxxxx
1-4 l: llfl
6-12 n: nnffnfnnmnffnx
4-6 m: xmvxnmpmm
5-7 m: mmmmbmmmmmmmmm
9-17 f: ffffflffbfffffcffff
4-10 k: kkklkkkkkhktkkbkzq
8-15 z: kdxxzzlhpzgbzjzz
2-5 q: qrqqbqqqqqqqkqq
3-5 t: zrttht
9-12 t: ttxgntjmvntctpfrt
2-3 k: kkkk
8-10 j: jjjjjjjjjj
2-9 k: vkwkhcqnk
9-10 t: ttttttthtt
4-6 b: bbbbbbbb
9-12 n: xnvnnvldhthlsn
2-4 w: wwwwwwj
6-10 t: tttttwttttvtt
3-10 j: jqjjjxjdjnjjjj
15-18 q: kqlncdqwclqpjzrbnq
7-8 p: gpwbjppp
3-13 m: mmmmlsmfvmhmmmm
7-10 s: wdshsrsgsl
8-16 f: fffffffxfffffffcf
16-18 s: ssskswhsvslwsssrsq
12-14 j: gjjjjkjgjkjhjvj
13-14 t: gtttvftwtgvhlt
6-7 v: vvvvvgbv
2-8 l: ssldslmvl
3-9 l: bflzllqkqlkll
8-9 n: rrnnnnnnsn
7-14 p: bqsrxgplkpdvbpkn
2-5 z: wzbclnsxt
2-4 k: knkxk
6-8 d: drddjddjdd
15-16 p: ztgptpfpcwppqrzppps
1-3 k: nmsqksv
7-10 n: pwhbcwnlznfnvrlnds
13-15 t: tttttttttttttttttt
10-12 b: bbbbbbdbbgfxbbbf
3-5 w: rwwwj
18-19 x: xxxxmxxxxwpxxxfxgln
1-4 g: lfsjtgggg
13-15 x: mxzgtxhrxjhxtnf
13-14 d: ddddddddddddlx
3-5 r: rrrtrrtmlr
1-7 t: thttttttttt
2-5 g: sngggj
8-9 n: tnnnnnnnn
6-10 w: wkwwjfwltk
12-18 n: nnnnnnnnnnnnnnsnnh
14-18 m: mmmmmmmmmmmmmmmmmmmm
5-15 v: fvvfrcqkvkggnpl
13-19 f: ffffffftfffdnffffpsf
13-15 k: kgkkkmkkkgftklb
4-6 h: hhhchvh
7-14 l: qmbdhdjbrglxql
13-17 w: kwwwwwwwwwwwdpwww
1-5 q: pqqqdqqqq
8-9 p: vhwphvpfp
2-4 h: hljmh
1-2 c: tmcc
3-5 f: dpnvwffhlp
3-5 m: mmmmmm
10-12 c: ngjnczmcscxc
2-4 x: mxxj
4-6 m: xbmkmm
1-6 l: kllllsblqhngl
11-18 x: xprkjcrxkgxxgwtbmx
4-6 k: vwxshkkkkbtfbhl
11-15 z: dzzkzjjzzzzzzzlmzbn
5-6 f: ffffnfffflfjff
3-6 d: ddddddbd
6-9 r: wrrrvrrrr
8-9 n: nnnnjnnnt
2-7 b: bxptdkctbrxfllpvj
3-4 x: hxxv
5-14 n: nrnnnlsnznnzrqnjxnp
1-3 w: wwww
9-12 x: xxmxxxxxxxxxtxx
10-14 j: jjnjjjjlvjkcsjjdllvj
4-6 w: wgwbwwww
10-12 t: ttqttttttttl
10-11 t: ttwtttttttv
9-15 t: ttttttttftttttttt
2-3 p: pfgp
2-4 z: brrksnvqjzwqjvjs
8-9 n: knnnftzjbqj
6-7 w: swjwwdwwwwwwwww
1-2 j: xjlrkjjztrjfpss
13-14 l: llllllllllllvlllllr
7-12 l: lllllllllllblllll
7-8 j: gqdcmjqh
3-9 g: gchkbvgvgw
15-17 b: bbbbcbbbgbbbbbmbg
1-7 h: qlmhhcdhhhhhhhhhh
2-15 c: ccccccccccccccscccc
1-2 q: xvch
3-9 w: wwwwwwxwww
2-4 x: jskx
3-7 t: btwsnvts
9-11 g: gkhgwctggbm
2-7 g: xvgwwltdvnzscbtqwb
1-11 k: kkqkpkkdkkkkkkkhkk
4-12 h: nbqlhjbqhxtnxlzlr
3-4 d: dwdd
8-9 k: kkkzbckklqqkhfkqkk
7-8 c: pcxmqdwc
2-4 v: qbvwvvnvvp
3-9 c: pfqcblwxcrmx
1-9 t: fwgtcrftktt
7-8 p: pppppppp
6-13 w: dnwfhwkjffpdwgzdf
10-14 k: kkkkkkhkkwkkkkkk
2-4 s: zscssddtpmqblmd
11-13 b: dbvzwthlcmbkb
1-4 k: kqlxwvbkckwzmqxvtcc
2-10 s: sxssssgsssxsssnss
3-9 w: nxrmwlpgw
10-13 w: wwsgwwwwwwwkw
9-13 v: vhvvwjvcvbvvg
5-7 n: fbvnjpt
3-4 x: xxxx
9-10 l: rlllmlllll
7-9 d: ddddddddhd
4-8 z: zzzhzzzf
11-12 m: mmmmmmmmmmkf
4-8 m: bmfzppcqttct
2-4 m: mfmcmmmcx
2-9 p: rppzgvshn
7-8 r: rrrrrrrrrrvr
6-7 p: hkltppp
7-10 m: mmmmmfmmtmmmpbmm
6-14 p: pppppppppppppxp
4-6 p: wbspppnlmc
2-4 n: xnfnl
2-5 q: nqkcqmvwp
2-3 d: ddkbkdjd
5-9 b: qxjbblbrb
14-16 b: bbbbbbbbbbbbbqbbb
5-6 p: dppppp
5-8 j: kxztnjjn
14-18 k: krkkkkckkkkmktkkkkd
7-8 n: nnngxnfpnn
16-17 c: ccmccccccccccccfcccc
1-3 g: wggg
1-2 c: cqcckc
2-8 g: gjwdkbds
10-17 s: hswqssmttskspdlkkss
14-16 b: bbbbbbbbbbbbpbbrbbbb
12-16 r: srrmcbrrcrzrdwzng
2-3 h: fcws
9-13 p: gkgpqpghpjbpz
9-10 m: mmmmmmmmmmm
3-4 b: brbb
2-3 p: gncvqdhp
2-7 g: gdggggggggggggg
2-7 j: jjjjjjrjqjjj
3-5 v: ltptjlntf
1-7 w: gwwwwwfww
7-10 z: zzzzzzmzzzz
10-12 x: xxhxxxxxxgxsxxxx
11-12 b: bbbbbbbbbbbbd
16-17 v: vvvvvvvvvvvvvvjht
1-4 x: bxxx
16-19 g: gggggggwggggggjgggg
5-10 q: qjpqqvlnkqxmlv
4-6 p: qrpffplvpp
7-9 r: rrrrrrgrb
2-3 g: bgjg
10-12 t: ttjttttnttdtt
2-4 g: dgng
11-12 r: rrmrrrlrtrrj
1-5 v: qvvvvvvvvvvvvvv
3-18 p: ftnfnpmjprmrzmhbnxj
10-12 w: dqnsjjxsqrwq
2-4 z: lzgkzsb
8-9 n: dwclxdtnndtpcgqmx
10-11 w: zjwdsphbbwlhp
2-9 d: zzprkgzczbs
14-19 c: gpjfrvsrcnbxbclctxc
1-9 f: fmhfvfffrfws
12-14 d: ddrddbddddddddhmdg
14-15 s: sslsssmsnssdxsj
2-10 v: ljppzjfvfnfp
1-2 z: qbwbzknrzzs
18-19 l: llllllllfllllllllll
2-3 p: ppgp
13-15 k: knkkkkkckkkkhkxk
3-6 v: vbjvmv
4-8 h: hmhcxfhg
12-14 v: vvngcvvvvkvgvs
2-3 j: xdjjrk
5-13 s: sssssrqsssssq
1-7 s: sssssssss
6-14 b: ptlvmbbrbxnvqbrmp
16-18 w: wwwswwnwwmwwwwwwwf
1-4 k: kkknkkkkk
1-4 g: ggrbk
9-11 r: rrrhrrrrrrrrr
11-13 x: xxxxxxxxxxxxnx
3-8 x: nsxvlvdfbkpxsgscn
12-15 h: hghhchvjhhhhlvhhhhh
11-12 n: nnnnnnnnnnjqn
10-13 r: jrzfzrzrqblmks
7-8 w: wwwwwwwh
3-4 k: kkbft
1-9 c: cccccjccccccn
2-7 r: rrvnrxrvrzsrbrs
3-10 l: llgdldmlplqlhdlll
4-8 m: mmzmbmgm
5-6 q: sfxqnftnbnqwq
5-6 v: vvvvgvvqv
9-14 h: dhmwrhzqqvhhhfhfhhht
4-7 p: jwwppvpklc
9-13 z: zzzzzzzzzpzzzx
13-14 l: fllklltlllllcphllll
12-15 m: htmbmqgljcmvmclgnm
9-10 b: bbbbbbbnbb
6-12 x: nxjbxxhxxxxgdxx
6-7 t: tttbwlk
8-11 q: fqqjtlswqgkqdqc
16-20 t: xplwqxbwtsfptbvtvcxt
3-4 k: kklkkkkkkxkkkk
3-9 m: kmmsvmpmxmgmb
6-12 j: jjtjjjjjjjjpjjwj
3-4 m: kkmbmzkx
7-8 f: gmfxlgfjtfst
1-3 w: wwwn
1-7 k: knkktkkn
13-16 v: vvvvvvvvvvvvvvvmvv
10-11 h: rhvdhnfhvtchlfhh
10-12 x: xgxwbqxkxxcwsfd
10-14 m: mmmrdxpcmcmmmkmmmmm
2-5 x: vvxpx
8-9 h: hhhhhhhmfh
16-19 j: jmwjjjjjjjjjjjjjjjz
2-3 r: sqrnr
14-19 p: ppppppppppppppppppk
2-5 w: wwwww
15-16 q: dppxtnhmxrhmncrqq
4-5 v: drhpp
1-4 p: pkhn
3-6 q: gwmrfwh
6-10 v: dlvvfhvvkb
1-8 q: qqqqqqqqqdqqqqqqqq
17-18 n: nnnnnnnnnxnnznnpnng
3-7 m: gmxzffwmbdm
12-14 m: dmzmcmmhjmqltm
3-16 w: drcbwtvqgbppbwzvm
8-10 d: ddbddddzdddddkpd
8-9 m: mmmmmmmmmmmm
1-3 l: glll
7-11 x: fxrxxdxxxqxnxx
6-7 d: ddddxgdd
7-8 g: hgggbggg
2-3 w: pwwtww
7-10 h: lhwbhjhzhx
3-14 b: bbbrvrbsfbnxrgqbbq
4-7 l: jzqkxlnpxlglfsll
6-7 b: hbpbbbb
2-4 w: pskwwxzpjvmwcnfr
13-15 m: mmmmmmmmxmpmxmmm
4-9 k: krxkzqzkkhrpqth
4-7 f: xfffkvfqzwhcfwkhq
4-10 q: qqqqqcqbqqq
14-15 s: lgszsdststlpgjbs
7-12 s: sspbsssskfns
7-8 d: cdddqpnd
13-15 p: ppppppppppppxppp
10-11 r: rrrfxrrrrrrrrr
10-12 z: zzzzzzzzzvzvzz
3-4 l: lllwll
7-9 p: ppppkpppqpppppsvx
3-4 k: kkkrk
4-5 v: zxmmvmhvr
14-15 r: rrrrrrrrrrrrrfjr
6-10 b: vwbgbbbbdbqsbb
5-7 j: jsjjjkv
3-4 m: tzmhr
11-13 r: rrrrrrrrrrqrhrr
1-4 s: psqmcssnk
5-6 z: zdkzzzz
3-5 p: cnpmbtknqdppmcjpzvcn
13-14 g: ggggkggggmtggd
14-17 c: nxmzcczccnvdcxpcmb
6-10 w: wlwwbdwwwwwwww
9-17 l: llllllllllllllllll
2-12 j: jpjdjjjzmjxj
1-3 n: szjntnnl
7-8 l: dpxlmhlbts
5-16 s: sssssssssssssssrs
1-6 m: pmqvlc
7-15 f: ffffffffqfkfffdxff
10-11 w: wwwwwwwwwwswwww
7-12 p: tkppvfpwksrp
4-7 f: fdjdgdvsksbfbnjkspc
4-11 b: bjmvfrmlmlbndl
1-3 r: rrrnxhgbwr
5-10 h: xhhmhhhlhbh
10-11 h: hghhhhhhdlhhh
5-6 g: gptglg
9-11 t: wtgtxtttqtmttt
5-11 f: jxqffhfsfmz
4-7 f: frjffbf
1-15 m: mmmmmmmmxmmmmmmmm
1-12 d: drwlbpdbzdgdjpnzmj
9-14 n: nfnmktjnncnnnln
1-2 h: pshhjhhhhf
2-4 t: tgttttttfb
2-4 w: dwpwhnxbf
7-11 b: vbcbzhbwhpb
4-5 k: hknck
5-12 m: mmmmtdmmmmmmmm
5-7 w: qwflwxq
2-5 g: jdnxdlclplvb
5-7 t: ttrtttttkr
8-18 l: lwscjwlmdlzlllnsllpw
2-8 c: cccxtccchbrkr
1-3 q: qqtqqqqq
3-13 d: dddddddbddddddd
1-7 r: jkpzrpfnrgpkc
9-10 t: ttttttttttt
11-12 w: wjwplwwwwwmw
9-12 r: rpsvrhrbnrwqch
6-11 p: zpzbpkpmtnptsnpbswc
4-6 t: jhzstt
3-4 t: ddpkcgpzhd
4-6 s: cvzshjfrsslxnslqddwt
1-3 c: cgsczhl
1-4 d: lddqdqd
6-7 v: vvvvvvb
5-8 w: wwwwwwwwww
5-11 p: ddswpbpppsqpp
5-6 x: dfzxxxhhqjvj
3-7 m: mmmmmmmmmm
4-8 g: ggggggggg
5-6 j: jjcjjn
5-6 n: nndtns
4-5 t: ltxkdpst
2-8 b: ldwkbzbxgpbbbb
11-12 w: wwqwdqwwwqhvwww
15-17 k: klkcxqbwrktxcmqlnb
5-6 k: tkqhkkkkrkjfd
12-13 x: nxxxrjxxxdjlxxbt
9-12 m: mmzmmmrmmfmgmmmmb
2-5 v: tkbhvlvp
12-14 v: dvbvvvvhrcvvvxxvvvvv
14-16 x: xxxxxxxxxxxxxrxxxx
6-7 v: xvswnvvm
6-9 c: vcpcksxwbdlc
5-11 s: sssssjssssrsdjsssq
6-16 j: jjjjjmjjjjjjjjjnj
8-12 g: ggggwggggggnggg
4-5 c: ccczk
14-15 l: lllllllllllllkm
10-11 r: rrrrrrrrrrrrr
3-5 n: dwnvnlj
2-4 x: xdxxxx
5-6 j: jjjjjjj
3-9 k: kkkkkhlrkktt
3-7 t: stqtgfdprtqjsgznrtjh
11-16 n: hsnnnnnnnnfnvnpqnnn
13-16 v: kdvbvxvvtvhvvvvq
1-3 v: vwpvkvdpxgc
14-17 v: vvvvvvvvvvvvvnvvhv
14-15 m: mmmmmmmmmmmmmtm
6-10 m: mmmmmhmmmm
5-8 t: tttjrttdsttfttwstf
6-7 c: ccqcvcc
2-5 v: vvvvvv
8-16 c: cccccccccwcpcccmcccc
4-5 t: ztvttktttttt
10-11 n: rnmnnnnnnnnnnnnpt
5-6 g: lgsggggg
15-18 s: lcsmgkjqzdpcgvsrng
2-6 p: wwpppp
9-10 v: vvvvsvvvmvv
6-11 c: qrmdjxzsmxcmcccgrr
17-18 b: bbbbbbbbbbbbbbbbbbbb
6-10 t: thtxgtpxwt
2-8 f: xkgbrpqfsrhhbnfpdg
3-8 c: gqkkvgkcqfwdc
5-6 c: jjcsjf
8-16 q: fbwdmlwljqqcrqsq
3-10 m: mjmmsmmmmmmcmm
5-15 x: xmrvcsjwxxdpsrxzcrzj
3-7 x: rxngzxxg
17-19 z: mmvfgzpmbvzsrmkgmmmb
3-4 z: zdzz
4-5 v: vzcvb
3-11 z: tzllpgzzmwxznh
8-11 x: ptgvnbxzsxwdb
2-3 r: rrrrr
6-10 b: bbmbbbbbbb
6-11 q: wvmqrzrllhxfzmpkp
13-17 v: vvrgvvsvvcqkvvvvbvvw
16-18 p: ppppppppnppgppppclp
13-15 g: gglggggggngggggggggg
15-17 b: bbbbbbbbbbbbbbbbb
3-6 t: tpwzktlzkdt
2-3 m: lmvtnfjzmm
1-7 j: jzjjfjx
15-17 r: rtfdnhrrhrrdcswrl
1-3 d: gdfdmddddwdddlsd
3-4 r: qrtr
10-11 m: mmmmmmmmmkc
2-5 n: gntnnnncc
9-14 b: bbbbbbbbbbbbbb
10-13 f: fxfffznffffzwffflz
5-12 j: vjjrjjjjngjjjjm
6-8 k: kkkrkklkkkkkkk
5-7 r: rrhzsxrjjw
17-18 g: gggggggggggggggggf
2-3 h: ghhvrh
1-3 j: hjjxjjjj
3-5 q: gbqnqkprckxqglkhw
17-18 n: ngnnnnnqnnnnnnnnnnnn
2-3 m: xlhmmq
6-7 p: kvvphgj
9-12 k: kpkzkkzkkkkkbwk
9-10 k: kkrkkkkkmt
5-10 t: tttttttttttttttt
10-11 l: ztdvlllzfltlwlglkhcj
7-12 t: bttttqtqttttttttg
3-4 z: xzvb
5-10 h: lhcdhkhhhhb
1-6 z: jqzzqzzzzzzzzzzzzz
6-7 x: qxxxxtxz
13-14 g: gggngggggggrgsgg
1-2 t: tttt
11-15 w: hpwhwmwlkbwtwmwlj
8-10 r: rnrhrrmprnrrr
5-12 z: rshzhwgzhfjb
15-16 s: sssqssssssssmsss
9-12 z: zdzzzzzzkzmz
10-12 c: mfgpskncfcfctjmt
5-10 p: sppwnpdpptppwdppppp
3-14 q: mnzfgfmvmsdlqg
1-13 s: sssssssfssssbsss
6-8 d: ddddddddd
2-5 j: vsbbjh
14-16 m: nmklmsrpjxwpdbmj
3-8 v: rfvvvjqv
18-20 p: pppppppppqhpflppbppp
7-11 x: xxxxxxwxxxx
3-4 l: llmvlll
8-9 w: grmvwtwbz
2-11 m: mmmmmmqmmmsmmmmmmmmm
6-13 h: hhhhhrshshhhlhhhh
3-12 t: tnttblttttcvrtttx
5-18 f: cfffcffvgffffrmlfx
1-3 n: rnjnnnnnnnnnnnnnnn
1-2 w: smmdq
1-5 v: vvvvvv
5-15 s: tssssscssffhsswssss
3-11 b: bbbbbbbbsbkbbbr
13-15 j: xjjpjjcjjjjjjcj
5-10 g: bvjvgpzgdgkmmzwnwrxz
2-7 q: qqqqqrq
10-12 d: fddddbdddxdqpd
5-7 c: hsccjccrlm
11-15 r: nrrrlrrvrdlrprw
13-14 r: drrtbrrrrrrrrcrrr
8-10 c: ccccxcchfjcccccxpc
8-9 s: sssssssss
1-10 r: rvlgkrrrrm
8-13 w: jwbwcwmwwvwwwwww
7-12 k: fxkkcnkkbvkxbkphx
7-8 l: llllmlvll
11-15 q: qdjpqwgfqjdqnnq
8-9 m: mmmmmmmvmmm
6-7 k: kkkksmkb
4-6 h: hhhlhhhhfhhhhhh
2-5 k: xzjlwb
3-12 j: sjwqrjzjgqrj
5-18 p: ppppppppppppppppphpp
1-3 g: gggrggggg
14-15 n: nnnnnnnnnnxnnhnnn
19-20 d: jkpzsxwsddzccjdkcptj
2-4 v: wpdz
1-8 w: dwjtngwwwrwhp
13-15 t: tttttctttttxvfrt
6-11 h: ksvshqhhdth
8-9 k: khfkdkppl
11-12 d: whlmcdmfgfddd
11-12 p: htvxpkfngthz
6-9 v: vqvmvvbbv
5-8 m: lghmmmrmmw
14-16 q: dtmqqrqqqqqgpgqtqr
2-11 f: bfjskxzlgvfml
10-19 p: kpppppppphppppppppp
5-7 j: rfbpzmjtjj
9-10 p: kpppppppqpp
3-15 k: hgkgrqblnjmsbvrghzdk
6-7 r: rrtwrwlfrswwr
3-4 k: fkkdv
12-20 g: ggggggggkggggggggkgh
3-5 x: xxxxpxxxxxxxxxb
8-10 k: kkkkkkkzkh
4-10 q: qqqmqqqqqcqq
4-12 t: ttgtqblzqzpttcxdtfn
18-20 s: sssbbsscsjvslsvsssss
3-6 x: xxxxxxx
4-5 t: tttttt
5-7 q: xqqqqqqqxkqqqqqqqtqq
2-4 s: zsvq
6-7 b: mmbcklx
1-13 z: zzfzkshpslwcn
1-14 d: ddpddtdddddmmf
8-13 j: jjjjjjjjjjjjjjjjjz
5-6 c: cjjlxb
10-12 v: vvvvvvtvvmvv
2-3 b: wfbbg
1-10 l: llllllllllllllllll
5-10 d: hdbhdgxcjd
10-13 t: ttttttttttttnt
5-6 h: vhmhhh
16-17 x: xxxxxxxxxxxxxxxsqx
6-14 g: gzggggzhggggzgg
15-20 f: ffbfxffffvfffffffhfd
2-3 d: xdvw
5-7 g: zgggjgq
2-12 g: ggggggggmgggggg
6-8 h: hhhhhhphhhlhjhhxfh
3-10 j: knjklstqxwcsjf
2-3 h: hvnwjxhpsc
7-8 w: wwwlwwgw
14-16 s: chgtpswssxsqtwzrsqt
5-6 d: zdbdkl
3-4 p: lwkpbrbp
8-14 c: cbhtccjmrccrcp
2-3 s: tctflmgdtsjjfxpl
3-4 g: gggjkctwdsgl
2-4 h: ghbh
4-13 h: fczphhvflghhhd
3-10 x: jkzhgljwsblcrmbwfx
12-13 p: npfgppprzpppc
7-12 l: sqbplmqnlmwph
1-8 p: hpppvpprppp
12-18 n: nhbznznxncnkcchscl
9-10 g: grjxmgzpgk
6-7 g: rcmkggggggg
1-7 b: bbbbbbbb
2-3 t: ttftzqt
8-10 l: twbjlnblhck
1-2 c: cvbc
4-9 d: mfpdddsnd
5-8 f: flpvbdrfl
7-12 s: rhspsxlbpsmsclzrdsfc
2-4 h: vhhh
1-10 k: bhkkkkkkxkkkzk
5-15 q: qqqqqqqqqqqqdqdqql
12-15 c: ljvcklwjvngfgfgrjsv
8-10 w: pwwtpbwwvwwrwww
5-13 b: tbjmbfmknjhbb
1-2 v: cssd
2-5 s: ssssss
3-4 h: bhhxxhfh
3-5 p: pfppp
13-20 l: lcxxllcfjmllclljllfl
2-4 p: sqpzk
2-4 l: xlllb
1-7 t: ttttttrttttrttttttxt
10-12 m: bwmmghzmqmmpmj
5-8 l: jtlljpql
5-6 d: lddddd
6-8 c: nljczccdwvnmrlqvlsc
8-9 d: dzdddcddt
10-11 z: zzzzzzzzmqj
3-4 s: msssss
3-5 z: xzvdzbzt
2-18 v: bvcbpwkbdmclbnbmsv
9-12 b: jrcccsndstzbxprkvtq
3-11 n: vlntglzvvcnngn
3-8 v: rpgckwptlvdqsrqqt
6-11 q: qdqdkqvkvhdrdqm
9-12 b: khbmbgbbvbqb
9-10 g: gtggggggczgg
3-5 c: zqctcs
15-18 z: kbzsdhbbzxfzzqdjzc
7-8 g: ggggggzx
9-10 s: sswssrssqms
14-17 g: ggggcggggggggpggcgg
10-15 g: qgzmbkjlggrhgkg
9-11 j: jjjjjjjjqqjjjjjj
5-6 c: cgcdcchcccbcc
2-4 g: gggg
5-13 h: plkhhrmxhxhmh
11-16 v: vkkqrvbvbcvvnvvvvv
6-7 c: rlfmqphqrhqkhch
3-5 z: hzspz
8-9 d: kddmdddpdvddln
5-11 k: wkqkcfkpvnkvh
4-7 r: fnzzwxrxr
15-16 r: rrrrrrrrrrrrrrwr
2-19 f: fvffffffffffffffffwf
9-11 v: hbvbvvgcvvvj
2-4 m: mrxpv
13-14 z: zztzgzzpzzzzzg
4-10 t: qtvtcrfmlkrgtwsvwtw
3-7 g: ggggggfgggggggg
5-8 c: ccccfcccnmccc
6-12 z: bzfcjzdznzwzrzbzzqrn
14-15 c: ccccccccccccczkccccc
3-4 j: jjjjjjf
1-2 x: kxxxx
3-4 s: sksj
17-19 c: hvchccvccdxgccnxdcc
3-6 r: trrrrrrr
10-11 c: ckcjzcrzcbc
1-7 p: pmqplfpvgq
3-4 h: hhmx
5-6 n: nnwndln
5-10 v: bkkvfgvqwdt
7-14 h: hkjlwvhdnhxhwcnhs
4-12 f: xxwfjfcwslrfzrxfkxj
2-3 c: ccccc
4-13 k: kkkdkkkkkkkkkkk
8-10 b: mqlljkpbbbxbrbfx
1-4 p: pppp
14-17 n: nnnnnnnnnnnnnnnngnn
5-6 d: dddddddvw
9-10 r: rjtrrrmqrrrzrrrrjrrm
7-11 x: bxxxxxrwxpmn
13-14 w: gwmwwwlwwjwjwx
2-4 d: dddddvddd
7-9 p: pjmdppgpspcslh
13-16 l: tllllzllpvllvlzd
9-11 q: qzmwqqzqtqqq
4-5 d: dvdngdd
9-11 j: xxxvjrmgjpk
3-4 c: rvvcn
15-16 r: rxvmlslkpmqdqtdd
2-5 b: sbflb
4-5 w: wntpw
8-16 n: nnnnnnnhnqnnnnnnn
5-6 n: nnnnnnn
2-5 q: bsjfhq
6-18 r: prrrqkmrrrvbrrrrdfrv
3-5 g: xnxlp
4-11 s: jsstsssjssfssss
14-16 d: dddddddddsdddddd
18-19 n: vgngvbhdjfrbnznhhjzn
11-13 f: ffffffffffgfgf
5-11 n: dbgvngchnkngt
3-4 f: gsff
2-4 r: rfdrlznkzg
10-18 z: zzgzwzzzzzzdzzmzhzzn
4-5 s: qscmbssss
11-15 x: xbxxxxgxxxbxxzw
2-10 h: dkrnxknmthcv
12-13 b: bbbbvbsbbbbgcbnb
4-5 m: mmlmmsmmh
3-6 j: njrjjkcr
10-12 x: xxxxwdnxxxxx
14-16 g: hggggggggngggggg
8-9 x: gjqfxxxtxxxb
16-17 f: ffffffffjffkffffmffb
2-8 z: tsktkzfxntrv
2-6 v: hvvswd
1-2 w: xddl
2-6 k: svwvvkqmzwjkx
9-12 p: ppppppppbppspppb
12-19 m: mdjmlhsmxmwcmmmmmmm
3-5 x: rxjxb
17-18 r: rrrrrrrrrrrrrrrrwk
2-9 b: cbfbqcfwbmwd
1-11 h: hhhhhbhhhhmvhhhh
2-3 j: jkjjgjhxj
5-6 f: fffffffffhf
17-18 j: jprvtszvgsbtxlrhljsz
1-4 m: mmhmmmp
2-6 p: xvfkpkc
1-2 f: xqtfcf
1-5 r: brrrrrr
7-10 w: wwhwwwdwwj
1-4 w: vwwdh
1-3 f: hnpvgfwth
10-12 k: kkkkkkkkkdkq
5-13 r: rrpqrrvrqrswzr
9-17 x: xjxxvxvbtxxxtpxpx
12-13 j: njrjkcjgbjjnj
2-4 l: lvll
12-17 p: dpppprpbppnvpppprp
4-18 b: zftbmbxgzfzdvdnvhb
12-16 r: lcqgqjthprlxrzrrx
2-7 m: msclccmxhsmf
3-4 b: bfkb
2-6 k: skfgrk
4-5 q: qqqhhx
6-8 c: cccmvcch
16-17 l: bxnlvbvwzvfvbcmxl
7-12 c: cccccccccccc
6-7 b: bbbbjsjbbbs
2-7 q: phxnfxqrqv
4-5 h: hhhhhh
9-15 n: nqnnglsjnnghxrn
3-4 h: hkkh
5-11 r: rlsjvrrrrrl
5-7 b: bbbbzbwbbbb
2-3 f: qczff
8-14 c: fccqccccccclccccck
1-8 r: rrbfmjsr
4-5 p: dpphz
11-13 d: wdmwkcqddrdvdz
8-15 h: hhhhhhhhhhhhhhhhh
6-10 l: dhgdclhlkltnc
14-15 t: tttntttnthtttzw
4-6 p: pppppdp
13-14 l: dvlnvlgtbpnhll
11-12 s: brsqgfsnpmwskhdnm
6-7 j: httjvjj
2-14 w: wwwfwjzwrzfwnwjwwm
8-9 w: wwrwwwwgt
2-5 r: dvrwb
7-9 b: wwvqbsbjb
1-12 l: lljxlbslwlgn
11-12 m: mmmmmmhmmmwbmkmmt
10-11 l: lblllmllldl
3-9 w: wwpwwwwbfwwwm
9-10 q: pcrqfqlskz
7-9 l: llvlllblklllx
6-7 g: qgggjmwg
5-10 v: vvvvvxbrvvp
9-10 d: hqddgkkdrpdd
17-18 q: qqqqqqqlqqqqqqqqdt
6-10 h: hspnhhzldxphdh
8-13 l: vvvscdnlblllml
6-12 p: ppkrprpxwpppwx
4-5 k: tkslb
7-8 d: hdjdhnzdd
9-10 x: wkxtblgxxjxxlqnfxxlx
8-9 g: rggggggdk
10-20 d: kcgdtbbswwdtvgdgxfwd
3-4 g: gggggg
16-17 l: llnzlqllllzllllmllll
4-10 r: nsrrrbzrfzcrrzrrdqk
4-6 k: kkkkkpkk
4-8 n: nnnmntnnrnnn
12-14 l: lllllllllwlqllll
3-6 r: rrrrrrr
1-6 s: ssskcshsxtd
7-15 d: ndrbdnntdmkddxd
9-10 j: pjjjjgjsjhjj
7-10 k: pkbkkkkkgkq
4-8 m: mmxmmmdmmmmm
9-13 c: ngjcrcccvbcvqdjmph
3-5 q: qqqqqq
7-10 s: fcssnsssssslxspr
3-5 k: kkkkvv
5-10 f: tlbcvgwfzlf
5-9 x: xxxxqxxxx
2-10 q: qrprhbrhjhb
3-4 g: gggmgg
8-10 j: jjjjjjjgjpjjj
2-4 v: dvzvvtfm
7-12 q: zvzqprjhqdcqfzr
12-13 f: ffffffffffffqf
2-3 f: fffsdwq
10-11 z: ztzzjzjzzzlzzz
5-7 k: kkkkqtkkkkk
6-9 z: dfbzhgsrzsp
2-4 b: wpqb
9-15 c: cwchcdhxlqzccxbb
8-11 q: qqxptqqvqrgqg
5-7 t: ttttztcvtjtkts
2-6 n: nnbmdnjxclwkffrnxff
3-7 p: pppppph
9-12 d: xhmfndzcddfddvgddf
1-5 h: hthmhvlthhhhh
6-7 m: mmmmmmm
6-7 j: jjjvjjjrj
1-5 q: mqnqwqqqqqjq
10-11 b: bmbbbdbpbbbbzbb
1-4 k: gvccvdltkwcdd
12-16 s: sssssssssssjssshs
4-10 k: wzvlkmdhcklhdp
10-13 z: zzzzzzzzzfzzj
6-12 g: bmzmvvggpgtm
3-11 m: nvcpfgvnsqmwxmmz
1-5 n: dnwnnnnnnnbndnnn
4-5 h: lhhhh
4-5 g: gggdg
2-5 h: xthqhfj
2-4 f: lfkf
4-6 k: rqbhrtzktmvmrxck
4-5 q: jqdsc
10-11 h: hhhhhhhhhvjh
2-17 r: rrrrrrrprwrrrfjrr
16-17 b: bbbbbbbbbbbbbbbbhbbb
3-5 z: pkvzzfrljrjctw
13-14 w: wwwwwwwjwwwwww
8-10 d: dddddddldzpq
1-4 b: sbbgb
2-10 d: vnhpzmvpcddhs
8-15 t: zftpwtrtqjqtfntp
11-12 j: djjjjjjjcjjcj
4-7 r: jrrtrrrvmzzrrvsl
2-4 r: rpkp
3-4 b: qbxc
10-11 w: wwwwwwfzkdmnwwv
6-14 z: mztxzzztmzwzzqvm
12-14 w: wwwwwwmsgwdwsqwjwww
6-10 f: zfhqjfhnjfdvwsfftf
2-11 q: mwbbqdncdfq
8-11 v: zvtvvwvfvvq
6-8 n: xnwhzmdskwhn
8-15 q: qqqqkqqqqqqqqqst
1-4 n: nnnnn
5-18 c: sqczchcwcccclccccccc
3-4 j: klgr
11-12 m: mmmmmmmmmmmm
2-3 d: qdxfmqwbmdnvj
1-5 m: cmmmm
6-7 l: llllllll
1-9 m: zmmmmmmmlmmmmmmm
9-11 m: dwspwrmjsxpc
5-6 p: qpppfz
10-19 t: fvtphwzsptqzntbkxqt
7-9 m: mpcmpmmmvptmm
3-9 h: hhhpqqwhhtm
11-16 p: pppppppppppppppvp
1-9 k: ktkklkkkkkkk
10-17 q: rthtqvgspqkvfkgkqfhj
11-14 g: ggxgggggxggzggcnggg
3-4 t: tttt
9-10 t: sqtbdttthtttm
1-4 t: ttkbgdzztbxd
3-8 f: gxfcrrsfntftvffnfqff
9-11 q: qqqqqqqjlqqq
12-13 v: vvvvvvvvvvvvk
7-11 b: nbxbbbsmbtkb
7-8 k: kkkkkknn
4-6 j: jjjjlv
13-16 m: mmcmmmmmmmmmmmmvs
7-9 k: kdkkkkrkgkk
1-4 c: crcdlrdbzc
1-16 k: kkkkkkkkkkgmkkktkkk
2-12 l: llllrlllllllll
4-9 g: gggbkgpgz
6-7 q: qqqqqqjq
6-7 v: hvvvvpm
10-14 t: ttfxmqtgtttttbtct
5-7 h: hwhhfrnch
4-13 w: zdlrqvxwwzsfrfq
4-5 h: hhhshhhh
2-4 n: vhjfnz
5-6 s: sssssss
11-13 n: nnwrnnnlnngnn
3-4 s: wbss
3-4 s: wnss
16-17 p: ppfprptkpmzkbjppp
2-4 v: pvxv
8-9 w: swwwwwwhwwnwwwxj
4-6 s: pzhkvss
4-5 x: wnxpx
4-5 f: fsfwp
4-5 z: zzdjz
3-6 v: vnvvvvvvvvvvv
5-6 f: wfxfff
4-7 z: zzzqfzz
3-5 q: qqjqsqqqf
3-7 w: kwwkmww
6-7 h: hhhhhhgh
2-5 v: vvbzvvkn
8-15 r: svrqpqrgrrhmzbms
9-17 n: jnnnncnnnnnxnnnnnp
5-6 n: dgnhsc
5-7 l: lplltbv
4-6 n: mmrnsbcqr
7-8 w: wwjwwwwww
1-16 c: bccccccfcccccccdcc
6-9 l: sjnlmxwllg
3-9 q: cqvhkwhtstwrl
5-9 h: khvxhhhgfchhknhhhz
8-9 c: ccccccccdc
2-19 n: jjxbmbwmnqbblfbgzsz
3-4 p: pppp
1-3 b: jzxbbb
3-6 h: hhhgjhhw
2-8 f: vfxftzkmlzk
11-19 h: mmdptdzhwdbjhvkccrhk
4-14 s: sssvsdpsssssspns
11-12 f: fffffffflfbk
2-13 h: nhbgtbjvbpmrnhf
1-3 t: ttttttttttttttttttm
3-4 t: tsttr
2-9 n: fnkknptqn
1-8 j: qjpjjjjjjtpxjqjw
2-12 c: clccccccccckccc
18-19 f: dpftffzcfhqffddfpff
1-4 j: trjj
9-11 z: zwzmzzczsdd
5-8 g: vrpbggfn
2-5 k: qksvzkj
2-4 f: wfdfjlfwmjrdmxx
4-12 l: bnplnlgqcwql
13-14 n: nqlfdnnnnnnnvbnwnlh
4-8 l: dgxhsrql
10-11 k: qvwcrkxtkjxlq
5-6 g: ckgggg
6-14 h: xbhhvzvxbhhhhhbhkzhh
6-9 w: whwdwrxgc
7-9 b: bbrbnjbfb
7-8 w: brwwkfvwwwww
2-11 g: gmggghngggg
12-17 l: bgslljzntbmvtkbgllgg
12-18 g: gggggggggggkggggggg
1-3 l: gllllllll
14-16 k: jkkqkkgkrkvxkkkkskgb
2-3 v: vljvgnvm
7-8 r: jrjvrprr
7-8 f: xxffrnff
2-18 j: jhjjjjjjjjjtjjfjjpjr
8-9 q: rfllhmnqtrkv
2-3 n: lnndv
2-15 s: hzzsrprnnjlwdfs
1-5 q: vqqqq
9-18 b: gxbpbbppbrbbnlkmbb
2-13 b: bbbbbbbbbbbbpb
6-7 t: mtrftthtttftttztttst
1-7 z: nfzzzzvzzczzzzzzzz
4-12 m: mmmcmmmmmmmmmm
9-11 p: jpswppqbmpfpzpg
10-11 c: ccccccpcccc
2-6 t: ztscdrkxxctdft
3-13 q: mqfqqqqjqqfqdqqq
16-20 z: zzjcxdmzgzzzppbtztzz
5-15 w: wwwpwhwqcwwwwwgw
2-4 p: pczp
5-7 d: ddddmdfd
2-3 f: fftc
1-3 v: vvmv
11-15 k: tjkcvkkkkgkzkkxqv
4-6 b: vdkvbn
7-8 c: wbcjhswc
9-10 l: lllbqrllll
4-5 s: sjnlw
12-14 j: mjtmzfjjtsgvgtq
1-3 l: llrllml
12-13 d: dngddlqdtgdcd
3-5 l: cblhld
3-4 r: trrq
1-3 c: kcccc
9-10 g: bgbgjggpvgpgpggg
3-6 d: szwlfm
13-14 f: ffffffffffffzfff
6-7 d: ddddddddddnnddddr
7-16 h: xmbpwmhsznmldhnxflc
4-6 q: qqqnqqqg
2-7 t: ttwbpmnthmjr
8-16 x: xbcxxbwxxrpxnfxd
2-3 d: dngdd
9-10 n: qkxfdljnnl
4-5 f: ftfffff
12-15 n: nnnnnncnnnnnnnsnn
1-2 d: dkdd
2-5 v: vvvvgv
1-14 v: jvvvvvvvvvvvvmvvv
5-6 r: rrrrrr
2-3 b: bnvbbbtbjgxfchnkhcjb
1-14 g: wjggxgggggggxgmrvcg
1-6 x: bhvxhxxxx
1-2 r: rprr
6-7 c: cccccccqc
4-8 b: bbgplbbcdtbbdbgbbhbz
1-4 w: wjgw
1-3 h: zhzzt
2-11 j: sjjrtjkjhjj
6-7 m: mlmrrmm
const fs = require("fs");
const readline = require("readline");
let result = 0;
let reg = /^(\d+)-(\d+)\s+(\w):\s*(\w+)\s*$/;
(async function () {
const rl = readline.createInterface({ input: fs.createReadStream("input.txt") });
for await (let line of rl) {
line = line.trim();
if (line.length > 0) {
const [, p1, p2, char, str] = reg.exec(line);
const x1 = str.length >= p1 && str.charAt(p1 - 1) === char;
const x2 = str.length >= p2 && str.charAt(p2 - 1) === char;
if (x1 ^ x2) {
result++;
}
}
}
console.log(result);
})();
const fs = require("fs");
const readline = require("readline");
let result = 0;
let reg = /^(\d+)-(\d+)\s+(\w):\s*(\w+)\s*$/;
(async function () {
const rl = readline.createInterface({ input: fs.createReadStream("input.txt") });
for await (let line of rl) {
line = line.trim();
if (line.length > 0) {
const [, min, max, char, str] = reg.exec(line);
let count = 0;
[...str].forEach((c) => (count += c === char));
result += count >= min && count <= max;
}
}
console.log(result);
})();
1918
1869
1821
1852
1981
1987
1989
1597
1634
1537
1991
1603
1543
1949
1879
1800
1761
2010
1810
1458
1755
1938
1500
2005
818
1493
1618
1923
1283
1952
1373
1605
1230
1321
1873
1853
1886
1372
1913
1871
159
733
1400
1880
1462
2007
1801
1982
1728
1640
1442
1525
1953
1791
1906
1946
1641
2009
1627
1935
1936
1908
1826
1291
1978
1884
1799
1464
1538
1365
1678
1872
1964
1863
1388
1912
1928
1471
1632
1336
1396
1948
1974
1331
1290
1992
1096
1889
1874
1341
757
1351
1876
1674
2002
1504
1865
1469
1792
1920
1925
1898
1899
1435
405
1488
1319
1322
1749
1867
1957
1944
1727
1293
1739
1285
1917
1897
1844
1966
1921
1905
1830
1484
1364
1782
1415
1412
1413
833
1857
1370
1890
1393
1262
1311
2008
1545
1896
1362
1862
1617
1864
608
1868
1689
1784
1806
1976
1870
1973
1993
1986
1998
1414
1858
1990
1841
1895
1779
1850
2001
1590
1902
1487
943
1808
782
1546
2004
1656
154
1661
1688
1731
1466
1927
1438
1387
1576
1793
1797
1979
1903
1638
1940
1911
1301
1669
1409
1578
1887
1860
1619
1939
1625
1941
1374
1766
1407
const fs = require("fs");
const readline = require("readline");
const source = Array.from({ length: 2021 }, () => 0);
(async function () {
const rl = readline.createInterface({ input: fs.createReadStream("input.txt") });
for await (let line of rl) {
line = line.trim();
if (line.length > 0) {
const n = parseInt(line, 10);
if (Number.isFinite(n) && n >= 0 && n <= 2020) {
source[n]++;
}
}
}
for (let i = 0; i < 1010; i++) {
if (source[i] === 0) {
continue;
}
for (let j = 0; j < 1010; j++) {
if (source[j] === 0) {
continue;
}
if (i === j && source[i] < 2) {
continue;
}
if (source[i] && source[j] && source[2020 - i - j]) {
return console.log(i * j * (2020 - i - j));
}
}
}
})();
const fs = require("fs");
const readline = require("readline");
const source = Array.from({ length: 2021 }, () => false);
let n1010 = 0;
(async function () {
const rl = readline.createInterface({ input: fs.createReadStream("input.txt") });
for await (let line of rl) {
line = line.trim();
if (line.length > 0) {
const n = parseInt(line, 10);
if (Number.isFinite(n) && n >= 0 && n <= 2020) {
source[n] = true;
if (n === 1010) {
n1010++;
}
}
}
}
if (n1010 > 1) {
return console.log(1010 * 1010);
}
for (let i = 0; i < 1010; i++) {
if (source[i] && source[2020 - i]) {
return console.log(i * (2020 - i));
}
}
})();
root = true
[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
max_line_length = 120