2nd 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 - 2nd December 2020
Check validity of passwords for the pattern
[minOccurencesOfChar]-[minOccurencesOfChar] [char]: [password]
Check validity of passwords for the pattern
[firstPositionOfChar]-[secondPositionOfChar] [char]: [password]
and where either thefirstPositionOfChar
orsecondPositionOfChar
contains the character.
For a more detailed description of the tasks check this out.
The password
variable is an array of strings containing the lines given by Advent of Code, which is individual for each user. I only show a small excert of this variable below. I use String Extensions for a more convenient solution.
Here is the solution: