Skip to content

Instantly share code, notes, and snippets.

@Azoy
Last active December 2, 2018 08:04
Show Gist options
  • Save Azoy/7d5eef870d92e154069c6d0bbcb6afdc to your computer and use it in GitHub Desktop.
Save Azoy/7d5eef870d92e154069c6d0bbcb6afdc to your computer and use it in GitHub Desktop.
Advent of Code 2018
// Part one
let input = """
"""
print(input.split(separator: "\n").map {
Int($0)!
}.reduce(0, +))
// Part Two
let input = """
"""
// Frequencies we reach
let values = input.split(separator: "\n").map {
Int($0)!
}
var freqs = [Int]()
var currentFreq = 0
var check = true
while check {
for value in values {
if !freqs.contains(currentFreq) {
freqs.append(currentFreq)
} else {
check = false
break
}
currentFreq += value
}
}
print(currentFreq)
// Part one
let input = """
"""
let boxes = input.split(separator: "\n")
var twoLetters = 0
var threeLetters = 0
var checkedLetters = [Character]()
var twoDone = false
var threeDone = false
for box in boxes {
for char in box {
guard !checkedLetters.contains(char) else {
continue
}
checkedLetters.append(char)
let charsInBox = box.filter { $0 == char }.count
if !twoDone && charsInBox == 2 {
twoDone = true
twoLetters += 1
}
if !threeDone && charsInBox == 3 {
threeDone = true
threeLetters += 1
}
if twoDone && threeDone {
break
}
}
checkedLetters.removeAll()
twoDone = false
threeDone = false
}
print(twoLetters * threeLetters)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment