13b
This commit is contained in:
parent
c4db5fad8d
commit
aeb51d7c68
@ -105,10 +105,7 @@ let package = Package(
|
||||
),
|
||||
.executableTarget(
|
||||
name: "13",
|
||||
dependencies: [
|
||||
.targetItem(name: "Runner", condition: nil),
|
||||
.product(name: "Collections", package: "swift-collections")
|
||||
]
|
||||
dependencies: [ .targetItem(name: "Runner", condition: nil) ]
|
||||
)
|
||||
]
|
||||
)
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
import Foundation
|
||||
import Runner
|
||||
import Collections
|
||||
|
||||
struct Coord: Hashable {
|
||||
var x: Int
|
||||
@ -46,29 +45,6 @@ struct Coord: Hashable {
|
||||
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 {
|
||||
let inputPath: String
|
||||
//var field = [String:Cave]()
|
||||
|
||||
required init(inputPath: String) {
|
||||
self.inputPath = inputPath
|
||||
@ -107,7 +78,6 @@ class Day13: Runnable {
|
||||
let input = try! String(contentsOfFile: inputPath)
|
||||
let parts = input
|
||||
.trimmingCharacters(in: .newlines)
|
||||
//.components(separatedBy: .newlines)
|
||||
.components(separatedBy: "\n\n")
|
||||
var dots = parts.first!
|
||||
.components(separatedBy: .newlines)
|
||||
@ -116,32 +86,28 @@ class Day13: Runnable {
|
||||
.components(separatedBy: .newlines)
|
||||
.map { FoldingInstruction(line: $0)! }
|
||||
|
||||
//printDots(dots: dots)
|
||||
//print("")
|
||||
|
||||
var isFirst = true
|
||||
for instruction in instructions {
|
||||
//dots.forEach { $0.fold(by: instruction) }
|
||||
dots = dots.map { $0.folding(by: instruction) }
|
||||
//print(instruction)
|
||||
//printDots(dots: dots)
|
||||
print(Set(dots).count)
|
||||
//print("")
|
||||
break
|
||||
if isFirst {
|
||||
print(Set(dots).count)
|
||||
isFirst = false
|
||||
}
|
||||
}
|
||||
/*print(dots.count)
|
||||
print(Set(dots).count)
|
||||
print(parts)*/
|
||||
|
||||
printDots(dots: dots)
|
||||
}
|
||||
|
||||
func printDots(dots:[Coord]) {
|
||||
let maxX = dots.map {$0.x}.max()!
|
||||
let maxY = dots.map {$0.y}.max()!
|
||||
for x in 0...maxX {
|
||||
for y in 0...maxY {
|
||||
print(dots.contains(Coord(x: x, y: y)) ? "#" : ".", terminator: "")
|
||||
let uniqueDots = Set(dots)
|
||||
var s = ""
|
||||
for y in 0...maxY {
|
||||
for x in 0...maxX {
|
||||
s += uniqueDots.contains(Coord(x: x, y: y)) ? "#" : "."
|
||||
}
|
||||
print("")
|
||||
s += "\n"
|
||||
}
|
||||
print(s)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user