Return non-optional array up to the last int from integers()
This commit is contained in:
parent
00d14b6e19
commit
81198be13a
4 changed files with 5 additions and 6 deletions
|
@ -6,10 +6,9 @@ extension Scanner {
|
||||||
return scanString(string) != nil
|
return scanString(string) != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func integers() -> [Int]? {
|
func integers() -> [Int] {
|
||||||
var numbers: [Int] = []
|
var numbers: [Int] = []
|
||||||
while !isAtEnd {
|
while let num = scanInt() {
|
||||||
guard let num = scanInt() else { return nil }
|
|
||||||
numbers.append(num)
|
numbers.append(num)
|
||||||
}
|
}
|
||||||
return numbers
|
return numbers
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
let input = Scanner(string: loadData(day: 1)).integers()!
|
let input = Scanner(string: loadData(day: 1)).integers()
|
||||||
|
|
||||||
for i in 0..<input.count {
|
for i in 0..<input.count {
|
||||||
for j in i..<input.count {
|
for j in i..<input.count {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import Foundation
|
||||||
let input = loadData(day: 10)
|
let input = loadData(day: 10)
|
||||||
let scanner = Scanner(string: input)
|
let scanner = Scanner(string: input)
|
||||||
|
|
||||||
var adapters = scanner.integers()!.sorted { $0 > $1 }
|
var adapters = scanner.integers().sorted { $0 > $1 }
|
||||||
adapters.append(0)
|
adapters.append(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import Foundation
|
||||||
let input = loadData(day: 9)
|
let input = loadData(day: 9)
|
||||||
let scanner = Scanner(string: input)
|
let scanner = Scanner(string: input)
|
||||||
|
|
||||||
let numbers = scanner.integers()!
|
let numbers = scanner.integers()
|
||||||
|
|
||||||
var weakness: Int? = nil
|
var weakness: Int? = nil
|
||||||
outer: for i in 25..<numbers.count {
|
outer: for i in 25..<numbers.count {
|
||||||
|
|
Loading…
Add table
Reference in a new issue