-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsolution.swift
More file actions
29 lines (27 loc) · 805 Bytes
/
solution.swift
File metadata and controls
29 lines (27 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import Foundation
public func solution(_ A:inout [Int]) -> Int {
// var dict[Int:Int] = [:]
// for x in A {
// if !dict[x] {
// dict[x] = 1
// } else {
// dict[x] = nil
// }
// }
// return dict.keys[0]
return A.reduce(0, ^)
}
let file: FileHandle? = FileHandle(forReadingAtPath: "input-01.txt")
if let file = file {
// Read all the data
let data = file.readDataToEndOfFile()
// Close the file
file.closeFile()
// Convert our data to string
let str = String(data: data, encoding: .utf8)!
let lines:[String] = str.characters.split{$0 == "\n"}.map(String.init)
var arr:[Int] = lines[0].components(separatedBy: " ").map{ Int($0)! }
print(solution(&arr))
} else {
print("File was not loaded")
}