This commit is contained in:
Max Nuding 2021-12-13 07:44:50 +01:00
parent c4db5fad8d
commit aeb51d7c68
Signed by: phlaym
GPG Key ID: A06651BAB6777237
2 changed files with 14 additions and 51 deletions

View File

@ -105,10 +105,7 @@ let package = Package(
), ),
.executableTarget( .executableTarget(
name: "13", name: "13",
dependencies: [ dependencies: [ .targetItem(name: "Runner", condition: nil) ]
.targetItem(name: "Runner", condition: nil),
.product(name: "Collections", package: "swift-collections")
]
) )
] ]
) )

View File

@ -7,7 +7,6 @@
import Foundation import Foundation
import Runner import Runner
import Collections
struct Coord: Hashable { struct Coord: Hashable {
var x: Int var x: Int
@ -46,29 +45,6 @@ struct Coord: Hashable {
return foldingLeft(by: x) return foldingLeft(by: x)
} }
} }
/*mutating func foldUp(by y: Int) {
guard self.y > y else {
return
}
self.y = y - (self.y - y)
}
mutating func foldLeft(by x: Int) {
guard self.x > x else {
return
}
self.x = x - (self.x - x)
}
mutating func fold(by instruction: FoldingInstruction) {
switch instruction {
case .up(let y):
foldUp(by: y)
case .left(let x):
foldLeft(by: x)
}
}*/
} }
@ -91,13 +67,8 @@ enum FoldingInstruction {
} }
} }
class Field {
var coords = [Coord]()
}
class Day13: Runnable { class Day13: Runnable {
let inputPath: String let inputPath: String
//var field = [String:Cave]()
required init(inputPath: String) { required init(inputPath: String) {
self.inputPath = inputPath self.inputPath = inputPath
@ -107,7 +78,6 @@ class Day13: Runnable {
let input = try! String(contentsOfFile: inputPath) let input = try! String(contentsOfFile: inputPath)
let parts = input let parts = input
.trimmingCharacters(in: .newlines) .trimmingCharacters(in: .newlines)
//.components(separatedBy: .newlines)
.components(separatedBy: "\n\n") .components(separatedBy: "\n\n")
var dots = parts.first! var dots = parts.first!
.components(separatedBy: .newlines) .components(separatedBy: .newlines)
@ -116,32 +86,28 @@ class Day13: Runnable {
.components(separatedBy: .newlines) .components(separatedBy: .newlines)
.map { FoldingInstruction(line: $0)! } .map { FoldingInstruction(line: $0)! }
//printDots(dots: dots) var isFirst = true
//print("")
for instruction in instructions { for instruction in instructions {
//dots.forEach { $0.fold(by: instruction) }
dots = dots.map { $0.folding(by: instruction) } dots = dots.map { $0.folding(by: instruction) }
//print(instruction) if isFirst {
//printDots(dots: dots) print(Set(dots).count)
print(Set(dots).count) isFirst = false
//print("") }
break
} }
/*print(dots.count) printDots(dots: dots)
print(Set(dots).count)
print(parts)*/
} }
func printDots(dots:[Coord]) { func printDots(dots:[Coord]) {
let maxX = dots.map {$0.x}.max()! let maxX = dots.map {$0.x}.max()!
let maxY = dots.map {$0.y}.max()! let maxY = dots.map {$0.y}.max()!
for x in 0...maxX { let uniqueDots = Set(dots)
for y in 0...maxY { var s = ""
print(dots.contains(Coord(x: x, y: y)) ? "#" : ".", terminator: "") for y in 0...maxY {
for x in 0...maxX {
s += uniqueDots.contains(Coord(x: x, y: y)) ? "#" : "."
} }
print("") s += "\n"
} }
print(s)
} }
} }