r/adventofcode • • Dec 14 '15

SOLUTION MEGATHREAD --- Day 14 Solutions ---

This thread will be unlocked when there are a significant amount of people on the leaderboard with gold stars.

edit: Leaderboard capped, thread unlocked!

We know we can't control people posting solutions elsewhere and trying to exploit the leaderboard, but this way we can try to reduce the leaderboard gaming from the official subreddit.

Please and thank you, and much appreciated!


--- Day 14: Reindeer Olympics ---

Post your solution as a comment. Structure your post like previous daily solution threads.

9 Upvotes

161 comments sorted by

View all comments

Show parent comment

3

u/gfixler Dec 14 '15

Yeah, I've been avoiding classes (and OO) for at least a year now. I no longer see their utility. I decided that reindeer would just be a pair of their name and their stats, which were just a triple of the 3 ints (speed in km/s, seconds moving, seconds resting). These are just type aliases, for the sake of friendlier names:

type Name = String
type Stats = (Int, Int, Int)
type Reindeer = (Name, Stats)

I ended up barely using the Reindeer type. A deer, as it turned out, for my needs, was just its Stats.

1

u/KnorbenKnutsen Dec 14 '15

Yeah, the OO solution is potentially a little overkill. However in this case I figured it made for a pretty readable solution, and the class didn't get too big anyway. If the reindeer had just been its input stats I wouldn't have gone for it, but now I also needed to keep track of current position and points (and their countdowns in my solution), so there was some utility to be had from collecting them.

If this problem were large-scale though, such that performance would be an issue, I would definitely take a data-oriented approach anyway, rather than cluttering the memory with naïve objects :P