Cleanup
This commit is contained in:
25
01/1.py
Normal file
25
01/1.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import sys
|
||||
|
||||
depths = []
|
||||
|
||||
for line in sys.stdin:
|
||||
depths.append(int(line))
|
||||
|
||||
total = 0
|
||||
for i in range(1, len(depths)):
|
||||
if depths[i - 1] < depths[i]:
|
||||
total += 1
|
||||
|
||||
print("a:", total)
|
||||
|
||||
|
||||
prev = 1000000
|
||||
total = 0
|
||||
for i in range(len(depths) - 2):
|
||||
new = sum(depths[i : i + 3])
|
||||
|
||||
if new > prev:
|
||||
total += 1
|
||||
prev = new
|
||||
|
||||
print("b:", total)
|
||||
40
01/AoC1/main.swift
Normal file
40
01/AoC1/main.swift
Normal 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)
|
||||
2000
01/input1.in
Normal file
2000
01/input1.in
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user