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