5th December solution - Advent of Code 2020 - swift

As part of Advent of Code (adventofcode.com) each day there are two programming tasks to be solved. All solutions are listed here.

I am writing the solutions in Swift with the Playground environment in xCode.

Tasks - 5th December 2020

Pretend you are one a plane where the seat ids are seatRow * 8 + seatColumn and the seat row and column are encoded the following way: BBFFBBFRLL where the first 8 character are binary notation for the row and the last 3 binary notation for the column. "B" and "R" maps to 1 whereas "F" and "L" map to 0 in the binary notation,

  1. Find highest seat id.

  2. Find missing seatId.

For a more detailed description of the tasks check this out.

The lines variable is an array of strings containing the encoded seat position given by Advent of Code, which is individual for each user.

Here is the solution:

Overview of all solutions of 2020:

Advent of Code 2020 Solutions Overview

4th December solution - Advent of Code 2020 - swift

As part of Advent of Code (adventofcode.com) each day there are two programming tasks to be solved. All solutions are listed here.

I am writing the solutions in Swift with the Playground environment in xCode.

Tasks - 4th December 2020

Validate passports consisting of key value pairs.

  1. Count how many passports contain all required keys.

  2. Count how many passports contain all required keys and a corresponding valid value.

For a more detailed description of the tasks check this out.

The lines variable is an array of strings containing the key value pairs given by Advent of Code, which is individual for each user. After each passport the lines variable contains a empty string.

Here is the solution:

Overview of all solutions of 2020:

Advent of Code 2020 Solutions Overview

3rd December solution - Advent of Code 2020 - swift

As part of Advent of Code (adventofcode.com) each day there are two programming tasks to be solved. All solutions are listed here.

I am writing the solutions in Swift with the Playground environment in xCode.

Tasks - 3rd December 2020

  1. Count the number of # in a grid when traversing through it going 3 right and 1 down.

  2. Count the number of # in a grid when traversing through it, going:

    • 1 right and 1 down,
    • 3 right and 1 down,
    • 5 right and 1 down,
    • 7 right and 1 down,
    • 1 right and 2 down and multiply these results.

For a more detailed description of the tasks check this out.

The lines variable is an array of strings containing the lines given by Advent of Code, which is individual for each user. I use String Extensions for a more convenient solution.

Here is the solution:

Overview of all solutions of 2020:

Advent of Code 2020 Solutions Overview