Prep for 3

This commit is contained in:
2021-12-03 05:02:33 +01:00
parent 74c9413ae8
commit 7c83ff9e7e
11 changed files with 1659 additions and 31 deletions

40
AoC1/main.swift Normal file
View File

@@ -0,0 +1,40 @@
//
// main.swift
// AoC1
//
// Created by Marijn Doeve on 01-12-2021.
//
import Foundation
var depths = [Int]()
let fileContent = try! String(contentsOfFile: CommandLine.arguments[1])
for line in fileContent.components(separatedBy: .newlines) {
if let line = Int(line) {
depths.append(line)
}
}
var total = 0
for i in 1..<depths.count {
if depths[i - 1] < depths[i] {
total += 1
}
}
print("a:", total)
var prev = 1000000
total = 0
for i in 1..<depths.count - 2 {
let new = depths[i..<i + 3].reduce(0, +)
if new > prev {
total += 1
}
prev = new
}
print("b:", total)