1
0

Added AOC 2020 day 03 - 14

This commit is contained in:
Mike Schwörer 2020-12-14 14:14:47 +01:00
parent 1bc31acd5c
commit 9cdd8dc391
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
37 changed files with 10657 additions and 0 deletions

View File

@ -0,0 +1,71 @@
--- Day 3: Toboggan Trajectory ---
With the toboggan login problems resolved, you set off toward the airport. While travel by toboggan might be easy, it's certainly not safe: there's very minimal steering and the area is covered in trees. You'll need to see which angles will take you near the fewest trees.
Due to the local geology, trees in this area only grow on exact integer coordinates in a grid. You make a map (your puzzle input) of the open squares (.) and trees (#) you can see. For example:
..##.......
#...#...#..
.#....#..#.
..#.#...#.#
.#...##..#.
..#.##.....
.#.#.#....#
.#........#
#.##...#...
#...##....#
.#..#...#.#
These aren't the only trees, though; due to something you read about once involving arboreal genetics and biome stability, the same pattern repeats to the right many times:
..##.........##.........##.........##.........##.........##....... --->
#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..
.#....#..#..#....#..#..#....#..#..#....#..#..#....#..#..#....#..#.
..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#
.#...##..#..#...##..#..#...##..#..#...##..#..#...##..#..#...##..#.
..#.##.......#.##.......#.##.......#.##.......#.##.......#.##..... --->
.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#
.#........#.#........#.#........#.#........#.#........#.#........#
#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...
#...##....##...##....##...##....##...##....##...##....##...##....#
.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.# --->
You start on the open square (.) in the top-left corner and need to reach the bottom (below the bottom-most row on your map).
The toboggan can only follow a few specific slopes (you opted for a cheaper model that prefers rational numbers); start by counting all the trees you would encounter for the slope right 3, down 1:
From your starting position at the top-left, check the position that is right 3 and down 1. Then, check the position that is right 3 and down 1 from there, and so on until you go past the bottom of the map.
The locations you'd check in the above example are marked here with O where there was an open square and X where there was a tree:
..##.........##.........##.........##.........##.........##....... --->
#..O#...#..#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..
.#....X..#..#....#..#..#....#..#..#....#..#..#....#..#..#....#..#.
..#.#...#O#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#
.#...##..#..X...##..#..#...##..#..#...##..#..#...##..#..#...##..#.
..#.##.......#.X#.......#.##.......#.##.......#.##.......#.##..... --->
.#.#.#....#.#.#.#.O..#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#
.#........#.#........X.#........#.#........#.#........#.#........#
#.##...#...#.##...#...#.X#...#...#.##...#...#.##...#...#.##...#...
#...##....##...##....##...#X....##...##....##...##....##...##....#
.#..#...#.#.#..#...#.#.#..#...X.#.#..#...#.#.#..#...#.#.#..#...#.# --->
In this example, traversing the map using this slope would cause you to encounter 7 trees.
Starting at the top-left corner of your map and following a slope of right 3 and down 1, how many trees would you encounter?
--- Part Two ---
Time to check the rest of the slopes - you need to minimize the probability of a sudden arboreal stop, after all.
Determine the number of trees you would encounter if, for each of the following slopes, you start at the top-left corner and traverse the map all the way to the bottom:
Right 1, down 1.
Right 3, down 1. (This is the slope you already checked.)
Right 5, down 1.
Right 7, down 1.
Right 1, down 2.
In the above example, these slopes would find 2, 7, 3, 4, and 2 tree(s) respectively; multiplied together, these produce the answer 336.
What do you get if you multiply together the number of trees encountered on each of the listed slopes?

View File

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

View File

@ -0,0 +1,55 @@
use crate::common::AdventOfCodeDay;
pub struct Day03 {
width: i32,
height: i32,
input: Vec<Vec<bool>>,
}
impl Day03 {
pub fn new() -> Self {
let input_bytes = include_bytes!("../res/03_input.txt");
let input_str = String::from_utf8_lossy(input_bytes);
let lines = input_str.lines().map(String::from).collect::<Vec<String>>();
Self {
width: lines[0].len() as i32,
height: lines.len() as i32,
input: lines.iter().map(|l| l.chars().map(|c| c=='#').collect()).collect(),
}
}
pub fn get(&self, x: i32, y: i32) -> bool {
if y >= self.height { return false }
return self.input[y as usize][(x % self.width) as usize]
}
pub fn treecount(&self, dx: i32, dy: i32) -> i32 {
(0..self.height).filter(|y| self.get(dx*y, dy*y)).count() as i32
}
}
impl AdventOfCodeDay for Day03 {
fn task_1(&self) -> String {
return self.treecount(3, 1).to_string()
}
fn task_2(&self) -> String {
verboseln!("[1,1]: {}", self.treecount(1, 1));
verboseln!("[3,1]: {}", self.treecount(3, 1));
verboseln!("[5,1]: {}", self.treecount(5, 1));
verboseln!("[7,1]: {}", self.treecount(7, 1));
verboseln!("[1,2]: {}", self.treecount(1, 2));
let prod = self.treecount(1, 1) *
self.treecount(3, 1) *
self.treecount(5, 1) *
self.treecount(7, 1) *
self.treecount(1, 2);
return prod.to_string();
}
}

View File

@ -0,0 +1,116 @@
--- Day 4: Passport Processing ---
You arrive at the airport only to realize that you grabbed your North Pole Credentials instead of your passport. While these documents are extremely similar, North Pole Credentials aren't issued by a country and therefore aren't actually valid documentation for travel in most of the world.
It seems like you're not the only one having problems, though; a very long line has formed for the automatic passport scanners, and the delay could upset your travel itinerary.
Due to some questionable network security, you realize you might be able to solve both of these problems at the same time.
The automatic passport scanners are slow because they're having trouble detecting which passports have all required fields. The expected fields are as follows:
byr (Birth Year)
iyr (Issue Year)
eyr (Expiration Year)
hgt (Height)
hcl (Hair Color)
ecl (Eye Color)
pid (Passport ID)
cid (Country ID)
Passport data is validated in batch files (your puzzle input). Each passport is represented as a sequence of key:value pairs separated by spaces or newlines. Passports are separated by blank lines.
Here is an example batch file containing four passports:
ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
byr:1937 iyr:2017 cid:147 hgt:183cm
iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
hcl:#cfa07d byr:1929
hcl:#ae17e1 iyr:2013
eyr:2024
ecl:brn pid:760753108 byr:1931
hgt:179cm
hcl:#cfa07d eyr:2025 pid:166559648
iyr:2011 ecl:brn hgt:59in
The first passport is valid - all eight fields are present. The second passport is invalid - it is missing hgt (the Height field).
The third passport is interesting; the only missing field is cid, so it looks like data from North Pole Credentials, not a passport at all! Surely, nobody would mind if you made the system temporarily ignore missing cid fields. Treat this "passport" as valid.
The fourth passport is missing two fields, cid and byr. Missing cid is fine, but missing any other field is not, so this passport is invalid.
According to the above rules, your improved system would report 2 valid passports.
Count the number of valid passports - those that have all required fields. Treat cid as optional. In your batch file, how many passports are valid?
--- Part Two ---
The line is moving more quickly now, but you overhear airport security talking about how passports with invalid data are getting through. Better add some data validation, quick!
You can continue to ignore the cid field, but each other field has strict rules about what values are valid for automatic validation:
byr (Birth Year) - four digits; at least 1920 and at most 2002.
iyr (Issue Year) - four digits; at least 2010 and at most 2020.
eyr (Expiration Year) - four digits; at least 2020 and at most 2030.
hgt (Height) - a number followed by either cm or in:
If cm, the number must be at least 150 and at most 193.
If in, the number must be at least 59 and at most 76.
hcl (Hair Color) - a # followed by exactly six characters 0-9 or a-f.
ecl (Eye Color) - exactly one of: amb blu brn gry grn hzl oth.
pid (Passport ID) - a nine-digit number, including leading zeroes.
cid (Country ID) - ignored, missing or not.
Your job is to count the passports where all required fields are both present and valid according to the above rules. Here are some example values:
byr valid: 2002
byr invalid: 2003
hgt valid: 60in
hgt valid: 190cm
hgt invalid: 190in
hgt invalid: 190
hcl valid: #123abc
hcl invalid: #123abz
hcl invalid: 123abc
ecl valid: brn
ecl invalid: wat
pid valid: 000000001
pid invalid: 0123456789
Here are some invalid passports:
eyr:1972 cid:100
hcl:#18171d ecl:amb hgt:170 pid:186cm iyr:2018 byr:1926
iyr:2019
hcl:#602927 eyr:1967 hgt:170cm
ecl:grn pid:012533040 byr:1946
hcl:dab227 iyr:2012
ecl:brn hgt:182cm pid:021572410 eyr:2020 byr:1992 cid:277
hgt:59cm ecl:zzz
eyr:2038 hcl:74454a iyr:2023
pid:3556412378 byr:2007
Here are some valid passports:
pid:087499704 hgt:74in ecl:grn iyr:2012 eyr:2030 byr:1980
hcl:#623a2f
eyr:2029 ecl:blu cid:129 byr:1989
iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm
hcl:#888785
hgt:164cm byr:2001 iyr:2015 cid:88
pid:545766238 ecl:hzl
eyr:2022
iyr:2010 hgt:158cm hcl:#b6652a ecl:blu byr:1944 eyr:2021 pid:093154719
Count the number of valid passports - those that have all required fields and valid values. Continue to treat cid as optional. In your batch file, how many passports are valid?

View File

@ -0,0 +1,984 @@
byr:1985
eyr:2021 iyr:2011 hgt:175cm pid:163069444 hcl:#18171d
eyr:2023
hcl:#cfa07d ecl:blu hgt:169cm pid:494407412 byr:1936
ecl:zzz
eyr:2036 hgt:109 hcl:#623a2f iyr:1997 byr:2029
cid:169 pid:170290956
hcl:#18171d ecl:oth
pid:266824158 hgt:168cm byr:1992 eyr:2021
byr:1932 ecl:hzl pid:284313291 iyr:2017 hcl:#efcc98
eyr:2024 hgt:184cm
iyr:2017 pid:359621042
cid:239 eyr:2025 ecl:blu byr:1986 hgt:188cm
eyr:2027 hgt:185cm hcl:#373b34 pid:807766874 iyr:2015 byr:1955
ecl:hzl
iyr:2017 hcl:#7d3b0c hgt:174cm
byr:1942 eyr:2025 ecl:blu pid:424955675
eyr:2026 byr:1950 hcl:#ceb3a1
hgt:182cm
iyr:2016 pid:440353084 ecl:amb
hcl:a4c546
iyr:1932 pid:156cm eyr:2034 hgt:193 ecl:zzz byr:2025
hcl:#ceb3a1 eyr:2020 pid:348696077 hgt:163cm
ecl:hzl
byr:1921 iyr:2016
ecl:gmt eyr:2031 iyr:2018 byr:1971 hgt:152in pid:454492414
hcl:z
hcl:#341e13 byr:1921 iyr:2020
pid:072379782 eyr:2022 hgt:166cm cid:253 ecl:brn
ecl:blu hgt:75in byr:1954 eyr:2026 iyr:2012 hcl:#623a2f pid:328598886
byr:2004 eyr:2035 hcl:#7d3b0c pid:359128744 iyr:2020 hgt:65cm
ecl:#70f23f
eyr:1988
pid:171cm byr:2003
iyr:1984
cid:50
hcl:z hgt:66cm ecl:#7a4c6e
pid:9632440323 eyr:1964 hgt:63cm
ecl:#fab0c5 hcl:z iyr:1945 byr:1986
pid:936403762 ecl:#337357 byr:1997
cid:196 iyr:2020
eyr:2030 hgt:165cm
hcl:#7d3b0c
byr:1931 pid:488791624 hgt:169cm ecl:blu
eyr:2029 hcl:#fffffd iyr:2013
hcl:#733820 hgt:76in pid:517689823
eyr:2028 byr:1988
ecl:brn iyr:2016
eyr:2023 hcl:#fffffd hgt:190cm iyr:2015 ecl:brn pid:739536900 byr:1951
ecl:brn
byr:1986 cid:262 hcl:#efcc98 pid:880203213 hgt:185cm iyr:2018 eyr:2029
pid:181cm hgt:113 hcl:z ecl:#2c2d2c iyr:1961 byr:2021 eyr:2031
hcl:#ceb3a1 iyr:2020
byr:1977
hgt:192cm
pid:338237458 eyr:2030 ecl:amb
iyr:1953 byr:2025 hgt:66cm eyr:1932
pid:181cm
ecl:#6f0b15 hcl:f79cb7
cid:109
hcl:#6b5442 pid:164cm ecl:blu
hgt:176cm byr:2015
iyr:2010 eyr:2029
eyr:2035
pid:085002665 ecl:#f88074 iyr:2018 hcl:#602927
hgt:169cm
byr:1958
hcl:z
pid:0468194841 iyr:2016 eyr:2007
hgt:152cm
ecl:#1c7a89 cid:124
hcl:z pid:233430735 byr:2021 eyr:2026
iyr:1953 ecl:#64769d hgt:184
hgt:70cm pid:156397147
iyr:2014 ecl:#d6ada0
byr:2030
hcl:#cfa07d
ecl:amb
byr:1990
iyr:2017 hgt:164cm hcl:10f33a
cid:293 eyr:2020 pid:332276985
pid:163252726 eyr:2026
hgt:163cm
iyr:2011 hcl:#efcc98
ecl:hzl byr:1936
hgt:157cm iyr:2019 pid:078770050 hcl:#efcc98 byr:1967 eyr:2030
ecl:gry cid:190
hgt:184cm ecl:amb pid:851379559 hcl:#ceb3a1 byr:1946 eyr:2022
iyr:2017 cid:280
hgt:171cm byr:1942 pid:830156471 hcl:#cfa07d ecl:gry eyr:2032
iyr:2022
byr:2013 ecl:#67cbe8 eyr:2024
pid:242908367
hgt:76cm
iyr:2025
hcl:796bda
ecl:amb iyr:2019
byr:1945 eyr:2021 hcl:#602927 pid:550065206
hgt:72in ecl:brn byr:1956 pid:253685193 iyr:2017 eyr:2023
hcl:#6b5442
eyr:2032 iyr:2019
hgt:176cm
ecl:oth pid:800237895 hcl:#888785 byr:1979
eyr:2026 iyr:2020 cid:226 pid:882830512
hcl:#866857 byr:1929 ecl:amb
hgt:60in
hcl:#cfa07d ecl:oth
iyr:2015 pid:807837948 byr:1966 eyr:2030 hgt:191in
byr:1969 iyr:2012 eyr:2024
cid:244 ecl:hzl hcl:#18171d pid:344160556
eyr:2020 pid:718422803
hcl:#18171d
hgt:181cm
byr:1925 ecl:amb
iyr:2019
byr:1943 pid:740807220 hgt:72in ecl:amb
iyr:2013 eyr:2022
hcl:#cfa07d
hcl:#733820
byr:1986 iyr:2016 hgt:184cm cid:333
pid:768188726 ecl:oth eyr:2030
eyr:2022 byr:1996 hcl:#341e13 ecl:hzl iyr:2015 hgt:160cm
pid:516401532
hgt:182cm ecl:grn pid:336742028 iyr:2014 hcl:#34f021 byr:1967
eyr:2029
byr:2030
hgt:142 iyr:2029 eyr:2040 hcl:426fc5
cid:312
pid:169cm
ecl:#069ff7
hgt:169cm ecl:gry hcl:#6b5442 iyr:2012 byr:1949 pid:131835020 eyr:2022
hgt:70cm iyr:2012
eyr:2037
hcl:64fd76
cid:175 pid:4880649770 ecl:grn byr:2029
iyr:2013 hcl:#7d3b0c eyr:2024 hgt:190cm pid:659772377 cid:226 ecl:oth byr:1958
ecl:lzr hgt:163cm pid:013605217
byr:2000
eyr:2020
hcl:z iyr:2024
cid:131 pid:896076106
hcl:#c0946f byr:1930
hgt:162cm eyr:2023 ecl:oth iyr:2017
byr:1935 iyr:2012
pid:942509879
ecl:amb
hgt:185cm cid:152 eyr:2024 hcl:#866857
ecl:#e490a3 hcl:4813a2 hgt:176cm pid:778369210 iyr:2020
eyr:2035 byr:2020
byr:2006 ecl:amb pid:148409219
hgt:189cm
eyr:2021 hcl:z iyr:2028
hgt:188in hcl:#9ed525
iyr:2018 ecl:grn eyr:2021
pid:065515632 byr:2012
cid:109 hgt:167cm
pid:545112664 ecl:grn hcl:#a62fea eyr:2026
iyr:2012
byr:1921
pid:174997024
iyr:2012
eyr:2030
ecl:grn
hgt:150cm
byr:1997
hcl:#866857
pid:451921339
hgt:181cm
hcl:#888785 iyr:2017 eyr:2026 byr:1936
ecl:hzl
hgt:187in
hcl:#866857 ecl:grn pid:623919686 eyr:2028 iyr:2011
byr:2016
byr:2001
ecl:gry eyr:2023 pid:324948416
hcl:ef16f8 cid:139 hgt:184in iyr:2026
byr:1954 hcl:#341e13 eyr:2023 pid:129321944 iyr:2012
hgt:183cm
ecl:amb
hgt:164cm pid:596870080
ecl:hzl eyr:2021 iyr:2017 hcl:#a97842
byr:1951
iyr:2013 byr:1944 hcl:#cfa07d
hgt:168cm cid:72 pid:160531632
ecl:grn
iyr:2012 pid:900043442 hcl:#ceb3a1 cid:124 byr:1941
ecl:blu hgt:156cm
eyr:2025
eyr:2021 hgt:61in iyr:2020 ecl:grn byr:1933
byr:1971 cid:175
eyr:2028 hcl:#efcc98 iyr:2013 hgt:170cm
pid:225213589
pid:147112660 hcl:#ceb3a1 eyr:2029 hgt:159cm ecl:grn iyr:2014
byr:1967
iyr:2015 pid:502975636 hgt:71in byr:1994
hcl:#18171d ecl:amb eyr:2029
byr:1948 hcl:#b6652a hgt:171in pid:181cm iyr:2019 ecl:grt cid:87
pid:859849571 ecl:amb hcl:#6b5442
hgt:193cm byr:1980
iyr:2017
eyr:2020
cid:125 pid:508147848
hcl:06ea75 iyr:1997 byr:2010 ecl:#c707f7 eyr:1970 hgt:161
eyr:2020 cid:326 byr:1989 ecl:gry hgt:160cm hcl:#cc080c pid:319135853 iyr:2010
ecl:utc
pid:531595917 hgt:180cm byr:1987
eyr:2024 hcl:#cfa07d iyr:2025
ecl:gry byr:2007
eyr:2028
iyr:2025
pid:6072964414 hgt:59cm hcl:#888785
pid:791025828 ecl:hzl hgt:178cm
iyr:2017
hcl:#733820
byr:1960 eyr:2021 cid:66
byr:1991 iyr:1934
cid:304 hgt:183cm ecl:grn
pid:408294229
eyr:2027 hcl:#623a2f
ecl:blu hgt:181cm eyr:2024 iyr:2010
pid:633234602 hcl:#2ce009
byr:1985
hcl:#c0946f hgt:192cm
iyr:2012 pid:120684397 ecl:grn eyr:2027
byr:1974
eyr:2026
pid:068304960 hgt:190cm byr:1925 iyr:2020 ecl:oth
hcl:#733820
hgt:168cm cid:307 iyr:2014 byr:1981 ecl:hzl pid:898831724 eyr:2026
hgt:73cm
eyr:2038
byr:1980 ecl:gry iyr:2027 pid:678846912 hcl:z
hgt:150cm cid:261 eyr:2021
hcl:z pid:159cm iyr:2014 ecl:hzl
byr:1955
pid:#172650 ecl:gry eyr:2040 hcl:z iyr:2013 hgt:169cm byr:2008 cid:290
iyr:2017 byr:1998
hcl:#ceb3a1 pid:274178898 eyr:2027 ecl:brn
hgt:183cm
eyr:2024 cid:183 ecl:grn
byr:1946
hgt:63in hcl:#6b5442 iyr:2017
hgt:97 byr:1990
iyr:2019
ecl:grn
pid:587580330
hcl:#341e13 eyr:2022
ecl:oth
pid:441517075 hcl:#c0946f iyr:2015 hgt:188cm eyr:2024 byr:1920
hgt:191in pid:185cm iyr:1993
hcl:93033d
eyr:2034 ecl:dne
pid:591478424 ecl:grn hcl:#888785
byr:1929 eyr:2023 hgt:173cm iyr:2017
iyr:1954
hgt:63cm
hcl:bdf2e0 ecl:amb pid:#912f46
byr:1956 iyr:2012 hgt:73in pid:986643426
ecl:blu
cid:235 eyr:2025
hcl:#cfa07d
cid:320 byr:1930
hgt:172cm
ecl:oth eyr:2024 iyr:2019
byr:1935 hgt:182cm pid:22794407 hcl:1b96fb eyr:1961 iyr:1941 ecl:#5e80cd cid:70
iyr:2020 eyr:2021
ecl:amb
hgt:59in pid:594829025 hcl:#93092e
byr:1976
hcl:#a97842 eyr:2030
byr:1937 iyr:2018 cid:295 ecl:oth
hgt:166cm pid:282634012
hgt:171cm hcl:#623a2f byr:1956
pid:068178613 cid:214
iyr:2012 eyr:2026 ecl:brn
byr:1921
hgt:161cm hcl:#888785
ecl:brn pid:010348794
eyr:2023 iyr:2011
hcl:#a97842 iyr:2010
byr:1955 eyr:2024
pid:473791166
ecl:brn
hgt:175cm
eyr:2028 ecl:grn pid:186196675 byr:1945 hgt:155cm cid:349
iyr:2011 hcl:#6b5442
hgt:161cm eyr:2030 cid:221
pid:994494879 hcl:#733820 iyr:2012 ecl:blu
byr:1957
eyr:1993 iyr:2022 hcl:z byr:2020 pid:013428192 hgt:62cm
ecl:dne
hgt:178cm eyr:2029 hcl:#733820 byr:1962 iyr:2017 ecl:blu pid:567713232
hcl:#fffffd
byr:1928 pid:390162554
eyr:2030 cid:79 hgt:150cm ecl:amb iyr:2019
eyr:2030 cid:320 hgt:171cm hcl:#888785 pid:540720799 ecl:amb iyr:2012 byr:1979
byr:1921
ecl:oth pid:204986110 eyr:2023 hgt:154cm iyr:2017 hcl:#341e13 cid:126
eyr:2020 cid:175 ecl:dne byr:1983 iyr:2016 hcl:#c0946f hgt:65cm
hgt:191cm
iyr:2010 cid:295 byr:1984 eyr:2025 hcl:#cfa07d pid:799775698
ecl:amb
iyr:2020 cid:278 hcl:#c0946f byr:1970 pid:773144393 eyr:2024 hgt:180cm
hgt:176cm
byr:1963
pid:252396293 iyr:2012 ecl:brn hcl:#ceb3a1
eyr:2030
pid:545130492
byr:2030 iyr:2020
hgt:190cm eyr:2034 ecl:blu hcl:#fffffd
hcl:#a97842 pid:032201787 hgt:190cm ecl:gry
eyr:2028 iyr:2012 byr:1994
hcl:#a97842 pid:064591809
ecl:hzl byr:1927 hgt:165cm
iyr:2011
eyr:2028
cid:77
byr:2005
hgt:125 iyr:1923 ecl:#605d73
eyr:2022 pid:90184674 hcl:z
cid:301 pid:106820988
iyr:2018
hcl:#cfa07d eyr:2029
byr:1993
hgt:193cm ecl:grn
hcl:#623a2f
cid:118
ecl:oth pid:75827285
hgt:189cm iyr:2010
eyr:2030 byr:1976
ecl:blu iyr:2023 eyr:1996
hgt:66cm cid:251 byr:1972 hcl:z
pid:557774244
byr:2002
hgt:169cm pid:629420566 eyr:2026 ecl:grn hcl:#341e13
cid:166 iyr:2019
iyr:2026 hcl:9b83a1 eyr:1979
ecl:dne hgt:111 pid:176cm
pid:#89718c byr:2026
hcl:2ca5c7 hgt:142 eyr:2040
ecl:lzr iyr:2029
ecl:grn
byr:2022 eyr:2020
pid:7024869 hgt:123 iyr:2019 hcl:z
hcl:#733820 hgt:155cm ecl:grn iyr:2020 byr:1955 eyr:2028
pid:217362007
hcl:#18171d ecl:gry
byr:1971 hgt:193cm
eyr:2020
pid:352009857 iyr:2013
byr:2018
hgt:175in ecl:xry iyr:2015
eyr:2036
cid:171 pid:6132398 hcl:#efcc98
pid:839955293
byr:1928 hcl:#fffffd ecl:hzl iyr:2011
hgt:162cm eyr:2023
hgt:175cm pid:482827478 eyr:2028
hcl:#6b5442 ecl:blu byr:1932 iyr:2010
iyr:2020 hcl:#866857
ecl:brn byr:1933 cid:269 pid:003931873 hgt:188cm
eyr:2022
byr:1981 hcl:#fffffd hgt:160cm cid:311 ecl:brn eyr:2025
pid:930857758 iyr:2014
hcl:#cfa07d hgt:73in
ecl:gry
pid:383281251
iyr:2013 byr:1934 eyr:2026
byr:1988 eyr:2026 pid:458002476
iyr:2017
hgt:175cm ecl:amb
eyr:1987
byr:2020 pid:299341304
hcl:#341e13 iyr:1935 cid:125
hgt:168cm
ecl:gry
iyr:2014 hcl:#b6652a pid:445799347
hgt:188cm byr:1960
eyr:2030 cid:290 ecl:amb
eyr:2023
hgt:75cm hcl:#733820 cid:195 byr:1933
ecl:amb pid:062770586 iyr:2019
hgt:168cm
eyr:2021
pid:725299968 ecl:grn byr:1932
iyr:2016 hcl:#888785
hgt:161cm hcl:#ceb3a1 byr:1962 eyr:2026 iyr:2013 ecl:amb pid:695426469 cid:227
ecl:dne hcl:#ceb3a1 iyr:2013 eyr:2022
pid:434786988 byr:1956 hgt:183cm
pid:697500517
byr:1968 hgt:169cm hcl:#fffffd ecl:grn cid:143
iyr:2010
eyr:2027
byr:2029 ecl:amb hgt:175in iyr:2015 hcl:#ceb3a1
pid:39839448
eyr:2021 cid:105
pid:0985607981 ecl:hzl iyr:2012
eyr:2021 byr:2024 hcl:5cad22
hgt:190cm
hcl:#b6652a hgt:178cm cid:222 byr:1992 ecl:grn
iyr:2011 pid:419544742
iyr:2019 byr:1960 ecl:hzl eyr:2021 hgt:184cm cid:66 hcl:#866857 pid:412920622
eyr:2025 hcl:#888785 iyr:2018 byr:1956 pid:698098389 ecl:grn hgt:173cm
ecl:blu byr:1935
pid:354892542 hgt:161cm
iyr:2018
eyr:2021 hcl:#b6652a
ecl:oth cid:287 iyr:2028 byr:1953 eyr:2027 hcl:#7d3b0c hgt:151cm
pid:211411839
iyr:2018 byr:1934 hcl:#a97842
pid:859748861
ecl:oth hgt:175cm eyr:2025
byr:1930 iyr:2018 eyr:2022
hgt:175cm
hcl:#292092
ecl:brn pid:987163365
hgt:167in hcl:#888785 eyr:2040 pid:4646402867 byr:2013 iyr:1941 ecl:#389aec
ecl:hzl hcl:#602927
hgt:168cm eyr:2026
cid:235 iyr:2016
byr:1942
iyr:1975 pid:11337832 ecl:#a25273 hgt:151 byr:2017
eyr:1979
hgt:71cm
byr:2003 hcl:7e7da7 pid:151cm ecl:#a8afb3 iyr:1937
eyr:2021 hgt:74in hcl:#cfa07d iyr:2014 byr:1932
pid:641867677 ecl:grn
ecl:gry hgt:185cm pid:556229206 iyr:2013
byr:1984
hcl:#fffffd eyr:2028
eyr:2020 byr:1989
ecl:grn pid:618876158 hcl:z
hgt:176cm iyr:2025
eyr:2025 byr:2001 hcl:#cdb7f9
pid:377402126 ecl:hzl hgt:184cm iyr:2019
byr:1939 hgt:180cm eyr:2029 ecl:oth hcl:#733820 iyr:2016
pid:733456875
pid:883743276
hcl:#7d3b0c eyr:2022 ecl:blu
byr:1928 hgt:150cm cid:150 iyr:2013
hgt:60cm ecl:#43f03d eyr:1994 byr:1975
iyr:1980 pid:169cm
hgt:104 byr:2029 eyr:2040 hcl:64a9b2
pid:83898860
iyr:1990
ecl:#938bbe
pid:284399238 ecl:gry hcl:#888785 iyr:2019 hgt:168cm byr:1944
eyr:2022
hcl:#733820 pid:486515752 ecl:grn hgt:188in byr:1941 iyr:2017 eyr:2005
iyr:2010
byr:1978 hgt:160cm eyr:2003
ecl:oth
hcl:#efcc98 pid:584668011
byr:1944 ecl:gry pid:962700562 iyr:2011 hcl:#866857 eyr:2022
hgt:191cm
hcl:z pid:758583213 iyr:1941 ecl:gry eyr:2007
hgt:67 byr:2022
cid:215
byr:1988
ecl:#ae2a9b hcl:#fe9d14 iyr:2012
pid:411550516 hgt:169cm eyr:2038
pid:400034647 byr:1927 hgt:165cm
iyr:2017 ecl:brn eyr:2024 cid:144 hcl:#341e13
hcl:#733820 hgt:153cm eyr:2027
byr:1935 pid:217121064 cid:120 iyr:2012 ecl:grn
hgt:168cm hcl:#866857 iyr:2012 pid:1527348755
byr:1946 eyr:2028 cid:184 ecl:amb
hcl:#a97842
byr:1967
hgt:152cm eyr:2030
ecl:blu
pid:929661915 iyr:2018
pid:671485026
hgt:188cm byr:1974 iyr:2015 ecl:grn cid:268 eyr:2021 hcl:#c0946f
pid:789877199 iyr:2011 cid:219 eyr:2029
ecl:oth byr:1991
hcl:#866857 hgt:154cm
cid:137 pid:059579902
eyr:2020 byr:1952
hcl:#18171d iyr:2020
hgt:172cm ecl:oth
pid:182cm iyr:1997 byr:2012
eyr:2034
hgt:161in ecl:#528abf hcl:b7d2fe
hgt:192cm ecl:oth iyr:2017 pid:264538307 byr:1994 cid:285
hcl:#18171d eyr:2030
hcl:#efcc98
pid:38036608
eyr:2010
iyr:2026
byr:2027
cid:239 ecl:zzz hgt:74
iyr:2012
eyr:2022 hgt:178cm
hcl:#888785
ecl:hzl
byr:1998 pid:000080585
pid:719620152 hcl:#b6652a cid:133
ecl:hzl
byr:1983 iyr:2012 hgt:175cm
eyr:2024
cid:155 eyr:1977 iyr:2019 ecl:#28de8b byr:1941 hcl:#602927 hgt:173cm pid:493773064
iyr:2010
pid:842124616 ecl:hzl eyr:2025 cid:146 hcl:#733820 hgt:166cm byr:1987
hcl:fd4dcf byr:2006 iyr:2011 pid:820797708 eyr:2020 hgt:189cm
ecl:gry
iyr:1971 pid:22107293 hcl:#5b3f01 cid:257
ecl:hzl
hgt:60cm eyr:2000 byr:1965
byr:1932 eyr:2028
hcl:#6b5442 ecl:amb pid:947149686
iyr:2015 hgt:187cm
hcl:#a97842
cid:260
hgt:167cm eyr:2027 byr:1973 ecl:oth pid:741678753 iyr:2016
pid:334234443 ecl:gry hcl:#18171d eyr:2020
iyr:2016 hgt:159cm byr:1926
hgt:118 eyr:1929 iyr:2013
pid:987139064
cid:196
hcl:#cfa07d ecl:#f72601 byr:1929
byr:1924
pid:623185744 iyr:2012 cid:341 hcl:#602927 hgt:192cm eyr:2022
iyr:2012 byr:1971 hgt:168cm cid:146 pid:673038025 hcl:#866857 eyr:2020 ecl:hzl
eyr:2023 iyr:2017
pid:205596613 cid:298 hcl:#341e13
hgt:169cm ecl:oth
byr:1996
ecl:blu pid:775831730
eyr:2029 iyr:1924 hgt:168cm hcl:z
byr:2023 hgt:181cm
pid:4365105095 iyr:2021
ecl:lzr eyr:2024 hcl:z
hgt:184cm byr:1987 pid:175cm ecl:#83a5fa eyr:2023
eyr:2021 pid:422371422 ecl:oth iyr:2015 hcl:#866857
byr:1963 hgt:174cm
pid:006970943
hcl:#2f22ef iyr:2020
ecl:gry
byr:1922
eyr:2024 hgt:163cm
cid:160 byr:2015
eyr:2038 hcl:z ecl:grt hgt:166 iyr:2026
pid:#14978f
hgt:178cm eyr:2021 iyr:2016 pid:471529794
hcl:#b6652a cid:192
ecl:grn byr:1970
iyr:2015 ecl:brn hcl:#602927 hgt:187cm
pid:729284172
eyr:2024 byr:1932
cid:153
ecl:dne eyr:2005
pid:178cm iyr:2028
byr:2029 hgt:160in hcl:482a92
byr:1995 iyr:2012 hcl:#866857 hgt:159cm
eyr:1950 ecl:gry pid:183cm
pid:875885919
hgt:159cm
iyr:2011
ecl:gry byr:1988 hcl:#341e13 eyr:2028
pid:2390267705 hcl:#7d3b0c byr:2009
eyr:2017 ecl:grn hgt:183cm iyr:2015
ecl:brn eyr:2029 hcl:#866857 iyr:2020 hgt:180cm byr:2001
pid:668021168
hcl:#c0946f
eyr:2024 ecl:amb pid:013487714 byr:1965 hgt:172cm cid:320 iyr:2020
eyr:2025 pid:115479767 hcl:#866857 ecl:oth
hgt:163cm iyr:2010 byr:1999
byr:1967 iyr:2011 cid:112 hcl:#733820
eyr:2040 ecl:grt
hgt:66 pid:804536366
hgt:163 pid:1764836278 eyr:2035
iyr:2021
hcl:z ecl:#f1bb27
hcl:#efcc98 hgt:176cm byr:1994 pid:590539278 ecl:grn iyr:2011 eyr:2021
iyr:2017 eyr:2024 hgt:167cm hcl:#b62e29 pid:495674801
byr:1970 ecl:brn
hgt:168cm pid:993244641
byr:1968
eyr:1926
hcl:#b6652a ecl:brn
iyr:2023
hgt:63in hcl:z pid:594070517
eyr:2021 ecl:oth
iyr:2017
byr:2000
eyr:2030 pid:272955042 cid:319 iyr:2011 ecl:amb byr:1999 hcl:#888785 hgt:158cm
eyr:2025
pid:814305816 byr:1945 ecl:brn hgt:162cm iyr:2018
hcl:#a97842
cid:229
byr:1996 eyr:2026 pid:582584802 hcl:#c0946f iyr:2020 ecl:grn
hgt:162cm
eyr:2027
hgt:155cm byr:1925
hcl:#888785
cid:182
iyr:2014 ecl:brn
pid:250884352
hgt:173cm cid:135
iyr:2017 pid:661330507 byr:1950 eyr:2020 ecl:gry hcl:#18171d
pid:208932950
eyr:2030 hgt:179cm
iyr:2013
ecl:oth
byr:1981
cid:58 hcl:#6b5442
hcl:#f183e7 iyr:2014
hgt:159cm pid:614579850 ecl:gry eyr:2029
cid:186 byr:1962
eyr:2027 hcl:#db3405 byr:1938 pid:194516631 cid:167 hgt:177cm ecl:oth
hgt:68in hcl:#733820 pid:228644594 eyr:2030 ecl:gry iyr:2010 cid:334 byr:1951
iyr:2017 hcl:#341e13
pid:#6a28c9 hgt:154cm ecl:gry
byr:1966 eyr:2023
pid:250155574 cid:84
hgt:157cm ecl:grn byr:1937 iyr:2017 eyr:2024 hcl:#b6652a
pid:831823039 eyr:2028 iyr:2015 ecl:gry
hgt:192cm cid:137 byr:1922
hcl:#6b5442
hgt:193cm byr:1941 eyr:2024 cid:56
hcl:#623a2f ecl:amb
pid:351293754 iyr:2016
byr:1947 iyr:2012 ecl:hzl hcl:#602927 eyr:2028 pid:252010138 hgt:152cm
hcl:#a97842 pid:801192586 ecl:hzl iyr:2018 hgt:193cm byr:1928 cid:323
eyr:2028
hgt:151cm
pid:756347561 ecl:hzl
eyr:2024 cid:161
iyr:2016 hcl:#623a2f
byr:2002
pid:648012871 iyr:2015 ecl:blu
eyr:2025 hcl:#623a2f byr:1973 hgt:177cm
byr:1999 hcl:#ceb3a1 cid:345 eyr:2025 ecl:#b29a96 pid:093304949
iyr:2017 hgt:93
hcl:#b6652a
iyr:2018 ecl:grn
byr:1951 pid:077278028 eyr:2024 hgt:62in
hgt:164cm pid:410770618 byr:1958
iyr:2019
eyr:2030
ecl:gry hcl:#fffffd cid:293
ecl:grt
eyr:2039
hcl:z pid:188cm byr:2022
iyr:2027 hgt:76cm
ecl:grn iyr:2012 hgt:150cm eyr:2024
byr:1926 pid:954310029 cid:64
hcl:#fffffd
ecl:oth eyr:2027 pid:091152959 hgt:180cm hcl:#ceb3a1 iyr:2015 cid:350
byr:1924
iyr:2017 hcl:#49a793 eyr:2021 cid:144 byr:1966
pid:717543257
hgt:161cm
ecl:hzl
eyr:2025 ecl:brn hgt:60in pid:391973520 byr:1928 cid:77
iyr:2012
hcl:#602927
iyr:2013 hgt:161cm pid:784483994 byr:1991
hcl:#cfa07d
eyr:2024 ecl:grn
ecl:hzl iyr:1967 byr:2009 cid:265 hgt:180in pid:168cm
eyr:1966
eyr:2024 iyr:2019 pid:534453983
byr:2028 ecl:oth hcl:#341e13 hgt:193cm
eyr:2029 iyr:2010 hcl:#623a2f ecl:gry hgt:152cm pid:572128647
byr:1996
iyr:2014 byr:1981 cid:176
ecl:grn hgt:183cm pid:974469723 eyr:2027
eyr:2029 pid:233353682 byr:1968
ecl:gry hgt:181cm iyr:2011
hcl:#efcc98
hgt:61 iyr:2005 cid:203 ecl:gmt pid:157cm hcl:z
byr:2013
iyr:2020
byr:1923 ecl:blu eyr:2026 pid:069770502 hgt:69cm
hcl:z
byr:1997 hgt:160cm
hcl:z iyr:2021 eyr:1920 pid:9374226872
ecl:hzl eyr:2024 pid:537492791 hgt:186cm byr:1952
hcl:#cfa07d
iyr:2020
hgt:73cm byr:1974
ecl:xry iyr:2016 cid:133
hcl:e741f5 pid:186cm
pid:161cm
byr:1950
eyr:2028 ecl:hzl hcl:#7d3b0c
iyr:2014 hgt:158cm
ecl:#2c491e
hcl:f8fe13 byr:2022
hgt:137 iyr:1948
eyr:2040 pid:#959a0f
byr:1923 hgt:70in
pid:904825661 hcl:#b6652a iyr:2010 eyr:2020
ecl:oth
iyr:2013
ecl:blu pid:858020233 byr:1950 hgt:61in
hcl:#18171d
iyr:2016
ecl:amb pid:613754206 byr:1975 hgt:164cm eyr:2025
byr:1938
iyr:2017 hcl:#623a2f cid:191 eyr:2027 hgt:174cm pid:287108745 ecl:amb
iyr:2025 hcl:#623a2f byr:2019 hgt:170cm
cid:233 pid:55323151 ecl:amb eyr:2037
ecl:amb
hgt:177cm hcl:#b6a3ce eyr:2025 byr:1967 pid:506927066
iyr:2018 cid:93
byr:1964 hgt:173cm eyr:2030 cid:106 pid:587635596 iyr:2012
hcl:#fb5993
ecl:hzl
ecl:lzr pid:190cm hcl:44746d eyr:1955 hgt:66cm iyr:1990 byr:2003
ecl:brn byr:1968 cid:216 hgt:181in hcl:#b6652a iyr:2016 eyr:2020 pid:0208311541
ecl:hzl hgt:181cm
eyr:1977 byr:2018 pid:527754216 hcl:#c0946f
ecl:grn hcl:#efcc98
byr:1935 eyr:2025 iyr:2018 hgt:65in pid:396444938 cid:293
hgt:64in ecl:oth
hcl:#18171d
pid:105602506 byr:1973
eyr:2022
iyr:2014
eyr:2039 hgt:64
ecl:#ab45a8 byr:2009
iyr:2025 pid:182cm hcl:d1614a cid:103

View File

@ -0,0 +1,151 @@
use crate::common::AdventOfCodeDay;
use regex::Regex;
#[derive(Debug)]
struct Data {
key: String,
value: String,
}
#[derive(Debug)]
struct Passport {
data: Vec<Data>,
}
pub struct Day04 {
input: Vec<Passport>,
}
fn parse_passport(p: String) -> Passport {
let rex_values = Regex::new(r"\s+").unwrap();
let data = rex_values
.split(&p)
.map(|q| q.split(':').map(String::from).collect::<Vec<String>>())
.filter(|q| q.len() == 2)
.map(|q| Data{ key: q[0].to_owned(), value: q[1].to_owned() })
.collect::<Vec<Data>>();
Passport {
data: data
}
}
impl Day04 {
pub fn new() -> Self {
let input_bytes = include_bytes!("../res/04_input.txt");
let input_str = String::from_utf8_lossy(input_bytes);
let rex_lines = Regex::new(r"(\r?\n){2}").unwrap();
let lines = rex_lines.split(&input_str.to_owned())
.map(String::from)
.map(parse_passport)
.collect::<Vec<Passport>>();
Self {
input: lines
}
}
}
impl Passport {
pub fn is_all_present(&self) -> bool {
if self.get("byr") == None { return false }
if self.get("iyr") == None { return false }
if self.get("eyr") == None { return false }
if self.get("hgt") == None { return false }
if self.get("hcl") == None { return false }
if self.get("ecl") == None { return false }
if self.get("pid") == None { return false }
//if self.get("cid") == None { return false }
return true
}
pub fn is_all_valid(&self) -> bool {
lazy_static! {
static ref REX_BYR: Regex = Regex::new(r"^[12][90][0-9][0-9]$").unwrap();
static ref REX_IYR: Regex = Regex::new(r"^20[12][0-9]$").unwrap();
static ref REX_EYR: Regex = Regex::new(r"^20[23][0-9]$").unwrap();
static ref REX_HGT: Regex = Regex::new(r"^[0-9]+(in|cm)$").unwrap();
static ref REX_HCL: Regex = Regex::new(r"^#[0-9a-f]{6}$").unwrap();
static ref REX_ECL: Regex = Regex::new(r"^(amb|blu|brn|gry|grn|hzl|oth)$").unwrap();
static ref REX_PID: Regex = Regex::new(r"^[0-9]{9}$").unwrap();
}
if self.get_and_validate("byr", &REX_BYR) == None { return false }
if self.get_and_validate("iyr", &REX_IYR) == None { return false }
if self.get_and_validate("eyr", &REX_EYR) == None { return false }
if self.get_and_validate("hgt", &REX_HGT) == None { return false }
if self.get_and_validate("hcl", &REX_HCL) == None { return false }
if self.get_and_validate("ecl", &REX_ECL) == None { return false }
if self.get_and_validate("pid", &REX_PID) == None { return false }
let byr = self.get("byr").unwrap().parse::<i32>().unwrap();
let iyr = self.get("iyr").unwrap().parse::<i32>().unwrap();
let eyr = self.get("eyr").unwrap().parse::<i32>().unwrap();
let hgt = self.get("hgt").unwrap();
if byr < 1920 { return false }
if byr > 2002 { return false }
if iyr < 2010 { return false }
if iyr > 2020 { return false }
if eyr < 2020 { return false }
if eyr > 2030 { return false }
if hgt.ends_with("cm") {
let v = hgt.replace("cm", "").parse::<i32>().unwrap();
if v < 150 { return false }
if v > 193 { return false }
} else { //in
let v = hgt.replace("in", "").parse::<i32>().unwrap();
if v < 59 { return false }
if v > 76 { return false }
}
return true
}
pub fn get_and_validate(&self, key: &str, rex: &Regex) -> Option<String> {
if let Some(val) = self.get(key) {
if rex.is_match(&val) {
return Some(val)
}
}
return None
}
pub fn get(&self, key: &str) -> Option<String> {
for dat in &self.data {
if dat.key == key {
return Some(String::from(&dat.value))
}
}
return None
}
}
impl AdventOfCodeDay for Day04 {
fn task_1(&self) -> String {
if is_verbose!() {
for r in &self.input {
verboseln!("{:?}", r);
verboseln!();
}
}
return self.input.iter().filter(|p| p.is_all_present()).count().to_string()
}
fn task_2(&self) -> String {
return self.input.iter().filter(|p| p.is_all_valid()).count().to_string()
}
}

View File

@ -0,0 +1,51 @@
--- Day 5: Binary Boarding ---
You board your plane only to discover a new problem: you dropped your boarding pass! You aren't sure which seat is yours, and all of the flight attendants are busy with the flood of people that suddenly made it through passport control.
You write a quick program to use your phone's camera to scan all of the nearby boarding passes (your puzzle input); perhaps you can find your seat through process of elimination.
Instead of zones or groups, this airline uses binary space partitioning to seat people. A seat might be specified like FBFBBFFRLR, where F means "front", B means "back", L means "left", and R means "right".
The first 7 characters will either be F or B; these specify exactly one of the 128 rows on the plane (numbered 0 through 127). Each letter tells you which half of a region the given seat is in. Start with the whole list of rows; the first letter indicates whether the seat is in the front (0 through 63) or the back (64 through 127). The next letter indicates which half of that region the seat is in, and so on until you're left with exactly one row.
For example, consider just the first seven characters of FBFBBFFRLR:
Start by considering the whole range, rows 0 through 127.
F means to take the lower half, keeping rows 0 through 63.
B means to take the upper half, keeping rows 32 through 63.
F means to take the lower half, keeping rows 32 through 47.
B means to take the upper half, keeping rows 40 through 47.
B keeps rows 44 through 47.
F keeps rows 44 through 45.
The final F keeps the lower of the two, row 44.
The last three characters will be either L or R; these specify exactly one of the 8 columns of seats on the plane (numbered 0 through 7). The same process as above proceeds again, this time with only three steps. L means to keep the lower half, while R means to keep the upper half.
For example, consider just the last 3 characters of FBFBBFFRLR:
Start by considering the whole range, columns 0 through 7.
R means to take the upper half, keeping columns 4 through 7.
L means to take the lower half, keeping columns 4 through 5.
The final R keeps the upper of the two, column 5.
So, decoding FBFBBFFRLR reveals that it is the seat at row 44, column 5.
Every seat also has a unique seat ID: multiply the row by 8, then add the column. In this example, the seat has ID 44 * 8 + 5 = 357.
Here are some other boarding passes:
BFFFBBFRRR: row 70, column 7, seat ID 567.
FFFBBBFRRR: row 14, column 7, seat ID 119.
BBFFBBFRLL: row 102, column 4, seat ID 820.
As a sanity check, look through your list of boarding passes. What is the highest seat ID on a boarding pass?
--- Part Two ---
Ding! The "fasten seat belt" signs have turned on. Time to find your seat.
It's a completely full flight, so your seat should be the only missing boarding pass in your list. However, there's a catch: some of the seats at the very front and back of the plane don't exist on this aircraft, so they'll be missing from your list as well.
Your seat wasn't at the very front or back, though; the seats with IDs +1 and -1 from yours will be in your list.
What is the ID of your seat?

View File

@ -0,0 +1,814 @@
FBFBBBFRLL
BFFFBFFRRR
BBFBFFFLLR
FBFFFBFLRR
FBFFBFBLLR
BFBBFBBRLL
BFFFFFFRLR
FBBBBFFLLR
FFBBFFFLRL
FFBFBBFLLR
FBFFFBBRRR
FBFFBFBLRR
FBBFBFFRLR
FBBBFBFRLL
FFBFFBBRLR
FBFBBBFRRL
BFFBBBFRRR
FBFBBBBLLR
FFBFFBBLLL
BFFBFBBLLR
BFFBFBBRLR
BFFBBBBLLL
FBBBBFBLLR
FFBFBBBLRR
FFBFBBFLRR
FFFBFBBRRL
FFFFFBBRLL
BFFFBFFLRR
FFFBFBBRLR
FBFFBBFLLR
BFBFFBBRRR
FBBFBBFLRL
BFBBFBFRRR
BFFFBBBLRL
BBFFFBFLLR
BFFFFBFLRR
BFFBFFBLLL
FFBBFBFRRR
BFBFFFBLLL
FBFBFFFRRR
BFBFBBBLLL
BFFFBBFLLL
BFBFFFBLLR
BFFBBBFRRL
FFFBBFFLLR
BFFBBBFLRR
FBFFBBBRLR
FBBFBBFLRR
FBBFFBFRRR
FBBFBBBRRL
FFFBFFBRRL
FBFBFFBRLL
FBFFBBFRLL
BFBFBFFRLL
FBFBFFFRLR
BFBFFBBRRL
FFBBFFBRRR
BFFBFBBLRL
FFBFBFBLLL
BBFFFBFRLL
FBFBBBFRRR
BFFBBFFLRR
BFBBFFBLRL
BFFFFFBLLL
BBFFFFFRLR
FBBFFBFRLL
FFBFBFFRRR
BFBBBBFLRR
BFFBBFFRLL
BFBBFFBLLL
BFFFFFBRRR
FBBFFFBLRL
FFFBBBFRLR
FFBBBFBRRL
BFFFBBBRRL
FFBFBFBRRR
FBBBBBFRRR
BBFBFFFRLL
FBFFFBBLRR
FBFBFFBRRR
BFBFBFBRLR
FBBBFFFRRL
BFBFFFBRLL
FBBBFFBLLL
BFBFBFFRLR
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RLL
FFBBBBFRLL
FFFFBFFLRR
FFBBBBBLRL
FBBBBBBLRR
FBBFFFBLLR
BBFFFBBRLL
BFFBBFFLRL
FFFBFBFRRR
FBFBFBBLLL
FBBBBBFRLL
FBBBBBBRRL
FBFBBBBRRL
FBFFBFFRRL
BFFFBBFLLR
BFFBFFFLRR
BFFBBFBLRR
FFFFBFBRLL
BFFBFFFLRL
FFBFFFBLRL
FBBFFFBLRR
BFBBBFFLRL
FBFFBBFLRL
BFFFBBBRLR
BFFBFBBRRR
BFFFFFBLRL
BBFBFFFLRL
BFBFBBFRRL
BBFFBFFLRR
FBFBFBBLRL
BFBFBBFRLR
FFFBBBBRRR
FBFFFFBLLR
FBFBBFFRLL
BFBFFBFRRR
FFFBFFBLLR
FBFBFBFLRL
FBBFBBBRLR
FFFBFBBLLR
FFBBFFFRLL
BFBFFBBRLR
BBFFFFBLLL
FFBBBFFRRR
BFFBFFFRLR
FFBFFBBLRL
FBBBFFBRRR
BFBFBBFRLL
BFBBBBFRRL
BFBBFFBRLL
BBFFFBBLRL
FFBBBBFRRR
BBFFFBFRRR
BFBFFFFLRR
FFFBFBBLRR
BFFBBFBRRL
FBBFBBBRRR
FBFBFFFLRL
BFBBFBFRLR
FFFBFFFLRL
FFBBBFBRRR
FBBFFBBRRR
BBFFFBBLLR
FFFBFFBLRL
FFBFBBBRRL
FFBBBFFLLR
FBFFBBFRLR
FBFFFBFLRL
FFBBFBBRRL
FFFBBFFRRL
FBBFBBFRLR
FBFBBFFRRR
FFFFBFFRRR
BFFFFFBLRR
BBFFFFBRRL
FBBBFFBLRR
BFFBFBFRLL
FFBFFFBRRL
FFBFBFBLLR

View File

@ -0,0 +1,67 @@
use crate::common::AdventOfCodeDay;
use std::u32;
#[derive(Debug)]
struct BoardingPass {
row: u32,
column: u32,
}
#[derive(Debug)]
pub struct Day05 {
input: Vec<BoardingPass>,
}
impl BoardingPass {
fn seat_id(&self) -> u32 { self.row * 8 + self.column }
}
fn parse_line(val: &str) -> BoardingPass {
let sval = val.to_owned()
.replace("F", "0")
.replace("B", "1")
.replace("R", "1")
.replace("L", "0");
BoardingPass {
row: u32::from_str_radix(&sval[0..7], 2).unwrap(),
column: u32::from_str_radix(&sval[7..10], 2).unwrap(),
}
}
impl Day05 {
pub fn new() -> Self {
let input_bytes = include_bytes!("../res/05_input.txt");
let input_str = String::from_utf8_lossy(input_bytes);
let data = input_str
.lines()
.map(parse_line)
.collect::<Vec<BoardingPass>>();
Self {
input: data
}
}
}
impl AdventOfCodeDay for Day05 {
fn task_1(&self) -> String {
verboseln!("{:?}", self.input);
return self.input.iter().map(|p| p.seat_id()).max().unwrap().to_string()
}
fn task_2(&self) -> String {
let min = self.input.iter().map(|p| p.seat_id() as u64).min().unwrap();
let sum = self.input.iter().map(|p| p.seat_id() as u64 - min).sum::<u64>(); // sum of all pass numbers
let allsum = (self.input.len() * (self.input.len() + 1) / 2) as u64; // sum if all pass numbers are there
let missing = (allsum - sum) + min; // diff = the _one_ missing number
return missing.to_string()
}
}

View File

@ -0,0 +1,79 @@
--- Day 6: Custom Customs ---
As your flight approaches the regional airport where you'll switch to a much larger plane, customs declaration forms are distributed to the passengers.
The form asks a series of 26 yes-or-no questions marked a through z. All you need to do is identify the questions for which anyone in your group answers "yes". Since your group is just you, this doesn't take very long.
However, the person sitting next to you seems to be experiencing a language barrier and asks if you can help. For each of the people in their group, you write down the questions for which they answer "yes", one per line. For example:
abcx
abcy
abcz
In this group, there are 6 questions to which anyone answered "yes": a, b, c, x, y, and z. (Duplicate answers to the same question don't count extra; each question counts at most once.)
Another group asks for your help, then another, and eventually you've collected answers from every group on the plane (your puzzle input). Each group's answers are separated by a blank line, and within each group, each person's answers are on a single line. For example:
abc
a
b
c
ab
ac
a
a
a
a
b
This list represents answers from five groups:
The first group contains one person who answered "yes" to 3 questions: a, b, and c.
The second group contains three people; combined, they answered "yes" to 3 questions: a, b, and c.
The third group contains two people; combined, they answered "yes" to 3 questions: a, b, and c.
The fourth group contains four people; combined, they answered "yes" to only 1 question, a.
The last group contains one person who answered "yes" to only 1 question, b.
In this example, the sum of these counts is 3 + 3 + 3 + 1 + 1 = 11.
For each group, count the number of questions to which anyone answered "yes". What is the sum of those counts?
--- Part Two ---
As you finish the last group's customs declaration, you notice that you misread one word in the instructions:
You don't need to identify the questions to which anyone answered "yes"; you need to identify the questions to which everyone answered "yes"!
Using the same example as above:
abc
a
b
c
ab
ac
a
a
a
a
b
This list represents answers from five groups:
In the first group, everyone (all 1 person) answered "yes" to 3 questions: a, b, and c.
In the second group, there is no question to which everyone answered "yes".
In the third group, everyone answered yes to only 1 question, a. Since some people did not answer "yes" to b or c, they don't count.
In the fourth group, everyone answered yes to only 1 question, a.
In the fifth group, everyone (all 1 person) answered "yes" to 1 question, b.
In this example, the sum of these counts is 3 + 0 + 1 + 1 + 1 = 6.
For each group, count the number of questions to which everyone answered "yes". What is the sum of those counts?

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,81 @@
use crate::common::AdventOfCodeDay;
use std::collections::HashSet;
use regex::Regex;
#[derive(Debug)]
struct DeclForm {
answers: HashSet<char>,
}
#[derive(Debug)]
struct Group {
forms: Vec<DeclForm>,
}
#[derive(Debug)]
pub struct Day06 {
groups: Vec<Group>,
}
fn parse_form(line: &str) -> DeclForm {
DeclForm {
answers: line.chars().collect(),
}
}
fn parse_group(lines: &str) -> Group {
Group {
forms: lines.lines().map(parse_form).collect(),
}
}
impl DeclForm {
fn contains(&self, c: char) -> bool {
self.answers.contains(&c)
}
}
impl Group {
pub fn all_questions_any_yes(&self) -> Vec<char> {
self.forms.iter().map(|p| p.answers.iter().collect::<Vec<&char>>()).flatten().collect::<HashSet<&char>>().iter().map(|p| **p).collect()
}
pub fn all_questions_all_yes(&self) -> Vec<char> {
self.forms[0].answers.iter().filter(|p| self.forms.iter().all(|f| f.contains(**p))).map(|p| *p).collect()
}
}
impl Day06 {
pub fn new() -> Self {
let input_bytes = include_bytes!("../res/06_input.txt");
let input_str = String::from_utf8_lossy(input_bytes);
let rex_lines = Regex::new(r"(\r?\n){2}").unwrap();
let data = rex_lines.split(&input_str.to_owned())
.map(parse_group)
.collect::<Vec<Group>>();
Self {
groups: data,
}
}
}
impl AdventOfCodeDay for Day06 {
fn task_1(&self) -> String {
if is_verbose!() {
for r in &self.groups {
verboseln!("{} {:?}", r.all_questions_any_yes().len(), r.all_questions_any_yes())
}
}
return self.groups.iter().map(|p| p.all_questions_any_yes().len()).sum::<usize>().to_string();
}
fn task_2(&self) -> String {
return self.groups.iter().map(|p| p.all_questions_all_yes().len()).sum::<usize>().to_string();
}
}

View File

@ -0,0 +1,61 @@
--- Day 7: Handy Haversacks ---
You land at the regional airport in time for your next flight. In fact, it looks like you'll even have time to grab some food: all flights are currently delayed due to issues in luggage processing.
Due to recent aviation regulations, many rules (your puzzle input) are being enforced about bags and their contents; bags must be color-coded and must contain specific quantities of other color-coded bags. Apparently, nobody responsible for these regulations considered how long they would take to enforce!
For example, consider the following rules:
light red bags contain 1 bright white bag, 2 muted yellow bags.
dark orange bags contain 3 bright white bags, 4 muted yellow bags.
bright white bags contain 1 shiny gold bag.
muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.
shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags.
dark olive bags contain 3 faded blue bags, 4 dotted black bags.
vibrant plum bags contain 5 faded blue bags, 6 dotted black bags.
faded blue bags contain no other bags.
dotted black bags contain no other bags.
These rules specify the required contents for 9 bag types. In this example, every faded blue bag is empty, every vibrant plum bag contains 11 bags (5 faded blue and 6 dotted black), and so on.
You have a shiny gold bag. If you wanted to carry it in at least one other bag, how many different bag colors would be valid for the outermost bag? (In other words: how many colors can, eventually, contain at least one shiny gold bag?)
In the above rules, the following options would be available to you:
A bright white bag, which can hold your shiny gold bag directly.
A muted yellow bag, which can hold your shiny gold bag directly, plus some other bags.
A dark orange bag, which can hold bright white and muted yellow bags, either of which could then hold your shiny gold bag.
A light red bag, which can hold bright white and muted yellow bags, either of which could then hold your shiny gold bag.
So, in this example, the number of bag colors that can eventually contain at least one shiny gold bag is 4.
How many bag colors can eventually contain at least one shiny gold bag? (The list of rules is quite long; make sure you get all of it.)
--- Part Two ---
It's getting pretty expensive to fly these days - not because of ticket prices, but because of the ridiculous number of bags you need to buy!
Consider again your shiny gold bag and the rules from the above example:
faded blue bags contain 0 other bags.
dotted black bags contain 0 other bags.
vibrant plum bags contain 11 other bags: 5 faded blue bags and 6 dotted black bags.
dark olive bags contain 7 other bags: 3 faded blue bags and 4 dotted black bags.
So, a single shiny gold bag must contain 1 dark olive bag (and the 7 bags within it) plus 2 vibrant plum bags (and the 11 bags within each of those): 1 + 1*7 + 2 + 2*11 = 32 bags!
Of course, the actual rules have a small chance of going several levels deeper than this example; be sure to count all of the bags, even if the nesting becomes topologically impractical!
Here's another example:
shiny gold bags contain 2 dark red bags.
dark red bags contain 2 dark orange bags.
dark orange bags contain 2 dark yellow bags.
dark yellow bags contain 2 dark green bags.
dark green bags contain 2 dark blue bags.
dark blue bags contain 2 dark violet bags.
dark violet bags contain no other bags.
In this example, a single shiny gold bag must contain 126 other bags.
How many individual bags are required inside your single shiny gold bag?

View File

@ -0,0 +1,594 @@
pale chartreuse bags contain 3 faded orange bags.
drab gold bags contain 5 dark aqua bags.
mirrored magenta bags contain 3 dotted violet bags.
posh black bags contain 3 dark lavender bags, 3 mirrored coral bags, 1 dotted chartreuse bag.
striped yellow bags contain 5 pale red bags, 2 light lime bags, 5 clear indigo bags.
bright aqua bags contain 2 vibrant orange bags, 4 clear lavender bags, 1 pale gray bag.
dim silver bags contain 2 bright blue bags, 3 faded olive bags, 1 faded cyan bag.
light beige bags contain 2 bright silver bags, 4 vibrant crimson bags.
dull cyan bags contain 2 drab beige bags, 3 mirrored turquoise bags, 2 mirrored indigo bags.
dark black bags contain 5 dull turquoise bags, 4 faded cyan bags, 4 plaid coral bags.
dotted bronze bags contain 3 light blue bags, 2 dull teal bags, 3 dull chartreuse bags, 1 plaid green bag.
light purple bags contain 3 clear tan bags, 3 dull tan bags.
wavy orange bags contain 3 wavy tan bags, 3 faded green bags, 1 shiny brown bag, 2 dim tan bags.
drab beige bags contain 1 vibrant tan bag, 3 pale chartreuse bags, 3 plaid indigo bags, 2 mirrored chartreuse bags.
light coral bags contain 4 faded green bags, 1 pale crimson bag, 3 light bronze bags, 4 posh blue bags.
wavy coral bags contain 5 vibrant cyan bags, 5 light blue bags, 1 dotted turquoise bag.
dotted plum bags contain 1 clear orange bag, 2 drab black bags, 5 dull chartreuse bags, 5 plaid fuchsia bags.
striped olive bags contain 4 clear brown bags, 2 shiny beige bags.
vibrant maroon bags contain 2 dotted beige bags, 4 plaid olive bags, 5 dull black bags, 5 mirrored aqua bags.
drab purple bags contain 2 light green bags, 1 clear orange bag.
shiny violet bags contain 5 drab white bags, 5 dark aqua bags, 3 muted gray bags, 4 wavy orange bags.
muted maroon bags contain 2 plaid red bags, 3 bright silver bags, 5 posh yellow bags, 1 bright yellow bag.
clear black bags contain 1 bright plum bag, 1 faded brown bag, 4 wavy chartreuse bags.
dotted maroon bags contain 5 mirrored turquoise bags.
drab silver bags contain 2 vibrant violet bags, 2 muted orange bags, 4 dull purple bags.
faded purple bags contain 1 bright lime bag, 2 striped brown bags, 5 dull maroon bags, 2 shiny olive bags.
dull maroon bags contain 1 clear lime bag.
pale salmon bags contain 5 striped blue bags, 5 posh blue bags.
plaid orange bags contain 1 pale coral bag, 3 shiny orange bags.
drab black bags contain 5 vibrant orange bags, 1 dotted tomato bag, 2 dim red bags, 3 muted blue bags.
dotted teal bags contain 3 light fuchsia bags, 5 vibrant tan bags.
plaid tan bags contain 5 dark brown bags.
shiny coral bags contain 2 pale green bags, 1 muted lavender bag.
plaid plum bags contain 5 drab lavender bags, 2 shiny teal bags, 1 plaid tan bag.
dim olive bags contain 1 dark beige bag, 1 drab coral bag, 5 muted chartreuse bags, 4 bright teal bags.
dim bronze bags contain 1 striped turquoise bag, 4 muted turquoise bags.
muted red bags contain 5 dark gray bags, 4 muted gray bags, 5 muted blue bags.
shiny crimson bags contain 2 dark aqua bags, 4 faded fuchsia bags, 3 faded tomato bags.
vibrant teal bags contain 1 dark cyan bag, 4 wavy lime bags, 1 bright crimson bag.
dark yellow bags contain 2 striped coral bags, 1 drab tomato bag.
posh orange bags contain 3 wavy lime bags, 3 clear lavender bags, 5 bright indigo bags.
shiny orange bags contain 3 striped gold bags.
wavy magenta bags contain 2 vibrant crimson bags, 3 mirrored teal bags, 1 shiny lime bag.
clear indigo bags contain 2 pale green bags.
wavy red bags contain 5 plaid indigo bags.
wavy crimson bags contain 2 dim teal bags.
clear chartreuse bags contain 2 dull gray bags, 4 plaid lime bags, 3 striped cyan bags.
muted beige bags contain 2 drab white bags.
dim plum bags contain 3 vibrant green bags, 1 clear red bag.
dotted white bags contain 5 wavy magenta bags.
shiny chartreuse bags contain 2 striped tan bags, 2 dim maroon bags, 5 plaid bronze bags, 4 dark white bags.
pale green bags contain 5 drab crimson bags, 3 dull teal bags, 4 plaid red bags.
clear purple bags contain 3 light indigo bags.
striped brown bags contain 1 light yellow bag.
bright plum bags contain 4 faded olive bags, 2 dotted crimson bags, 3 pale green bags, 1 light yellow bag.
posh crimson bags contain 3 bright aqua bags.
dotted olive bags contain 4 striped tomato bags, 4 faded chartreuse bags, 2 dull bronze bags, 2 shiny olive bags.
striped magenta bags contain 2 posh indigo bags, 3 dotted tomato bags.
vibrant chartreuse bags contain 5 light crimson bags, 5 light bronze bags.
light cyan bags contain 1 faded red bag, 1 light silver bag.
faded teal bags contain 5 vibrant crimson bags, 3 drab gray bags, 5 striped turquoise bags, 1 pale plum bag.
mirrored aqua bags contain 1 vibrant white bag.
dull violet bags contain 2 dull orange bags, 1 light green bag.
clear orange bags contain 5 dark green bags.
muted silver bags contain 4 striped indigo bags, 3 mirrored lime bags, 1 bright lavender bag.
posh green bags contain 4 drab gold bags, 4 dim black bags, 4 faded gold bags.
dark bronze bags contain 1 faded plum bag, 5 mirrored teal bags, 5 striped indigo bags, 4 muted salmon bags.
shiny teal bags contain 4 plaid tomato bags, 3 clear brown bags, 4 dull silver bags, 2 wavy orange bags.
light gold bags contain 4 pale tan bags, 3 vibrant gray bags, 5 wavy tan bags, 5 dark violet bags.
bright indigo bags contain 5 shiny silver bags, 4 wavy indigo bags, 5 dark gold bags.
bright gray bags contain 5 shiny lime bags, 4 dull aqua bags.
dotted orange bags contain 1 dim red bag, 4 striped blue bags, 3 bright lavender bags.
dark indigo bags contain 4 drab indigo bags, 1 dotted turquoise bag.
pale lavender bags contain 2 vibrant green bags, 4 dim yellow bags, 1 mirrored yellow bag, 1 bright blue bag.
dotted silver bags contain 2 posh blue bags, 3 posh maroon bags.
plaid salmon bags contain 4 light yellow bags.
plaid magenta bags contain 3 striped gold bags, 2 mirrored black bags, 3 dull tan bags.
wavy blue bags contain 3 faded teal bags, 4 drab blue bags, 1 dotted gold bag.
muted black bags contain 1 drab teal bag, 3 muted lime bags.
clear violet bags contain 3 bright lavender bags, 1 vibrant plum bag, 3 wavy white bags, 1 shiny chartreuse bag.
bright teal bags contain 1 muted chartreuse bag, 4 dull indigo bags, 5 striped tomato bags, 1 drab white bag.
drab lime bags contain 3 posh maroon bags.
shiny tan bags contain 3 faded chartreuse bags, 3 wavy orange bags, 4 drab white bags, 4 light chartreuse bags.
light green bags contain 4 dotted tan bags, 1 dim salmon bag.
pale tan bags contain 3 posh green bags.
light gray bags contain 3 posh brown bags, 3 dim green bags, 3 mirrored tan bags, 1 mirrored yellow bag.
clear gray bags contain 4 dim brown bags.
drab magenta bags contain 4 dark aqua bags, 5 faded tomato bags.
pale violet bags contain 2 bright violet bags, 1 bright indigo bag, 2 muted salmon bags.
vibrant black bags contain 1 bright magenta bag, 4 vibrant crimson bags, 4 clear blue bags, 2 light chartreuse bags.
striped white bags contain 3 plaid yellow bags, 3 muted orange bags, 1 shiny gold bag, 5 light white bags.
wavy turquoise bags contain 5 wavy tan bags, 4 posh chartreuse bags, 5 posh red bags, 3 muted purple bags.
light white bags contain 3 shiny brown bags, 1 striped tan bag, 2 bright lime bags, 5 shiny yellow bags.
faded orange bags contain 3 dim silver bags, 5 wavy tomato bags, 4 wavy chartreuse bags, 1 shiny black bag.
mirrored fuchsia bags contain 2 plaid lime bags, 3 vibrant salmon bags.
dull aqua bags contain 5 clear brown bags, 3 dull indigo bags, 3 dull green bags, 2 muted gold bags.
dim gray bags contain 5 dark bronze bags, 4 dark silver bags, 3 wavy cyan bags.
dull tomato bags contain 4 drab tan bags, 3 striped brown bags.
dim gold bags contain 3 shiny tomato bags, 2 dim tomato bags.
striped beige bags contain 3 shiny violet bags, 3 striped aqua bags, 3 muted blue bags, 3 shiny gold bags.
mirrored coral bags contain 2 muted coral bags, 3 shiny teal bags.
vibrant white bags contain 1 clear brown bag, 3 drab gold bags, 2 wavy crimson bags, 5 light plum bags.
posh tan bags contain 3 dim salmon bags, 1 faded gold bag, 1 drab gray bag, 4 shiny coral bags.
drab tan bags contain 4 bright magenta bags, 3 dull green bags, 1 drab crimson bag, 4 dark green bags.
striped coral bags contain 2 drab tan bags, 4 wavy purple bags.
dark white bags contain 1 bright magenta bag.
striped red bags contain 3 plaid black bags.
drab coral bags contain 4 dotted violet bags, 2 pale magenta bags, 5 posh purple bags, 4 light lime bags.
pale yellow bags contain 5 plaid black bags, 3 shiny olive bags, 3 clear brown bags.
faded coral bags contain 2 pale salmon bags, 5 dim teal bags, 3 vibrant crimson bags.
faded black bags contain 2 wavy white bags, 5 faded brown bags, 4 drab beige bags.
dim salmon bags contain 4 vibrant white bags, 3 wavy salmon bags, 2 wavy lime bags, 2 bright purple bags.
dim black bags contain 3 dull tan bags, 2 striped beige bags, 2 plaid brown bags.
plaid cyan bags contain 2 muted coral bags, 3 dim red bags.
dotted gold bags contain 3 dotted orange bags, 3 striped coral bags, 1 clear magenta bag, 1 dotted crimson bag.
mirrored white bags contain 4 clear brown bags, 2 drab crimson bags, 4 shiny gold bags, 2 posh red bags.
vibrant olive bags contain 4 striped indigo bags, 5 dim salmon bags, 5 bright magenta bags.
dim teal bags contain 5 striped blue bags, 4 dull aqua bags, 5 dark cyan bags, 2 wavy magenta bags.
faded chartreuse bags contain no other bags.
clear yellow bags contain 5 wavy olive bags, 1 drab tomato bag, 2 plaid red bags.
mirrored bronze bags contain 1 vibrant beige bag, 5 clear cyan bags, 3 muted aqua bags, 5 striped turquoise bags.
vibrant tan bags contain 2 dull tomato bags, 5 dark aqua bags, 3 muted gray bags.
light olive bags contain 4 dark white bags, 2 dim teal bags.
light lavender bags contain 5 wavy indigo bags, 3 posh olive bags, 4 striped brown bags.
dotted gray bags contain 1 dim red bag, 5 light tomato bags, 2 dull gray bags, 4 light black bags.
plaid olive bags contain 5 wavy purple bags, 2 posh blue bags, 3 faded purple bags, 1 pale fuchsia bag.
muted salmon bags contain 5 shiny tan bags.
dark olive bags contain 4 mirrored black bags.
striped turquoise bags contain 4 pale olive bags, 2 pale tomato bags, 3 bright yellow bags.
plaid fuchsia bags contain 4 clear silver bags.
vibrant magenta bags contain 1 vibrant green bag, 2 muted silver bags, 4 light plum bags, 5 pale teal bags.
vibrant bronze bags contain 2 dull gold bags, 2 bright coral bags.
mirrored purple bags contain 1 drab tomato bag, 3 faded silver bags.
light lime bags contain 5 shiny violet bags, 4 wavy aqua bags.
pale gold bags contain 3 vibrant brown bags, 5 dim red bags.
dim orange bags contain 4 dark cyan bags, 3 light chartreuse bags, 3 wavy orange bags, 5 dark green bags.
clear fuchsia bags contain 4 posh blue bags, 4 mirrored lavender bags.
pale bronze bags contain 3 pale silver bags, 2 dotted tomato bags, 4 plaid gold bags.
dotted aqua bags contain 3 drab magenta bags, 3 dull green bags.
posh silver bags contain 5 striped lavender bags, 1 dotted maroon bag.
dim coral bags contain 1 wavy bronze bag, 5 striped gray bags, 2 light indigo bags, 2 dim orange bags.
bright green bags contain 5 drab plum bags.
striped teal bags contain 1 light fuchsia bag, 5 vibrant aqua bags, 3 mirrored white bags.
dim crimson bags contain 5 posh gray bags.
drab salmon bags contain 3 bright olive bags, 5 dim tan bags.
muted green bags contain 2 dark beige bags, 4 posh coral bags.
light tan bags contain 5 wavy white bags, 3 dim indigo bags, 3 bright green bags, 5 clear lavender bags.
posh teal bags contain 4 pale salmon bags.
muted cyan bags contain 4 posh yellow bags.
bright turquoise bags contain 3 posh indigo bags, 2 mirrored salmon bags, 2 dim magenta bags.
vibrant salmon bags contain 5 light tomato bags.
dark violet bags contain 3 light bronze bags, 5 dark gold bags, 1 striped magenta bag, 4 faded lavender bags.
faded maroon bags contain 5 plaid teal bags, 5 light turquoise bags, 5 posh white bags, 4 drab orange bags.
dotted magenta bags contain 4 shiny chartreuse bags, 5 drab turquoise bags, 4 bright tomato bags, 2 striped maroon bags.
dotted beige bags contain 5 clear white bags.
bright magenta bags contain no other bags.
dull red bags contain 2 muted lavender bags.
drab green bags contain 2 dotted cyan bags, 4 striped white bags, 3 muted magenta bags.
posh brown bags contain 5 muted lavender bags, 2 posh red bags, 5 drab magenta bags.
faded tan bags contain 3 bright purple bags, 5 plaid tomato bags, 3 dull teal bags.
faded brown bags contain 2 light silver bags, 5 mirrored tan bags, 2 clear tan bags, 2 drab gold bags.
striped black bags contain 3 vibrant yellow bags, 3 dull blue bags, 1 dull aqua bag, 5 dull teal bags.
faded white bags contain 1 muted maroon bag, 1 dark gray bag, 5 dark white bags.
drab aqua bags contain 3 muted white bags, 4 dark cyan bags, 5 pale tomato bags.
dull teal bags contain 2 plaid red bags, 5 mirrored teal bags.
vibrant plum bags contain 2 dim salmon bags, 3 light purple bags, 2 muted gray bags.
plaid crimson bags contain 5 shiny blue bags, 1 dull bronze bag.
wavy violet bags contain 3 dotted tomato bags, 3 striped brown bags.
clear cyan bags contain 1 drab crimson bag, 2 shiny lime bags.
shiny green bags contain 5 muted gray bags.
posh purple bags contain 2 vibrant white bags.
plaid lime bags contain 2 clear crimson bags, 3 bright magenta bags, 5 shiny silver bags, 1 posh blue bag.
dotted violet bags contain 1 dark teal bag, 5 faded crimson bags.
pale maroon bags contain 5 mirrored lime bags, 5 clear olive bags, 5 shiny orange bags, 4 mirrored fuchsia bags.
wavy indigo bags contain 5 plaid lime bags, 5 plaid fuchsia bags, 2 faded chartreuse bags, 4 dotted tomato bags.
faded silver bags contain 5 striped lavender bags, 4 muted lavender bags, 5 plaid brown bags.
drab violet bags contain 1 posh white bag.
bright white bags contain 3 light cyan bags, 1 dark indigo bag, 2 pale turquoise bags, 1 pale brown bag.
faded olive bags contain 2 clear lime bags, 4 muted chartreuse bags.
muted violet bags contain 1 clear lavender bag, 1 dark green bag, 3 dark cyan bags.
shiny gray bags contain 2 dull tan bags, 1 shiny olive bag.
plaid blue bags contain 3 dark aqua bags, 4 muted silver bags, 5 pale beige bags, 1 drab chartreuse bag.
posh fuchsia bags contain 5 posh red bags, 2 muted gray bags.
faded blue bags contain 1 plaid fuchsia bag, 1 mirrored turquoise bag, 2 plaid indigo bags, 1 dark aqua bag.
bright brown bags contain 4 drab violet bags, 5 shiny lime bags, 2 bright beige bags.
mirrored teal bags contain 5 dark gray bags.
bright violet bags contain 2 dotted crimson bags, 3 striped coral bags, 5 shiny maroon bags, 3 dull lavender bags.
striped plum bags contain 2 dim orange bags, 4 clear blue bags, 3 shiny violet bags.
plaid green bags contain 2 bright teal bags, 5 striped lime bags.
muted fuchsia bags contain 4 clear gold bags, 2 vibrant plum bags, 5 bright black bags.
bright purple bags contain 3 vibrant crimson bags, 1 dotted maroon bag, 4 dark gold bags.
faded cyan bags contain 4 dim teal bags.
wavy fuchsia bags contain 5 dull yellow bags, 2 light yellow bags, 5 bright black bags.
wavy salmon bags contain 1 shiny black bag, 3 bright teal bags, 5 clear yellow bags, 1 dull maroon bag.
dark fuchsia bags contain 1 muted violet bag, 3 light cyan bags.
clear salmon bags contain 4 light beige bags, 4 vibrant green bags, 3 pale yellow bags, 1 muted turquoise bag.
pale purple bags contain 1 bright blue bag, 5 pale bronze bags.
posh salmon bags contain 3 faded cyan bags, 4 posh maroon bags, 1 plaid green bag, 2 shiny silver bags.
bright blue bags contain 3 vibrant green bags, 2 drab gray bags.
shiny brown bags contain no other bags.
dark gold bags contain 5 vibrant aqua bags, 2 posh yellow bags.
mirrored violet bags contain 2 pale silver bags, 1 posh fuchsia bag.
bright fuchsia bags contain 3 muted brown bags, 3 plaid purple bags, 2 faded coral bags, 3 mirrored turquoise bags.
dim beige bags contain 2 dull lime bags, 3 dim gold bags, 3 plaid fuchsia bags, 1 posh yellow bag.
shiny white bags contain 1 pale fuchsia bag, 3 shiny beige bags, 3 posh aqua bags, 5 clear tan bags.
posh red bags contain 3 bright magenta bags, 2 dark aqua bags, 4 dark cyan bags.
vibrant fuchsia bags contain 3 striped indigo bags.
faded tomato bags contain 3 wavy olive bags, 5 shiny brown bags, 5 shiny tan bags.
dull purple bags contain 4 plaid teal bags, 4 dull indigo bags, 3 dull bronze bags, 4 faded tan bags.
shiny magenta bags contain 4 pale tomato bags, 4 shiny brown bags.
wavy tan bags contain no other bags.
dull salmon bags contain 3 faded crimson bags, 5 shiny fuchsia bags, 4 dotted silver bags.
pale magenta bags contain 2 faded chartreuse bags.
vibrant purple bags contain 3 muted orange bags, 5 dotted brown bags.
shiny turquoise bags contain 4 dotted turquoise bags, 1 dotted purple bag, 4 dim black bags.
shiny black bags contain 2 clear brown bags, 4 vibrant yellow bags, 1 vibrant aqua bag, 5 mirrored teal bags.
shiny cyan bags contain 3 dotted coral bags.
dim magenta bags contain 3 bright purple bags, 2 wavy white bags, 2 shiny fuchsia bags, 2 shiny yellow bags.
pale beige bags contain 3 dim orange bags, 5 wavy purple bags.
wavy bronze bags contain 5 posh yellow bags, 1 pale green bag, 5 dark cyan bags.
dull blue bags contain 4 wavy tan bags.
striped lime bags contain 5 striped crimson bags, 1 bright plum bag, 5 plaid yellow bags.
faded magenta bags contain 1 plaid green bag, 2 vibrant silver bags, 1 dim turquoise bag.
muted white bags contain 5 bright lime bags, 4 light fuchsia bags, 4 light violet bags, 4 dark aqua bags.
pale fuchsia bags contain 1 striped tomato bag, 1 drab crimson bag, 4 shiny yellow bags.
posh cyan bags contain 5 dark maroon bags.
dim indigo bags contain 3 dark gold bags, 5 bright maroon bags.
faded fuchsia bags contain 4 plaid tomato bags, 2 mirrored red bags.
shiny red bags contain 5 dull olive bags, 1 posh tan bag, 4 bright green bags.
posh maroon bags contain 4 clear blue bags, 5 muted chartreuse bags.
shiny indigo bags contain 4 wavy orange bags.
dim violet bags contain 1 dotted chartreuse bag, 2 mirrored lime bags, 1 drab chartreuse bag.
dim lime bags contain 4 posh fuchsia bags, 5 dull blue bags, 2 dull silver bags, 2 bright lime bags.
muted blue bags contain 5 mirrored lime bags.
dotted fuchsia bags contain 2 wavy magenta bags.
bright beige bags contain 1 mirrored maroon bag.
light bronze bags contain 1 posh maroon bag, 1 dotted maroon bag, 3 clear silver bags.
posh olive bags contain 2 wavy orange bags.
shiny salmon bags contain 2 light teal bags, 5 dark violet bags.
plaid tomato bags contain 5 shiny tan bags, 5 drab white bags.
striped blue bags contain 3 dark cyan bags, 2 pale magenta bags, 3 striped indigo bags.
bright lime bags contain 4 dark cyan bags.
vibrant crimson bags contain no other bags.
mirrored salmon bags contain 1 pale gray bag, 5 dark plum bags.
dim brown bags contain 4 faded fuchsia bags, 4 dull indigo bags.
clear aqua bags contain 1 mirrored black bag, 1 light bronze bag, 2 mirrored maroon bags, 4 mirrored white bags.
clear red bags contain 1 bright lavender bag.
dark maroon bags contain 1 light chartreuse bag.
bright silver bags contain 1 wavy tan bag, 3 plaid black bags, 2 dark gray bags.
faded lime bags contain 1 pale silver bag, 3 drab teal bags.
plaid lavender bags contain 1 plaid fuchsia bag.
faded yellow bags contain 4 dull blue bags.
dark blue bags contain 1 dotted red bag, 1 bright indigo bag, 2 posh tan bags.
light aqua bags contain 3 shiny olive bags, 2 dotted brown bags, 1 dull green bag.
striped gray bags contain 5 faded crimson bags, 4 clear white bags.
dark chartreuse bags contain 5 faded lime bags.
plaid chartreuse bags contain 3 shiny teal bags.
wavy gray bags contain 5 plaid lime bags, 5 wavy olive bags, 5 dim orange bags.
dull yellow bags contain 5 faded chartreuse bags, 2 clear crimson bags, 4 faded fuchsia bags.
muted magenta bags contain 4 mirrored teal bags, 3 drab silver bags, 3 drab lavender bags, 2 mirrored orange bags.
pale turquoise bags contain 3 bright lavender bags, 1 shiny tan bag, 4 posh teal bags, 2 posh cyan bags.
light turquoise bags contain 1 plaid gold bag.
pale brown bags contain 4 muted orange bags.
posh chartreuse bags contain 1 plaid lime bag, 4 shiny gray bags, 3 pale bronze bags, 3 vibrant bronze bags.
posh gray bags contain 3 dim salmon bags.
wavy tomato bags contain 3 vibrant salmon bags, 5 vibrant yellow bags, 2 vibrant green bags, 3 striped brown bags.
dotted indigo bags contain 5 shiny fuchsia bags, 1 posh lime bag, 1 muted beige bag.
pale lime bags contain 4 wavy fuchsia bags.
dull lime bags contain 2 light bronze bags, 3 light beige bags, 4 wavy tomato bags.
shiny olive bags contain 5 dull aqua bags, 5 muted gray bags, 5 posh olive bags.
muted teal bags contain 3 dull teal bags, 5 bright magenta bags.
dull white bags contain 5 striped yellow bags, 1 dim aqua bag.
shiny silver bags contain 4 shiny olive bags, 4 wavy orange bags, 2 mirrored red bags.
dim turquoise bags contain 4 drab gold bags.
clear brown bags contain no other bags.
mirrored olive bags contain 4 dim aqua bags.
striped purple bags contain 5 wavy tan bags.
faded violet bags contain 4 dull tan bags.
faded salmon bags contain 5 striped fuchsia bags, 1 muted lime bag.
mirrored yellow bags contain 2 dark orange bags.
wavy gold bags contain 2 muted salmon bags.
pale tomato bags contain 1 vibrant crimson bag, 5 light black bags, 3 dotted brown bags.
clear bronze bags contain 1 mirrored black bag, 3 wavy red bags, 4 faded white bags, 5 vibrant bronze bags.
mirrored silver bags contain 3 wavy salmon bags, 4 drab brown bags, 1 striped green bag, 4 mirrored lime bags.
dull bronze bags contain 1 dim orange bag, 1 light maroon bag, 5 wavy bronze bags, 2 posh blue bags.
posh lime bags contain 2 dark bronze bags.
light teal bags contain 4 dotted cyan bags, 4 dark crimson bags, 4 striped orange bags, 4 pale black bags.
dark lime bags contain 2 posh red bags.
vibrant yellow bags contain 4 dull indigo bags.
vibrant green bags contain 3 bright silver bags, 1 striped fuchsia bag, 5 dim tan bags.
mirrored lavender bags contain 1 dull maroon bag, 1 bright silver bag, 4 drab teal bags, 2 posh blue bags.
bright salmon bags contain 1 dark aqua bag.
clear green bags contain 3 vibrant blue bags, 4 dotted salmon bags, 5 striped violet bags.
clear lavender bags contain 2 faded silver bags, 5 dim tan bags, 4 drab white bags.
dim chartreuse bags contain 4 dark gray bags.
posh blue bags contain 1 clear silver bag, 5 clear crimson bags, 2 light beige bags.
dim maroon bags contain 5 dotted fuchsia bags.
muted crimson bags contain 1 dark cyan bag.
drab cyan bags contain 4 wavy brown bags.
faded lavender bags contain 3 posh coral bags, 2 dotted violet bags, 3 pale gray bags, 4 plaid beige bags.
dim aqua bags contain 5 dim tan bags, 3 posh olive bags.
posh magenta bags contain 3 bright orange bags, 4 bright salmon bags, 1 vibrant beige bag.
plaid purple bags contain 2 mirrored gray bags, 5 mirrored tan bags.
muted tomato bags contain 1 dotted tomato bag, 4 bright magenta bags, 1 striped turquoise bag.
dull black bags contain 5 wavy coral bags, 4 wavy beige bags, 1 drab lavender bag, 4 dark beige bags.
mirrored maroon bags contain 4 shiny teal bags, 3 light blue bags, 1 light aqua bag, 3 faded tan bags.
posh aqua bags contain 3 dotted orange bags, 4 wavy crimson bags, 5 pale magenta bags, 5 posh fuchsia bags.
muted lavender bags contain 4 faded green bags, 1 dark aqua bag, 4 posh maroon bags, 2 dark white bags.
posh tomato bags contain 2 posh black bags.
dull gold bags contain 1 faded turquoise bag, 4 drab brown bags, 4 shiny turquoise bags.
plaid violet bags contain 3 bright plum bags, 4 clear olive bags, 4 drab bronze bags.
pale silver bags contain 5 wavy olive bags, 5 dull indigo bags, 1 light plum bag, 4 dark gray bags.
dull brown bags contain 1 dim orange bag.
shiny beige bags contain 5 faded purple bags.
striped cyan bags contain 1 muted black bag, 4 dull aqua bags.
dotted green bags contain 4 wavy white bags, 2 shiny violet bags, 4 muted chartreuse bags.
dotted chartreuse bags contain 5 dull bronze bags.
plaid aqua bags contain 2 shiny indigo bags, 5 muted lavender bags, 3 light blue bags, 4 vibrant salmon bags.
mirrored beige bags contain 2 light white bags, 1 wavy coral bag.
light orange bags contain 3 drab salmon bags, 3 clear lavender bags, 4 dark beige bags, 1 clear purple bag.
dark tan bags contain 1 posh olive bag.
muted lime bags contain 3 faded chartreuse bags, 4 muted silver bags, 3 vibrant salmon bags, 1 mirrored blue bag.
posh gold bags contain 5 vibrant magenta bags.
faded beige bags contain 5 faded black bags, 4 clear coral bags, 4 bright olive bags, 1 faded lime bag.
vibrant turquoise bags contain 3 clear cyan bags, 1 dotted fuchsia bag.
faded bronze bags contain 4 posh teal bags, 3 plaid tomato bags, 4 dark bronze bags.
shiny blue bags contain 3 drab indigo bags, 1 dark lime bag.
plaid yellow bags contain 1 plaid lime bag.
shiny aqua bags contain 1 vibrant tomato bag, 4 dark aqua bags, 5 vibrant cyan bags, 4 striped coral bags.
mirrored indigo bags contain 5 vibrant turquoise bags.
wavy cyan bags contain 1 light yellow bag, 4 faded fuchsia bags, 2 clear silver bags, 3 vibrant fuchsia bags.
dull gray bags contain 2 mirrored turquoise bags, 2 posh yellow bags.
dim yellow bags contain 4 light silver bags.
striped crimson bags contain 3 dim salmon bags.
pale coral bags contain 4 vibrant violet bags, 4 posh teal bags, 3 drab aqua bags.
faded aqua bags contain 3 bright magenta bags, 4 muted aqua bags, 3 light salmon bags, 3 light black bags.
drab orange bags contain 2 drab purple bags, 5 light black bags, 5 dull blue bags, 1 bright purple bag.
drab bronze bags contain 3 clear violet bags, 3 drab crimson bags, 3 dotted yellow bags, 5 muted salmon bags.
drab blue bags contain 3 faded violet bags, 4 bright lavender bags, 2 vibrant cyan bags.
pale olive bags contain 4 shiny yellow bags, 1 dull yellow bag, 2 striped tomato bags.
light salmon bags contain 2 shiny gold bags, 2 light silver bags, 4 wavy magenta bags.
wavy brown bags contain 4 dim indigo bags, 3 pale olive bags, 3 mirrored orange bags.
vibrant beige bags contain 5 light lavender bags, 3 wavy bronze bags, 1 plaid yellow bag, 2 dark aqua bags.
clear tan bags contain 3 posh fuchsia bags, 1 pale fuchsia bag.
dotted turquoise bags contain 3 light maroon bags.
dull magenta bags contain 2 dark tomato bags.
dull chartreuse bags contain 5 light chartreuse bags, 2 dotted chartreuse bags.
bright red bags contain 1 dotted brown bag, 1 posh yellow bag, 5 light white bags, 4 shiny maroon bags.
bright bronze bags contain 4 bright salmon bags, 4 plaid bronze bags, 2 dim chartreuse bags.
vibrant gold bags contain 2 faded purple bags, 3 mirrored maroon bags, 3 dull gray bags.
vibrant cyan bags contain 2 faded olive bags, 4 dull silver bags, 3 mirrored lime bags, 4 faded red bags.
mirrored plum bags contain 3 dark orange bags, 5 plaid lavender bags, 5 dim red bags.
clear white bags contain 3 striped beige bags.
drab fuchsia bags contain 4 striped magenta bags, 2 vibrant violet bags, 4 pale aqua bags.
dark purple bags contain 5 striped violet bags.
mirrored tomato bags contain 5 drab olive bags.
dull olive bags contain 4 wavy purple bags.
wavy maroon bags contain 4 pale gold bags.
vibrant blue bags contain 1 faded lime bag, 4 light plum bags.
clear teal bags contain 4 dark green bags, 5 clear brown bags.
clear beige bags contain 4 shiny cyan bags, 3 striped salmon bags.
drab indigo bags contain 5 drab tan bags, 4 shiny black bags, 4 striped brown bags.
muted bronze bags contain 4 dark chartreuse bags, 5 pale crimson bags, 4 vibrant gold bags.
muted olive bags contain 3 wavy olive bags, 5 dark bronze bags, 4 bright aqua bags, 1 dotted yellow bag.
dull beige bags contain 1 dull purple bag.
dotted yellow bags contain 3 dim plum bags, 2 plaid lavender bags.
wavy lavender bags contain 1 vibrant violet bag, 4 posh blue bags, 1 posh plum bag.
dim fuchsia bags contain 5 pale yellow bags, 4 faded plum bags, 5 bright lime bags.
plaid gray bags contain 5 dark violet bags, 2 dotted crimson bags, 4 dull fuchsia bags, 1 drab magenta bag.
vibrant coral bags contain 2 shiny cyan bags, 4 pale magenta bags, 5 striped coral bags, 3 pale teal bags.
drab yellow bags contain 4 clear orange bags, 5 faded fuchsia bags.
dark red bags contain 5 mirrored maroon bags, 3 clear blue bags, 2 striped crimson bags, 2 dotted violet bags.
mirrored cyan bags contain 5 dotted maroon bags, 5 posh turquoise bags, 2 faded gray bags.
muted yellow bags contain 1 light cyan bag, 2 dim orange bags, 5 dull olive bags, 5 light green bags.
wavy aqua bags contain 2 muted cyan bags, 4 mirrored green bags, 5 muted tomato bags.
vibrant lavender bags contain 1 dotted gold bag, 1 light chartreuse bag, 3 mirrored gray bags.
bright black bags contain 1 striped lavender bag, 2 shiny tan bags, 4 bright lime bags.
wavy chartreuse bags contain 4 mirrored red bags.
dull turquoise bags contain 5 faded red bags, 1 light brown bag, 1 clear magenta bag.
dull silver bags contain 4 dark gray bags, 1 faded green bag.
pale black bags contain 1 plaid indigo bag, 3 light tomato bags, 4 drab blue bags.
clear tomato bags contain 1 dim tan bag, 1 clear lavender bag, 1 striped fuchsia bag, 5 clear orange bags.
dark cyan bags contain 4 shiny brown bags.
pale blue bags contain 1 clear green bag.
dotted lavender bags contain 3 dotted maroon bags, 5 wavy salmon bags, 2 pale tomato bags, 5 mirrored blue bags.
pale orange bags contain 4 pale silver bags, 4 striped lime bags.
drab chartreuse bags contain 2 dark gold bags, 5 clear crimson bags, 3 dull green bags.
striped violet bags contain 4 plaid lime bags.
muted gold bags contain no other bags.
mirrored gray bags contain 1 light green bag, 1 striped beige bag.
bright lavender bags contain 2 clear blue bags.
striped gold bags contain 3 muted turquoise bags.
dim white bags contain 1 vibrant lavender bag.
wavy beige bags contain 4 light chartreuse bags, 5 dark lime bags.
dim tomato bags contain 2 wavy aqua bags, 3 faded salmon bags.
light blue bags contain 2 wavy purple bags, 1 dull olive bag.
drab brown bags contain 5 drab magenta bags, 2 muted teal bags.
wavy olive bags contain 3 pale green bags, 5 muted gray bags.
bright chartreuse bags contain 1 clear yellow bag, 2 dotted olive bags, 1 posh olive bag.
posh violet bags contain 5 muted tomato bags, 5 light aqua bags, 3 pale cyan bags, 2 mirrored chartreuse bags.
dotted blue bags contain 4 plaid yellow bags, 3 vibrant bronze bags, 2 dull maroon bags, 3 shiny silver bags.
pale white bags contain 3 plaid brown bags, 2 mirrored aqua bags, 2 dim turquoise bags.
dull lavender bags contain 1 light blue bag, 5 drab tan bags, 3 light yellow bags.
pale cyan bags contain 5 pale green bags, 5 dull tomato bags, 4 vibrant orange bags.
mirrored tan bags contain 1 mirrored blue bag, 5 wavy purple bags.
plaid maroon bags contain 5 bright orange bags, 1 dull fuchsia bag, 5 dull indigo bags, 4 light white bags.
drab plum bags contain 5 pale silver bags, 1 clear yellow bag, 5 dotted fuchsia bags.
muted aqua bags contain 2 posh blue bags, 3 muted chartreuse bags, 1 drab tan bag, 3 dotted brown bags.
striped lavender bags contain 3 posh yellow bags, 5 drab white bags, 1 muted gold bag.
posh bronze bags contain 1 mirrored lime bag, 2 muted cyan bags, 3 muted aqua bags.
dotted brown bags contain 1 dotted orange bag, 3 striped blue bags, 3 dotted teal bags, 4 wavy magenta bags.
light chartreuse bags contain no other bags.
dotted purple bags contain 3 muted lavender bags.
vibrant violet bags contain 3 light violet bags.
dark green bags contain 3 mirrored teal bags, 3 bright magenta bags, 2 light chartreuse bags.
faded indigo bags contain 3 faded fuchsia bags, 4 dim magenta bags.
bright cyan bags contain 4 vibrant olive bags, 4 faded olive bags, 1 posh teal bag.
drab white bags contain no other bags.
clear magenta bags contain 1 dotted maroon bag, 2 wavy olive bags, 5 drab white bags.
light yellow bags contain 4 shiny brown bags, 4 light fuchsia bags, 1 mirrored turquoise bag, 2 drab teal bags.
dark beige bags contain 4 dim crimson bags, 5 mirrored turquoise bags, 3 posh yellow bags, 1 dull chartreuse bag.
dark teal bags contain 5 mirrored tan bags, 5 vibrant tomato bags, 2 bright violet bags, 2 striped silver bags.
pale plum bags contain 2 drab white bags.
light red bags contain 2 striped blue bags, 2 bright violet bags, 4 clear orange bags.
plaid brown bags contain 4 light maroon bags, 5 dull bronze bags, 3 plaid black bags.
plaid bronze bags contain 4 muted salmon bags, 1 light violet bag, 4 plaid black bags.
bright orange bags contain 5 light green bags, 2 wavy plum bags, 5 faded coral bags.
plaid black bags contain 5 dark green bags, 3 dull indigo bags, 3 dim tan bags.
shiny lime bags contain 5 bright lime bags.
shiny fuchsia bags contain 2 dotted tan bags, 3 drab white bags.
bright gold bags contain 1 drab magenta bag, 4 pale salmon bags.
shiny gold bags contain 1 drab white bag, 2 wavy purple bags, 2 muted gray bags, 5 clear crimson bags.
plaid beige bags contain 3 dotted yellow bags.
vibrant silver bags contain 2 muted gold bags, 5 dim teal bags, 4 mirrored white bags, 2 clear blue bags.
dotted black bags contain 1 wavy crimson bag, 5 vibrant purple bags.
mirrored brown bags contain 4 drab aqua bags, 4 dark teal bags, 5 striped plum bags.
dotted red bags contain 5 bright lime bags, 5 vibrant magenta bags, 1 striped turquoise bag.
bright tan bags contain 2 dull yellow bags, 2 posh tomato bags.
striped aqua bags contain 3 clear blue bags, 1 dark maroon bag.
dotted coral bags contain 1 vibrant silver bag, 3 dark green bags, 4 posh gray bags, 2 light red bags.
mirrored lime bags contain 3 mirrored white bags, 1 plaid tomato bag, 2 shiny yellow bags, 2 vibrant black bags.
dark gray bags contain 3 faded green bags, 3 vibrant crimson bags.
wavy lime bags contain 5 wavy salmon bags, 2 faded tomato bags.
dotted lime bags contain 5 drab brown bags, 1 faded salmon bag, 2 wavy violet bags, 4 posh olive bags.
light black bags contain 5 striped indigo bags.
shiny yellow bags contain 5 wavy tan bags, 5 drab white bags, 4 posh olive bags.
bright yellow bags contain 3 posh red bags, 2 plaid black bags.
dull tan bags contain 4 clear brown bags, 3 wavy tan bags.
shiny tomato bags contain 2 shiny orange bags, 4 light lavender bags, 1 plaid lavender bag.
vibrant aqua bags contain 5 pale green bags, 3 drab crimson bags, 2 shiny brown bags.
striped salmon bags contain 2 posh orange bags.
light silver bags contain 1 shiny yellow bag, 4 mirrored turquoise bags, 1 bright coral bag, 2 posh maroon bags.
striped fuchsia bags contain 3 drab white bags, 3 faded chartreuse bags, 4 vibrant black bags, 3 wavy tan bags.
bright tomato bags contain 3 light beige bags, 4 drab teal bags.
shiny plum bags contain 4 clear bronze bags.
vibrant red bags contain 3 bright magenta bags.
mirrored orange bags contain 2 mirrored white bags, 3 dotted brown bags, 3 bright silver bags, 4 pale teal bags.
dull indigo bags contain no other bags.
wavy yellow bags contain 4 wavy white bags.
muted turquoise bags contain 2 posh red bags, 3 dark green bags, 4 mirrored white bags.
striped indigo bags contain 3 dark cyan bags, 5 clear blue bags, 2 faded chartreuse bags.
mirrored green bags contain 4 mirrored chartreuse bags, 3 striped red bags.
plaid white bags contain 1 vibrant salmon bag, 1 dark yellow bag, 2 vibrant violet bags.
dark plum bags contain 4 muted coral bags, 4 mirrored blue bags, 1 vibrant aqua bag.
drab turquoise bags contain 1 dotted purple bag, 1 light plum bag.
light maroon bags contain 2 wavy purple bags, 2 dim orange bags, 1 mirrored white bag, 3 striped tomato bags.
shiny maroon bags contain 2 bright blue bags.
drab crimson bags contain 1 bright magenta bag, 3 drab white bags.
dark aqua bags contain 3 shiny brown bags, 5 dark gray bags.
posh turquoise bags contain 2 shiny gray bags.
muted indigo bags contain 4 wavy purple bags.
dotted salmon bags contain 1 vibrant violet bag, 1 mirrored lavender bag.
plaid indigo bags contain 2 wavy indigo bags, 2 dark white bags, 3 wavy tan bags, 3 vibrant crimson bags.
muted brown bags contain 3 posh yellow bags, 4 shiny lime bags, 5 striped lavender bags.
vibrant gray bags contain 1 mirrored silver bag, 2 light coral bags, 1 faded gold bag, 1 dull fuchsia bag.
drab tomato bags contain 1 wavy tan bag, 1 shiny tan bag, 1 clear crimson bag.
wavy white bags contain 3 muted blue bags, 2 wavy plum bags, 4 dim silver bags, 3 mirrored tan bags.
shiny lavender bags contain 1 posh coral bag, 2 dotted crimson bags, 2 plaid red bags, 1 striped silver bag.
dull fuchsia bags contain 4 light bronze bags, 3 clear gray bags, 1 bright coral bag.
drab teal bags contain 5 muted chartreuse bags, 4 dull silver bags, 5 vibrant black bags, 3 shiny olive bags.
clear crimson bags contain 4 clear brown bags, 3 drab crimson bags, 4 clear blue bags, 1 vibrant black bag.
posh beige bags contain 5 plaid teal bags.
clear silver bags contain 3 plaid tomato bags, 3 bright silver bags, 1 mirrored white bag.
mirrored red bags contain 2 striped indigo bags, 2 drab teal bags.
posh indigo bags contain 3 faded red bags.
dark silver bags contain 5 wavy tan bags, 2 dotted maroon bags.
drab red bags contain 2 dotted chartreuse bags, 3 mirrored tan bags, 5 pale plum bags.
plaid turquoise bags contain 4 dim silver bags, 1 bright orange bag.
dim blue bags contain 1 muted lavender bag, 1 wavy plum bag.
plaid coral bags contain 2 shiny coral bags.
striped silver bags contain 2 muted brown bags.
vibrant tomato bags contain 1 muted black bag.
dark turquoise bags contain 2 light silver bags.
vibrant lime bags contain 2 light beige bags, 3 bright green bags, 5 faded purple bags.
mirrored chartreuse bags contain 2 wavy tan bags, 5 dim tan bags.
light plum bags contain 5 faded green bags.
dim tan bags contain 1 faded chartreuse bag, 2 clear brown bags, 1 faded green bag, 2 muted gold bags.
shiny bronze bags contain 5 drab aqua bags.
dotted tomato bags contain 4 wavy magenta bags.
mirrored crimson bags contain 1 dim bronze bag.
light crimson bags contain 3 posh red bags.
dull coral bags contain 3 striped crimson bags, 4 mirrored salmon bags.
drab lavender bags contain 3 dim salmon bags.
dotted crimson bags contain 3 dark cyan bags, 4 posh blue bags, 2 light fuchsia bags.
dotted tan bags contain 2 posh fuchsia bags, 4 dim black bags.
dark coral bags contain 2 mirrored green bags, 4 shiny white bags, 2 shiny tomato bags.
striped orange bags contain 1 muted violet bag, 5 pale cyan bags, 2 drab tomato bags, 3 faded violet bags.
pale aqua bags contain 3 shiny fuchsia bags, 4 shiny violet bags.
wavy plum bags contain 4 light chartreuse bags, 5 vibrant tan bags, 4 muted lime bags.
mirrored turquoise bags contain 4 shiny brown bags, 4 drab tan bags.
dark magenta bags contain 5 faded violet bags, 2 posh lavender bags.
striped bronze bags contain 3 light silver bags, 3 mirrored brown bags, 3 posh purple bags, 4 drab turquoise bags.
faded red bags contain 2 dark cyan bags, 2 striped tan bags, 4 mirrored violet bags.
faded turquoise bags contain 1 striped crimson bag.
clear gold bags contain 3 clear crimson bags, 5 faded green bags, 4 dim tan bags.
clear coral bags contain 3 striped salmon bags.
faded gray bags contain 4 light salmon bags, 5 clear orange bags, 1 dim yellow bag, 2 wavy green bags.
posh lavender bags contain 2 clear silver bags, 1 wavy indigo bag, 4 faded brown bags, 2 light white bags.
pale red bags contain 3 clear orange bags.
dim lavender bags contain 1 posh silver bag.
vibrant orange bags contain 2 pale magenta bags.
pale gray bags contain 2 dark aqua bags, 2 mirrored turquoise bags, 2 striped fuchsia bags, 5 wavy purple bags.
pale teal bags contain 2 striped brown bags, 4 shiny brown bags.
muted tan bags contain 3 dotted purple bags, 5 clear blue bags, 5 bright plum bags.
dotted cyan bags contain 1 mirrored chartreuse bag, 2 dotted gray bags, 5 pale tomato bags, 1 mirrored lime bag.
dark brown bags contain 4 vibrant orange bags, 3 faded olive bags, 5 posh blue bags.
dull orange bags contain 5 posh coral bags, 5 vibrant green bags, 3 dull maroon bags, 1 striped tomato bag.
plaid silver bags contain 1 muted turquoise bag, 1 wavy green bag.
dull crimson bags contain 4 faded red bags, 1 dotted plum bag, 2 plaid orange bags, 1 posh yellow bag.
muted orange bags contain 4 pale yellow bags, 1 dark maroon bag, 5 mirrored white bags.
wavy black bags contain 4 mirrored blue bags, 4 drab chartreuse bags, 4 dull aqua bags.
light magenta bags contain 2 muted coral bags, 3 wavy violet bags.
faded crimson bags contain 2 dim orange bags, 3 vibrant crimson bags, 4 clear lime bags, 5 wavy olive bags.
light fuchsia bags contain 2 dull green bags, 4 dull indigo bags.
mirrored black bags contain 1 wavy magenta bag, 3 light bronze bags, 3 dull teal bags.
striped tan bags contain 5 vibrant yellow bags, 3 dull silver bags, 5 mirrored teal bags.
dark crimson bags contain 1 mirrored teal bag, 2 muted maroon bags, 5 dull green bags.
light indigo bags contain 5 dotted purple bags.
light brown bags contain 4 dark fuchsia bags, 1 bright olive bag.
wavy purple bags contain 3 vibrant black bags, 5 dull teal bags, 1 bright magenta bag.
posh white bags contain 5 muted purple bags, 5 drab silver bags.
faded gold bags contain 2 dull teal bags, 5 muted orange bags, 3 mirrored lavender bags, 2 clear orange bags.
clear maroon bags contain 2 dim crimson bags, 3 dim maroon bags, 5 wavy salmon bags, 5 mirrored black bags.
bright maroon bags contain 5 dark bronze bags, 4 pale coral bags.
clear turquoise bags contain 1 muted gold bag.
bright coral bags contain 3 striped lavender bags, 4 drab tomato bags, 1 bright lime bag.
wavy teal bags contain 3 faded tan bags.
mirrored gold bags contain 4 faded violet bags.
dark orange bags contain 5 muted purple bags, 1 drab turquoise bag, 5 pale beige bags.
dull green bags contain 1 faded chartreuse bag.
posh plum bags contain 1 dull turquoise bag.
plaid red bags contain 4 wavy orange bags.
faded green bags contain 2 wavy tan bags, 2 muted gold bags.
drab maroon bags contain 5 striped fuchsia bags, 5 light indigo bags.
clear blue bags contain 5 bright magenta bags, 2 muted gold bags, 1 faded chartreuse bag.
shiny purple bags contain 3 mirrored lavender bags, 3 light crimson bags, 2 light turquoise bags, 1 drab aqua bag.
wavy silver bags contain 5 mirrored tan bags, 2 dotted crimson bags, 3 pale magenta bags, 5 vibrant plum bags.
drab gray bags contain 4 mirrored red bags, 4 plaid yellow bags, 4 muted silver bags, 3 light black bags.
striped maroon bags contain 5 dull teal bags, 1 bright indigo bag, 3 clear gray bags.
striped tomato bags contain 2 clear gold bags, 4 plaid red bags, 1 vibrant yellow bag, 2 dark aqua bags.
vibrant brown bags contain 4 vibrant orange bags.
wavy green bags contain 5 striped coral bags, 5 clear brown bags, 4 drab gold bags, 3 faded green bags.
dark tomato bags contain 3 wavy gray bags, 4 clear yellow bags, 4 light fuchsia bags, 1 drab plum bag.
plaid gold bags contain 3 faded red bags.
light tomato bags contain 1 striped black bag.
clear olive bags contain 2 drab lime bags.
dim red bags contain 4 light yellow bags, 5 vibrant yellow bags, 3 dark green bags, 2 vibrant aqua bags.
vibrant indigo bags contain 1 vibrant silver bag.
pale crimson bags contain 4 wavy green bags, 1 striped fuchsia bag, 4 posh indigo bags.
clear lime bags contain 1 wavy tan bag.
muted gray bags contain 1 faded green bag, 2 dull silver bags, 4 drab crimson bags.
striped chartreuse bags contain 2 vibrant silver bags, 2 shiny tan bags, 3 muted silver bags, 2 shiny maroon bags.
muted coral bags contain 5 dark maroon bags, 1 clear lavender bag, 4 bright teal bags, 4 faded cyan bags.
posh coral bags contain 2 clear brown bags.
bright crimson bags contain 2 vibrant salmon bags.
muted plum bags contain 1 pale silver bag.
dull plum bags contain 2 shiny cyan bags, 3 faded salmon bags.
bright olive bags contain 3 dim brown bags, 5 dark brown bags, 1 muted white bag.
clear plum bags contain 5 clear chartreuse bags, 5 striped aqua bags.
muted chartreuse bags contain 1 faded crimson bag, 1 dark cyan bag.
muted purple bags contain 1 bright plum bag, 2 light olive bags, 2 striped red bags, 4 pale magenta bags.
posh yellow bags contain 4 wavy purple bags, 3 dark green bags, 3 striped tomato bags, 3 light chartreuse bags.
light violet bags contain 5 plaid black bags, 1 muted brown bag, 1 vibrant aqua bag.
drab olive bags contain 1 dim brown bag, 2 dull blue bags.
pale indigo bags contain 3 dark magenta bags, 2 dull blue bags.
mirrored blue bags contain 5 clear crimson bags, 1 clear orange bag, 3 drab tomato bags.
striped green bags contain 2 shiny black bags, 4 dotted chartreuse bags, 4 wavy white bags.
plaid teal bags contain 4 dark green bags, 5 muted chartreuse bags, 5 vibrant aqua bags, 4 dotted olive bags.
faded plum bags contain 2 drab white bags, 4 light blue bags, 2 clear lavender bags, 3 vibrant white bags.
dim green bags contain 2 faded green bags, 2 bright magenta bags.
dark lavender bags contain 2 muted lime bags, 2 faded tomato bags, 5 wavy purple bags, 3 light olive bags.
dim purple bags contain 4 dotted plum bags.
dark salmon bags contain 1 dull violet bag, 3 bright indigo bags.
dim cyan bags contain 5 dim crimson bags, 2 clear brown bags, 1 muted brown bag, 4 light silver bags.

View File

@ -0,0 +1,111 @@
use crate::common::AdventOfCodeDay;
use std::collections::VecDeque;
use std::collections::HashSet;
use regex::Regex;
#[derive(Debug)]
struct Rule {
parent: String,
children: Vec<(usize, String)>,
}
pub struct Day07 {
input: Vec<Rule>,
}
fn parse_line(line: &str) -> Rule {
lazy_static! {
static ref REX_LINE: Regex = Regex::new(r"^(?P<bag>[a-z]+ [a-z]+) bags contain (?P<inner>(?:(?:(?:[0-9]+ (?:[a-z]+ [a-z]+)) bags?(?:, |\.)?)+)|no other bags\.)$").unwrap();
static ref REX_INNER: Regex = Regex::new(r"(?P<num>[0-9]+) (?P<bag>[a-z]+ [a-z]+) bags?[.,]").unwrap();
}
if let Some(rline) = REX_LINE.captures(line) {
let parent = rline.name("bag").unwrap().as_str().to_owned();
if rline.name("inner").unwrap().as_str() == "not other bags." {
return Rule {
parent: parent,
children: vec![],
}
}
let childs = REX_INNER
.captures_iter(rline.name("inner").unwrap().as_str())
.map(|p| (p.name("num").unwrap().as_str().parse::<usize>().unwrap(), p.name("bag").unwrap().as_str().to_owned()))
.collect::<Vec<(usize, String)>>();
return Rule {
parent: parent,
children: childs,
}
} else {
panic!(format!("no regex line match: '{}'", line.to_owned()));
}
}
impl Day07 {
pub fn new() -> Self {
let input_bytes = include_bytes!("../res/07_input.txt");
let input_str = String::from_utf8_lossy(input_bytes);
let data = input_str
.lines()
.map(parse_line)
.collect::<Vec<Rule>>();
Self {
input: data
}
}
fn find_rule(&self, bag: &str) -> Option<&Rule> {
for r in &self.input {
if r.parent == bag {
return Some(r);
}
}
return None;
}
fn can_contain(&self, parent: &str, child: &str) -> bool {
let mut candidates: VecDeque<String> = VecDeque::new();
let mut visited: HashSet<String> = HashSet::new();
candidates.push_back(parent.to_owned());
visited.insert(parent.to_owned());
while !candidates.is_empty() {
let cand = candidates.pop_back().unwrap();
if let Some(rule) = self.find_rule(cand.as_str()) {
for rulechild in &rule.children {
let rcname = rulechild.1.to_owned();
if rcname == child {
return true;
} else if !visited.contains(&rcname) {
candidates.push_back(rcname.to_owned());
visited.insert(rcname);
}
}
}
}
return false;
}
fn get_full_children_count(&self, name: &str) -> usize {
self.find_rule(name).unwrap().children.iter().map(|p| p.0 + p.0 * self.get_full_children_count(&p.1)).sum()
}
}
impl AdventOfCodeDay for Day07 {
fn task_1(&self) -> String {
self.input.iter().filter(|p| self.can_contain(p.parent.as_str(), "shiny gold")).count().to_string()
}
fn task_2(&self) -> String {
self.get_full_children_count("shiny gold").to_string()
}
}

View File

@ -0,0 +1,83 @@
--- Day 8: Handheld Halting ---
Your flight to the major airline hub reaches cruising altitude without incident. While you consider checking the in-flight menu for one of those drinks that come with a little umbrella, you are interrupted by the kid sitting next to you.
Their handheld game console won't turn on! They ask if you can take a look.
You narrow the problem down to a strange infinite loop in the boot code (your puzzle input) of the device. You should be able to fix it, but first you need to be able to run the code in isolation.
The boot code is represented as a text file with one instruction per line of text. Each instruction consists of an operation (acc, jmp, or nop) and an argument (a signed number like +4 or -20).
acc increases or decreases a single global value called the accumulator by the value given in the argument. For example, acc +7 would increase the accumulator by 7. The accumulator starts at 0. After an acc instruction, the instruction immediately below it is executed next.
jmp jumps to a new instruction relative to itself. The next instruction to execute is found using the argument as an offset from the jmp instruction; for example, jmp +2 would skip the next instruction, jmp +1 would continue to the instruction immediately below it, and jmp -20 would cause the instruction 20 lines above to be executed next.
nop stands for No OPeration - it does nothing. The instruction immediately below it is executed next.
For example, consider the following program:
nop +0
acc +1
jmp +4
acc +3
jmp -3
acc -99
acc +1
jmp -4
acc +6
These instructions are visited in this order:
nop +0 | 1
acc +1 | 2, 8(!)
jmp +4 | 3
acc +3 | 6
jmp -3 | 7
acc -99 |
acc +1 | 4
jmp -4 | 5
acc +6 |
First, the nop +0 does nothing. Then, the accumulator is increased from 0 to 1 (acc +1) and jmp +4 sets the next instruction to the other acc +1 near the bottom. After it increases the accumulator from 1 to 2, jmp -4 executes, setting the next instruction to the only acc +3. It sets the accumulator to 5, and jmp -3 causes the program to continue back at the first acc +1.
This is an infinite loop: with this sequence of jumps, the program will run forever. The moment the program tries to run any instruction a second time, you know it will never terminate.
Immediately before the program would run an instruction a second time, the value in the accumulator is 5.
Run your copy of the boot code. Immediately before any instruction is executed a second time, what value is in the accumulator?
--- Part Two ---
After some careful analysis, you believe that exactly one instruction is corrupted.
Somewhere in the program, either a jmp is supposed to be a nop, or a nop is supposed to be a jmp. (No acc instructions were harmed in the corruption of this boot code.)
The program is supposed to terminate by attempting to execute an instruction immediately after the last instruction in the file. By changing exactly one jmp or nop, you can repair the boot code and make it terminate correctly.
For example, consider the same program from above:
nop +0
acc +1
jmp +4
acc +3
jmp -3
acc -99
acc +1
jmp -4
acc +6
If you change the first instruction from nop +0 to jmp +0, it would create a single-instruction infinite loop, never leaving that instruction. If you change almost any of the jmp instructions, the program will still eventually find another jmp instruction and loop forever.
However, if you change the second-to-last instruction (from jmp -4 to nop -4), the program terminates! The instructions are visited in this order:
nop +0 | 1
acc +1 | 2
jmp +4 | 3
acc +3 |
jmp -3 |
acc -99 |
acc +1 | 4
nop -4 | 5
acc +6 | 6
After the last instruction (acc +6), the program terminates by attempting to run the instruction below the last instruction in the file. With this change, after the program terminates, the accumulator contains the value 8 (acc +1, acc +1, acc +6).
Fix the program so that it terminates normally by changing exactly one jmp (to nop) or nop (to jmp). What is the value of the accumulator after the program terminates?

View File

@ -0,0 +1,633 @@
acc +37
acc -1
nop +512
acc +0
jmp +60
acc -3
nop +317
jmp +130
acc +22
acc +34
jmp +486
acc -18
nop +610
acc -14
nop +274
jmp +439
acc -6
acc -1
acc -4
acc +7
jmp +175
nop +179
jmp +197
jmp +76
acc -1
acc +24
jmp +472
acc +8
acc -15
acc +0
jmp +551
acc +46
acc +27
jmp +1
acc +45
jmp +153
acc +14
jmp +207
jmp +1
jmp +557
nop +424
jmp +571
nop -19
nop +9
acc +2
acc +29
jmp +14
acc -10
acc +43
acc +43
jmp +75
jmp +311
jmp +517
acc -6
acc +13
jmp +140
nop +348
acc +0
jmp +275
jmp +52
jmp +110
acc +11
acc +15
jmp +13
acc +7
jmp +216
jmp +174
nop +24
acc -16
acc +46
acc -17
jmp +519
acc -15
acc +46
acc -4
jmp +309
acc +14
acc +36
acc -15
jmp +244
acc +37
acc +43
jmp +146
jmp +260
jmp +217
acc +39
jmp +454
nop +16
nop +255
acc +31
jmp +13
acc +38
acc +45
acc +24
jmp +534
acc +13
acc +44
acc +34
jmp +286
jmp +1
acc -12
jmp -45
jmp +147
acc -2
acc +24
nop +391
acc +11
jmp +242
acc +1
acc +28
jmp +423
acc +5
jmp +319
acc +45
nop +350
acc +34
acc +7
jmp +47
nop +32
acc +2
acc +0
jmp +252
acc -4
acc +23
jmp +452
acc -5
acc +48
jmp -104
acc +38
jmp +172
acc +7
acc +31
jmp +5
acc +19
acc +12
acc +26
jmp +232
acc -12
nop +121
nop +80
acc +46
jmp +126
jmp +82
nop +69
jmp -128
acc +18
acc +45
acc +14
acc +45
jmp +219
jmp +422
acc +2
acc +40
acc +13
jmp +450
acc +48
jmp +172
acc +19
acc -10
jmp +69
nop +336
nop -6
jmp +265
jmp -136
jmp +350
acc +31
acc +39
nop +389
nop +404
jmp +16
acc +13
nop -41
acc -2
acc -14
jmp +159
jmp -111
acc +40
acc +36
acc -17
jmp -143
acc +36
acc +29
acc +19
acc +0
jmp +159
jmp +279
acc +31
jmp +346
acc +15
nop +173
acc +48
jmp -183
acc +16
acc +31
jmp +418
acc -13
jmp +280
acc +30
nop +229
jmp -139
acc +0
acc +9
jmp +354
acc +12
jmp +310
jmp -129
acc -8
jmp -96
acc -3
acc +1
jmp +51
jmp +303
acc +28
jmp -186
acc +36
acc -10
nop +72
nop +345
jmp +200
acc +6
acc -14
jmp +87
nop +318
jmp +273
nop +309
acc +50
jmp +147
jmp +387
acc +38
nop -169
acc +44
jmp +28
nop +208
nop +43
acc +26
acc -13
jmp -160
jmp +233
acc +22
jmp +357
jmp +374
acc -6
acc +38
jmp +100
jmp -36
acc +38
nop +330
acc +46
jmp -43
acc +34
nop +239
acc +45
acc +15
jmp +48
acc +49
acc +20
acc -5
acc +41
jmp +70
jmp +211
jmp +144
acc +29
acc +36
acc -15
jmp -24
jmp +1
jmp -17
acc -18
acc +27
acc +34
jmp -21
jmp +1
acc +35
acc -5
acc +24
jmp +337
nop -240
jmp +180
acc -1
nop +49
jmp +260
acc +40
acc +42
jmp -165
acc +31
acc +30
nop -234
jmp +27
acc +45
acc +48
acc +44
acc -19
jmp +70
acc +20
acc +18
jmp +219
acc +46
jmp -85
acc +43
acc +21
jmp -4
acc +37
acc +26
acc +16
jmp -257
acc +39
acc +7
jmp -260
acc +42
acc +10
acc +36
acc +47
jmp +2
jmp -249
acc +20
acc -1
acc +21
jmp +74
jmp +31
acc +32
jmp +64
acc +34
jmp -255
acc -8
acc -2
acc +26
jmp -102
jmp +229
acc -14
acc +25
jmp -154
acc -15
jmp -92
nop -37
acc -5
acc +50
acc +43
jmp +73
acc +1
acc -17
acc +19
acc +24
jmp -319
nop -225
jmp -304
acc +49
acc +5
acc -17
jmp +14
acc +42
acc -9
acc -10
acc +45
jmp -125
jmp -46
acc +13
acc +11
nop +199
acc -19
jmp -159
acc +1
jmp +253
acc +7
jmp +233
nop -76
acc +31
acc +44
jmp -18
acc +47
nop +227
jmp +178
nop -22
jmp -44
jmp +24
nop +122
acc +20
acc +43
jmp -81
acc -15
acc +10
acc +40
jmp +108
acc +45
jmp +35
acc +44
jmp +36
nop -2
nop -320
jmp +1
acc +47
jmp -6
acc -16
acc +49
nop +56
jmp +104
acc +40
jmp -159
acc +30
jmp +56
acc +47
acc -6
acc +47
acc +2
jmp -102
acc +45
jmp -262
acc +36
acc +42
acc -17
jmp -90
acc +18
nop +7
acc -14
jmp -194
acc +16
acc +31
acc +26
jmp -257
acc +25
jmp -367
jmp +69
nop -102
acc +47
jmp -356
nop -105
acc +6
jmp -42
acc +40
jmp -368
acc +42
jmp +84
acc +17
acc +14
acc -17
acc -14
jmp -80
acc +42
acc +11
acc -14
jmp -77
acc -12
acc +8
acc -19
jmp -206
acc +6
acc +18
nop +94
acc -2
jmp -330
acc -15
jmp -367
acc -15
acc +40
jmp +143
jmp -178
acc -1
jmp +140
acc +13
acc +47
jmp -271
acc +29
nop -30
nop -344
jmp -251
jmp +98
acc +45
acc -17
acc +5
jmp +1
jmp -299
acc +34
acc +7
acc +7
nop +16
jmp -106
jmp -399
jmp -291
acc -4
acc +26
jmp -376
nop -444
nop +59
acc +27
nop +89
jmp -188
acc +21
nop -246
acc +6
jmp -24
acc +35
jmp +1
jmp -361
acc +48
acc -5
acc +19
jmp +74
jmp -56
jmp +43
acc +50
nop -275
acc +39
acc -11
jmp -258
acc +8
jmp -190
acc +46
jmp +1
nop -188
acc -15
jmp +12
nop -5
nop -444
acc +0
jmp -129
acc -11
acc +28
jmp -452
acc -4
acc +24
nop -176
jmp -56
acc +47
acc +33
jmp -432
jmp -19
acc +32
jmp +1
acc +7
nop -179
jmp -49
nop -66
acc +20
jmp -122
acc +1
acc +10
acc +16
jmp +40
acc +11
acc +6
jmp -454
acc -2
acc +12
nop -228
jmp -165
acc +42
nop -212
acc +49
jmp -286
acc +42
acc +24
acc +38
jmp -440
acc +29
acc +8
acc +21
jmp -288
acc +2
jmp -427
acc +17
acc +45
acc +33
jmp -333
acc +6
jmp -445
nop -283
acc -18
jmp +1
jmp +1
jmp -492
jmp +53
acc +26
jmp -107
nop -377
jmp -155
acc +22
jmp -523
jmp -127
acc +2
nop -168
acc +15
jmp -343
acc +34
acc +0
acc +0
jmp -241
acc +30
acc +40
acc +46
acc -11
jmp -216
acc +31
jmp -86
acc +34
acc -15
nop -4
jmp -74
acc -1
acc +13
acc -2
jmp -119
acc +21
nop -516
acc +24
jmp -580
nop -200
acc +18
jmp -318
acc +0
nop -483
acc +15
acc -9
jmp -30
jmp -462
jmp -476
acc +18
acc -14
jmp -91
acc -6
acc +32
nop -611
acc +8
jmp -613
acc +23
acc +7
acc +30
acc +48
jmp -222
jmp -326
acc +46
nop -108
acc +17
acc -16
jmp +1

View File

@ -0,0 +1,167 @@
use crate::common::AdventOfCodeDay;
use itertools::Itertools;
use std::collections::HashSet;
use std::fmt::Display;
#[derive(Debug, Clone)]
struct HGCProgramm {
code: Vec<HGCCommand>,
}
impl HGCProgramm {
fn parse_program(codestr: String) -> HGCProgramm {
HGCProgramm {
code: codestr.lines().map(HGCCommand::parse).collect(),
}
}
}
#[derive(Debug, Clone)]
struct HGCCommand {
cmdtype: HGCCommandType,
argument: i32,
}
impl HGCCommand {
fn parse(line: &str) -> HGCCommand {
let (str_cmd, str_arg) = line.split(' ').collect_tuple::<(_, _)>().unwrap();
HGCCommand {
cmdtype: HGCCommandType::parse(str_cmd),
argument: str_arg.parse::<i32>().unwrap(),
}
}
}
#[derive(Debug, PartialEq, Clone)]
enum HGCCommandType {
NOP,
ACC,
JMP,
}
impl HGCCommandType {
fn parse(val: &str) -> HGCCommandType {
match val {
"acc" => HGCCommandType::ACC,
"jmp" => HGCCommandType::JMP,
"nop" => HGCCommandType::NOP,
_ => panic!("not a cmd")
}
}
}
impl Display for HGCCommandType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
#[derive(Debug)]
struct HGCMachineState {
trace: bool,
acc: i32,
ip: usize,
}
impl HGCMachineState {
fn new() -> HGCMachineState {
HGCMachineState {
trace: is_verbose!(),
acc: 0,
ip: 0,
}
}
fn exec_step(&mut self, prog: &HGCProgramm) {
self.exec_single(&prog.code[self.ip])
}
fn exec_single(&mut self, cmd: &HGCCommand) {
if self.trace {
verboseln!("ip: {: <4} || cmd:[{}({: <5})] (acc: {})", self.ip, cmd.cmdtype, cmd.argument, self.acc)
}
if cmd.cmdtype == HGCCommandType::NOP {
self.ip += 1;
} else if cmd.cmdtype == HGCCommandType::JMP {
self.ip = (self.ip as i32 + cmd.argument) as usize;
} else if cmd.cmdtype == HGCCommandType::ACC {
self.acc += cmd.argument;
self.ip += 1;
}
}
}
pub struct Day08 {
input: HGCProgramm,
}
impl Day08 {
pub fn new() -> Self {
let input_bytes = include_bytes!("../res/08_input.txt");
let input_str = String::from_utf8_lossy(input_bytes);
Self {
input: HGCProgramm::parse_program(input_str.to_owned().to_string())
}
}
fn find_loop(prog: &HGCProgramm) -> (i32, bool) {
let mut vm = HGCMachineState::new();
let mut visited: HashSet<usize> = HashSet::new();
visited.insert(vm.ip);
loop {
vm.exec_step(prog);
if visited.contains(&vm.ip) {
return (vm.acc, false);
}
visited.insert(vm.ip);
if vm.ip == prog.code.len() {
return (vm.acc, true);
}
}
}
}
impl AdventOfCodeDay for Day08 {
fn task_1(&self) -> String {
return Day08::find_loop(&self.input).0.to_string();
}
fn task_2(&self) -> String {
for i in 0..self.input.code.len() {
if self.input.code[i].cmdtype == HGCCommandType::ACC {
continue;
}
let mut progclone = self.input.clone();
if self.input.code[i].cmdtype == HGCCommandType::JMP {
progclone.code[i] = HGCCommand {
cmdtype: HGCCommandType::NOP,
argument: self.input.code[i].argument,
}
} else if self.input.code[i].cmdtype == HGCCommandType::NOP {
progclone.code[i] = HGCCommand {
cmdtype: HGCCommandType::JMP,
argument: self.input.code[i].argument,
}
} else {
panic!();
}
if let (acc, true) = Day08::find_loop(&progclone) {
return acc.to_string();
}
}
panic!();
}
}

View File

@ -0,0 +1,82 @@
--- Day 9: Encoding Error ---
With your neighbor happily enjoying their video game, you turn your attention to an open data port on the little screen in the seat in front of you.
Though the port is non-standard, you manage to connect it to your computer through the clever use of several paperclips. Upon connection, the port outputs a series of numbers (your puzzle input).
The data appears to be encrypted with the eXchange-Masking Addition System (XMAS) which, conveniently for you, is an old cypher with an important weakness.
XMAS starts by transmitting a preamble of 25 numbers. After that, each number you receive should be the sum of any two of the 25 immediately previous numbers. The two numbers will have different values, and there might be more than one such pair.
For example, suppose your preamble consists of the numbers 1 through 25 in a random order. To be valid, the next number must be the sum of two of those numbers:
26 would be a valid next number, as it could be 1 plus 25 (or many other pairs, like 2 and 24).
49 would be a valid next number, as it is the sum of 24 and 25.
100 would not be valid; no two of the previous 25 numbers sum to 100.
50 would also not be valid; although 25 appears in the previous 25 numbers, the two numbers in the pair must be different.
Suppose the 26th number is 45, and the first number (no longer an option, as it is more than 25 numbers ago) was 20. Now, for the next number to be valid, there needs to be some pair of numbers among 1-19, 21-25, or 45 that add up to it:
26 would still be a valid next number, as 1 and 25 are still within the previous 25 numbers.
65 would not be valid, as no two of the available numbers sum to it.
64 and 66 would both be valid, as they are the result of 19+45 and 21+45 respectively.
Here is a larger example which only considers the previous 5 numbers (and has a preamble of length 5):
35
20
15
25
47
40
62
55
65
95
102
117
150
182
127
219
299
277
309
576
In this example, after the 5-number preamble, almost every number is the sum of two of the previous 5 numbers; the only number that does not follow this rule is 127.
The first step of attacking the weakness in the XMAS data is to find the first number in the list (after the preamble) which is not the sum of two of the 25 numbers before it. What is the first number that does not have this property?
--- Part Two ---
The final step in breaking the XMAS encryption relies on the invalid number you just found: you must find a contiguous set of at least two numbers in your list which sum to the invalid number from step 1.
Again consider the above example:
35
20
15
25
47
40
62
55
65
95
102
117
150
182
127
219
299
277
309
576
In this list, adding up all of the numbers from 15 through 40 produces the invalid number from step 1, 127. (Of course, the contiguous set of numbers in your actual list might be much longer.)
To find the encryption weakness, add together the smallest and largest number in this contiguous range; in this example, these are 15 and 47, producing 62.
What is the encryption weakness in your XMAS-encrypted list of numbers?

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,91 @@
use crate::common::AdventOfCodeDay;
use std::collections::HashSet;
pub struct Day09 {
input: Vec<u64>,
}
impl Day09 {
pub fn new() -> Self {
let input_bytes = include_bytes!("../res/09_input.txt");
let input_str = String::from_utf8_lossy(input_bytes);
let data = input_str
.lines()
.map(|p| p.parse::<u64>().unwrap())
.collect::<Vec<u64>>();
Self {
input: data
}
}
fn all_combinations(data: Vec<&u64>) -> HashSet<u64> {
let mut hs: HashSet<u64> = HashSet::new();
for i1 in 0..24 {
for i2 in (i1+1)..25 {
hs.insert(data[i1] + data[i2]);
}
}
return hs;
}
fn find_invalid(&self) -> u64 {
for i in 25..self.input.len() {
let comb = Day09::all_combinations(self.input.iter().skip(i-25).take(25).collect());
if !comb.contains(&self.input[i]) {
return self.input[i];
}
}
panic!();
}
}
impl AdventOfCodeDay for Day09 {
fn task_1(&self) -> String {
return self.find_invalid().to_string();
}
fn task_2(&self) -> String {
let target = self.find_invalid();
let mut sum = self.input[0];
let mut idx1 = 0; //inclusive
let mut idx2 = 0; //inclusive
loop {
if sum == target {
verboseln!("[{}..{}] [[{:?}]] = {} ({})",
idx1,
idx2,
self.input.iter().skip(idx1).take(idx2-idx1+1).collect::<Vec<&u64>>(),
self.input.iter().skip(idx1).take(idx2-idx1+1).sum::<u64>(),
target);
return (self.input.iter().skip(idx1).take(idx2-idx1+1).min().unwrap() + self.input.iter().skip(idx1).take(idx2-idx1+1).max().unwrap()).to_string();
} else if sum < target {
idx2 += 1;
sum += self.input[idx2];
} else if sum > target {
sum -= self.input[idx1];
idx1 += 1;
}
verboseln!("[{}..{}] = {}", idx1, idx2, sum);
}
}
}

View File

@ -0,0 +1,139 @@
--- Day 10: Adapter Array ---
Patched into the aircraft's data port, you discover weather forecasts of a massive tropical storm. Before you can figure out whether it will impact your vacation plans, however, your device suddenly turns off!
Its battery is dead.
You'll need to plug it in. There's only one problem: the charging outlet near your seat produces the wrong number of jolts. Always prepared, you make a list of all of the joltage adapters in your bag.
Each of your joltage adapters is rated for a specific output joltage (your puzzle input). Any given adapter can take an input 1, 2, or 3 jolts lower than its rating and still produce its rated output joltage.
In addition, your device has a built-in joltage adapter rated for 3 jolts higher than the highest-rated adapter in your bag. (If your adapter list were 3, 9, and 6, your device's built-in adapter would be rated for 12 jolts.)
Treat the charging outlet near your seat as having an effective joltage rating of 0.
Since you have some time to kill, you might as well test all of your adapters. Wouldn't want to get to your resort and realize you can't even charge your device!
If you use every adapter in your bag at once, what is the distribution of joltage differences between the charging outlet, the adapters, and your device?
For example, suppose that in your bag, you have adapters with the following joltage ratings:
16
10
15
5
1
11
7
19
6
12
4
With these adapters, your device's built-in joltage adapter would be rated for 19 + 3 = 22 jolts, 3 higher than the highest-rated adapter.
Because adapters can only connect to a source 1-3 jolts lower than its rating, in order to use every adapter, you'd need to choose them like this:
The charging outlet has an effective rating of 0 jolts, so the only adapters that could connect to it directly would need to have a joltage rating of 1, 2, or 3 jolts. Of these, only one you have is an adapter rated 1 jolt (difference of 1).
From your 1-jolt rated adapter, the only choice is your 4-jolt rated adapter (difference of 3).
From the 4-jolt rated adapter, the adapters rated 5, 6, or 7 are valid choices. However, in order to not skip any adapters, you have to pick the adapter rated 5 jolts (difference of 1).
Similarly, the next choices would need to be the adapter rated 6 and then the adapter rated 7 (with difference of 1 and 1).
The only adapter that works with the 7-jolt rated adapter is the one rated 10 jolts (difference of 3).
From 10, the choices are 11 or 12; choose 11 (difference of 1) and then 12 (difference of 1).
After 12, only valid adapter has a rating of 15 (difference of 3), then 16 (difference of 1), then 19 (difference of 3).
Finally, your device's built-in adapter is always 3 higher than the highest adapter, so its rating is 22 jolts (always a difference of 3).
In this example, when using every adapter, there are 7 differences of 1 jolt and 5 differences of 3 jolts.
Here is a larger example:
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
In this larger example, in a chain that uses all of the adapters, there are 22 differences of 1 jolt and 10 differences of 3 jolts.
Find a chain that uses all of your adapters to connect the charging outlet to your device's built-in adapter and count the joltage differences between the charging outlet, the adapters, and your device. What is the number of 1-jolt differences multiplied by the number of 3-jolt differences?
--- Part Two ---
To completely determine whether you have enough adapters, you'll need to figure out how many different ways they can be arranged. Every arrangement needs to connect the charging outlet to your device. The previous rules about when adapters can successfully connect still apply.
The first example above (the one that starts with 16, 10, 15) supports the following arrangements:
(0), 1, 4, 5, 6, 7, 10, 11, 12, 15, 16, 19, (22)
(0), 1, 4, 5, 6, 7, 10, 12, 15, 16, 19, (22)
(0), 1, 4, 5, 7, 10, 11, 12, 15, 16, 19, (22)
(0), 1, 4, 5, 7, 10, 12, 15, 16, 19, (22)
(0), 1, 4, 6, 7, 10, 11, 12, 15, 16, 19, (22)
(0), 1, 4, 6, 7, 10, 12, 15, 16, 19, (22)
(0), 1, 4, 7, 10, 11, 12, 15, 16, 19, (22)
(0), 1, 4, 7, 10, 12, 15, 16, 19, (22)
(The charging outlet and your device's built-in adapter are shown in parentheses.) Given the adapters from the first example, the total number of arrangements that connect the charging outlet to your device is 8.
The second example above (the one that starts with 28, 33, 18) has many arrangements. Here are a few:
(0), 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 17, 18, 19, 20, 23, 24, 25, 28, 31,
32, 33, 34, 35, 38, 39, 42, 45, 46, 47, 48, 49, (52)
(0), 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 17, 18, 19, 20, 23, 24, 25, 28, 31,
32, 33, 34, 35, 38, 39, 42, 45, 46, 47, 49, (52)
(0), 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 17, 18, 19, 20, 23, 24, 25, 28, 31,
32, 33, 34, 35, 38, 39, 42, 45, 46, 48, 49, (52)
(0), 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 17, 18, 19, 20, 23, 24, 25, 28, 31,
32, 33, 34, 35, 38, 39, 42, 45, 46, 49, (52)
(0), 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 17, 18, 19, 20, 23, 24, 25, 28, 31,
32, 33, 34, 35, 38, 39, 42, 45, 47, 48, 49, (52)
(0), 3, 4, 7, 10, 11, 14, 17, 20, 23, 25, 28, 31, 34, 35, 38, 39, 42, 45,
46, 48, 49, (52)
(0), 3, 4, 7, 10, 11, 14, 17, 20, 23, 25, 28, 31, 34, 35, 38, 39, 42, 45,
46, 49, (52)
(0), 3, 4, 7, 10, 11, 14, 17, 20, 23, 25, 28, 31, 34, 35, 38, 39, 42, 45,
47, 48, 49, (52)
(0), 3, 4, 7, 10, 11, 14, 17, 20, 23, 25, 28, 31, 34, 35, 38, 39, 42, 45,
47, 49, (52)
(0), 3, 4, 7, 10, 11, 14, 17, 20, 23, 25, 28, 31, 34, 35, 38, 39, 42, 45,
48, 49, (52)
In total, this set of adapters can connect the charging outlet to your device in 19208 distinct arrangements.
You glance back down at your bag and try to remember why you brought so many adapters; there must be more than a trillion valid ways to arrange them! Surely, there must be an efficient way to count the arrangements.
What is the total number of distinct ways you can arrange the adapters to connect the charging outlet to your device?

View File

@ -0,0 +1,95 @@
76
12
97
28
132
107
145
121
84
34
115
127
22
23
11
135
113
82
140
119
69
77
83
36
13
37
92
133
122
99
147
112
42
62
65
40
123
139
33
129
149
68
41
16
48
109
5
27
142
81
90
9
78
103
26
100
141
59
55
120
126
1
35
2
20
114
58
54
10
51
116
93
6
134
108
47
70
91
138
63
19
64
148
106
21
98
43
30
146
46
128
73
94
87
29

View File

@ -0,0 +1,104 @@
use crate::common::AdventOfCodeDay;
use itertools::Itertools;
use std::collections::HashMap;
pub struct Day10 {
input: Vec<u32>,
}
impl Day10 {
pub fn new() -> Self {
let input_bytes = include_bytes!("../res/10_input.txt");
let input_str = String::from_utf8_lossy(input_bytes);
let data = input_str
.lines()
.map(|p| p.parse::<u32>().unwrap())
.collect::<Vec<u32>>();
Self {
input: data
}
}
fn path_count(cache: &mut HashMap<usize, u128>, list: &Vec<u32>, idx: usize) -> u128 {
if idx == 0 {
return 1;
}
if let Some(cv) = cache.get(&idx) {
verboseln!("(#) {}", idx);
return *cv;
}
verboseln!("[::] {}", idx);
let mut r = 0;
let me = list[idx];
for delta in 1..4 {
let other_idx = idx as i32 - delta;
if other_idx < 0 {
continue;
}
let other = list[other_idx as usize];
if me - other <= 3 {
r += Day10::path_count(cache, list, other_idx as usize);
}
}
cache.insert(idx, r);
return r;
}
}
impl AdventOfCodeDay for Day10 {
fn task_1(&self) -> String {
let (min, max) = self.input.iter().minmax().into_option().unwrap();
verboseln!("min := {}", min);
verboseln!("max := {}", max);
let diff = self.input
.iter()
.chain([0, *max + 3].iter())
.sorted()
.collect::<Vec<&u32>>()
.windows(2)
.map(|p| p[1] - p[0])
.collect::<Vec<u32>>();
let c1 = diff.iter().filter(|v| **v == 1).count();
let c3 = diff.iter().filter(|v| **v == 3).count();
verboseln!("{} * {} = {}", c1, c3, c1*c3);
return (c1 * c3).to_string() //TODO
}
fn task_2(&self) -> String {
let max = self.input.iter().max().unwrap();
let all = self.input
.iter()
.chain([0, *max + 3].iter())
.sorted()
.map(|p| *p)
.collect::<Vec<u32>>();
let mut hmap: HashMap<usize, u128> = HashMap::new();
//for i in 0..(all.len()) {
// Day10::path_count(&mut hmap, &all, i);
//}
let total = Day10::path_count(&mut hmap, &all, all.len()-1);
return total.to_string();
}
}

View File

@ -0,0 +1,208 @@
--- Day 11: Seating System ---
Your plane lands with plenty of time to spare. The final leg of your journey is a ferry that goes directly to the tropical island where you can finally start your vacation. As you reach the waiting area to board the ferry, you realize you're so early, nobody else has even arrived yet!
By modeling the process people use to choose (or abandon) their seat in the waiting area, you're pretty sure you can predict the best place to sit. You make a quick map of the seat layout (your puzzle input).
The seat layout fits neatly on a grid. Each position is either floor (.), an empty seat (L), or an occupied seat (#). For example, the initial seat layout might look like this:
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
Now, you just need to model the people who will be arriving shortly. Fortunately, people are entirely predictable and always follow a simple set of rules. All decisions are based on the number of occupied seats adjacent to a given seat (one of the eight positions immediately up, down, left, right, or diagonal from the seat). The following rules are applied to every seat simultaneously:
If a seat is empty (L) and there are no occupied seats adjacent to it, the seat becomes occupied.
If a seat is occupied (#) and four or more seats adjacent to it are also occupied, the seat becomes empty.
Otherwise, the seat's state does not change.
Floor (.) never changes; seats don't move, and nobody sits on the floor.
After one round of these rules, every seat in the example layout becomes occupied:
#.##.##.##
#######.##
#.#.#..#..
####.##.##
#.##.##.##
#.#####.##
..#.#.....
##########
#.######.#
#.#####.##
After a second round, the seats with four or more occupied adjacent seats become empty again:
#.LL.L#.##
#LLLLLL.L#
L.L.L..L..
#LLL.LL.L#
#.LL.LL.LL
#.LLLL#.##
..L.L.....
#LLLLLLLL#
#.LLLLLL.L
#.#LLLL.##
This process continues for three more rounds:
#.##.L#.##
#L###LL.L#
L.#.#..#..
#L##.##.L#
#.##.LL.LL
#.###L#.##
..#.#.....
#L######L#
#.LL###L.L
#.#L###.##
#.#L.L#.##
#LLL#LL.L#
L.L.L..#..
#LLL.##.L#
#.LL.LL.LL
#.LL#L#.##
..L.L.....
#L#LLLL#L#
#.LLLLLL.L
#.#L#L#.##
#.#L.L#.##
#LLL#LL.L#
L.#.L..#..
#L##.##.L#
#.#L.LL.LL
#.#L#L#.##
..L.L.....
#L#L##L#L#
#.LLLLLL.L
#.#L#L#.##
At this point, something interesting happens: the chaos stabilizes and further applications of these rules cause no seats to change state! Once people stop moving around, you count 37 occupied seats.
Simulate your seating area by applying the seating rules repeatedly until no seats change state. How many seats end up occupied?
--- Part Two ---
As soon as people start to arrive, you realize your mistake. People don't just care about adjacent seats - they care about the first seat they can see in each of those eight directions!
Now, instead of considering just the eight immediately adjacent seats, consider the first seat in each of those eight directions. For example, the empty seat below would see eight occupied seats:
.......#.
...#.....
.#.......
.........
..#L....#
....#....
.........
#........
...#.....
The leftmost empty seat below would only see one empty seat, but cannot see any of the occupied ones:
.............
.L.L.#.#.#.#.
.............
The empty seat below would see no occupied seats:
.##.##.
#.#.#.#
##...##
...L...
##...##
#.#.#.#
.##.##.
Also, people seem to be more tolerant than you expected: it now takes five or more visible occupied seats for an occupied seat to become empty (rather than four or more from the previous rules). The other rules still apply: empty seats that see no occupied seats become occupied, seats matching no rule don't change, and floor never changes.
Given the same starting layout as above, these new rules cause the seating area to shift around as follows:
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
#.##.##.##
#######.##
#.#.#..#..
####.##.##
#.##.##.##
#.#####.##
..#.#.....
##########
#.######.#
#.#####.##
#.LL.LL.L#
#LLLLLL.LL
L.L.L..L..
LLLL.LL.LL
L.LL.LL.LL
L.LLLLL.LL
..L.L.....
LLLLLLLLL#
#.LLLLLL.L
#.LLLLL.L#
#.L#.##.L#
#L#####.LL
L.#.#..#..
##L#.##.##
#.##.#L.##
#.#####.#L
..#.#.....
LLL####LL#
#.L#####.L
#.L####.L#
#.L#.L#.L#
#LLLLLL.LL
L.L.L..#..
##LL.LL.L#
L.LL.LL.L#
#.LLLLL.LL
..L.L.....
LLLLLLLLL#
#.LLLLL#.L
#.L#LL#.L#
#.L#.L#.L#
#LLLLLL.LL
L.L.L..#..
##L#.#L.L#
L.L#.#L.L#
#.L####.LL
..#.#.....
LLL###LLL#
#.LLLLL#.L
#.L#LL#.L#
#.L#.L#.L#
#LLLLLL.LL
L.L.L..#..
##L#.#L.L#
L.L#.LL.L#
#.LLLL#.LL
..#.L.....
LLL###LLL#
#.LLLLL#.L
#.L#LL#.L#
Again, at this point, people stop shifting around and the seating area reaches equilibrium. Once this occurs, you count 26 occupied seats.
Given the new visibility method and the rule change for occupied seats becoming empty, once equilibrium is reached, how many seats end up occupied?

View File

@ -0,0 +1,99 @@
LLLLLLL.LLLLLLLLLLLLLLL.LLL.LLLL.LLLLLLL.L.LLLLLLL.LLLLLL.LLLLLLLL.LLLLL..LLLLLLLLLLLLLLLLLL
LLLLLLL.LLLLLL.LLLL.LLL.LLLLLLLLLL.LLLLLLL.LLLLL.L.LLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLL
.LLLLLLLLLLLLLLL.LLLLLL.LLLLLL.LLLLLLLL.LL.LLLLLLL.LLL.LL.LLLLLLLLLLL.LLL..LLLLLLLL.LLLLLLLL
LLLLLLLLLLLLLLL..LLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLL.L.LLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLL
LLLLL.L.LLLLLLLLLLLLLLL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LLLLLLLLL.LLLLLLLL
LLL.LLLLLLLLLLLL.LLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLL.LLLLLL.LLL.LLLLLLLLLLL.LLLLLLLLL.LLLLLLLL

View File

@ -0,0 +1,249 @@
use crate::common::AdventOfCodeDay;
use std::fmt::Display;
#[derive(Debug, PartialEq, Clone)]
enum BoardCell {
Floor,
Empty,
Full,
}
#[derive(Clone)]
struct Board {
cells: Vec<Vec<BoardCell>>,
width: usize,
height: usize,
}
impl Board {
fn parse(dat: &str) -> Board {
Board {
height: dat.lines().count(),
width: dat.lines().next().unwrap().len(),
cells: dat.lines().map(Board::parse_line).collect()
}
}
fn parse_line(dat: &str) -> Vec<BoardCell> {
dat.chars().map(|c| match c {
'.' => BoardCell::Floor,
'L' => BoardCell::Empty,
'#' => BoardCell::Full,
_ => panic!(),
}).collect()
}
fn adjac(&self, x: i32, y: i32) -> u32 {
let mut c = 0;
for dx in -1..=1 {
for dy in -1..=1 {
if dx == 0 && dy == 0 {
continue;
}
if x+dx < 0 || y+dy < 0 || x+dx >= self.width as i32 || y+dy >= self.height as i32 {
continue;
}
if self.cells[(y+dy) as usize][(x+dx) as usize] == BoardCell::Full {
c+=1;
}
}
}
return c;
}
fn adjac2(&self, x: i32, y: i32) -> u32 {
let mut c = 0;
for dx in -1..=1 {
for dy in -1..=1 {
if dx == 0 && dy == 0 {
continue;
}
if x+dx < 0 || y+dy < 0 || x+dx >= self.width as i32 || y+dy >= self.height as i32 {
continue;
}
if self.adjac_ray(x, y, dx, dy) {
c+=1;
}
}
}
return c;
}
fn adjac_ray(&self, x : i32, y: i32, dx: i32, dy: i32) -> bool {
for i in 1.. {
let rx = x + dx * i;
let ry = y + dy * i;
if rx < 0 || ry < 0 || rx >= self.width as i32 || ry >= self.height as i32 {
return false;
}
if self.cells[ry as usize][rx as usize] == BoardCell::Full {
return true;
}
if self.cells[ry as usize][rx as usize] == BoardCell::Empty {
return false;
}
}
panic!();
}
fn step(&self) -> Board {
let mut nc = self.cells.clone();
for y in 0..self.height {
for x in 0..self.width {
if self.cells[y][x] == BoardCell::Full {
if self.adjac(x as i32, y as i32) >= 4 {
nc[y][x] = BoardCell::Empty; // If a seat is occupied (#) and four or more seats adjacent to it are also occupied, the seat becomes empty.
}
} else if self.cells[y][x] == BoardCell::Empty {
if self.adjac(x as i32, y as i32) == 0 {
nc[y][x] = BoardCell::Full; // If a seat is empty (L) and there are no occupied seats adjacent to it, the seat becomes occupied.
}
}
}
}
Board {
width: self.width,
height: self.height,
cells: nc,
}
}
fn step2(&self) -> Board {
let mut nc = self.cells.clone();
for y in 0..self.height {
for x in 0..self.width {
if self.cells[y][x] == BoardCell::Full {
if self.adjac2(x as i32, y as i32) >= 5 {
nc[y][x] = BoardCell::Empty; // it now takes five or more visible occupied seats for an occupied seat to become empty
}
} else if self.cells[y][x] == BoardCell::Empty {
if self.adjac2(x as i32, y as i32) == 0 {
nc[y][x] = BoardCell::Full; // If a seat is empty (L) and there are no occupied seats adjacent to it, the seat becomes occupied.
}
}
}
}
Board {
width: self.width,
height: self.height,
cells: nc,
}
}
fn total_occupied(&self) -> u32 {
self.cells.iter().map(|p| p.iter().filter(|p| **p == BoardCell::Full).count() as u32).sum()
}
}
impl PartialEq for Board {
fn eq(&self, other: &Self) -> bool {
if self.width != other.width {
return false;
}
if self.height != other.height {
return false;
}
for y in 0..self.height {
for x in 0..self.width {
if self.cells[y][x] != other.cells[y][x] {
return false;
}
}
}
return true;
}
}
impl Display for Board {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut r = String::with_capacity(self.width * self.height + self.height + 1);
for y in 0..self.height {
for x in 0..self.width {
r.push_str(match self.cells[y][x] {
BoardCell::Floor => ".",
BoardCell::Empty => "L",
BoardCell::Full => "#",
});
}
r.push_str("\n");
}
writeln!(f, "{}", r)
}
}
pub struct Day11 {
input: Board,
}
impl Day11 {
pub fn new() -> Self {
let input_bytes = include_bytes!("../res/11_input.txt");
let input_str = String::from_utf8_lossy(input_bytes);
Self {
input: Board::parse(&input_str)
}
}
}
impl AdventOfCodeDay for Day11 {
fn task_1(&self) -> String {
verboseln!("{}", self.input);
verboseln!("> Initial");
let mut board = self.input.clone();
loop {
let newboard = board.step();
verboseln!("{}", newboard);
verboseln!("> {}", newboard.total_occupied());
verboseln!();
if newboard == board {
return newboard.total_occupied().to_string();
}
board = newboard;
}
}
fn task_2(&self) -> String {
verboseln!("{}", self.input);
verboseln!("> Initial");
let mut board = self.input.clone();
loop {
let newboard = board.step2();
verboseln!("{}", newboard);
verboseln!("> {}", newboard.total_occupied());
verboseln!();
if newboard == board {
return newboard.total_occupied().to_string();
}
board = newboard;
}
}
}

View File

@ -0,0 +1,65 @@
--- Day 12: Rain Risk ---
Your ferry made decent progress toward the island, but the storm came in faster than anyone expected. The ferry needs to take evasive actions!
Unfortunately, the ship's navigation computer seems to be malfunctioning; rather than giving a route directly to safety, it produced extremely circuitous instructions. When the captain uses the PA system to ask if anyone can help, you quickly volunteer.
The navigation instructions (your puzzle input) consists of a sequence of single-character actions paired with integer input values. After staring at them for a few minutes, you work out what they probably mean:
Action N means to move north by the given value.
Action S means to move south by the given value.
Action E means to move east by the given value.
Action W means to move west by the given value.
Action L means to turn left the given number of degrees.
Action R means to turn right the given number of degrees.
Action F means to move forward by the given value in the direction the ship is currently facing.
The ship starts by facing east. Only the L and R actions change the direction the ship is facing. (That is, if the ship is facing east and the next instruction is N10, the ship would move north 10 units, but would still move east if the following action were F.)
For example:
F10
N3
F7
R90
F11
These instructions would be handled as follows:
F10 would move the ship 10 units east (because the ship starts by facing east) to east 10, north 0.
N3 would move the ship 3 units north to east 10, north 3.
F7 would move the ship another 7 units east (because the ship is still facing east) to east 17, north 3.
R90 would cause the ship to turn right by 90 degrees and face south; it remains at east 17, north 3.
F11 would move the ship 11 units south to east 17, south 8.
At the end of these instructions, the ship's Manhattan distance (sum of the absolute values of its east/west position and its north/south position) from its starting position is 17 + 8 = 25.
Figure out where the navigation instructions lead. What is the Manhattan distance between that location and the ship's starting position?
--- Part Two ---
Before you can give the destination to the captain, you realize that the actual action meanings were printed on the back of the instructions the whole time.
Almost all of the actions indicate how to move a waypoint which is relative to the ship's position:
Action N means to move the waypoint north by the given value.
Action S means to move the waypoint south by the given value.
Action E means to move the waypoint east by the given value.
Action W means to move the waypoint west by the given value.
Action L means to rotate the waypoint around the ship left (counter-clockwise) the given number of degrees.
Action R means to rotate the waypoint around the ship right (clockwise) the given number of degrees.
Action F means to move forward to the waypoint a number of times equal to the given value.
The waypoint starts 10 units east and 1 unit north relative to the ship. The waypoint is relative to the ship; that is, if the ship moves, the waypoint moves with it.
For example, using the same instructions as above:
F10 moves the ship to the waypoint 10 times (a total of 100 units east and 10 units north), leaving the ship at east 100, north 10. The waypoint stays 10 units east and 1 unit north of the ship.
N3 moves the waypoint 3 units north to 10 units east and 4 units north of the ship. The ship remains at east 100, north 10.
F7 moves the ship to the waypoint 7 times (a total of 70 units east and 28 units north), leaving the ship at east 170, north 38. The waypoint stays 10 units east and 4 units north of the ship.
R90 rotates the waypoint around the ship clockwise 90 degrees, moving it to 4 units east and 10 units south of the ship. The ship remains at east 170, north 38.
F11 moves the ship to the waypoint 11 times (a total of 44 units east and 110 units south), leaving the ship at east 214, south 72. The waypoint stays 4 units east and 10 units south of the ship.
After these operations, the ship's Manhattan distance from its starting position is 214 + 72 = 286.
Figure out where the navigation instructions actually lead. What is the Manhattan distance between that location and the ship's starting position?

View File

@ -0,0 +1,795 @@
N5
W1
F61
W2
R90
F50
N2
F40
E4
F48
R180
F17
W4
N5
F3
W3
F1
R90
S2
F23
L90
S3
W3
S4
E4
L90
W3
S3
E4
N2
F28
S2
W2
L180
E3
R90
E3
F83
W5
S4
W3
N2
W5
F90
N2
F82
N2
F2
S4
L90
N3
L90
S2
F12
S3
F40
L90
F56
N1
F29
W2
S2
R270
S4
F14
E4
R90
E2
S2
E2
F82
L90
N3
R180
R90
S1
W1
L90
S2
F78
W2
F52
N4
W5
F38
L90
W2
S2
L90
F66
R90
F62
E3
S5
L90
F99
F2
E4
R90
N3
W4
N1
F71
E2
N3
N2
R90
E2
F66
S4
R90
E5
F29
E5
L90
W2
N2
E3
F18
L180
F17
W1
R90
W3
S5
R90
S3
R180
N5
F69
W1
W3
L180
F72
W5
N1
R180
W3
W4
F85
W4
L90
E4
N5
F73
R90
F70
E4
F79
S5
R180
E2
F35
E4
L270
W2
L90
N5
R90
N4
F64
W2
R270
F33
N5
E4
F94
W1
N1
R90
F79
F46
E1
R180
S3
W3
F72
E1
W4
F95
W2
L90
N3
L90
F85
W3
W1
F54
N3
E1
N4
E5
L90
F61
W2
F7
L180
F87
N4
W1
F87
F3
E3
F63
R90
S4
R180
S4
R180
R90
R90
E5
N4
E2
F86
S3
F98
N4
F70
L90
E4
F26
W4
F19
L90
S4
W4
F84
N1
E4
L180
S2
F74
S1
F86
R90
S2
F78
N4
S2
W1
N5
E2
F38
W4
N1
F75
S1
E1
N3
S1
F54
N3
F88
N5
L180
F15
S2
S2
E2
N3
F97
S3
N3
E3
N5
E3
R90
F87
L90
F15
L90
E5
R90
F70
N3
W2
F47
W2
W3
F17
R90
F95
E4
F28
W4
R90
E2
R180
N4
R180
W4
R270
F73
W1
N2
L90
S1
F65
E1
F42
N2
F74
R90
F21
W5
S1
N5
R90
E4
N5
S5
F99
W4
L180
W1
F83
N2
W2
F87
E2
S3
W1
L180
F89
S1
W2
E2
L90
S2
W1
S5
R180
E5
N1
F82
S3
F7
L90
F31
L90
N3
F84
W3
N4
F100
N1
E2
R90
F90
N3
F43
R90
F2
W4
L90
F87
L90
E3
F71
L180
N1
L90
E4
N3
F31
W1
F80
R270
N1
E4
N1
F22
N4
E1
F57
R90
N3
W2
L180
N3
L180
W4
F59
S4
F10
N5
L90
S3
L90
E1
F96
E4
N3
F54
L180
F47
W1
N4
E1
S4
R180
L90
N1
R90
N3
R90
N4
R90
S3
F59
N5
L90
E4
F72
W4
F76
R90
E3
F70
L180
N3
W2
R90
F65
L90
F71
S3
F43
R90
W2
N2
R90
W1
R90
S4
R180
S1
E3
F72
L90
F61
L90
F75
S1
S5
F15
R90
E3
N2
L270
F48
N1
R180
W2
F69
E4
R90
R90
W1
S5
W5
R90
S4
S3
F51
F43
E2
N5
L180
F89
W1
R90
F59
R90
E2
F51
R90
F91
W4
S5
E4
L90
S5
R90
F44
F47
E4
W1
F77
S5
R90
N2
F87
N4
R90
W5
R90
W5
F89
L90
F61
E2
F29
N4
R90
F31
S1
L90
E5
N2
F7
L180
S4
F63
W4
N5
S2
N1
E5
F87
S5
R180
F14
W4
R180
E1
L90
F67
E2
L90
E5
S2
L90
W2
R90
F94
W4
R90
W3
S3
R90
N5
F55
L90
F43
L90
N5
F16
E4
N2
L270
W3
E1
N2
R180
F51
N5
N1
F36
W4
F38
N5
W1
F29
R180
L90
N1
W3
E1
F78
E1
N1
E2
F57
E4
F83
W5
F32
N3
W4
F36
N2
E3
F74
N4
F54
W5
L90
S1
F42
W4
S5
E3
F64
W2
R180
S2
E1
N2
R90
W3
F36
N3
R90
S2
F53
W2
F85
E5
N2
F9
E1
F83
L90
E5
F44
L90
F92
W5
R270
E4
S1
F6
L90
F96
R90
N1
E4
N1
W3
S2
S4
F39
E1
S1
F82
S3
F78
L90
N4
E1
N2
R90
F63
S3
L180
F52
W2
F49
W2
L270
N1
R180
E3
F79
F73
N1
R90
N3
R180
S2
F35
S1
F43
S1
R90
S4
W4
F12
S1
F2
N3
E4
L90
F51
R90
N4
F90
R90
F99
E3
N1
R90
S3
L270
W5
L90
R270
F50
N5
F33
S3
F18
L90
E4
L180
W4
R90
F21
W4
F24
W2
E5
N3
W1
R90
W3
S3
F82
W1
S1
F12
N3
L90
F37
R180
F36
F27
E3
S3
F36
W4
S1
F6
R90
F59
S1
E1
R180
S2
W3
L90
F45
R90
E1
F29
S5
W3
S5
W4
L270
S2
F13
E4
F28
R90
F80
S4
E1
S2
F62
R90
F26
L180
F19
W2
L180
W5
F15
N1
F68
E4
F75
S2
F58
S4
R180
E3
N1
L90
S2
F12
R90
E5
S5
W4
N5
W1
R180
S1
F70
R90
F97
L90
E3
S3
L270
E1
F51
N4
L180
N1
R90
F42

View File

@ -0,0 +1,108 @@
use crate::common::AdventOfCodeDay;
#[derive(Debug)]
enum CType {
North,
East,
South,
West,
TurnRight,
TurnLeft,
Forward,
}
#[derive(Debug)]
pub struct Day12 {
input: Vec<(CType, i32)>,
}
impl Day12 {
pub fn new() -> Self {
let input_bytes = include_bytes!("../res/12_input.txt");
let input_str = String::from_utf8_lossy(input_bytes);
let data = input_str
.lines()
.map(Day12::parse_cmd)
.collect::<Vec<(CType, i32)>>();
Self {
input: data
}
}
fn parse_cmd(line: &str) -> (CType, i32) {
(match &line[0..1] {
"N" => CType::North,
"E" => CType::East,
"S" => CType::South,
"W" => CType::West,
"L" => CType::TurnLeft,
"R" => CType::TurnRight,
"F" => CType::Forward,
_ => panic!(),
}, line[1..].parse::<i32>().unwrap())
}
}
impl AdventOfCodeDay for Day12 {
fn task_1(&self) -> String {
if is_verbose!() {
for e in &self.input { verboseln!("{:?}", e); }
verboseln!();
verboseln!();
}
let deltas: [(i32,i32); 4] = [(1,0),(0,1),(-1,0),(0,-1)];
let mut x: i32 = 0;
let mut y: i32 = 0;
let mut d: i32 = 0;
for cmd in &self.input {
match cmd.0 {
CType::North => { y -= cmd.1; },
CType::East => { x += cmd.1; },
CType::South => { y += cmd.1; },
CType::West => { x -= cmd.1; },
CType::TurnLeft => { d = (d + 16 - (cmd.1 / 90)) % 4 },
CType::TurnRight => { d = (d + 16 + (cmd.1 / 90)) % 4 },
CType::Forward => { x += deltas[d as usize].0 * cmd.1; y += deltas[d as usize].1 * cmd.1; },
}
verboseln!("[{},{}|{}] {:?}", x, y, d, cmd);
}
return (x.abs() + y.abs()).to_string();
}
fn task_2(&self) -> String {
let mut ship_x: i32 = 0;
let mut ship_y: i32 = 0;
let mut wp_x: i32 = 10;
let mut wp_y: i32 = 1;
verboseln!("Ship:[{},{}] WP:[{},{}]", ship_x, ship_y, wp_x, wp_y);
for cmd in &self.input {
match cmd.0 {
CType::North => { wp_y += cmd.1; },
CType::East => { wp_x += cmd.1; },
CType::South => { wp_y -= cmd.1; },
CType::West => { wp_x -= cmd.1; },
CType::TurnLeft => { for _ in 0..(cmd.1/90) { (wp_x, wp_y) = (-wp_y, wp_x); } },
CType::TurnRight => { for _ in 0..(cmd.1/90) { (wp_x, wp_y) = ( wp_y, -wp_x); } },
CType::Forward => { ship_x = ship_x + wp_x*cmd.1; ship_y = ship_y + wp_y*cmd.1; },
}
verboseln!("Ship:[{},{}] WP:[{},{}] {:?}", ship_x, ship_y, wp_x, wp_y, cmd);
}
return (ship_x.abs() + ship_y.abs()).to_string();
}
}

View File

@ -0,0 +1,112 @@
--- Day 13: Shuttle Search ---
Your ferry can make it safely to a nearby port, but it won't get much further. When you call to book another ship, you discover that no ships embark from that port to your vacation island. You'll need to get from the port to the nearest airport.
Fortunately, a shuttle bus service is available to bring you from the sea port to the airport! Each bus has an ID number that also indicates how often the bus leaves for the airport.
Bus schedules are defined based on a timestamp that measures the number of minutes since some fixed reference point in the past. At timestamp 0, every bus simultaneously departed from the sea port. After that, each bus travels to the airport, then various other locations, and finally returns to the sea port to repeat its journey forever.
The time this loop takes a particular bus is also its ID number: the bus with ID 5 departs from the sea port at timestamps 0, 5, 10, 15, and so on. The bus with ID 11 departs at 0, 11, 22, 33, and so on. If you are there when the bus departs, you can ride that bus to the airport!
Your notes (your puzzle input) consist of two lines. The first line is your estimate of the earliest timestamp you could depart on a bus. The second line lists the bus IDs that are in service according to the shuttle company; entries that show x must be out of service, so you decide to ignore them.
To save time once you arrive, your goal is to figure out the earliest bus you can take to the airport. (There will be exactly one such bus.)
For example, suppose you have the following notes:
939
7,13,x,x,59,x,31,19
Here, the earliest timestamp you could depart is 939, and the bus IDs in service are 7, 13, 59, 31, and 19. Near timestamp 939, these bus IDs depart at the times marked D:
time bus 7 bus 13 bus 59 bus 31 bus 19
929 . . . . .
930 . . . D .
931 D . . . D
932 . . . . .
933 . . . . .
934 . . . . .
935 . . . . .
936 . D . . .
937 . . . . .
938 D . . . .
939 . . . . .
940 . . . . .
941 . . . . .
942 . . . . .
943 . . . . .
944 . . D . .
945 D . . . .
946 . . . . .
947 . . . . .
948 . . . . .
949 . D . . .
The earliest bus you could take is bus ID 59. It doesn't depart until timestamp 944, so you would need to wait 944 - 939 = 5 minutes before it departs. Multiplying the bus ID by the number of minutes you'd need to wait gives 295.
What is the ID of the earliest bus you can take to the airport multiplied by the number of minutes you'll need to wait for that bus?
--- Part Two ---
The shuttle company is running a contest: one gold coin for anyone that can find the earliest timestamp such that the first bus ID departs at that time and each subsequent listed bus ID departs at that subsequent minute. (The first line in your input is no longer relevant.)
For example, suppose you have the same list of bus IDs as above:
7,13,x,x,59,x,31,19
An x in the schedule means there are no constraints on what bus IDs must depart at that time.
This means you are looking for the earliest timestamp (called t) such that:
Bus ID 7 departs at timestamp t.
Bus ID 13 departs one minute after timestamp t.
There are no requirements or restrictions on departures at two or three minutes after timestamp t.
Bus ID 59 departs four minutes after timestamp t.
There are no requirements or restrictions on departures at five minutes after timestamp t.
Bus ID 31 departs six minutes after timestamp t.
Bus ID 19 departs seven minutes after timestamp t.
The only bus departures that matter are the listed bus IDs at their specific offsets from t. Those bus IDs can depart at other times, and other bus IDs can depart at those times. For example, in the list above, because bus ID 19 must depart seven minutes after the timestamp at which bus ID 7 departs, bus ID 7 will always also be departing with bus ID 19 at seven minutes after timestamp t.
In this example, the earliest timestamp at which this occurs is 1068781:
time bus 7 bus 13 bus 59 bus 31 bus 19
1068773 . . . . .
1068774 D . . . .
1068775 . . . . .
1068776 . . . . .
1068777 . . . . .
1068778 . . . . .
1068779 . . . . .
1068780 . . . . .
1068781 D . . . .
1068782 . D . . .
1068783 . . . . .
1068784 . . . . .
1068785 . . D . .
1068786 . . . . .
1068787 . . . D .
1068788 D . . . D
1068789 . . . . .
1068790 . . . . .
1068791 . . . . .
1068792 . . . . .
1068793 . . . . .
1068794 . . . . .
1068795 D D . . .
1068796 . . . . .
1068797 . . . . .
In the above example, bus ID 7 departs at timestamp 1068788 (seven minutes after t). This is fine; the only requirement on that minute is that bus ID 19 departs then, and it does.
Here are some other examples:
The earliest timestamp that matches the list 17,x,13,19 is 3417.
67,7,59,61 first occurs at timestamp 754018.
67,x,7,59,61 first occurs at timestamp 779210.
67,7,x,59,61 first occurs at timestamp 1261476.
1789,37,47,1889 first occurs at timestamp 1202161486.
However, with so many bus IDs in your list, surely the actual earliest timestamp will be larger than 100000000000000!
What is the earliest timestamp such that all of the listed bus IDs depart at offsets matching their positions in the list?

View File

@ -0,0 +1,2 @@
1000391
19,x,x,x,x,x,x,x,x,x,x,x,x,37,x,x,x,x,x,383,x,x,x,x,x,x,x,23,x,x,x,x,13,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,29,x,457,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,17

View File

@ -0,0 +1,94 @@
use crate::common::AdventOfCodeDay;
pub struct Day13 {
input_time: u32,
input_bus: Vec<Option<u32>>,
}
impl Day13 {
pub fn new() -> Self {
let input_bytes = include_bytes!("../res/13_input.txt");
let input_str = String::from_utf8_lossy(input_bytes);
let t = input_str.lines().next().unwrap().parse::<u32>().unwrap();
let b = input_str.lines().skip(1).next().unwrap().split(',').map(|p| p.parse::<u32>().ok()).collect::<Vec<Option<u32>>>();
Self {
input_time: t,
input_bus: b,
}
}
fn ext_euclid(a: i128, b: i128) -> (i128, i128, i128) {
if a == 0 {
return (b, 0, 1);
}
let (gcd, x1, y1) = Day13::ext_euclid(b%a, a);
let x = y1 - (b/a) * x1;
let y = x1;
return (gcd, x, y);
}
}
impl AdventOfCodeDay for Day13 {
fn task_1(&self) -> String {
let mut b = self.input_bus
.iter()
.flat_map(|p| p.iter())
.map(|p| *p)
.collect::<Vec<u32>>();
b.sort_by(|a,b| (self.input_time % b).cmp(&(self.input_time % a)));
verboseln!("{}", self.input_time);
verboseln!("{:?}", b);
verboseln!("{:?}", b.iter().map(|p| p - self.input_time % p).collect::<Vec<u32>>());
return (b[0] * (b[0] - self.input_time % b[0])).to_string();
}
fn task_2(&self) -> String {
// https://en.wikipedia.org/wiki/Chinese_remainder_theorem
// https://mathepedia.de/Chinesischer_Restsatz.html
let formulas = self.input_bus
.iter()
.enumerate()
.filter(|(_,p)| p.is_some())
.map(|(i,p)| (i, p.unwrap()))
.map(|(i,p)| ((-(i as i128) % p as i128 + p as i128) as i128 % p as i128, p as i128))
.collect::<Vec<(i128, i128)>>();
if is_verbose!() {
verboseln!();
//for (i,b) in &formulas { verboseln!("t = {: <3} | {: <3}", i, b); }
for (i,b) in &formulas { verboseln!("t % {: <3} = {: <3}", b, i); }
verboseln!();
}
let mut m = 1;
for (_, mi) in &formulas { m *= mi; }
let mut x = 0;
for (ai, mi) in &formulas {
let (gcd, ri, si) = Day13::ext_euclid(*mi as i128, m / *mi as i128);
let ei = si * (m / *mi as i128);
x += ai * ei;
verbosedbg!(m, m / *mi as i128, ai, mi, gcd, ri, si, ei, x);
verboseln!();
}
x = ((x % m) + m) % m;
return x.to_string() //TODO
}
}

View File

@ -0,0 +1,95 @@
--- Day 14: Docking Data ---
As your ferry approaches the sea port, the captain asks for your help again. The computer system that runs this port isn't compatible with the docking program on the ferry, so the docking parameters aren't being correctly initialized in the docking program's memory.
After a brief inspection, you discover that the sea port's computer system uses a strange bitmask system in its initialization program. Although you don't have the correct decoder chip handy, you can emulate it in software!
The initialization program (your puzzle input) can either update the bitmask or write a value to memory. Values and memory addresses are both 36-bit unsigned integers. For example, ignoring bitmasks for a moment, a line like mem[8] = 11 would write the value 11 to memory address 8.
The bitmask is always given as a string of 36 bits, written with the most significant bit (representing 2^35) on the left and the least significant bit (2^0, that is, the 1s bit) on the right. The current bitmask is applied to values immediately before they are written to memory: a 0 or 1 overwrites the corresponding bit in the value, while an X leaves the bit in the value unchanged.
For example, consider the following program:
mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
mem[8] = 11
mem[7] = 101
mem[8] = 0
This program starts by specifying a bitmask (mask = ....). The mask it specifies will overwrite two bits in every written value: the 2s bit is overwritten with 0, and the 64s bit is overwritten with 1.
The program then attempts to write the value 11 to memory address 8. By expanding everything out to individual bits, the mask is applied as follows:
value: 000000000000000000000000000000001011 (decimal 11)
mask: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
result: 000000000000000000000000000001001001 (decimal 73)
So, because of the mask, the value 73 is written to memory address 8 instead. Then, the program tries to write 101 to address 7:
value: 000000000000000000000000000001100101 (decimal 101)
mask: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
result: 000000000000000000000000000001100101 (decimal 101)
This time, the mask has no effect, as the bits it overwrote were already the values the mask tried to set. Finally, the program tries to write 0 to address 8:
value: 000000000000000000000000000000000000 (decimal 0)
mask: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
result: 000000000000000000000000000001000000 (decimal 64)
64 is written to address 8 instead, overwriting the value that was there previously.
To initialize your ferry's docking program, you need the sum of all values left in memory after the initialization program completes. (The entire 36-bit address space begins initialized to the value 0 at every address.) In the above example, only two values in memory are not zero - 101 (at address 7) and 64 (at address 8) - producing a sum of 165.
Execute the initialization program. What is the sum of all values left in memory after it completes?
--- Part Two ---
For some reason, the sea port's computer system still can't communicate with your ferry's docking program. It must be using version 2 of the decoder chip!
A version 2 decoder chip doesn't modify the values being written at all. Instead, it acts as a memory address decoder. Immediately before a value is written to memory, each bit in the bitmask modifies the corresponding bit of the destination memory address in the following way:
If the bitmask bit is 0, the corresponding memory address bit is unchanged.
If the bitmask bit is 1, the corresponding memory address bit is overwritten with 1.
If the bitmask bit is X, the corresponding memory address bit is floating.
A floating bit is not connected to anything and instead fluctuates unpredictably. In practice, this means the floating bits will take on all possible values, potentially causing many memory addresses to be written all at once!
For example, consider the following program:
mask = 000000000000000000000000000000X1001X
mem[42] = 100
mask = 00000000000000000000000000000000X0XX
mem[26] = 1
When this program goes to write to memory address 42, it first applies the bitmask:
address: 000000000000000000000000000000101010 (decimal 42)
mask: 000000000000000000000000000000X1001X
result: 000000000000000000000000000000X1101X
After applying the mask, four bits are overwritten, three of which are different, and two of which are floating. Floating bits take on every possible combination of values; with two floating bits, four actual memory addresses are written:
000000000000000000000000000000011010 (decimal 26)
000000000000000000000000000000011011 (decimal 27)
000000000000000000000000000000111010 (decimal 58)
000000000000000000000000000000111011 (decimal 59)
Next, the program is about to write to memory address 26 with a different bitmask:
address: 000000000000000000000000000000011010 (decimal 26)
mask: 00000000000000000000000000000000X0XX
result: 00000000000000000000000000000001X0XX
This results in an address with three floating bits, causing writes to eight memory addresses:
000000000000000000000000000000010000 (decimal 16)
000000000000000000000000000000010001 (decimal 17)
000000000000000000000000000000010010 (decimal 18)
000000000000000000000000000000010011 (decimal 19)
000000000000000000000000000000011000 (decimal 24)
000000000000000000000000000000011001 (decimal 25)
000000000000000000000000000000011010 (decimal 26)
000000000000000000000000000000011011 (decimal 27)
The entire 36-bit address space still begins initialized to the value 0 at every address, and you still need the sum of all values left in memory at the end of the program. In this example, the sum is 208.
Execute the initialization program using an emulator for a version 2 decoder chip. What is the sum of all values left in memory after it completes?

View File

@ -0,0 +1,546 @@
mask = 01100101XX0010111010X010X10001010111
mem[59869] = 296403277
mem[50029] = 14565
mem[52488] = 627950233
mem[48318] = 113982010
mem[22257] = 82
mem[27870] = 17795
mem[55511] = 4594118
mask = 00000X00000110111110X000XX00010XX001
mem[61743] = 13086
mem[3724] = 4029841
mem[10560] = 236422779
mem[28511] = 7957
mem[32609] = 3123
mem[3930] = 26884
mask = 0110000XX1001011111X111010X010000100
mem[42884] = 252696502
mem[18565] = 820
mem[28279] = 105604729
mem[41611] = 1567094
mem[36341] = 5551
mem[35962] = 28056
mask = X111X001010010X1111X0XX1X11X10001X00
mem[52299] = 24969
mem[41449] = 160272674
mem[34903] = 14302599
mem[35962] = 71766
mask = X11001010XX010111010XX10100000X00101
mem[44250] = 536
mem[21842] = 494315083
mem[51716] = 3417
mem[37939] = 242985
mask = 111100X1010XX011X1111100X000000010X0
mem[35845] = 48792746
mem[26794] = 1026647
mem[47814] = 92296
mem[63043] = 3100
mem[26635] = 2181
mem[40164] = 2436842
mask = 0X1111X0X10110101011X100011X01010010
mem[63001] = 36102371
mem[47565] = 2512786
mask = 010X000111X1X01X1110XX01111100101X10
mem[18403] = 512
mem[58372] = 65318068
mem[53197] = 15875
mem[58632] = 231362257
mask = 0X1010X11110101X011000X0000000111001
mem[4095] = 116134614
mem[63365] = 186252884
mem[19024] = 2449
mem[30536] = 1021
mem[49282] = 447504
mem[16658] = 98394885
mask = 0111000111001011X11011000X1111X0100X
mem[64187] = 1431
mem[11141] = 1904
mem[39855] = 61495
mask = 1111000XX100X01X111111111110XX011X11
mem[44407] = 1449308
mem[43902] = 2006
mem[62547] = 3478
mask = 0X1010010100X011101000X00010X0100111
mem[3885] = 140726549
mem[3307] = 938307640
mem[22257] = 71231
mem[41243] = 508095
mem[25091] = 24579
mask = X0000000XX011011111010X000XX0X000X01
mem[22764] = 96570583
mem[36352] = 56148675
mask = 0X0X0011X110111010X001X10XX000101010
mem[38443] = 1755
mem[56360] = 25308
mask = 11X0X00000X11X11111001XXXXX100001111
mem[7833] = 785
mem[4380] = 2874
mask = 0X1000X11X0XX0X1101001011110001X0000
mem[61544] = 144576256
mem[2156] = 1658
mem[26571] = 28977534
mem[43902] = 1032904266
mem[21524] = 463
mask = 100X000010011011111XX01010001010X101
mem[47123] = 5438
mem[28936] = 39885
mem[55045] = 946386
mem[43630] = 143495580
mem[10560] = 3231
mask = 0110000X1X00101111XXX0000000010010X1
mem[39551] = 524769
mem[37150] = 397326
mem[153] = 2696665
mem[43255] = 44
mem[14355] = 14827
mem[51242] = 445851
mask = X1X000X1110X10111X101100100X0X000XX0
mem[40969] = 756383545
mem[26794] = 100307329
mem[48938] = 1863389
mem[2345] = 2535119
mem[53880] = 1759799
mask = 11X0X0001X0110111X001X0011XX000XX000
mem[8343] = 11387
mem[48589] = 60
mem[27590] = 5929131
mem[3690] = 63744500
mem[520] = 31249543
mem[24387] = 473
mem[21573] = 32235112
mask = 11101001011X10111X10X111X00000000000
mem[50565] = 563
mem[26571] = 3496
mem[3930] = 418
mem[35770] = 7558838
mem[12614] = 1619627
mask = 011X010111001X11111001100000X00XX1X1
mem[50701] = 111977200
mem[19006] = 10909
mem[16052] = 74134
mem[43094] = 14253
mem[50557] = 608639
mem[59406] = 1422
mask = 110X00001101101X11100XX011X000000011
mem[52383] = 4751812
mem[1669] = 833448227
mem[35841] = 439768021
mem[43630] = 7511
mem[53126] = 343642
mem[60802] = 1256603
mask = 11100XXX11XX101111101100000X00X01010
mem[49511] = 4982217
mem[51824] = 270
mem[51349] = 1890
mem[59808] = 3773655
mask = 111000XX110X10X11110011010110101101X
mem[57730] = 57401
mem[35630] = 973239
mem[54672] = 138240715
mem[8136] = 10996
mem[55459] = 401980
mem[17187] = 941
mask = X111XX01X100101111X00X0001000000X011
mem[41484] = 1242838
mem[29717] = 1145160
mem[27394] = 1108224
mem[2816] = 272760856
mask = 1XX00101000010111010X1111000X0010010
mem[32201] = 304518
mem[16394] = 79826575
mem[39941] = 13157
mem[35282] = 760997
mem[63951] = 7011404
mem[8985] = 123284486
mask = 011X100111000011X110X0110000X1111010
mem[34856] = 39388801
mem[18190] = 3208452
mask = 1X000X11XX1010111X10001111X00X101X00
mem[32295] = 1729184
mem[48809] = 3708309
mem[17960] = 66227
mem[39063] = 5571972
mem[34523] = 1100265
mem[17724] = 1074235
mask = 1X000000100110X111101X1001010000010X
mem[2309] = 1178
mem[56623] = 5006
mem[41091] = 951374
mem[63942] = 21970475
mem[8120] = 1167
mem[50184] = 5634
mask = 11X0001X111111X11010100XX0101X111000
mem[63703] = 31429
mem[19083] = 32307
mem[48832] = 3825073
mask = 11X000111111X11110X00000001000011X11
mem[53491] = 953
mem[39752] = 91899271
mask = 111XX011X1011011111XX110X00X00000000
mem[63089] = 3036
mem[38445] = 356279
mem[40137] = 10955
mem[37568] = 477812
mem[18443] = 85
mask = 11X1100101X0101111X000X001X111101XX1
mem[64998] = 758355504
mem[10506] = 5946
mem[58372] = 800
mem[40606] = 1267021
mem[42753] = 86680
mem[38503] = 9164580
mask = 1X110000XX100000X100010001110000X010
mem[4805] = 898
mem[50969] = 219378
mem[3182] = 14757
mask = 01101X0111X01011X0X000000111X0101001
mem[26794] = 289
mem[27899] = 67683
mask = X1X0001111XX1X1X10X0X0111110000010X0
mem[60968] = 128881
mem[21049] = 153946
mem[4625] = 6492
mem[13554] = 14536684
mask = 1110100X1X0110111X001011X1111X0X010X
mem[49387] = 48190714
mem[5514] = 58395
mem[59861] = 2590
mem[59717] = 706
mask = 110000XX1101X01111100001111000X00000
mem[52288] = 594838
mem[47711] = 256545
mem[37150] = 5576185
mask = X1001000100X101110X0X1001X01X1X00X0X
mem[12194] = 1010012
mem[55682] = 745
mem[19810] = 54828
mask = X111100111001011X10X0110110X00000011
mem[10747] = 10766086
mem[40969] = 6443091
mem[2563] = 7520
mask = X110X001X10010111X1001X0001010X00X11
mem[16385] = 16194
mem[9178] = 1770
mem[3885] = 584370
mem[32909] = 551495
mem[21842] = 534
mem[59406] = 4042521
mask = X110X0001100101X11100X00XXX0X00000X1
mem[62127] = 1228052
mem[34922] = 165241779
mem[38187] = 7559
mask = 00X101X111X0X1X1011010001X11111X0111
mem[37035] = 51004
mem[64187] = 9284
mem[38834] = 163012800
mask = 0X1X1001110010X111101X00101101001011
mem[41856] = 13039831
mem[63376] = 1043992
mask = 00X000000X01X01111X01X011001101X11X0
mem[14490] = 10619
mem[63497] = 64
mem[8985] = 2445
mem[3372] = 2134806
mem[43902] = 25402
mem[63408] = 2150231
mem[35251] = 252
mask = 01100001010X101X11X0XX0X000010000010
mem[11427] = 40388
mem[5594] = 2064
mem[14642] = 3216356
mem[33886] = 16148
mem[22872] = 317877
mem[16905] = 22391
mem[59260] = 14964908
mask = 11X01000X10X1011110010000101X1XXX1X0
mem[40205] = 162183
mem[52774] = 21039251
mem[47529] = 13977
mask = 111X1X0101X0101111100X1011X10X0001XX
mem[50214] = 131677558
mem[37828] = 45776303
mem[25486] = 270926
mem[3307] = 100144082
mask = 0X1X0101110011X1XX1010X010001X00X110
mem[24709] = 4703889
mem[20251] = 4768780
mem[23739] = 292844
mem[33886] = 59676
mem[29424] = 157758852
mem[48117] = 434386871
mask = 111010010100X01X1X10101111XX10000X00
mem[24094] = 50839
mem[40525] = 62507
mem[16058] = 11731
mem[57853] = 286
mem[13702] = 252
mem[61517] = 92673
mem[28899] = 10302
mask = 0X101000011X10X111001X10101001011010
mem[39054] = 164757015
mem[46804] = 194909
mem[17096] = 16017
mem[50214] = 474
mem[55787] = 471712
mask = 010X0X0X110110111X1X10000X000XX011X0
mem[50969] = 44594
mem[62079] = 4008
mem[26760] = 1302
mem[40242] = 450994
mask = 00100000000010X1010011X100X10X000111
mem[13951] = 29184
mem[44387] = 733
mem[56481] = 1419987
mem[21049] = 113460142
mask = 111000X01101101X10001X01110X01000001
mem[37955] = 23023
mem[23639] = 7326
mem[41939] = 125079
mask = 010X101X00X110XXX011010100X10011100X
mem[4000] = 325975899
mem[65121] = 332644116
mem[41463] = 345
mem[16748] = 1087582
mem[37842] = 894
mask = X110100111X01011X11011XX00X0101X0001
mem[19704] = 11095
mem[8715] = 72847
mem[41939] = 6370749
mem[12294] = 6805400
mem[21842] = 79
mask = 01XX1X10XX011X1X101X01010001X1010011
mem[50017] = 55985
mem[49915] = 1470
mem[38942] = 1053875
mem[16748] = 874238254
mem[59353] = 678489
mem[57733] = 14739
mask = 111111XX01X010X11110000001X11000111X
mem[40606] = 199
mem[17692] = 1696176
mem[11913] = 4169294
mask = 01101X0X01001011101XXX10001100001010
mem[23120] = 237551058
mem[28299] = 142
mask = 1X10X0011110101X1X1X11001100110X1001
mem[6118] = 115871
mem[19568] = 514315
mem[24764] = 365
mask = 1110X0X11X0XX0X1111X11011X0000000000
mem[47355] = 25865880
mem[51774] = 163286264
mem[37432] = 2954
mem[31036] = 12067
mask = 01110X01110010111XX001100001010X1101
mem[28516] = 323191
mem[43255] = 3274
mem[58073] = 86929637
mask = 01XX0001XX11001111X0X100X1010X101000
mem[18330] = 378470
mem[39651] = 1052033
mem[7784] = 143118549
mem[32641] = 10950293
mem[4029] = 836004
mask = 0110010X0100XX1X10101010101000X01110
mem[64998] = 399249156
mem[16391] = 2391
mem[15113] = 25159
mem[35039] = 1672488
mem[44901] = 4947519
mask = 001000X11101101X1X1000X0X00000111000
mem[23194] = 192980783
mem[2379] = 26471
mem[52040] = 748413
mask = XX101X11X1X01110X1100X0011X01110111X
mem[35610] = 3487435
mem[15827] = 1447
mem[52266] = 8003180
mem[6315] = 254747938
mem[38582] = 21341903
mem[23012] = 1942
mem[52040] = 1040637609
mask = 1110X011110XX0011111X001X000000111X0
mem[19431] = 6438
mem[55404] = 381
mem[49702] = 21205234
mem[28299] = 43345
mem[32419] = 3944214
mem[15970] = 1406843
mask = 0110X001XX010X01XX1X1010111001000000
mem[63608] = 2388415
mem[19550] = 397
mem[64770] = 354
mask = 011XX011X1101X10X11001X0X0001X101001
mem[27886] = 54971772
mem[61000] = 547
mem[9281] = 5472661
mem[32039] = 20450
mem[47529] = 214406
mem[32922] = 2186075
mask = X1X0000X0100101110X00100000010000101
mem[54996] = 136156
mem[1645] = 1422
mem[645] = 51359613
mask = 010X000110X100X1110000010011110010XX
mem[58473] = 54000741
mem[50214] = 118839
mem[60719] = 4225
mask = 11101000110010101X10X11011X00010X011
mem[4967] = 2810
mem[55561] = 270767273
mem[50906] = 323094280
mem[544] = 1779102
mem[12700] = 122462
mem[20654] = 71
mask = 01100001X0X1000101X011101X100000X00X
mem[40754] = 6033263
mem[3724] = 640
mem[6776] = 274
mask = 00110X0111001111X010110000X010X00110
mem[59461] = 40987
mem[49367] = 418940480
mem[12155] = 58648
mem[50876] = 55597938
mem[39338] = 125566
mask = 01100001X110101111X001101X1100X0100X
mem[16658] = 13293
mem[19410] = 355061209
mem[30127] = 9284451
mem[35805] = 2422
mask = 1X11X0010100X01X111X1101XX1101010011
mem[10560] = 116
mem[42153] = 4817997
mem[40333] = 970832
mem[19083] = 63018397
mask = 011XX0X111XX101111100XX0101010011010
mem[51898] = 95230576
mem[49059] = 481728904
mem[25416] = 1192004
mem[6045] = 244681888
mem[22225] = 208962448
mask = X11X100XX1X0101111XX1110101X110110X0
mem[10560] = 3688
mem[50016] = 3038
mem[25234] = 52018301
mask = X11XX001X100101111100110X011110X1XXX
mem[8343] = 111304110
mem[9100] = 833307
mem[43853] = 836994
mem[9178] = 24458493
mem[59596] = 257520799
mask = 101X0X0000100X0X010000X1X0010X0XX111
mem[13597] = 887
mem[16422] = 232
mem[52384] = 120276377
mem[10834] = 6933
mem[16058] = 992102418
mem[24456] = 92155
mask = X11000010100101111X01100001X10001XX1
mem[37568] = 26930
mem[16385] = 232190606
mem[8340] = 113193119
mem[35910] = 832
mask = 11111001010010111110100XX1X11X100111
mem[56429] = 6105943
mem[33886] = 8020
mem[51774] = 168714
mask = 1111100101101X11110000000X0110001X0X
mem[37828] = 28012
mem[51551] = 320681847
mem[34281] = 52088
mask = 0110X001110XX01111100010X00X010X1010
mem[36720] = 26721
mem[39098] = 8365128
mem[28279] = 994775
mem[59762] = 1466626
mem[17088] = 910296
mem[33578] = 4789
mem[31320] = 11279
mask = X1010000X1011011101001XX000X010011X1
mem[58476] = 20790
mem[33584] = 339
mem[21127] = 471449302
mask = 0100X01X1101X011X010010XX0000X011000
mem[39915] = 1754512
mem[51774] = 183707725
mem[43094] = 2797257
mem[21120] = 8809
mask = X010000X00XXX0X1X10010X11101X0100110
mem[48113] = 54854990
mem[43108] = 127392
mem[57733] = 4840137
mem[17088] = 7272071
mem[65436] = 1211
mask = X11010X01100101010100X11111000101X01
mem[38787] = 139
mem[9667] = 37073154
mem[18731] = 370
mem[4538] = 15900
mem[13202] = 517905282
mask = X11000011100001X1110X01001100X001010
mem[12467] = 932
mem[14070] = 12280
mem[40105] = 184487874
mem[33314] = 832859
mask = 0X100000X1001011X11X1000X10001X0X000
mem[17724] = 3496777
mem[53907] = 23167
mem[63544] = 1614248
mem[50209] = 2618603
mem[36348] = 384412976
mem[44536] = 16223523
mask = X110X1011X0011X11110X111X0X00001X000
mem[4784] = 11971978
mem[10982] = 398035940
mem[7005] = 515
mem[35241] = 1093398
mem[63779] = 1906
mask = 1100X00XX001101111X0X101X1010X001011
mem[36341] = 2194817
mem[40531] = 724
mem[5658] = 468782968
mem[62005] = 1168
mem[3491] = 1329281
mem[49511] = 672
mem[49173] = 1048435
mask = 1110XX0010X1101X11X01X1010011101010X
mem[44290] = 660182
mem[21184] = 291220
mem[39098] = 2769543
mem[30987] = 24159
mask = 1010X00X00100X1111000X011XX10100X110
mem[48117] = 29838
mem[23924] = 4158
mem[46502] = 501874
mem[32481] = 713511
mask = XX1000111XX1X01110X0X1001001X000100X
mem[11848] = 60796
mem[35576] = 125075628
mem[7365] = 367051456
mem[49453] = 2467302
mem[63274] = 2446
mask = X1100X01X10010111X10X10000X00000XXX1
mem[59406] = 7522
mem[26316] = 194122
mem[33419] = 24756556
mem[17066] = 827
mask = 111100010100001011111X101011X000X0X0
mem[28511] = 54553
mem[9469] = 136199
mem[6481] = 674106955
mem[4029] = 62909806
mask = 0010000000011X0X110X11X11XX100100011
mem[19006] = 23636330
mem[49695] = 113355
mem[9478] = 25169678
mem[26475] = 7337
mem[1712] = 89775255
mem[32101] = 917
mask = 1X00X00X1101101111X010X011100000XXX0
mem[24770] = 10592648
mem[40969] = 757841
mem[42211] = 7319070
mem[42753] = 277734
mem[30310] = 11988774
mem[19470] = 89618256
mem[2816] = 89780492

View File

@ -0,0 +1,130 @@
use crate::common::AdventOfCodeDay;
use std::collections::HashMap;
pub struct Day14 {
input: Vec<String>,
}
impl Day14 {
pub fn new() -> Self {
let input_bytes = include_bytes!("../res/14_input.txt");
let input_str = String::from_utf8_lossy(input_bytes);
let lines = input_str
.lines()
.map(|p| String::from(p))
.collect::<Vec<String>>();
Self {
input: lines
}
}
}
impl AdventOfCodeDay for Day14 {
fn task_1(&self) -> String {
let mut mask_set: u64 = 0;
let mut mask_unset: u64 = 0;
let mut mem: HashMap<u64, u64> = HashMap::new();
for line in &self.input {
if line.starts_with("mask = ") {
let strmask = &line[7..];
mask_set = u64::from_str_radix(&strmask.replace("X", "0"), 2).unwrap();
mask_unset = u64::from_str_radix(&strmask.replace("X", "1"), 2).unwrap();
verboseln!("Mask: {} -> set:{} | unset:{}", strmask, mask_set, mask_unset);
} else if line.starts_with("mem[") {
let addr = line.replace("mem[", "").replace("] =", "").split(' ').nth(0).unwrap().parse::<u64>().unwrap();
let value = line.replace("mem[", "").replace("] =", "").split(' ').nth(1).unwrap().parse::<u64>().unwrap();
let masked_val = (value | mask_set) & mask_unset;
mem.insert(addr, masked_val);
verboseln!("Set: {} := {} (orig: {})", addr, masked_val, value);
}
}
return mem.iter().map(|(_,v)| v).sum::<u64>().to_string();
}
fn task_2(&self) -> String {
let mask_36: u64 = 0b111111_111111_111111_111111_111111_111111;
let mut addr: Vec<(u64,u64)> = Vec::with_capacity(1024);
let mut mem: HashMap<u64, u64> = HashMap::new();
for line in &self.input {
if line.starts_with("mask = ") {
let strmask = &line[7..];
let mask_set = u64::from_str_radix(&strmask.replace("X", "0"), 2).unwrap();
let mask_unset = 0u64;
verboseln!("{0} | {0}", strmask);
verboseln!("{:0>36b} | {:0>36b}", mask_set, mask_unset);
verboseln!();
let floats = strmask.chars().rev().enumerate().filter(|(_,v)| *v == 'X').map(|(i,_)| i).collect::<Vec<usize>>();
addr.clear();
for fmask in 0..(2u64.pow(floats.len() as u32)) {
let mut nf_mask_set = mask_set;
let mut nf_mask_unset = mask_unset;
let mut ii = 0;
for i in &floats {
let fbmask = 1u64 << *i;
if fmask & (1<<ii) != 0 {
nf_mask_set = nf_mask_set | fbmask;
} else {
nf_mask_unset = nf_mask_unset | fbmask;
}
ii += 1;
}
addr.push((nf_mask_set, nf_mask_unset));
verboseln!("{:0>36b} | {:0>36b} ( {:0>10b} )", nf_mask_set, nf_mask_unset, fmask);
}
verboseln!();
verboseln!();
} else if line.starts_with("mem[") {
let val_addr = line.replace("mem[", "").replace("] =", "").split(' ').nth(0).unwrap().parse::<u64>().unwrap();
let val_value = line.replace("mem[", "").replace("] =", "").split(' ').nth(1).unwrap().parse::<u64>().unwrap();
for (mset,munset) in &addr {
let masked_addr = ((val_addr | mset) & !munset) & mask_36;
mem.insert(masked_addr, val_value);
}
verboseln!("Write into {} mems", addr.len());
verboseln!();
}
}
return mem.iter().map(|(_,v)| v).sum::<u64>().to_string();
}
}

View File

@ -75,5 +75,28 @@ return
[
['day' => 1, 'parts' => 2, 'title' => 'Report Repair', 'language' => 'rust', 'solutions' => ['1009899', '44211152'] ],
['day' => 2, 'parts' => 2, 'title' => 'Password Philosophy', 'language' => 'rust', 'solutions' => ['564', '325'] ],
['day' => 3, 'parts' => 2, 'title' => 'Toboggan Trajectory', 'language' => 'rust', 'solutions' => ['181', '1260601650'] ],
['day' => 4, 'parts' => 2, 'title' => 'Passport Processing', 'language' => 'rust', 'solutions' => ['222', '140'] ],
['day' => 5, 'parts' => 2, 'title' => 'Binary Boarding', 'language' => 'rust', 'solutions' => ['842', '617'] ],
['day' => 6, 'parts' => 2, 'title' => 'Custom Customs', 'language' => 'rust', 'solutions' => ['6683', '3122'] ],
['day' => 7, 'parts' => 2, 'title' => 'Handy Haversacks', 'language' => 'rust', 'solutions' => ['296', '9339'] ],
['day' => 8, 'parts' => 2, 'title' => 'Handheld Halting', 'language' => 'rust', 'solutions' => ['1684', '2188'] ],
['day' => 9, 'parts' => 2, 'title' => 'Encoding Error', 'language' => 'rust', 'solutions' => ['69316178', '9351526'] ],
['day' => 10, 'parts' => 2, 'title' => 'Adapter Array', 'language' => 'rust', 'solutions' => ['1904', '10578455953408'] ],
['day' => 11, 'parts' => 2, 'title' => 'Seating System', 'language' => 'rust', 'solutions' => ['2321', '2102'] ],
['day' => 12, 'parts' => 2, 'title' => 'Rain Risk', 'language' => 'rust', 'solutions' => ['2270', '138669'] ],
['day' => 13, 'parts' => 2, 'title' => 'Shuttle Search', 'language' => 'rust', 'solutions' => ['1915', '294354277694107'] ],
['day' => 14, 'parts' => 2, 'title' => 'Docking Data', 'language' => 'rust', 'solutions' => ['12408060320841', '4466434626828'] ],
//['day' => 15, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => ['', ''] ],
//['day' => 16, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => ['', ''] ],
//['day' => 17, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => ['', ''] ],
//['day' => 18, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => ['', ''] ],
//['day' => 19, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => ['', ''] ],
//['day' => 20, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => ['', ''] ],
//['day' => 21, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => ['', ''] ],
//['day' => 22, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => ['', ''] ],
//['day' => 23, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => ['', ''] ],
//['day' => 24, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => ['', ''] ],
//['day' => 25, 'parts' => 1, 'title' => '', 'language' => 'rust', 'solutions' => ['', ''] ],
],
];