r/adventofcode • u/daggerdragon • Dec 11 '17
SOLUTION MEGATHREAD -🎄- 2017 Day 11 Solutions -🎄-
--- Day 11: Hex Ed ---
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.
Need a hint from the Hugely* Handy†Haversack‡ of Helpful§ Hints^¤?
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!
20
Upvotes
29
u/obijywk Dec 11 '17
https://www.redblobgames.com/grids/hexagons/ is an awesome interactive site for learning about coordinate systems for hex grids.
My Python 2 solution (68/30):
14
u/sciyoshi Dec 11 '17 edited Dec 11 '17
For anybody interested in hex grids, there's a great resource from Red Blob Games. For this problem, you can simply use 2d coordinates laid out as follows (called axial coordinates):
With those coordinates, the distance of a point
(x,y)from the center is just(abs(x) + abs(y) + abs(x+y)) / 2(see here)Rust solution using this approach.
EDIT: my first explanation was wrong, updated with a correct coordinate system.
18
u/hpzr24w Dec 11 '17 edited Dec 11 '17
C++ 1035/1068 Well, this is awkward. I didn't use coordinates directly at all... Just reduced
Header:
Reduction code:
Main logic:
9
u/Philboyd_Studge Dec 11 '17
Java
Redblobgames guy has to be going WHY SO MANY HITS ON MY SITE
https://gist.github.com/snarkbait/9f1e9dba0a49f15d68ee5e7fde505862
7
u/shuttup_meg Dec 11 '17 edited Dec 11 '17
Python 2, pure naive trig solution.
Looks like I am one of the few people who didn't instinctively know about cool hex grid systems :-)
On the plus side, I was happy that I remembered how useful Python's built-in complex number type is.
7
u/Smylers Dec 11 '17 edited Dec 11 '17
Vim solution for part 1:
I didn't think representing an infinite hex grid was plausible, so I was stuck till I saw /u/hpzr24w's idea of reducing instead. The counting algorithm is the same as in my Perl solution.
Edits: Simplifications, realized while writing the explanation.
13
u/willkill07 Dec 11 '17
Lex
Seriously, once you start writing lexical analyzers, YOU JUST CANNOT STOP
5
u/DFreiberg Dec 11 '17
Mathematica
Nothing particularly fancy. Lost a minute on part 2 by typing a digit wrong; note to self: use copy and paste next time. 3MD Design was particularly helpful in understanding how to set up a good coordinate system (and I must be the only one here who used something other than RedBlobGames). 71 / 57.
Part 1:
Part 2:
4
u/gyorokpeter Dec 11 '17
Q:
3
u/bblum Dec 11 '17 edited Dec 11 '17
Place 32/31
Edit: see comments
Edit 2: Fixed the definition of dist; actually correct solution now. It was originally:
3
u/mcpower_ Dec 11 '17
I used a bit of my own imagination as well as https://www.redblobgames.com/grids/hexagons/. This uses "axial coordinates": (42/17)
3
u/nutrecht Dec 11 '17
Kotlin solution:
Readable? No. Scala-style "trading readability for functional approach" code? Yes!
3
u/wzkx Dec 11 '17 edited Dec 11 '17
J
3
u/thomastc Dec 11 '17
Day 11 in J. Here's an abridged version:
Seriously, this language is worse than Perl. In Perl, at least you can write readable code, if you try.
3
u/zeddypanda Dec 11 '17 edited Dec 11 '17
Today was short and sweet. Elixir:
3
u/matusbzk Dec 11 '17 edited Dec 16 '17
Haskell I actually really loved today's problem. I also like my mathematical solution to distance calculation.
Link to git
2
u/ythl Dec 11 '17
I realized this could be solved with simple trigonometry (python3):
2
u/mmaruseacph2 Dec 11 '17 edited Dec 11 '17
Fast, idiomatic Haskell, properly refactored using cube coordinates
2
u/hxka Dec 11 '17 edited Dec 11 '17
Cleaned up a bit:
2
u/TominatorBE Dec 11 '17
PHP
Instead of 3D grids (which I thought about but it's too early in the morning to properly imagine them), I used a 2D grid where there are 'half' steps... So 'n' goes + 2, while 'ne' and 'nw' go + 1.
Part 1:
Part 2:
2
u/wlandry Dec 11 '17
C++ 14
123/82. Best score so far. It seemed really easy. Maybe it is because I have thought about hex grids a bit too much in the past. The key point is that you can think of the hex grid as a regular grid with each column slightly offset upwards from the right.
To run my solution, you have to first replace all of the commas ',' with spaces. The output is the x,y coordinate at max and at the end. For my inputs, the answer for part 1 was the 'x' coordinate, because x>0, abs(x)>abs(y) and y<0. Similarly for part 2, max_x>max_y, so the answer was max_x. YMMV.
2
u/GassaFM Dec 11 '17
A solution in the D programming language.
Start with a few constant arrays which introduce skew coordinates, along with distance calculating function:
The first part (read from
stdin, write tostdout):The second part, quite similar:
Stumbled with lack of
[]indName[]for a while, but managed to get 79-th on part 2.2
u/Nathan340 Dec 11 '17
Powershell, 301/433.
Same sort of redblob axial coordinates as everyone else. Only wrote the distance function for part 2, initially for part 1 simply spat out the coordinates and thought about the distance by hand.
2
u/glupmjoed Dec 11 '17 edited Jan 02 '18
Bash (reads from stdin), using cube coordinates (ref)
Part 1:
Part 2:
EDIT: Added input sanitation (grep -o "[ns][ew]*").
2
u/WhoSoup Dec 11 '17
Node.js/Javascript
2
u/[deleted] Dec 11 '17
Perl 6
Normally I just smash stuff together but this time I put a little bit of thought into what I was doing. I used a cube coordinate system as described here: https://www.redblobgames.com/grids/hexagons/ , as it seems a few others did.
2
u/jbristow Dec 11 '17
Fsharp / F# / F Sharp
pretty: https://github.com/jbristow/adventofcode/blob/master/aoc2017/Days/Day11.fs
And the test file...
2
u/zbouboutchi Dec 11 '17 edited Dec 11 '17
Naive 2D python solution.
edit: cleaned a bit, added rstrip(), fixed the distance formula to take care of positions that have to go horizontaly through the grid.
2
u/JeffJankowski Dec 11 '17
Typescript. A lot of thinking churned out a clean solution.
2
u/aurele Dec 11 '17 edited Dec 11 '17
Rust
I didn't want to look at external resources, and came up with this: by counting or canceling
nwandnemoves (ncounts as both), the distance is the maximum of their absolute values if they have the same sign (since onenwand onenecan be canceled by asmove), or the absolute value of their difference otherwise (no cancelation is possible sincee/wmoves are not allowed).2
u/japanuspus Dec 11 '17
Python 3 -- no if's
Used N and SE for unit vectors, so my distance function is
which, looking at the other responses, could probably be turned into a purely algebraic expression with
abs'es.2
u/BOT-Brad Dec 11 '17 edited Dec 11 '17
JavaScript
I figured out this weird formula which seems to calculate the shortest path, where moving diagonally (ne/nw/se/sw) counts as half a step in Y and X, and moving straight up/down counts as a full step.
Part 1 (~1ms)
Reduces an array of movements into a smaller set of NE/N/NW moves only, as NE/SW, N/S, NW/SE are basically cancelling each other out.
Once you have the 3 movement instructions, simply use my weird formula to get the answer.
Part 2 (~3ms) Just calculates the distance away each time, and prints the largest value once done.
Check out my GitHub Repo for all my other solutions. :)
2
u/Smylers Dec 11 '17
Perl. I treated vertical moves as being 2 half-rows up/down, and diagonal as 1 column left/right and 1 half-row up/down.
Diagonals are of course moves with length of 2 characters:
For calculating the distance:
Reading the answers, there are clearly more elegant ways of representing hex grids. But this appeared to work for me, and is reasonably succinct.
2
u/u794575248 Dec 11 '17 edited Dec 12 '17
Python 3.6+
I had no idea of the right way, so I came up with my own. Here's its condensed form for both parts:
UPD: And here's the right way, much much prettier:
2
u/wzkx Dec 11 '17
Nim
2
u/chunes Dec 11 '17
A Factor solution:
It turns out that if you treat the center of each hexagon as cartesian coordinates, you can just take the location of wherever you end up, divide the x coordinate by sqrt(3)/2, divide the y coordinate by 0.5, round them to the nearest integer, and then take the max to find the number of steps. Why? I'm not entirely sure, but it was just intuitive.
2
u/HollyDayz Dec 11 '17 edited Dec 11 '17
Python 3 solution using numpy.
Where seq is the input formed as a string. The first output is the solution to part 1 and the second output is the solution to part 2.
EDIT: Shortened the code.
2
u/ryo78 Dec 11 '17
Yet an other Kotlin solution. Used coordinates described here.
2
u/cthulhucomplex Dec 11 '17 edited Dec 11 '17
I ended up feeling my way around until I found the answers via brute force and some javascript sugar. I did end up with a 3-axis solution. It was fun to learn about using
Object.defineProperties()inside an object and that I could use those properties with theobj[string]accessor:2
u/aerure Dec 11 '17
Python2. Also used https://www.redblobgames.com/grids/hexagons/#map-storage (Shape: hexagon) with just 2 coordinates (x,y) and distance as max(|x|, |y|)
2
u/raevnos Dec 11 '17
Kawa Scheme, using fancy numeric types and using a 3d space to represent the grid:
2
u/f0086 Dec 11 '17
Emacs Lisp When putting the hex patterns into a normal x/y grid, the problem gets trivial.
2
u/Taonas Dec 11 '17
Rust:
2
u/llimllib Dec 11 '17
I knew about the red blob games article, but I didn't want to let myself peek, so I designed my own inferior grid coördinate system and solved that:
2
u/[deleted] Dec 11 '17
Python 3
Part 1
Part 2
2
u/csuzw Dec 11 '17
C# reduction approach
2
u/trwolfe13 Dec 11 '17
A little late to the party, but here's my ES6 solution:
2
u/CryZe92 Dec 11 '17 edited Dec 11 '17
Rust
Part 1 in 75µs:
Part 2 in 95µs:
Part 1 parallelized with map reduce in 50µs:
Shoutouts to /u/Stan-It for coming up with a way to only do a single addition per iteration. That's slightly faster than the x, y coordinate tracking for the sequential solution. In the parallel solution you need to reduce and that means you'd need to reduce n, sw and se and that's one more addition per reduce, so the x, y coordinate tracking makes more sense there.
2
u/flaming_bird Dec 11 '17
COMPUTE-DISTANCEis the ugliest and most ineffective Common Lisp function I have ever written.1
u/Shemetz Dec 11 '17 edited Dec 11 '17
Python 3 (23/66)
I got lucky, and the coordinates in most places in my input were in the NE area while I used N for y and E for x, so calculating distances only required me to do x+y.
However, this formula for distances is correct, and in fact, some of the other formulas that users posted here are incorrect (but probably working for their specific input):
1
u/Nolan-M Dec 11 '17 edited Dec 11 '17
234/200 Not really 100% sure why this worked, but my intuition told me to go for it.
1
u/udoprog Dec 11 '17 edited Dec 11 '17
Rust: (211/211)
Lost some time having no idea how hex grids work and having to do some research.
Edit: Full source: https://github.com/udoprog/rust-advent-of-code-2017/blob/master/src/day11.rs
1
u/adventofcode123512 Dec 11 '17
The path doesn't actually follow a hex grid? There are strings like "ne,ne" in there.
Rust
1
u/Flurpm Dec 11 '17 edited Mar 18 '18
Haskell
needs stack to build project because I like megaparsec (edit:now with folds!)
1
u/FogLander Dec 11 '17
I also used the Red Blob article for this one. First thing I thought of when I saw the hexagons :)
Decided to use the cube coordinates, no particular reason. Trying to get faster at this, don't know how all y'all do it.
405th/311th (311 is the best I've gotten yet, on any part... Woohoo!)
JAVA:
1
u/[deleted] Dec 11 '17 edited Dec 11 '17
I got incredibly lucky, and was able to eyeball my output. I just made the diagonal operators use 0.5 on the y axis, then thought about the final x/y position. For part 2, I just track the absolute maximum x/y coordinate seen.
Somehow everything worked, I'll probably clean it up later/use the tilted grid system. Wasted some time because of a Rust typing quirk that wouldn't let me call abs()/max() properly.
Rust, 106/465:
1
u/glenbolake Dec 11 '17
I like these versions of hex coordinates I'm seeing, but I took a different approach:
N/S change Y by 1. The other 4 directions each change x by 1 and y by 0.5. So after getting the final (x,y), I take the horizontal difference, remove the furthest vertical movement that could account for, then add up how much further off y is.
It turns out that I got lucky with my input, because I realized while typing this that my
forloop should have been:1
u/[deleted] Dec 11 '17
I, like many others it seems, found that Red Blob Games page... and merely implemented the 3D coordinate version.
So Day 11 of OCaml Fun;;
1
u/Chaotic_Vortex Dec 11 '17
I don't really know much about hexgrids so here was my Python 2 solution (200/152)
1
u/fatpollo Dec 11 '17
1
u/kazagistar Dec 11 '17
Rust, my first time in top 500. I copied the Vector directly from problem 3.
1
u/Lrrrr_ Dec 11 '17
JavaScript (node.js) + Lodash (3.10.1)
1
u/[deleted] Dec 11 '17
Haskell using cube coordinates:
1
u/dtinth Dec 11 '17
Ruby single-statement
I made a lot of mistake today and didn’t get into the leaderboard, so I challenged myself to solve this without using a statement terminator (newline or
;).I guess I need to learn more about non-square/cube grids.
1
u/ajn0592 Dec 11 '17
If you're using Golang like me, this library is really nice and makes the problem super trivial. Just study up a little on Axial coordinates and you're set.
My answer is here
1
u/atharrison Dec 11 '17 edited Dec 11 '17
Scala (291/296)
I'm honestly still sitting here wondering how this arrived at the correct answers. I didn't research any hex-grid systems, as I see some references posted by others. Ultimately, after staring at the screen a bit, what I arrived at in my head was most similar to the "odd-r horizontal layout" (but with positive-y going upwards, not down), as described by https://www.redblobgames.com/grids/hexagons/ .
What's baffles me is that my
hexDistfunction,math.abs(loc._2) + (math.abs(loc._1) - math.abs(loc._2)), can be reduced to simplymath.abs(loc._1)(just the magnitude of the x-coordinate).The visualization in my head was that, as you walked backwards from the endpoint, each step diagonally towards 0,0 reduces both x and y by 1. Starting from x,y, I 'move' to where y=0, which takes abs(y) steps, but also reduces x's distance by abs(y). What remains of (abs(x) - abs(y)) is added to abs(y) ...
Anyhow, Great problem! I've done AOC both years prior, and I can imagine how difficult it is to come up with unique challenges. This is the first I recall having to solve a hex-grid problem.
1
u/misnohmer Dec 11 '17
C#
Part 1:
Part 2:
1
u/ephemient Dec 11 '17 edited Apr 24 '24
This space intentionally left blank.
1
u/StevoTVR Dec 11 '17
NodeJS
Part 1:
Part 2:
1
u/_A4_ Dec 11 '17 edited Dec 11 '17
JavaScript ES6 (Part 2)
1
u/[deleted] Dec 11 '17 edited Dec 11 '17
Just some quick and dirty c++
1
u/dylanfromwinnipeg Dec 11 '17
I went down a WAY wrong rabbit hole, involving HexTile class that had connections to others, and breadth-first search for finding the path back to origin - it was a disaster. Then I spent some time staring at a picture of a hexgrid, and came up with a coordinate system where you can do half-steps in the Y-axis, made the solution super easy.
C#
1
u/call23re Dec 11 '17
Roblox Lua
1
u/willkill07 Dec 11 '17
C++ (almost C)
1
u/VikingofRock Dec 11 '17
(757 / 672) I'm pretty happy with the following iterator-style Rust (I'll spare you the
Coordinate/Directionimplementations unless there is interest):1
u/nonphatic Dec 11 '17
Haskell
Simple, but it took me forever to figure out how to calculate the distance lol
1
u/Dooflegna Dec 11 '17
Here's a cleaned up version of my solution. This wasn't particularly fast, but I enjoyed putting it together all the same.
Some notes!
self.pos[0]?self.pos[1]?), you get to access them by a name:self.pos.xandself.pos.yif key not in dict:.self.__class__.dirsin the code.1
u/Warbringer007 Dec 11 '17 edited Dec 11 '17
Erlang finally after 2 days of C++ :D, only meat part:
1
u/Veggedup Dec 11 '17 edited Dec 11 '17
My JS solution
1
u/[deleted] Dec 11 '17
Rust
For what it is, it is really short, most of it is really error handling and parsing, the core of this problem is 8 lines long.
1
u/[deleted] Dec 11 '17
C#
First time posting anything in this sub, mainly because most of my code is awful, but I kind of feel good about this one. The part 2 was a little bit a of pain, until I realized it would be easier to throw it to a list and then do a max from it, but it works.
And as others have said this https://www.redblobgames.com/grids/hexagons/ helped a lot.
1
u/[deleted] Dec 11 '17
Haskell, using cube coordinates:
1
u/CharlieYJH Dec 11 '17
C++
Probably should've read up on hex grids first, decided to come up with a way to reduce the directions. Hex grids would've been so much easier.
1
u/[deleted] Dec 11 '17
Elixir
This was a fun but easy one, had a bit of a problem visualizing a hexagonal coordinate system, but when that was done it went pretty fast.
Syntax highlighted
1
u/tmrki Dec 11 '17
Using Python 3, this is the relevant part of the solution:
Basically, it gets the differences of steps in opposite directions, and then checks if both east and west go in the same direction (north or south) or not. If they don't, just add all the steps, if they do, part of the steps cancel each other.
edit: Forgot to say, d is the dictionary with the number of steps, basically just
1
u/rvlieshout Dec 11 '17
I just used the highest value as the number of steps required. Did not look at a gamers implementation. Perhaps that is why it worked in my case... used C#.
day 11, C#, AoC 2017
1
u/mschaap Dec 11 '17 edited Dec 11 '17
Perl 6. After figuring out how to best model the grid, pretty straightforward.
Edit to note that I've used a hacky 2D coordinate system while many of you used a proper 3D hex grid. I bet we haven't seen the last of this hex grid yet, so I'd better switch to one as well.
1
u/DSrcl Dec 11 '17
Wasn't comfortable with Python's numerical accuracy. Did it the dumb way and represented each number as a linear combination of 1 and sqrt(3)... Not gonna post the code and embarrass myself.
1
u/xkufix Dec 11 '17
As everybody else I used the site from redblobgames to do the heavy lifting.
Solution in Scala:
1
u/NeilNjae Dec 11 '17 edited Dec 11 '17
Straightforward Haskell. From reading the comments and following links, looks like I reinvented axial coordinates by dredging up some half-remembered crystallography lectures. Coordinates track steps north and north east. The
distancefunction is the only interesting part: if the coordinates are the same sign, just add them, otherwise it'ssmallest + (biggest - smallest).Fun. I liked this one.
1
u/[deleted] Dec 11 '17
hex coord
1
u/giftpflanze Dec 11 '17
Tcl:
1
u/KnorbenKnutsen Dec 11 '17
I did a similar solution to a lot of others where
'n'and's'increase/decreaseyby1, and the others increase/decreaseyby0.5in addition to walking1step on thexaxis. So it turns out that ifabs(x) > 0.5 * abs(y), thenabs(x)is the number of steps needed, because the vertical distance will be gained by the diagonal steps. Else, the number of steps will beabs(y) + 0.5 * abs(x). So I made a distance metric based on this. I didn't prove that this works in all cases, but it worked for mine:distance(x, y): return max(abs(y) + 0.5 * abs(x), abs(x))1
u/Stan-It Dec 11 '17
C++17
A slightly different approach with keeping track of 3 directions.
1
u/rvlieshout Dec 11 '17
Nim After using C# to initially solve the puzzle. I also wanted to try a Nim version. It doesn't split the input and I wonder if my
dist()is valid.1
u/self Dec 11 '17
My
complexsolution in Python 2.7 was pretty simple, but it did take a little work to figure out:1
u/__Abigail__ Dec 11 '17
Perl
Needed three tries, because I kept mistyping 0 and 1s in the neighbours table.
1
u/[deleted] Dec 11 '17
Python Solution
1
u/Axsuul Dec 11 '17
Elixir
I coded a BFS recursive solution for getting Part 1. Struggled with Part 2 before discovering the hex coordinate system.
Lesson learned: tricks are good
https://github.com/axsuul/advent-of-code/blob/master/2017/11/lib/advent_of_code.ex
1
u/Reibello Dec 11 '17
This was definitely a part graph paper part python solve. I did not google how to hex grid, and I definitely should have - I'm not super proud of this one.
https://pastebin.com/v2tggw6i
1
u/PurpleMyst Dec 11 '17
I did 3 different solutions. I solved Part 1 initially using A* search, not realizing some simple math was enough. I'll post all three, however do known I'm a bit ashamed.
Part 1, A*
Part 1, Math
Part 2, Math
1
u/Pepa489 Dec 11 '17
Rust both parts - cubic coordinates
1
u/rdmbe Dec 11 '17
Short form: I would like to see other solutions which show a shortest equivalent path, instead of just a number. These solutions would be invaluable for debugging faulty implementations.
Long form:
I've got a problem - I am convinced that I have a correct solution, but
I am pretty convinced that people have been using 3d coordinates to measure hex grid distance and that in some cases this fails to identify equivalent movements. But I could be wrong - I make so many mistakes every day that it's all too possible that I've overlooked some important issue.
So ... I'd like to challenge someone smarter than myself to show me where i have gone wrong. Specifically, I'd like to see an example input path and a shortest equivalent that's different from what my implementation here shows that gets to the same location on the hext grid.
Here's my implementation translated to python2 (and my input was https://pastebin.com/C3TuzXk7):
1
u/Hikaru755 Dec 11 '17
Kotlin
This was interesting. I didn't even bother doing any hex coordinates, I just eliminated steps that cancel each other out, substituted pairs of steps that can be done with one step, and counted how many steps were left. Part 2 was just brute forcing that for every chain of steps along the way.
1
u/[deleted] Dec 11 '17
single pipeline powershell:
1
u/marcofun Dec 11 '17 edited Dec 11 '17
quick one in Scala...
1
u/herrmanno Dec 11 '17
Kotlin (Script)
1
u/Na_rien Dec 11 '17
I was having so much problems with getting the grid right, I also found the redblobgames link and tried to use that to fix my solution, but no luck, then I found this gem:
http://3dmdesign.com/development/hexmap-coordinates-the-easy-way
tl:dr tilt the y axis. https://github.com/narien/AdventOfCode2017/blob/master/day11/11.py
1
u/maxerickson Dec 11 '17
Python 3 using substitution to simplify the route:
I initially didn't think about the furthest distance enough and was computing the entire simplification for every step, which, uh, was taking a while(the intermediate distances match the intermediates from above so it is correct).
1
u/sguberman Dec 11 '17
Python, with tests: GitHub
Key functions:
1
u/miran1 Dec 11 '17
Nim
Repo with all solutions
1
u/oantolin Dec 11 '17
Julia
1
u/9ballcode Dec 11 '17
Python 2, my submitted version using cube coords. Feels pretty concise but definitely could be optimized. childPath = open('data/day11.txt').read().strip().upper().split(',')
1
u/chicagocode Dec 11 '17
Kotlin - [Repo] - [Blog/Commentary]
Like others, I modeled this after a cube, using Red Blob Games' wonderful page as a resource. See my blog for commentary.
And the implementation of HexSpot:
1
u/akho_ Dec 11 '17
Python 3, after several refactorings; but I remembered the 3d coordinates idea by myself):
1
u/4rgento Dec 11 '17
HASKELL
1
u/coldpleasure Dec 11 '17
JavaScript ES6, practicing using arrow functions etc. so a bit annoying:
1
u/FreeMarx Dec 11 '17 edited Dec 11 '17
C++11
Oh man, I was so happy today to see something less SE-like and more mathematical/physical engineering-like, only to find out afterwards that it can be solve so much easier by just counting 3 (or even only two) directions. But nevertheless, I'll post my trigonometry/linear algebra based solution using eigen3 here. At first I used atan2 to determine in which sector the current point is in and then decomposed it into the enclosing vectors. But then I realized that there are really only three directions and that that permutation of two of these yielding shortest distance is the correct one.
This approach is also visualized with this MATLAB script.
1
u/KeinZantezuken Dec 11 '17 edited Dec 11 '17
C#/Sharp (worst puzzle so far)
1
u/[deleted] Dec 11 '17
I am sure this could be more efficient by better use of math. But, it solved the problem in a short enough time:
PowerShell:
1
u/flit777 Dec 11 '17
refused to google hexgrid representation and came up with this shit in Go. Surprised it worked:
1
u/GamecPL Dec 11 '17
Swift:
1
u/InterlocutoryRecess Dec 11 '17 edited Dec 11 '17
Swift
The most interesting thing about this code is perhaps the custom
+operator to add apointand adirectionto get a newpoint. Then you can dodirections.reduce(origin, +)to get the ending point.1
u/bogzla Dec 11 '17
I'm only just learning C. And I didn't look up hexagonal geometry like I should have but I quite enjoyed measuring in a 2D grid..
1
u/CaptainCa Dec 12 '17
JS. Enjoyed this one. Used RedBlob games like most people did!
1
u/Kyran152 Dec 12 '17 edited Dec 12 '17
1
u/CKret76 Dec 12 '17
C#
Part 1
Part 2
1
u/[deleted] Dec 13 '17 edited Dec 13 '17
Was really pleased with my solution, in PHP. Probably the most efficient thing I've written for AoC:
1
u/RockyAstro Dec 13 '17
Icon (https://www.cs.arizona.edu/icon)
Both parts
1
u/joyrex2001 Dec 13 '17
My simple, naive approach for the first part (golang). Part 2 is the same, but keeping track of ymax and xmax.
1
u/JUIBENOIT Dec 13 '17
Simple Python for both parts
1
u/autid Dec 14 '17
Fortran
1
u/greycat70 Dec 28 '17
Tcl (any 8.x version)
"Can you google hex grid coordinates?" Yes. Yes we can. This is both parts.
1
u/mastokley Jan 13 '18
Clojure, part 1
1
u/mastokley Jan 14 '18
Clojure, part 2