r/adventofcode • • Dec 06 '18

SOLUTION MEGATHREAD -šŸŽ„- 2018 Day 6 Solutions -šŸŽ„-

--- Day 6: Chronal Coordinates ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Advent of Code: The Party Game!

Click here for rules

Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!

Card prompt: Day 6

Transcript:

Rules for raising a programmer: never feed it after midnight, never get it wet, and never give it ___.


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked at 0:26:52!

32 Upvotes

387 comments sorted by

View all comments

2

u/mduser63 Dec 06 '18 edited Dec 06 '18

I'm still not able to solve part 2, despite my code producing the same result as several solutions posted here in various languages. My input starts with 275, 276. I get 32750 for part 2, which is rejected.

EDIT: The last digit in my input got lost when I pasted it into a file šŸ¤¦ā€ā™‚ļø. Fixed now.

My Swift code:

struct Coordinate: Hashable {
    var x: Int
    var y: Int

    func distance(to other: Coordinate) -> UInt {
        return (other.x - x).magnitude + (other.y - y).magnitude
    }
}

let lines = input.components(separatedBy: "\n")
let coords = lines.map { $0.components(separatedBy: ", ") }.map { Coordinate(x: Int($0[0])!, y: Int($0[1])!) }

let minX = coords.map { $0.x }.min()!
let minY = coords.map { $0.y }.min()!
let maxX = coords.map { $0.x }.max()!
let maxY = coords.map { $0.y }.max()!

var allPoints = Set<Coordinate>()
for x in 0...maxX {
    for y in 0...maxY {
        allPoints.insert(Coordinate(x: x, y: y))
    }
}

// Part 2

let region = allPoints.filter { point in
    coords.reduce(0) { $0 + point.distance(to: $1) } < 10000
}
print("Part 2: \(region.count)")

1

u/daggerdragon Dec 06 '18

Resubmit your answer and try again, please.

1

u/mduser63 Dec 06 '18

Just did, same result. I’m locked out for 10 minutes now.

1

u/Philboyd_Studge Dec 06 '18

I have the same input as you. That is not the correct answer for part 2.

1

u/mduser63 Dec 06 '18

The last digit in my input got lost when I pasted it into a file šŸ¤¦ā€ā™‚ļø. Fixed now.

1

u/flomine Dec 06 '18

Can you share the complete input?

1

u/mduser63 Dec 06 '18
275, 276
176, 108
270, 134
192, 224
252, 104
240, 271
144, 220
341, 303
344, 166
142, 347
207, 135
142, 353
343, 74
90, 210
82, 236
124, 295
41, 226
298, 109
276, 314
50, 303
131, 42
119, 335
275, 125
113, 289
347, 230
192, 329
158, 316
154, 356
171, 350
165, 59
257, 129
306, 55
334, 203
55, 63
268, 198
44, 103
230, 199
41, 181
357, 328
331, 85
256, 290
168, 290
353, 77
81, 328
136, 316
138, 213
352, 271
139, 222
139, 318
194, 239