diff --git a/common/Extensions.swift b/common/Extensions.swift index 72906a4..883b80b 100644 --- a/common/Extensions.swift +++ b/common/Extensions.swift @@ -6,10 +6,9 @@ extension Scanner { return scanString(string) != nil } - func integers() -> [Int]? { + func integers() -> [Int] { var numbers: [Int] = [] - while !isAtEnd { - guard let num = scanInt() else { return nil } + while let num = scanInt() { numbers.append(num) } return numbers diff --git a/day1/main.swift b/day1/main.swift index a70f62f..b89eeba 100644 --- a/day1/main.swift +++ b/day1/main.swift @@ -1,6 +1,6 @@ import Foundation -let input = Scanner(string: loadData(day: 1)).integers()! +let input = Scanner(string: loadData(day: 1)).integers() for i in 0.. $1 } +var adapters = scanner.integers().sorted { $0 > $1 } adapters.append(0) diff --git a/day9/main.swift b/day9/main.swift index 3dbf41a..961a4e7 100644 --- a/day9/main.swift +++ b/day9/main.swift @@ -3,7 +3,7 @@ import Foundation let input = loadData(day: 9) let scanner = Scanner(string: input) -let numbers = scanner.integers()! +let numbers = scanner.integers() var weakness: Int? = nil outer: for i in 25..