Fork me on GitHub
#adventofcode
<
2018-12-17
>
misha00:12:17

no regrets

misha00:12:11

@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

misha00:12:15

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

taylor00:12:39

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

taylor00:12:07

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

fellshard01:12:15

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.

fellshard01:12:17

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.

misha01:12:52

woah, verbosy

fellshard01:12:10

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

fellshard01:12:45

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

misha09:12:36

that's mfikes' macro

fellshard09:12:43

Oop! You're right, thanks

Average-user02:12:59

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

ā˜ļø 4
taylor02:12:33

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

taylor02:12:56

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

fellshard02:12:08

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

taylor02:12:51

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

taylor02:12:41

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

Average-user02:12:42

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

taylor02:12:30

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

norman03:12:51

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

potetm03:12:58

not on github either?

potetm03:12:05

looks like all of lambdaisland is gone

norman03:12:37

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

potetm03:12:03

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

potetm03:12:27

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

norman03:12:52

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

lilactown07:12:50

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

norman04:12:09

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)

lilactown07:12:10

you could clone it and install it locally

norman07:12:27

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

norman08:12:31

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

misha14:12:39

day 17, no transients, no deqs.

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

potetm15:12:36

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.

norman15:12:30

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

misha16:12:42

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)

misha16:12:05

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

borkdude16:12:51

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

ihabunek16:12:21

it took me WAY too long to do todays task

ihabunek16:12:35

you'll need to zoom out

ihabunek16:12:12

not very tidy but i need to work/sleep

pesterhazy18:12:35

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

Ben Grabow19:12:39

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.

pesterhazy20:12:16

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

pesterhazy20:12:24

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

pesterhazy20:12:08

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

Ben Grabow20:12:02

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.

pesterhazy20:12:03

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

pesterhazy20:12:19

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

Ben Grabow21:12:01

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.

pesterhazy21:12:56

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/

pesterhazy21:12:13

but the logic is quite different

pesterhazy21:12:53

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

Average-user19:12:01

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

Ben Grabow22:12:57

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

gklijs22:12:45

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

Ben Grabow22:12:26

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

markw22:12:47

what specific line of code is causing the overflow?

Ben Grabow22:12:48

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]

markw22:12:15

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

Ben Grabow22:12:30

Not rolling my own.

Ben Grabow22:12:08

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.

pesterhazy22:12:59

Never use concat with lazy-seq

pesterhazy22:12:58

it's a known footgun

pesterhazy22:12:51

I use into instead of concat wherever I can

Ben Grabow22:12:28

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