adventofcode

Happy Advent 2020! Please put answers in the pinned threads or create one if it does not exist yet. | https://github.com/adventofcode-clojurians/adventofcode-clojurians | Join the private leaderboard with code 217019-4a55b8eb
misha 2018-12-17T00:01:17.673300Z

no regrets

misha 2018-12-17T00:03:11.674700Z

@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

misha 2018-12-17T00:05:15.675800Z

case is way more obvious, and no need for open system

taylor 2018-12-17T00:19:39.677300Z

I just looked at day 16 and it reminds me of a chapter in the reasoned schemer about Bitwise math

taylor 2018-12-17T00:21:07.678200Z

Seems like the difference between the register and immediate instructions would make it more difficult to model though

misha 2018-12-17T09:38:36.704100Z

that's mfikes' macro

fellshard 2018-12-17T09:53:43.704300Z

Oop! You're right, thanks

fellshard 2018-12-17T01:24:15.679500Z

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.

fellshard 2018-12-17T01:25:17.680100Z

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.

misha 2018-12-17T01:36:52.681200Z

woah, verbosy

taylor 2018-12-17T01:47:18.681400Z

this book is really useful for learning it https://mitpress.mit.edu/books/reasoned-schemer

fellshard 2018-12-17T01:55:10.681700Z

Yeah, I don't golf my solutions. I prefer verbose but comprehensible, I can always refactor later.

fellshard 2018-12-17T01:58:45.681900Z

That macro in your solution is quite tight, though šŸ™‚

Average-user 2018-12-17T02:00:59.682800Z

For that 16 part2 I really would have liked to be using Prolog

ā˜ļø 1
taylor 2018-12-17T02:05:33.684300Z

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

taylor 2018-12-17T02:18:56.684900Z

maybe b/c a purpose-built constraint solver for a particular problem is easier than describing the constraints in a more general solver

fellshard 2018-12-17T02:23:08.685100Z

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

taylor 2018-12-17T02:42:51.686100Z

I was imagining most of the complexity being in writing goals for each operation

taylor 2018-12-17T02:43:41.687500Z

Though I also imagine you could ā€œcheatā€ by using non-relational goals/predicates too

Average-user 2018-12-17T02:43:42.687700Z

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

taylor 2018-12-17T02:46:30.689600Z

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

2018-12-17T03:00:51.691300Z

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 ā€¦ šŸ˜ž

2018-12-17T03:12:58.691700Z

not on github either?

2018-12-17T03:13:05.692Z

looks like all of lambdaisland is gone

2018-12-17T03:33:37.693800Z

Iā€™m not sure, but itā€™s disappointing that the only way to consume a project would be deps.edn.

2018-12-17T03:35:03.694100Z

how do you do that if itā€™s not on github?

2018-12-17T03:35:27.694500Z

lol nm ā€” the link you provided has a typo šŸ˜›

2018-12-17T03:41:52.695200Z

Oh - thatā€™s odd. Not sure how that happenedā€¦ šŸ™‚

Average-user 2018-12-17T04:01:14.695500Z

look at this

Average-user 2018-12-17T04:01:15.695600Z

https://github.com/Yomguithereal/react-blessed

2018-12-17T04:09:09.698400Z

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)

lilactown 2018-12-17T07:22:50.698900Z

Iā€™ve run into a few broken things in react-blessed in the past that put me off of it šŸ˜•

lilactown 2018-12-17T07:24:10.699300Z

you could clone it and install it locally

2018-12-17T07:36:27.700700Z

Yes, thereā€™s many things I could do to work around the unfortunate decision, but none of them are very satisfying.

2018-12-17T08:26:31.703300Z

Day 17 - my code really shouldnā€™t be this slowā€¦

misha 2018-12-17T14:45:39.705200Z

day 17, no transients, no deqs.

"Elapsed time: 150.130027 msecs"
"Elapsed time: 115.159781 msecs"

2018-12-17T15:33:36.707400Z

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.

2018-12-17T15:55:30.711400Z

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ā€¦

borkdude 2018-12-17T16:04:51.712400Z

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

misha 2018-12-17T16:15:42.712900Z

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)

misha 2018-12-17T16:19:05.713100Z

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

ihabunek 2018-12-17T16:27:21.713700Z

it took me WAY too long to do todays task

ihabunek 2018-12-17T16:27:35.714200Z

you'll need to zoom out

ihabunek 2018-12-17T16:28:01.714400Z

solution here: https://git.sr.ht/~ihabunek/aoc2018/tree/master/clojure/src/aoc2018/day17.clj

1
ihabunek 2018-12-17T16:28:12.714700Z

not very tidy but i need to work/sleep

2018-12-17T17:59:49.715500Z

https://www.twitch.tv/timpote

pesterhazy 2018-12-17T18:48:35.716400Z

I'm stuck on day17 p1 - my code works on the sample but not the full input šŸ˜ž

pesterhazy 2018-12-17T18:49:04.716800Z

My answer is too high: https://github.com/pesterhazy/advent2018/blob/master/src/advent/puzzle17.clj#L51

Average-user 2018-12-17T19:36:01.718Z

I was wondering if it would be possible to implement day 15 with core.async

2018-12-17T19:49:39.718400Z

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.

pesterhazy 2018-12-17T20:39:16.718600Z

@ben.grabow I'm starting from [0 500] now, which should be correct

pesterhazy 2018-12-17T20:39:24.718800Z

I don't think that's it...

pesterhazy 2018-12-17T20:40:08.719Z

I guess it's possible that the whole tree-walking approach is flawed and only happens to work on the small sample

2018-12-17T20:45:02.719200Z

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.

pesterhazy 2018-12-17T20:48:03.719400Z

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

pesterhazy 2018-12-17T20:49:19.719700Z

I can't figure out where the flaw in the reasoning is

2018-12-17T21:00:01.719900Z

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.

pesterhazy 2018-12-17T21:00:56.720100Z

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/

pesterhazy 2018-12-17T21:01:13.720500Z

but the logic is quite different

pesterhazy 2018-12-17T21:02:53.720700Z

you're right that my visit function is a mess of course

2018-12-17T22:35:57.721700Z

Any tips for tracking down a stack overflow on LazySeq realization? I get to a depth of around y=800 before my algorithm dies.

gklijs 2018-12-17T22:39:45.722Z

Try to use recur, https://clojuredocs.org/clojure.core/recur the extra calls are re-used so don't add up to the stack.

2018-12-17T22:40:26.722200Z

I am using recur everywhere, as far as I can tell.

markw 2018-12-17T22:40:47.722400Z

what specific line of code is causing the overflow?

2018-12-17T22:41:48.722600Z

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]

markw 2018-12-17T22:43:15.722800Z

have you created any lazy seqs yourself? or just using via built-in e.g. map, iterate etc.

2018-12-17T22:43:30.723Z

Not rolling my own.

2018-12-17T22:44:08.723200Z

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.

pesterhazy 2018-12-17T22:44:59.724100Z

Never use concat with lazy-seq

pesterhazy 2018-12-17T22:45:58.724500Z

it's a known footgun

pesterhazy 2018-12-17T22:45:59.724700Z

https://stuartsierra.com/2015/04/26/clojure-donts-concat

pesterhazy 2018-12-17T22:46:51.725Z

I use into instead of concat wherever I can

2018-12-17T22:58:28.725200Z

Well it's a lot slower with into instead of concat, so maybe that's a good sign :rolling_on_the_floor_laughing: