2020-12-11 22:25:14 +01:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
extension Scanner {
|
|
|
|
@discardableResult
|
|
|
|
func string(_ string: String) -> Bool {
|
|
|
|
return scanString(string) != nil
|
|
|
|
}
|
|
|
|
|
2020-12-22 07:46:43 +01:00
|
|
|
func integers() -> [Int] {
|
2020-12-11 22:25:14 +01:00
|
|
|
var numbers: [Int] = []
|
2020-12-22 07:46:43 +01:00
|
|
|
while let num = scanInt() {
|
2020-12-11 22:25:14 +01:00
|
|
|
numbers.append(num)
|
|
|
|
}
|
|
|
|
return numbers
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension String {
|
|
|
|
func lines() -> [String] {
|
|
|
|
var result: [String] = []
|
|
|
|
enumerateLines { line, _ in result.append(line) }
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
}
|
2020-12-14 18:49:31 +01:00
|
|
|
|
|
|
|
extension Sequence {
|
|
|
|
func print(_ prefix: String = "") -> Self {
|
|
|
|
Swift.print(prefix, Array(self))
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
}
|
2020-12-16 07:51:50 +01:00
|
|
|
|
|
|
|
extension Collection where Element: Collection {
|
|
|
|
func flatten() -> [Element.Element] {
|
|
|
|
flatMap { $0 }
|
|
|
|
}
|
|
|
|
}
|