         .flatMap{
             $0
         }
-        .sorted(by: { (s1: Int, s2:Int) -> Bool in
-            s1 < s2
+    
+// Part 1 Solution
+    let sortedArray1 = singleItemArray.sorted(by: { (v1: Int, v2:Int) -> Bool in
+        v1 < v2
     })
-    if singleItemArray[0] + singleItemArray[1] > singleItemArray[2] {
+    
+    if sortedArray1[0] + sortedArray1[1] > sortedArray1[2] {
         triangleCount += 1
     }
-}
-print(triangleCount)
-
-var triangleCount2 = 0
-var part2TriangleArray = [[Int]](arrayLiteral: [],[],[])
-var row = 0
-triangles.enumerateLines { (line, _) in
-    let singleItemArray = line.components(separatedBy: CharacterSet.newlines)[0].components(separatedBy: CharacterSet.whitespaces)
-        .filter{
-            $0 != ""
-        }
-        .map{ item in
-            Int(item)
-        }
-        .flatMap{
-            $0
-    }
+// Part 2 Solution
     if row < 3 {
         for i in 0...2 {
             part2TriangleArray[i].append(singleItemArray[i])

    if row == 3 {
        row = 0
        part2TriangleArray.forEach { item in
            let sortedArray = item.sorted(by: { (s1: Int, s2:Int) -> Bool in
                s1 < s2
            })
            if sortedArray[0] + sortedArray[1] > sortedArray[2] {
                triangleCount2 += 1
            }
        }
        part2TriangleArray = [[Int]](arrayLiteral: [],[],[])
    }

}

print(triangleCount2)



import UIKit

guard let triangles = try? String(contentsOf: #fileLiteral(resourceName: "input.txt")) else { fatalError() }

var triangleCount = 0
var triangleCount2 = 0
var part2TriangleArray = [[Int]](arrayLiteral: [],[],[])
var row = 0
triangles.enumerateLines { (line, hi) in
    var singleItemArray = line.components(separatedBy: CharacterSet.whitespaces)
        .filter{
            $0 != ""
        }
