no regrets
@mfikes I almost went multimethods way exclusively to write this line, but then didn't :kappa: https://github.com/mfikes/advent-of-code/blob/master/src/advent_2018/day_16.cljc#L54
case
is way more obvious, and no need for open system
I just looked at day 16 and it reminds me of a chapter in the reasoned schemer about Bitwise math
Seems like the difference between the register and immediate instructions would make it more difficult to model though
that's mfikes' macro
Oop! You're right, thanks
Since 'assembly simulations' are a recurring theme year over year, I've made myself a toolkit of techniques for creating a quick-'n'-dirty parser + interpreter. It's handy to know the pattern for things like that.
The way I think of it is to use a uniform function signature: given an 'address' and a set of registers, return a value. Then I have one function - immediate
- that just uses the 'address' as a value and ignores the registers, and another - register
- that uses the 'address' to retrieve a value from the registers.
woah, verbosy
this book is really useful for learning it https://mitpress.mit.edu/books/reasoned-schemer
Yeah, I don't golf my solutions. I prefer verbose but comprehensible, I can always refactor later.
That macro in your solution is quite tight, though š
For that 16 part2 I really would have liked to be using Prolog
Iād like to see a logic program for this one too, but I kinda doubt itād be any more concise/obvious than e.g. mfikesā solution
maybe b/c a purpose-built constraint solver for a particular problem is easier than describing the constraints in a more general solver
16 lvars binding op-code to operation, such that no counter-examples for that binding exist? Seems it'd be straightforward if all you needed in your database is a suite of counterexamples
I was imagining most of the complexity being in writing goals for each operation
Though I also imagine you could ācheatā by using non-relational goals/predicates too
The idea of logic programming is to describe what you want, not how you will get what you want. So ideally it would be more obvious, but not necessarily more concise
For example, in the chapters on bitwise math in the reasoned schemer, it takes quite a bit of work to setup all the prerequisite relational goals
Well, I was going to check out https://github.com/lambdaaisland/trikl based on an earlier recommendation of it a few days ago, but itās not on clojars ā¦ š
not on github either?
looks like all of lambdaisland is gone
Iām not sure, but itās disappointing that the only way to consume a project would be deps.edn.
how do you do that if itās not on github?
lol nm ā the link you provided has a typo š
Oh - thatās odd. Not sure how that happenedā¦ š
look at this
I think someone posted that too. Iām not in cljs for on the aoc stuff, which is where I wanted to try this. But, I think Iām going to try and find a way to try this at work for some tooling, since on most days I write more js than clj. (and weāre trying to find some places to re-introduce cljs)
Iāve run into a few broken things in react-blessed in the past that put me off of it š
you could clone it and install it locally
Yes, thereās many things I could do to work around the unfortunate decision, but none of them are very satisfying.
Day 17 - my code really shouldnāt be this slowā¦
day 17, no transients, no deqs.
"Elapsed time: 150.130027 msecs"
"Elapsed time: 115.159781 msecs"
Hey! People who are learning clojure and doing AoC! Last week I did a code review on stream, and I found it to be a fun and interesting exercise. https://www.twitch.tv/videos/349004355?t=55m30s If anyone wants me to do the same for their AoC code, please let me know! I wonāt do one every day (and I wonāt do one today), but Iād like to do one a couple times a week if enough submissions roll in.
150ms has me beat by ā¦ a lot. Iām doing one point per iteration and Iām running in 8min total. Besides filling more than one point per iteration, Iāll have to do a performance pass this morning for sureā¦
These are the scores for Advent of CLJC so far. Note that I only implemented the scoring a few days ago, so I have to re-run a lot of solutions to be able to register a score. I might get to that in a couple of days. https://gist.github.com/borkdude/d7f42d4110e8a330d1d70f9242b14496
https://github.com/akovantsev/adventofcode/blob/master/src/adventofcode/2018/day17.clj
1 iteration is 1 Y step for me, after which you either backtrack to Y-1 (no outlets in one of the puddles), or descent to Y+1 (all puddles have at least 1 outlet)
there is a bit of waist, when, say, out of 5 puddles only 1 has no outlet, so next (backtrack) iteration you scan all 5 of those for outlets again (against new "walls" updated with settled water). But that's like 2 incs and 2 lookups per puddle, which is essentially 0
it took me WAY too long to do todays task
here's a text visualization https://gist.githubusercontent.com/ihabunek/295c9ede42f0ce8e983ce9e5114979eb/raw/440e78df6d54ceb5b7de934b152feec55054b5c2/aoc2018.day17
you'll need to zoom out
solution here: https://git.sr.ht/~ihabunek/aoc2018/tree/master/clojure/src/aoc2018/day17.clj
not very tidy but i need to work/sleep
I'm stuck on day17 p1 - my code works on the sample but not the full input š
My answer is too high: https://github.com/pesterhazy/advent2018/blob/master/src/advent/puzzle17.clj#L51
I was wondering if it would be possible to implement day 15 with core.async
The spring is at x=500, y=0
. I'm not sure it matters but it looks like you might have the x and y values flipped? I see that your ordered-pairs are [y x]
, so that's fine, but I also see (visit [puzzle-min-y 500] :down)
which doesn't seem right.
@ben.grabow I'm starting from [0 500] now, which should be correct
I don't think that's it...
I guess it's possible that the whole tree-walking approach is flawed and only happens to work on the small sample
I considered doing some kind of tree-walking thing until I realized that it's actually a DAG not a tree. Two outlets can fill up the same pond, so they need to know about each other.
yeah I discovered that as well but thought if I remember whether the square was settled or not, I can re-use that information: https://github.com/pesterhazy/advent2018/blob/master/src/advent/puzzle17.clj#L105
I can't figure out where the flaw in the reasoning is
I wish I could help more, but it's really difficult to tell what you're doing inside visit
. It would help to break it down into steps and pull a bunch of that code out into smaller functions.
This person has an (even more) imperative solution, with a similar approach to mine: https://www.reddit.com/r/adventofcode/comments/a6wpup/2018_day_17_solutions/ebyq6mj/
but the logic is quite different
you're right that my visit
function is a mess of course
Any tips for tracking down a stack overflow on LazySeq
realization? I get to a depth of around y=800
before my algorithm dies.
Try to use recur, https://clojuredocs.org/clojure.core/recur the extra calls are re-used so don't add up to the stack.
I am using recur
everywhere, as far as I can tell.
what specific line of code is causing the overflow?
Haven't tracked down the line of code yet. The stack trace gives me an endless sequence of
[clojure.core$seq__5124 invokeStatic "core.clj" 137]
[clojure.core$concat$fn__5215 invoke "core.clj" 717]
[clojure.lang.LazySeq sval "LazySeq.java" 40]
[clojure.lang.LazySeq seq "LazySeq.java" 49]
[clojure.lang.RT seq "RT.java" 528]
have you created any lazy seqs yourself? or just using via built-in e.g. map, iterate etc.
Not rolling my own.
I am doing merge-with concat
in several places to merge some maps. Since I see concat
in the stacktrace I am suspicious of those.
Never use concat with lazy-seq
https://gist.github.com/bgrabow/7641f00f27a2632b7e597116dab31eab
it's a known footgun
I use into
instead of concat
wherever I can
Well it's a lot slower with into
instead of concat
, so maybe that's a good sign :rolling_on_the_floor_laughing: