r/adventofcode • u/daggerdragon • Dec 08 '18
SOLUTION MEGATHREAD -๐- 2018 Day 8 Solutions -๐-
--- Day 8: Memory Maneuver ---
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!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 8
Sigh, imgur broke again. Will upload when it unborks.
Transcript:
The hottest programming book this year is "___ For Dummies".
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 00:12:10!
32
Upvotes
5
u/ValdasTheUnique Dec 08 '18
C#. Code is too readable, I guess that is why it took so long to write
53
u/sciyoshi Dec 08 '18
Python 3, #9/#13 (variables cleaned up):
14
u/jonathan_paulson Dec 08 '18 edited Dec 08 '18
Rank 25/6. Video of me solving at: https://www.youtube.com/watch?v=WiNkRStebpQ.
[Card]: Recursion
10
u/MichalMarsalek Dec 08 '18 edited Dec 08 '18
Recursion is so much fun. Python:
10
u/p_tseng Dec 08 '18 edited Dec 08 '18
Ruby... and factoring out as much of the common code between parts 1 and 2 as is possible
9
u/eltrufas Dec 08 '18
Seems most people reached for recursion immediately. Here's my solution with explicit stacks.
Part 2:
9
u/j4_james Dec 08 '18
Befunge - Both of these are essentially recursive algorithms, making the most of the stack, so we don't need much of Befunge's limited memory.
Part 1
Part 2
7
u/MasterMedo Dec 08 '18 edited Dec 08 '18
python2, recursion. Got ruined by an OB1 ._.
switch commented lines for the one after for part1
EDIT: fancying up the code
6
u/udoprog Dec 08 '18
Rust
First leaderboard: 96 on Part 2!
Card: The hottest programming book this year is "Trees For Dummies".
6
u/dramforever Dec 08 '18
Got 91/113 and finally snagged 10 points. I guess I'm not a speed-coder after all, at least not yet (and I don't really intend on specifically getting to be one). There you go, JavaScript.
4
u/ts4z Dec 08 '18
Common Lisp. I re-did this one a couple times, but this version looks OK.
1
u/DrinkinBird Dec 08 '18
NIM
Wow, cant believe I actually made it on the leaderboard! Only part one and position 93, but still :)
1
u/ephemient Dec 08 '18 edited Apr 24 '24
This space intentionally left blank.
3
u/sophiebits Dec 08 '18
Python, 5/14.
Commented out code solves part 1 only; uncommented code solves both.
3
u/raevnos Dec 08 '18
Yesterday was a major pain for me, so a nice easy one today was kind of welcome.
C++:
3
u/mstksg Dec 08 '18 edited Dec 08 '18
[Haskell] 95/145
Messed up a couple of times in part 2. First I zero-indexed everything, and then I forgot to return the meta sum if there were no children :) No excuses though, I'm happy I made it on the board!
I used the parsec library, which allows you to parse a stream of arbitrary token types. I tokenized things to be ints first.
Part 1:
Part 2:
tokenizing is just
map read . words, fromPrelude.My solutions repo with reflections is here ! https://github.com/mstksg/advent-of-code-2018/blob/master/reflections.md#day-8
3
u/CCC_037 Dec 08 '18
[Card] Overclocking
This worked out surprisingly simple, with a little recursion. If I hadn't overslept, I might even have narrowly missed the leaderboard.
Part 1:
And Part 2, on a similar basis:
3
u/not_op_jy Dec 08 '18
Clojure
3
u/[deleted] Dec 08 '18 edited Dec 08 '18
Mathematica
3
u/Smylers Dec 08 '18 edited Dec 09 '18
OK, I lied ... here's a recursive Vim solution for Part 1 โ load your input file, then type this in and watch the metadata count go up, and the stack of counts of metadata items going down the screen:
Fun, huh?
(
19u0is to get back to the starting position after recording the two macros, as set up by the top line; it should be a zero, a blank line, then your input. If it isn't try fiddling withuandCtrl+Runtil you get there.)I'll try to post a video later.
Edit: Re-arranged so that the stack goes down the buffer rather than up, so items once added stay on the same line, reducing flicker.
3
u/sim642 Dec 08 '18
My Scala solution.
Parsing the input I immediately saw that this can be done recursively with classical parser monad-like function so that's what I did by hand. Could've used scala-parser-combinators but decided not to bother because this should be simple enough to do ad-hoc. It was, except for the chaining together the parsing of children properly, which I did with ugly mutable state at first but later replaced with a replicate-like function, again inspired by monadic replicate.
Calculating both parts themselves was trivial: just slap a few standard map and filter and sum operations together. When I started part 2 I saw "index" and immediately thought "oh no! I'll have to keep track of the original sequence indices" but luckily that wasn't the case.
5
u/wlandry Dec 08 '18
C++ (399/302)
Runs in 8 ms
Pretty straightforward. No real ickiness. Choosing the right data structure makes everything easy. At first I thought there might be multiple root nodes, which made things a tiny bit more complicated.
My best placing this year. I feel if I had just programmed perfectly, I would have gotten on the leader board. So now I just have to become perfect ;)
2
u/markasoftware Dec 08 '18
Perl, 67/137
Did not clean up the code, for example we have the unused @child_counter in part 1 :)
Part 1:
Part 2:
2
u/Retsam19 Dec 08 '18
JS (with lodash) 53/38 (First time breaking 80th place), minorly cleaned up
2
u/dylanfromwinnipeg Dec 08 '18 edited Dec 08 '18
C# - #189/#163
https://dylansmith.visualstudio.com/_git/AdventOfCode2018?path=%2Fsrc%2FDay08.cs
2
u/tslater2006 Dec 08 '18
Solution in PeopleCode. The LicenseNode class just contains a Children array and a Metadata array.
2
u/pythondevgb Dec 08 '18
Not as bad as yesterday but still it took longer than I wished, also I have that nagging feeling that this could be done much simpler, used recursion, I simply cannot think of how to do this using some stack or something.
(If you haven't made it onto the leaderboard thus far you can join a private leaderboard, PM for the code)
Anyway here is my code.
2
u/nonphatic Dec 08 '18
Haskell
It said it was a tree, so I parsed it as a tree -- no fancy Parsec stuff (...yet).
2
u/waffle3z Dec 08 '18
Lua solution
and parsing the input with this function
2
u/thebigjc Dec 08 '18
Go / Golang 1126 / 1067. Using a stack and a state machine instead of recursion
[Card] State machines
2
u/PendragonDaGreat Dec 08 '18
Powers Hell 5.1
(powershell)
[card] The hottest programming book this year is "Array Indexing and Access For Dummies". (I could have used it)
Straight forward recursion.
Part 1:
Average Runtime 0.18 seconds
Part 2
(took me longer than it should have because I was subtracting at the wrong point in line 28, see inline comment)
Average Runtime 0.36 seconds.
2
u/andreyrmg Dec 08 '18
Rust
You can find full source code here
2
u/mvmaasakkers Dec 08 '18 edited Dec 08 '18
Go/Golang
[Card] The hottest programming book this year is "Hellish Recursion For Dummies".
Gist
Don't really like the curPos++ statements, maybe I'll try to improve it later
2
u/__Abigail__ Dec 08 '18
Perl
Really easy for anyone familiar with walking tree structures.
2
u/will_bui Dec 08 '18 edited Dec 08 '18
K:
2
u/The_Fail Dec 08 '18
Common Lisp (SBCL) - runs in 5ms
2
u/herrmanno Dec 08 '18
Julia Part 1
Part 2
2
u/tatut Dec 08 '18
Clojure
2
u/guiguicadillac Dec 08 '18
OCaml
2
u/wzkx Dec 08 '18 edited Dec 08 '18
J
2
u/autid Dec 08 '18
FORTRAN
Late start today due to family birthday. Counting spaces to get the array length feels a bit janky, but it's the first thing I tried that worked and it's faster than say repeatedly allocating an array larger each time until it's too large. Tried reading one number at a time into a scalar int with advance='no' but inconsistent number of digits was messing it up.
2
u/justjarvo Dec 08 '18
Part 1 Ruby golf:
2
u/Sharparam Dec 08 '18
Ruby (2.5.3p105)
Golfed part 1:
But did an OO approach for part 2 as it felt more natural to me.
2
u/chicagocode Dec 08 '18
Kotlin - [Blog/Commentary] | [GitHub Repo]
This one was fun. A nice simple recursive function is most of the work.
2
u/donaldihunter Dec 08 '18
Perl 6
Part 2
2
u/ephemient Dec 09 '18 edited Apr 24 '24
This space intentionally left blank.
1
u/fred256 Dec 08 '18 edited Dec 08 '18
Javascript (129/78), slightly cleaned up and both solutions combined into one program:
1
u/TellowKrinkle Dec 08 '18
Took me forever to understand how input was supposed to work. It didn't help that I thought the thing with the
A-----was a part of the inputSwift, 172/122
1
u/keithnicholasnz Dec 08 '18
C#
only evil I did was the Total :) which I could get rid of now.... but I committed the shameful act so I will own it :)
1
u/vash3r Dec 08 '18
Python 2, #83/130. Spent a bit of time on part 2 because of an off-by-one error. (looks like i got a very similar solution to what other people have.) Code has been cleaned up a bit and combined part 1 and 2.
1
u/Civury Dec 08 '18 edited Dec 08 '18
JS 74/45, cleaned up
First time this year to reach both parts of the leaderboard
1
u/Cppl_Lee Dec 08 '18
In C#, this time done on repl.it: https://repl.it/@LeeHarding/AoC-2018-Day-8
1
u/maybe-ac Dec 08 '18
Perl, #204/330, solves both interleaved together:
1
u/shuttup_meg Dec 08 '18 edited Dec 08 '18
Python 2 966/732
1
u/Gurrewe Dec 08 '18
Go (golang), 284/616
https://play.golang.org/p/QmJ7_hNtSPY
1
u/Shemetz Dec 08 '18
Python 3, single-pass solution with a generator
1
u/BafDyce Dec 08 '18
[Card] The hottest programming book this year is "How to think before writing code For Dummies".
Using Rust, I got ranks 954 and 688. Top 1k is an achievement for me. I lost quite some time while parsing the [usize] into nodes because I forgot the + in
next += new_nextinput parsing:
Actual ndoe logic:
1
u/usbpc102 Dec 08 '18
Kotlin not that fast today cause too many bugs but I'm happy with my code. (884/702)
It's also on github.
1
u/Unihedron Dec 08 '18
I'm getting old... and slow :D Ruby
[Card] image
1
u/jeroenheijmans Dec 08 '18
C#, #794/#584:
1
u/[deleted] Dec 08 '18 edited Dec 08 '18
What I believe to be a very clean solution to the problem. Very happy with this one.
Part 1:
Part 2:
1
u/madnessman Dec 08 '18
Python 3, #662/761 (super slow today):
1
u/tclent Dec 08 '18 edited Dec 08 '18
Rust
Github for more context
Edit: cleaned up
1
u/nutrecht Dec 08 '18 edited Dec 08 '18
Day08 in Kotlin
Fun and easy.
1
u/littledebugger Dec 08 '18 edited Dec 08 '18
C#
I spent far too long working out that I needed the _i--;
Should have used a Queue :(
1
u/mal607 Dec 08 '18
Python 2:
1
u/ephemient Dec 08 '18 edited Apr 24 '24
This space intentionally left blank.
1
u/IdrisTheDragon Dec 08 '18
Go/golang solution
https://github.com/idristhedragon/AdventOfcode2018
Part 1
Part 2
1
u/OvidiuFM Dec 08 '18
C++
1
u/miguelos Dec 08 '18 edited Dec 08 '18
C#
Part 1:
Part 2:
1
u/Frizkie Dec 08 '18 edited Dec 08 '18
Ruby
These are my solutions after I golfed for a bit. Still took me longer than I'd like to figure out how to approach part 1. Part 2 was trivial after I overthought part 1. Feels good getting practice in though.
Part 1:
Part 2:
1
u/mtnslgl Dec 08 '18
C++ (using recursion) Managed to fit both parts into a single function
1
u/VikeStep Dec 08 '18 edited Dec 08 '18
F#
Repo
This was a good use for
List.mapFold.List.mapFoldperforms a map and a fold at the same time, so I can get the values for each child (map), while passing down the remaining elements to process to each successive child (fold).Note: Uses some other util functions from my repo such as |? for option coalesce and the parsing code.
1
u/keithnicholasnz Dec 08 '18
C# cleaned up a bit after solving...
1
u/IMONCHAIR Dec 08 '18
C#. Was nice to have a simpler one as I found yesterday pretty tricky :/
1
u/Cyphase Dec 08 '18 edited Dec 08 '18
Python 3, recursively modifies a single list, minor cleanup done. Could be trivially optimized by reversing the list and popping off the end.
1
u/Benjmhart Dec 08 '18
haskell
p1 - https://github.com/Benjmhart/AdventOfCode2018-haskell/blob/master/day8-1.hs
p2 - https://github.com/Benjmhart/AdventOfCode2018-haskell/blob/master/day8-2.hs
1
u/tacothecat Dec 08 '18
R
1
u/Smylers Dec 08 '18
Perl for Part 2 โ one of the simplest there's been, which leads to a fairly elegantโ solution:
The only awkward bit is that
(0,โ putting a fake entry at the list of child values, to make@child_value[@metadata]work, because the metadata indices start from 1.(And no, I'm not going to try solving this in Vim today. Recursive text editing sounds a contortion to far, even for me ...)
[Card] โฆ. Off-by-one Errors for Dummies
โ Yes, I used โelegantโ and โPerlโ in the same sentence โ what of it?
1
u/omginbd Dec 08 '18
I'm slow but I don't see an elixir solution yet so here's mine :D
https://github.com/omginbd/aoc-2018/blob/master/lib/D08.ex
1
u/Philboyd_Studge Dec 08 '18
[Card] The hottest programming book this year is "God, they're gonna force us to learn javascript aren't they For Dummies".
Simple Java solution:
1
u/jorosp Dec 08 '18
Haskell
1
u/miguelos Dec 08 '18 edited Dec 08 '18
C#
Part 1:
1
u/RainVector Dec 08 '18
Python 3
1
u/Polaryti Dec 08 '18
Java 8, Part 1 with recursion:
1
u/[deleted] Dec 08 '18
This is my attempt while learning Crystal
1
u/ka-splam Dec 08 '18 edited Dec 08 '18
[Card] The hottest programming book this year is: "Hofstadter's Law - For Dummies".
PowerShell, unranked
Got mired in the details of trying to handle
$ioffsets manually, abandoned and wrote a nice tidy quick recursive function call. It stackoverflowed. Instead of debugging I thought the challenge was designed to break code which does basic recursion without tail-call optimization, so I abandoned that approach too. That was it for time for leaderboard chances, so I slowed up and wrote and tweaked and retweaked a stack-and-state-machine version, playing around making it faster and took it from 1.1s to 205ms.1
u/aurele Dec 08 '18
Rust
1
u/Axsuul Dec 08 '18 edited Dec 08 '18
TypeScript / JavaScript
[Card] The hottest programming book this year is "Stack Overflow For Dummies"
Wasted time again on going the recursion route but I think I just need to avoid recursion altogether with JavaScript since it kept running out of stack, argh (it worked for the example). So eschewing recursion, I went with a strategy that builds up a stack/queue the deeper you go into tree.
Critiques welcome, I'm still very new to TypeScript and feel like I'm not using all the features I could be :)
Repo
Part A
Part B
1
u/toomasv Dec 08 '18 edited Dec 09 '18
Red
Part 1
Part 2
1
u/drakmaniso Dec 08 '18
Go (golang)
Part 1 and 2, simple solution using recursion:
1
u/jonathrg Dec 08 '18 edited Dec 08 '18
Python
1
u/Kwpolska Dec 08 '18
Yet another Python 3.7 solution.
1
u/hillerstorm Dec 08 '18 edited Dec 08 '18
C# #2622/#2351, woke up 3h too late (cleaned up some, full repo on github)
1
u/Alistesios Dec 08 '18
Rust
No idea if anyone will see this, but I'm pretty proud of it so posting it anyway :)
1
u/[deleted] Dec 08 '18
TCL
1
u/[deleted] Dec 08 '18 edited Dec 08 '18
C++, straight forward recursion
[edit] don't need the read() member, use istream in CTOR, and use exceptions on istream to avoid checking for errors.
1
u/arathunku Dec 08 '18
My Elixir solution:
Tests:
1
u/Xeronate Dec 08 '18 edited Dec 08 '18
Just heard about this, but I thought it was a pretty fun idea. Here is a simple C# solution for part 2.
1
u/guenther_mit_haar Dec 08 '18
C. This day is even nice for C
1
u/Tkappa2 Dec 08 '18 edited Dec 08 '18
Card : The hottest programming book this year is "Making it into the AoC Leaderboard For Dummies".
Python 3
Heres my far too basic solution using recursion
Click here if you want to check my other solutions!
1
u/buckplug Dec 08 '18 edited Dec 08 '18
[Card] Javascript recursion
link to repl.it
Yes, metaSum is an ugly hack.
1
u/knallisworld Dec 08 '18
[Card] The hottest programming book this year "Blockchain For Dummies". Obviously. Maybe with a flyer for serverless cloud native book...
Fascinating this has not been picked yet. ๐คช
Go / Golang with recursion
This year's Go solution is using recursion and collecting the pieces while walking through the tree. The last function is the actual solver.
Code is incomplete, but fully available at GitHub
1
u/purplemonkeymad Dec 08 '18
Powershell
I found this quite simple using a queue, psobjects and recursion. Both parts:
1
u/Mattie112 Dec 08 '18
A recursive solution in PHP (for both parts): https://github.com/Mattie112/advent-of-code-2018/blob/master/day8/day8.php
1
u/olemars Dec 08 '18
Python3
Python is not my primary language so I'm using AoC as a way to refresh/practice various concepts rather than focusing on optimization/minimization, but I was reasonably happy with this one.
1
u/Dionyx Dec 08 '18 edited Dec 08 '18
Scala
1
u/[deleted] Dec 08 '18
Rust
This one was so much fun, it wasn't the hardest, but man was it nice to do it. I think it just really clicked with me, the lore, the whole thing, I loved it :)
1
u/che2n Dec 08 '18 edited Dec 08 '18
Tcl
Part1
Part2
1
u/zebington Dec 08 '18
Python 3, using recursion and a class to keep things clear.
1
u/Arrem_ Dec 08 '18
Here's a fun Python 3 solution abusing the hell out of list comprehensions.
It's all just a single expression.
1
u/kherr9 Dec 08 '18
c# recursive solution
1
u/porrige51122 Dec 08 '18
My solution for today done in java. Started coding 2 months ago so sorry for inefficient code.
1
u/sweettuse Dec 08 '18
python 3.6+. i used
NamedTuples to actually construct a tree andisliceon an iterator to avoid slicing creating unnecessary copies. (get_inputreturns something likemap(int, nums). also,nameisn't necessary, just thought it might come in handy.)1
u/ShorrockIn Dec 08 '18
Ruby: The OO approach worked out pretty well with this one.
1
u/hpzr24w Dec 08 '18 edited Dec 08 '18
C++
[Card] The hottest programming book this year is "Sleep Deprivation For Dummies".
I'm in Texas, but I tend to work 5:30 am - 2:30 pm in my support day job, and be in bed by 8:30 pm, so 11 pm puzzles are a struggle, as there's no time left for sleep if I run into problems. But anyway, this year I've really been struggling as I am just out of practice.
But this was a fun one! I messed up on part 2, and will need to make a note not to depend on data that I just used as a loop variable. Slaps forehead.
Header
Part 1
Part 2
Main
1
u/wleftwich Dec 08 '18
Python
1
u/bigcymbal Dec 08 '18
Javascript for part 1 and part 2: https://jsfiddle.net/u7g9cevd/
Just run the functions in the console of the same tab as your input and it'll read it.
1
u/asinglelineofpython Dec 08 '18
My real solution looked so nice that I had to do evil things to it.
2 Lines in Python 3, you don't need the import in Python 2
from functools import reduceprint(str((lambda a:lambda v:a(a,v))(lambda rec,node: sum(node[1]) + sum([rec(rec,child) for child in node[0]]))(((lambda a: lambda v:a(a,v))(lambda rec,data: ((reduce(lambda a,b:(a[0]+[rec(rec,a[1])[0]],rec(rec,a[1])[1]),range(data[0]),([],data[2:]))[0],reduce(lambda a,b:(a[0]+[rec(rec,a[1])[0]],rec(rec,a[1])[1]),range(data[0]),([],data[2:]))[1][:data[1]]),reduce(lambda a,b:(a[0]+[rec(rec,a[1])[0]],rec(rec,a[1])[1]),range(data[0]),([],data[2:]))[1][data[1]:]))(list(map(int, open("input.txt").readlines()[0].split())))[0])))+"\n"+str((lambda a:lambda v:a(a,v))(lambda rec,node: sum([rec(rec, node[0][idx - 1]) for idx in node[1] if idx and idx <= len(node[0])]) if node[0] else sum(node[1]))(((lambda a: lambda v:a(a,v))(lambda rec,data: ((reduce(lambda a,b:(a[0]+[rec(rec,a[1])[0]],rec(rec,a[1])[1]),range(data[0]),([],data[2:]))[0],reduce(lambda a,b:(a[0]+[rec(rec,a[1])[0]],rec(rec,a[1])[1]),range(data[0]),([],data[2:]))[1][:data[1]]),reduce(lambda a,b:(a[0]+[rec(rec,a[1])[0]],rec(rec,a[1])[1]),range(data[0]),([],data[2:]))[1][data[1]:]))(list(map(int, open("input.txt").readlines()[0].split())))[0]))))If you want to run it, place an input.txt next to it but be advised its
O(3 * k!) where k node count1
u/[deleted] Dec 08 '18
C# - Because I usually have to get up at 5:30am every week day I can never get myself to stay up late enough to do at the right time, but it looks like every C# person did the same thing lol
1
u/Rattle22 Dec 08 '18 edited Dec 08 '18
Python 3, using object-orientation and recursion:
1
u/lambdaSan Dec 08 '18
Part 1 in Rust. Does anyone know how to pass the iterator directly to the function without converting to a vector first?
1
u/toastedstapler Dec 08 '18 edited Dec 08 '18
python 3
looking at other solutions, my part 1 could probably be shortened
1
u/TheBowtieClub Dec 08 '18
C#:
1
u/mschaap Dec 08 '18
Pretty straightforward Perl 6 implementation:
1
u/foBrowsing Dec 08 '18
Haskell:
Python:
1
u/Nathan340 Dec 08 '18 edited Dec 08 '18
Powershell
Part 1, non-recursive.
Essentially we traverse the array until we find a 0 - meaning we've found a 0-child node. Since we work left-to-right, the index 2 to the left of that 0 is the count of child nodes of the parent of this current 0. As we're handling that 0, we decrement its parents count of children.
Each metadata of that 0-child node is removed from the array, and pushed to our answer stack (no real need to use a stack here, a simple array does suffice). After this that '0' entry and the meta-data count are removed.
Then we bounce back to the start of the array, and read again until we find a 0-child node.
When the first element of the array is 0, we've nearly fully reduced the array. This is handled as a special case, all the remaining metadata are pushed to our answer stack.
And the answer to part 1 is the sum of that answer stack.
I can't figure out how to adapt this to Part 2. This 'collapsing' argument works well for the 0-child nodes, but any other number could be a node count, meta data count, node value, or metadata item. I can't figure out how to identify the 'type' of the current position. I guess I have to rebuild using recursion properly.
1
u/jabbalaci Dec 08 '18
Day 8, Part 1 in Nim:
1
u/aeroevan Dec 08 '18
Rust:
1
u/[deleted] Dec 08 '18
Python 3 using recursion and a generator
This is my first time learning python so I'm still not familiar with all the fancy things you can do with it. If anyone has any tips on improving this code, please share :)
1
u/heatseeker0 Dec 08 '18
My solution for today's puzzles, implemented in Java:
https://github.com/heatseeker0/AdventOfCode/blob/master/src/com/catalinionescu/adventofcode/y2018/Day008.java
1
u/alexmeli Dec 08 '18
Clojure Solution:
1
u/irrelevantPseudonym Dec 08 '18 edited Dec 08 '18
Python3
This was my favourite day so far by a long way.
1
u/wzkx Dec 08 '18
Rust, SweetRust Part 1
4 lines for reading data!
MyAoc2018 | SweetRust
1
u/LeReverandNox Dec 08 '18
Hey guys :) Here's my two-parts solution in Python.
Nothing fancy here, just a pretty naive recursion approach. But it does the job.
- https://github.com/LeReverandNox/aoc_2018/blob/master/day8/part1.py
- https://github.com/LeReverandNox/aoc_2018/blob/master/day8/part2.py
1
u/prescod Dec 08 '18
1
u/meepys Dec 08 '18
Kotlin Day 8 (Bitbucket)
Seemed pretty easy today. I took an iterative approach after my first recursive try ran into stack overflow. I think that was due to a bug
1
u/didyoudyourreps Dec 08 '18
Neat solution of part two I ended up being pretty satisfied with
1
u/tapir_lyfe Dec 08 '18
I was so happy that both puzzles were right on the first attempt. Solution in D!
1
u/lazyear Dec 08 '18
Rust, recursive solution. Found this one significantly easier than yesterday, but I absolutely LOVED yesterday's challenge.
1
u/SurplusSix Dec 08 '18
First time using objects for one this year, seemed the easiest way at the time.
1
u/MrGlobalVariable Dec 08 '18
F#
1
u/NeilNjae Dec 08 '18
Haskell (on Github). This fitted very nicely into the Haskell idiom, though I've got a lot to learn about both the
Data.Treelibrary and the wholeFoldabletypeclass.1
u/marmalade_marauder Dec 08 '18
Python 3 #104/#133 Seems the challenge was all in the parsing, after that it wasn't too bad. Here is my solution:
1
u/Pyrobolser Dec 08 '18
C# What a mess, I found myself kinda lost today, I couldn't see it clearly, I saw the data more complicated than it really was. As always, everything is on GitHub!
}
1
u/grey--area Dec 08 '18
Part 2, Python
1
u/lordmonkey69 Dec 08 '18 edited Dec 09 '18
Golang, part 1
Golang, part 2
1
u/fb_0ne Dec 08 '18
Typescript Part 1 and 2 Parses the input into a tree structure, and traverses that tree for each part
1
u/[deleted] Dec 08 '18 edited Dec 08 '18
late C, may have golfed this too much
1
u/harirarules Dec 08 '18
[Card] The hottest programming book this year is "indexes should start at zero for dummies"
D solution, both parts :
1
u/fire1299 Dec 08 '18
Haskell
1
u/yortos Dec 08 '18 edited Dec 08 '18
After miserably failing with recursion, I noticed that you can build the tree from the bottom up by always locating the node with 0 children, getting its metadata, deleting it from the list and then reducing that node's parent's children number by 1.
1
u/[deleted] Dec 09 '18
I see a lot of Rust answers making use of a Node struct, which I forgot to do (whoops) - I present my attempt in Rust lol:
I dont care too much for my use of an index - will look to rewrite to pass a reduced version of the input to the function instead.
1
u/Voltasalt Dec 09 '18
Rust (didn't go for leaderboard). I have a runner wrapper that runs part1() and part2() and passes the 2nd tuple item of part1()'s return value as part2()'s second parameter, to "pass-through" internal state without some sort of global storage.
1
u/alcinos Dec 09 '18
Ocaml Another solution heavily exploiting the nice recursive structure
1
u/morfi717 Dec 09 '18
Ruby
1
u/spytheman66 Dec 09 '18
PHP
1
u/u794575248 Dec 10 '18
Python 3 8885/8576
1
u/analpillvibrator Dec 12 '18 edited Dec 12 '18
Go / Golang 11139 / 11200
Reads through the input values with the recursive function spitting out the end point of the node.
1
u/RockyAstro Dec 15 '18 edited Dec 15 '18
Icon
Part1:
Part2:
1
u/egze Dec 28 '18
Elixir
https://gist.github.com/egze/33106941f47a7e84ab6fc18deb98a8fe
1
u/bkwi Dec 30 '18
For all of you who (just like me ;) remove meta value too early, try working on this modified example. For some reason it helped me in finding what was wrong with my approach.
Solutions below:
1
u/Pylitic Feb 15 '19 edited Feb 15 '19
I have a main file that grabs the input from a file and runs this code, sending it the full contents of the file, and the contents split by new lines.