From a391f550e2af9522e1c64d7695b4fa60257ca3a6 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Sat, 12 Dec 2020 11:05:59 +0000 Subject: [PATCH] Tidying, and adding problems --- advent05/src/advent05.hs | 7 +- problems/day04.html | 222 +++++++++++++++++++++++++++++++++++++++ problems/day05.html | 157 +++++++++++++++++++++++++++ problems/day06.html | 185 ++++++++++++++++++++++++++++++++ 4 files changed, 567 insertions(+), 4 deletions(-) create mode 100644 problems/day04.html create mode 100644 problems/day05.html create mode 100644 problems/day06.html diff --git a/advent05/src/advent05.hs b/advent05/src/advent05.hs index 06d0ecc..40a72a1 100644 --- a/advent05/src/advent05.hs +++ b/advent05/src/advent05.hs @@ -1,7 +1,7 @@ -- import Debug.Trace import Numeric -import qualified Data.Set as S +import Data.List main :: IO () main = @@ -12,12 +12,11 @@ main = part1 = maximum . map convert -part2 passes = S.elemAt 0 $ expecteds `S.difference` knowns +part2 passes = head $ expecteds \\ ns where ns = map convert passes highest = maximum ns lowest = minimum ns - knowns = S.fromList ns - expecteds = S.fromList [lowest..highest] + expecteds = [lowest..highest] directionToInt :: Char -> Int directionToInt dir = if dir `elem` "BR" then 1 else 0 diff --git a/problems/day04.html b/problems/day04.html new file mode 100644 index 0000000..0fa2d68 --- /dev/null +++ b/problems/day04.html @@ -0,0 +1,222 @@ + + + + +Day 4 - Advent of Code 2020 + + + + + + + +

Advent of Code

Neil Smith (AoC++) 8*

   0x0000|2020

+ + + +
+ +

--- 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?

+
+

Your puzzle answer was 247.

--- 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?

+
+

Your puzzle answer was 145.

Both parts of this puzzle are complete! They provide two gold stars: **

+

At this point, you should return to your Advent calendar and try another puzzle.

+

If you still want to see it, you can get your puzzle input.

+

You can also this puzzle.

+
+ + + + + + \ No newline at end of file diff --git a/problems/day05.html b/problems/day05.html new file mode 100644 index 0000000..461ddce --- /dev/null +++ b/problems/day05.html @@ -0,0 +1,157 @@ + + + + +Day 5 - Advent of Code 2020 + + + + + + + +

Advent of Code

Neil Smith (AoC++) 12*

   var y=2020;

+ + + +
+ +

--- 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?

+
+

Your puzzle answer was 922.

--- 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?

+
+

Your puzzle answer was 747.

Both parts of this puzzle are complete! They provide two gold stars: **

+

At this point, you should return to your Advent calendar and try another puzzle.

+

If you still want to see it, you can get your puzzle input.

+

You can also this puzzle.

+
+ + + + + + \ No newline at end of file diff --git a/problems/day06.html b/problems/day06.html new file mode 100644 index 0000000..801715d --- /dev/null +++ b/problems/day06.html @@ -0,0 +1,185 @@ + + + + +Day 6 - Advent of Code 2020 + + + + + + + +

Advent of Code

Neil Smith (AoC++) 12*

      /*2020*/

+ + + +
+ +

--- 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?

+
+

Your puzzle answer was 6683.

--- 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?

+
+

Your puzzle answer was 3122.

Both parts of this puzzle are complete! They provide two gold stars: **

+

At this point, you should return to your Advent calendar and try another puzzle.

+

If you still want to see it, you can get your puzzle input.

+

You can also this puzzle.

+
+ + + + + + \ No newline at end of file -- 2.34.1