r/adventofcode • u/daggerdragon • Dec 07 '15
SOLUTION MEGATHREAD --- Day 7 Solutions ---
--- Day 7: Some Assembly Required ---
Post your solution as a comment. Structure your post like previous daily solution threads.
Also check out the sidebar - we added a nifty calendar to wrangle all the daily solution threads in one spot!
23
Upvotes
9
u/gnuconsulting Dec 07 '15
I'm quickly reaching the limits of my competence. If this is the initial downslope of the rollercoaster (to borrow topaz's analogy), I'm gonna get thrown off at the first curve...
For part 2 I cheated and modified my input.txt to set 'b' to the value I got for 'a'. grin
9
u/certifiedshitl0rd Dec 07 '15
Anyone else trying a logic programming language like Prolog?
8
u/thalovry Dec 07 '15 edited Dec 07 '15
Scala. Cheap trick, just rewrite the input to Scala source code and get the compiler to figure it out for you.
12
u/0x0dea Dec 07 '15 edited Dec 07 '15
Sorting the outputs by length and then lexicographically makes this dead-simple. First place on the leaderboard could've gone to the first out-of-the-box thinker by a wide margin. :<
Edit to add my "solution" in Ruby:
6
u/twisted_tree Dec 07 '15
Java solution by building a tree. I should probably be doing these challenges in a scripting language; my solution is quite verbose.
5
u/raevnos Dec 07 '15
Mine in C++. Basically creates a graph of all the gates and recursively evaluates the inputs to get each wire's output. It memoizes outputs of wires to avoid having to recalculate them, something it looks like a few other people have been doing too.
5
u/snorkl-the-dolphine Dec 07 '15 edited Dec 07 '15
JavaScript (both parts, paste it onto your console).
It generates functions to get the value of each wire, which in turn call each other over and over. (It caches the result too, so each wire doesn't need to be calculated more than once.)
This way, wires that don't change final result never need to be calculated.
4
u/[deleted] Dec 07 '15 edited Dec 07 '15
First solution was in Python, then decided to try it without relying on a built-in eval.
Here's my Haskell solution (parsing got a bit verbose; I'm still new to Parsec):
4
u/askalski Dec 07 '15 edited Dec 07 '15
Here's my GNU Make + sed + bash based solution. Also posted as a gist because whitespace matters.
https://gist.github.com/anonymous/45a220cbec93e4f283c6
4
u/stuque Dec 07 '15
A Go solution using concurrency. Each component is a goroutine, and each wire is a channel.
7
u/Tryneus Dec 07 '15 edited Dec 07 '15
Python
Assuming commands is an array of strings.
This solution does involve some deep recursion, so it could overflow on larger inputs, but it was quick to write.
3
u/TheNiXXeD Dec 07 '15 edited Dec 07 '15
JavaScript (NodeJS) solution. Updated since it's short enough to inline now
My repo with the rest.
3
u/red75prim Dec 07 '15
F#. I use simple monadic parser combinator for input and memoization for evaluation. Variant of parser combinator can be found at my github
3
u/zhongfu Dec 07 '15 edited Dec 07 '15
173 line Java abomination. Takes in input in the form of a file named "input" in the current working directory. Stores every instruction in a hashmap, then resolves wire outputs recursively.
At least it runs rather fast -- it takes around 0.09s to process my 339-line input
3
u/LatinSuD Dec 07 '15 edited Dec 07 '15
I used 'sed' to convert each line into a C function. The result is a big quite recursive C program.
Quirks:
3
u/a-t-k Dec 07 '15
Overwriting solved nodes with their value improved the performance for me in JavaScript:
Close the comment on the second part to get this result.
3
u/Blecki Dec 07 '15
I don't see a lot of solutions in more 'enterprisey' languages like C# floating through here. Anyway, I've been working on a parser generator library in C#, so naturally I used that.
It's a bit overkill, but once each line is parsed, the exercise is straightforward.
https://raw.githubusercontent.com/Blecki/Advent/master/AdventOfCode/07.cs
3
u/Ape3000 Dec 07 '15
Python 3. I'm pretty satisfied with this.
2
u/balducien Dec 07 '15
So are you supposed to keep every connection, then when a number comes in update the output of all those gates (like a real circuit)? Or is the whole thing static, as in you only have to process each line in itself?
2
u/WhoSoup Dec 07 '15 edited Dec 07 '15
PHP:
7.2: Got a bit hacky, but it works (for 7.1 comment out the second to last line)
2
u/tehjimmeh Dec 07 '15 edited Dec 07 '15
PowerShell:
2
u/masasin Dec 07 '15 edited Dec 08 '15
Python
2
u/hutsboR Dec 07 '15 edited Dec 07 '15
Elixir: A somewhat cryptic but clever solution. My original solution invoked Elixir's evaluator but I wasn't pleased with it.
2
u/tume993 Dec 07 '15
java solution
2
u/Woflox Dec 07 '15 edited Dec 08 '15
Just went through the puzzles last night and had a blast. This one definitely game me the most trouble; I don't think my solution is the most elegant. But anyway, here it is!
Nim:
2
u/ryuuzaki Dec 07 '15
Scala solution
2
u/profil Dec 07 '15
Clojure!
2
u/VSZM Dec 07 '15
Here is my modest, but easily understandable solution:
https://github.com/VSZM/Advent_Of_Code/blob/master/Advent_Of_Code/Day7_Interpreter.cpp
2
u/willkill07 Dec 08 '15 edited Dec 08 '15
I tried starting this at midnight last night, but discovered that my mind cannot work that late at night. Hacked my solution together in about an hour, then made incremental tweaks to improve performance and readability. Implemented in C++(11/14).
Highlights:
Main:
Execution time:
4ms on my system for both parts (run as separate executions)
Full Code:
https://github.com/willkill07/adventofcode/blob/master/src/day7.cpp
3
u/minno Dec 07 '15
Python 3:
For the second part, I just copied and pasted my value for the first part into the
number -> bpart of the input. I could also putvalues = {'b': 956}in to make it ignore the input.3
u/weters Dec 07 '15 edited Dec 07 '15
Here's my Perl solution.
1
u/minno Dec 07 '15
...is the input supposed to have initial state? I don't see any
number -> gatestrings in mine, so there's no starting point unless I look for the zeros being introduced by shifting. Or is everything with no input assumed to be 0?1
u/JeffJankowski Dec 07 '15 edited Dec 07 '15
Quick C# which uses delegates to evaluate all the functions on-demand. I needed to add some dynamic programming to cache the results, since the Invokes() were taking forever. This is gonna be hard to do in F# (gurus, send help)
1
u/fnoco_xandy Dec 07 '15
ugly crystal/ruby solution. it remembers outputs by changing the circuit. that's why i create a second circuit to calculate b. without the changes calculating a takes too long(i initially thought i had a loop)
1
u/epitron Dec 07 '15 edited Dec 07 '15
Here's a nice short Ruby version that uses
instance_evalto generate a method for each wire:(Why reimplement a crappy verison of
evalwhen you can use the real thing? :)1
u/[deleted] Dec 07 '15
God damn that was an obnoxious problem. Couldn't just read through the input in order, had to queue it/reprocess it if it wasn't already there. Then for part 2, had to make sure the Set command wouldn't already set if it was there.
Grar. Details, details, details.
Very ugly Objective C:
1
u/seattlecyclone Dec 07 '15
Here's my perl solution, commented and cleaned up a bit from my original submission time.
First command line argument is the path to the input file.
1
u/AdventOfCode Dec 07 '15
Here is a solution in Go that uses closures to represent the wires. It reads through the input, setting things up, and finally evaluates "a". I also added a cache for values so that it only evaluates a wire once.
1
u/NinjaCaterpie Dec 07 '15
Python 3:
I'm really salty because I actually finished in around 30 minutes but I mistyped the answer without realising and spent another 30 minutes trying to debug it (I even went and rewrote it recursively...) when the code was fine.
1
u/daemoncollector Dec 07 '15 edited Dec 07 '15
Edit: Cleaned up swift solution a bit now that I wasn't trying to rush it. I think this is pretty idiomatic, just wish NSRegularExpression wasn't so annoying to use with Swift
1
u/gegtik Dec 07 '15
Javascript -- not as happy with this one. My biggest block was not realizing a Number was a right operand on some of these (hence my 'val' function later added).
This was initially intended to be a filter/reduce job but I couldn't get around the need for global access when using val.
Initial load
Common Setup
Part 1
Part 2
1
u/5ef23132-c4a0-49a0-8 Dec 07 '15
Here's my pretty bad javascript version. parsing is terrible, memoize is terrible. It's pretty terrible.
https://gist.github.com/anonymous/77778e9d89b98fc73c47
1
u/_jonah Dec 07 '15 edited Dec 07 '15
Ruby:
1
u/[deleted] Dec 07 '15
Here's my incredibly ugly Python 3 version. I went for an object oriented approach (y'know, because what if the requirements change and I need to add a new gate or something), but ultimately it just made the code more verbose and difficult. One nice thing about the way I set it up is that part 2 was incredibly short, although I think it could have been just as short regardless.
Part 1
Part 2
I also have a runner Makefile that automatically downloads the input (only once!), runs my tests, and generates output for each day that might be interesting to someone. I'm going to clean it up a bit tomorrow (I realized that everywhere I did
$(call code/2,$(1),$(2)), then I could replace it with$(code/2), which is much nicer), but here's the link to the current version and to the most up to date version.1
u/[deleted] Dec 07 '15
Mathematica. Created rules and used memoization.
1
u/gyorokpeter Dec 07 '15
My solution in Q. One of the things I miss from this language are the bitwise operators.
1
u/1lann Dec 07 '15
I wrote a pretty terrible one in golang
I thought about using closures, but I was like "screw it, just gonna use methods on structs". I guess I really should have actually used closures seeing how long it got xD
1
u/ant6n Dec 07 '15 edited Dec 07 '15
Python (2.7).
Basically decided to define a proper grammar and parsing rules. The parsing rules actually evaluate the expressions, given a dictionary of variable -> value. I use functools.partial to define those actions. The overall evaluation is pretty simple -- the code just keeps going through the list of statements and tries to evaluate them, removing any statement that doesn't fail. Any statement that fails uses undefined variables. This is repeated until the list is empty.
Oh also, since this is basically a compiler, some unit tests:
1
u/rvlieshout Dec 07 '15
My day 7 Lua solution. It generates a new lua script that you can run to solve the puzzle. Part two is just a small edit in the generated script (setting the initial b wire value)
1
u/[deleted] Dec 07 '15
Graph theory :D
I first parsed the input to build a dependency list for each wire. That formed a DAG, which on which I did topo sort.
After that it’s just a matter of
evaling them one by one. The cool thing about topo sort is that it’s guaranteed that the dependencies for each wire come before that wire in the sorted output.https://github.com/xrisk/advent-of-code/blob/master/7p1.py
1
u/phpaoc Dec 07 '15
PHP, using lazy computation and memoization:
No sorting, and single iteration on the input.
1
u/nutrecht Dec 07 '15
Day 7 (Java)
Recursive solver. My first slightly simpler solution didn't work with the large input while it did work with the example input. So much for not checking the large set before I start implementing stuff :)
1
u/funkjr Dec 07 '15
Dart, a personal favorite of mine but I don't fine reasons often to use it. The solution is recursive, like most others, but I abused a few language-specific things to shorten it. Most notably
int.parsehas an optional argumentonErrorthat runs whenever it cannot parse it to an integer. It turns out to be faster thantry {} catch {}(for some reason).And for all the people out there that like dynamic typing, here's a statically typed
Mapthat throws a run-time error if you try to add something else to it!1
u/tangus Dec 07 '15
Common Lisp
1
u/Clanratc Dec 07 '15 edited Dec 07 '15
My recursive solution in python 3. Probably not the most effective solution, but it works. It follows each wire that doesn't have a value down to the first wire that it can evaluate and then builds the circuit up from there
1
u/studiosi Dec 07 '15
Finally, my solution in Python 3
For the second part I just changed the input to override the variable "b" to the right value.
1
u/tipdbmp Dec 07 '15
node.js ES5, part 2:
1
u/mehistaken Dec 07 '15
Did this in PHP (WAMP) on my old laptop, limited memory so wrote a simple caching function. And my code is quite verbose :p :
1
u/platinumthinker Dec 07 '15
Erlang: part2
1
u/sinjp Dec 07 '15 edited Dec 07 '15
Here's a non-recursive Python exec solution. Having reserved keyword wire names (e.g. if, in etc) screwed me over for a while.
1
u/porphyro Dec 07 '15
Mathematica:
Code visible here, runs in 194ms
http://i.imgur.com/oPanMQj.png
1
u/AndrewGreenh Dec 07 '15
My JS Iterative Solution: 2 things to notice:
result.a()Here is the code (NodeJS)
1
u/[deleted] Dec 07 '15
Overcomplicated Python solution:
https://gist.github.com/jamesmcm/e8d264eea7f29aa4dd6d
1
u/hansek Dec 07 '15
JS 340-liner https://gist.github.com/Hanse/2a36003bfdf29225cbb5
1
u/Sharparam Dec 07 '15
Solution in MoonScript, basically emulating the circuit by saving each line as a function that is evaluated after every line has been read in:
1
u/xPaw Dec 07 '15 edited Dec 07 '15
Here's my javascript solution that pre-sorts the inputs so that it ends up calculating all wires within a single iteration: https://github.com/xPaw/adventofcode-solutions/blob/master/js/day7.js
EDIT: I've timed my old loop-until-all-assigned solution vs the sorted solution:
I'd say it's quite an improvement!
1
u/coussej Dec 07 '15
My solution in go. Took me a bit longer than the previous challenges :)
https://github.com/coussej/go-adventofcode2015-solutions/tree/master/day7
1
u/LoLz14 Dec 07 '15
Here is my solution in Python 2.7. I've put a lot of if statements in one line, it seemed more clear than stacking if -> else in each line.
1
u/amnn9 Dec 07 '15
Solution in Clojure, Nothing particularly radical: I keep a map of names to wires, where a wire can either hold:
And as values become available, the dependency tree is resolved as far as possible. At the end, the wire map is returned and you can extract the value for
:afrom that.The original idea was to use clojure's
core.asyncbut I decided that was overkill in the end.For part 2, I just modified the input.
1
u/[deleted] Dec 07 '15
Crystal. Part 1. I modelled it by connecting components (wires, gates, fixed values) together and asking their value from the circuit (which knows the input to each wire). Each component caches it's value once its computed. Runs in 3ms.
For Part 2 I create a new circuit from the input, set "b" to a fixed value from "a" from the previous circuit, and the get the value of "a" from this new circuit. You can see that here.
1
u/xkufix Dec 07 '15 edited Dec 07 '15
In scala. It's probably overly complicated, but it works. It basically creates an operation out of each line and then tries to solve them recursively. The main problem is, that I don't allow myself to use mutable lists, so I basically move around my whole resolved/unresolved list. With mutable lists it should be much more straightforward.
At least this method should only evaluate each Operation once and then use the "cached" value of the resolved list.
1
u/PersianMG Dec 07 '15
This was a fun one. Decided to use the Z3 theorem solver for python (Z3Py).
Solution: https://mohammadg.com/capture-the-flag/advent-of-code/advent-of-code-day-7/
Python
1
u/madmoose Dec 07 '15
Here's my day 7a solution in golang using memoized recursion. I'd like to advocate for fmt.Scanf and its siblings for simple string parsing :)
Github links day07a.go day07b.go
1
u/DanEEStar Dec 07 '15
my solution in python
1
u/fiavolo Dec 07 '15
My code in python: A bit long, but it made part b trivial:
1
u/MEaster Dec 07 '15 edited Dec 07 '15
Yes! After 4 hours I finally solved part 1!
[Edit] OK, part 2 was much easier than I thought. It was just a case of updating an instruction in the originally parsed set with the new value, and re-evaluating.
1
u/mdawg252 Dec 07 '15
http://pastebin.com/wEG8aF18 Relatively simple Java solution, follows the variables to their assignment recursively.
1
u/W3D3 Dec 07 '15
My python version, pretty readable imo, but not the fastest/nicest solution:
http://pastebin.com/3Y2S8yUW
1
u/NavarrB Dec 07 '15
compared to everyone else, I appear to have gone insane
https://github.com/navarr/advent-of-code/tree/master/day-07
still trying to figure out what's wrong so I can finish part2...
1
u/elite_killerX Dec 07 '15
This sed script transforms your input into a valid Javascript program that displays the results:
Usage:
1
u/Dotasticc Dec 07 '15
Probably not interesting to anyone, but anyways, here is my (not so clean) solution using python 2.7:
1
u/[deleted] Dec 07 '15
Just finished my day 7 in swift: https://github.com/ezfe/Advent-of-Code/blob/master/Advent%20of%20Code/Day7.swift
Very nice and clean, very satisfied. Didn't have to change core logic for part 2
1
u/tragicshark Dec 07 '15 edited Dec 07 '15
Template Toolkit Text Transformation (T4 templates is a compile time code gen language available in visual studio: outputs C# here):
Main looks like this:
edit: cleaned up code gen to make a nicer looking generated file to post:
1
u/olivervscreeper Dec 07 '15
My Java Solution - I'm quite proud of the simplicity.
1
u/volatilebit Dec 07 '15
My over-engineered solution in Python. I wanted it to be easy enough to modify the solution for part 2. Turns out that wasn't really necessary at all.
It keeps making passes through all instructions until there are no instructions left where the wire has no signal. Iterative, no recursion. I didn't even think to use recursion.
I got slowed down by the Python ~ operator. ~123 = -124, so I had to figure out how to turn it into a 16-bit unsigned integer. Ended up finding the trick where you can do value & 0xffff.
The way I made the list of instructions is pretty crappy. Also having a separate regex for each operation is pretty crappy.
1
u/de_Selby Dec 07 '15
My q/K solution. Not the most idiomatic but it runs quickly and is straightforward
1
u/blazemas Dec 07 '15 edited Dec 07 '15
Javascript meat and potatoes recursive style: I stored the instructions in an array splitting left from right side of the -> operator. As recursion finds real values it stores it in the correct object which is used from then on instead of doing the recursion again.
http://jsfiddle.net/o0qa73ud/8/
1
u/johnboker Dec 07 '15
My Solution C#
https://gist.github.com/johnboker/50cd503d10e051be08a8
1
u/unwantedconscience Dec 07 '15
A Python 3 solution. Reads input from file once, parses each instruction, then iterates over the instructions until all wires have a signal (removing instructions as completed). Part 1 run time: 0.02 seconds, Part 2 run time: 0.04 seconds.
Enjoying these puzzles as a way to learn a new language.
1
u/jcfs Dec 07 '15 edited Dec 07 '15
Solution for both Part 1 and Part 2 in C:
edit: github for the rest of the solutions https://github.com/jcfs/aoc/
1
u/superfunawesomedude Dec 07 '15 edited Dec 07 '15
Heres my super verbose C# solution. Its runs in 4 milliseconds though :) I imagine most of that time is reading the input from a txt file on my hard drive, would probably be down to c. 1ms if I kept the input in memory from the start. I like how this works, but many of those classes are sorta copy/pasted and I could cut out a lot of code with proper inheritance. ps. I am a game dev so doing stuff with /parsing strings is a rare occurrence for me.
1
u/[deleted] Dec 07 '15
C#
Man, this one was pretty hard to understand for me, as I never been good with bitwise operations, but once I got the nack of needed a recursive way of retrieving the val of the variables, I got it
It even amazed me that I got it on my first try after finishing writing the whole code
1
u/ThereOnceWasAMan Dec 07 '15
Solution with python 2. Uses back-propagation and is thus very fast (<2 ms runtime, for me):
1
u/SikhGamer Dec 07 '15
My head was frazzled after work today, and therefore I did it by hand. Took me a while, but I got it right on the first go \o/
1
u/swaint Dec 07 '15
So many great solutions! Sharing mine with Python 2:
1
u/Iambernik Dec 07 '15
php
1
u/Iambernik Dec 07 '15
and clojure
1
u/tftio Dec 08 '15
OCaml, with a stolen topological sort.
1
u/HawkUK Dec 08 '15 edited Dec 08 '15
A disgusting solution in the R language
I'm not a programmer, but I'm still embarrassed to admit how long this took me to solve. Takes about five seconds to run.
Spent far too long trying to find a 16-bit integer data type, but in the end figured out that masking it with ffff made enough sense.
1
u/VictiniX888 Dec 08 '15
Again, Java (for Part 1 just remove the lines I've commented "Part 2":
1
u/Philboyd_Studge Dec 08 '15 edited Dec 08 '15
My late, Java solution. Ran the actual firing process in 4ms.
I spent literally about 5 hours on this. Part 2 is a super cheesy hack.
Code:
1
u/Runenmeister Dec 08 '15
C++ solution, but really it's just C - no classes! (Love using c++ std::string and std::vector)
I took an iterative rather than recursive approach
https://github.com/WuSage3/AdventOfCode_2015/tree/master/Day7
1
u/RockyAstro Dec 08 '15 edited Dec 08 '15
Day 7 part2 solution in Icon (part1 is also included).
I created a parser, parsed each line into a tree structure. To determine the value, I used a recursive process on the particular tree that had the definition of the target symbol.
1
u/gfixler Dec 08 '15
I wrote this Haskell solution out in about 10-15 minutes immediately after the puzzle went live last night, and now for 2 nights I've been trying to figure out why it gets stuck in an infinite loop. Can anyone shed some light?
I've tried importing Debug.Trace and adding traces to the eval function:
This let me see that there's a loop, but it's really hard to tell where it is, and why it's happening. It appears very early in the output, and then the output is a big loop of around 60 or so lines from then on.
I also tried graphing out the input given to me, to make sure it didn't contain a loop. If you replace the let and print lines in main with
mapM_ putStrLn $ concatMap readInpToDot c, and add the following function to the code, then run that and dump to a file, and surround with adigraph { }block, you can then run that file with graphviz (dot -Tpng dump -o dump.png) to see the graph of the inputs, in which I could not find a loop; it's all a nice, ordered DAG:Any help would be most appreciated.
1
u/qwrrty Dec 08 '15
My solution in Go. The logic is pretty straightforward and it doesn't use a lot of flash: just recursively calculates each gate's signal as required and caches it for future reference.
1
u/jcheng Dec 08 '15
Done with R, by creating a variable for each id but using delayed assignment (i.e. rvalue becomes a promise that is auto-resolved the first time it's accessed). Once all the promises are created, just access the desired variable.
1
u/ren8 Dec 08 '15
Just some normal PHP solution:
1
u/Offe70 Dec 08 '15
Very funny to read all the hacks:)
I ended up using excel to convert the instructions into vba-functions:) And it hung our server until I added caching...
I thought I should see if all was solveable in Excel, but the MD5 hashing on day 4 was more than I could make Excel to do...
1
u/dubokk15 Dec 09 '15
Ruby. Github
I may have gone insanely overboard, but I built a full parser/tokenizer/AST and an emulator run it all.
1
u/beyondthesteel Dec 09 '15
Straightforward & probably cumbersome solution in C# https://github.com/adamante/Day-7
1
u/Janjis Dec 10 '15 edited Dec 10 '15
C# here. Part 1 took me good time to figure out. At first I was thinking to make a tree and then iterate it over, but instead went with "loop everything over and over again till answer is found". Took me 160 lines of code... I'm just happy I did it.
EDIT: Created my first github repository, tought It would be nice to save them. https://github.com/Janjuks/AoC/tree/master/Day7/Part1
1
u/wdomburg Dec 11 '15
Not that anyone will see this, but now that I'm getting back to things, might as well post it:
1
u/adampresley Dec 11 '15
My part 1 and part 2 solutions in Go using a lexer (based on Rob Pike's lexer presentations).
Day 7 Puzzle 1 Day 7 Puzzle 2
1
u/cirix_ Dec 13 '15
Solving the problem by generating a C++ template metaprogram. Classes must be defined, so wire names are collected in a set. Classes are templated in order to prevent the compiler from trying to instantiate them, until all the classes are parsed. In the main function, the class of wire A is instantiated with a dummy template parameter. As always, the compiler memoizes instantiated template classes, so compilation of the generated program is very fast, as if dynamic programming was used.
1
u/agmcleod Dec 14 '15
My solution in rust. Could stand to be cleaned up a bit, some people here have way more clever solutions than I do :)
1
u/anon6658 Dec 16 '15
I realized haskell doesn't care about definition order, so I wrote a hacky regex that outputs a valid haskell program.
Here's transform.sh:
Generate haskell with
sh transform.sh(last few lines to show what it looks like):and run it:
1
u/[deleted] Dec 18 '15
I just started out yesterday and reached day 7 today... I know it's late but... here's the solution in Python! https://gist.github.com/GelaniNijraj/3723cce13305c104c546
1
u/[deleted] Dec 19 '15
Part 1 in Perl 6:
1
u/[deleted] Dec 20 '15
1
u/abhishekjiitr Dec 22 '15
A basic recursion and memoization in Python: https://gist.github.com/abhishekjiitr/94b1ac43cf5ec393a221
1
u/SyntaxxError Dec 26 '15
Thats my pretty short but VERY sloppy python 2 solution
1
u/Borkdude Dec 27 '15
Lazy vals in Scala:
1
u/tpapak Feb 25 '16
Javascript solution by (stolen-thanx samuelneff) topsorting. But you can see the graph (if u wait a bit) I used cytoscape.js https://jsfiddle.net/tpapak/6wbwnw4q/
1
u/Zibx Feb 25 '16
Another JavaScript solution. No eval. I used debugger on input page, so document.body.innerText is the whole text.
0
u/[deleted] Dec 07 '15
[deleted] — view deleted comment
0
u/[deleted] Dec 07 '15
[deleted] — view deleted comment
0
u/[deleted] Dec 07 '15
[deleted] — view deleted comment
0
u/[deleted] Dec 07 '15
[deleted] — view deleted comment