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
devn 2018-12-03T00:00:48.354700Z

[["frank" "hello"] [nil "how is everyone?"] ["ethel" "good, you?"]] => [["frank" "hello"] ["frank" "how is everyone?"] ["ethel" "good, you?"]]

devn 2018-12-03T00:00:49.354900Z

something like that

devn 2018-12-03T00:02:00.355500Z

i forget the structure of the input, so that might be nonsensical at this point, but remember feeling like i'd unlocked some kind of secret when i found that

devn 2018-12-03T00:03:34.355900Z

found it:

(defn forward-propagate
  "If the keyword (kw) specified does not exist in the next map in the
  sequence, use the previous value of the keyword (kw).

  Example:
  (forward-propagate :nickname '({:nickname \"Fred\"} {:nickname nil}))
  => ({:nickname \"Fred\"} {:nickname \"Fred\"})"
  [mapseq kw]
  (rest
   (reductions
    (fn [{prev kw} next]
      (update-in next [kw] #(or % prev)))
    {}
    mapseq)))

devn 2018-12-03T00:03:58.356100Z

name suggestions welcome 😄

devn 2018-12-03T00:05:51.357Z

shame on me for the clever destructuring, shadowing next, a docstring that doesn't show the real true desired behavior, and other things

devn 2018-12-03T00:06:26.357400Z

written before update was a thing, so there's another wart

devn 2018-12-03T00:07:51.357900Z

</bikeshed>

2018-12-03T00:22:15.358600Z

I'm not sure if placing in the top 1000 is any good 😕 I think two years ago I managed to get in the top 50 but perhaps there are a lot more doing it nowadays

dpsutton 2018-12-03T00:23:07.359400Z

it's all by time right? seems like being somewhere such that midnight on the east coast happens at a bright and thoughful hour is key to getting on the leader board

2018-12-03T00:25:19.359700Z

and being smart! 😄

2018-12-03T02:20:13.360800Z

@mfikes I just dumped code while I was on the move earlier, but got it down to 0.7ms w/ a proper benchmark

2018-12-03T02:20:25.361100Z

(sry for the spoiler ya’ll, wasn’t thinking)

joaohgomes 2018-12-03T03:56:32.361400Z

Had the same idea 🙂 https://github.com/gomes-work/advent2018/blob/master/src/advent2018/day_2.clj

taylor 2018-12-03T04:19:40.362400Z

I used Quil to make a visualization of day 2 part 2 string comparisons https://youtu.be/Y_UuASYf6bM

💗 1
erwinrooijakkers 2018-12-03T09:46:33.374500Z

Hahaha this is awesome

erwinrooijakkers 2018-12-03T09:46:41.374700Z

Do same for day 3 😛

taylor 2018-12-03T13:42:41.398500Z

I did but it’s not very exciting. Just a bunch of multicolor rectangles

borkdude 2018-12-03T16:12:13.403300Z

Is it the green one?

taylor 2018-12-03T16:14:34.403600Z

haha it’s basically impossible to see without animating it; it’s in the top-right quadrant but I can’t even find it now looking at the still image

2018-12-03T05:28:54.363Z

Today’s was a little more fun imo 🙂

3
ClashTheBunny 2018-12-03T06:25:08.364500Z

It took a bit to think about a good solution to the first one, and I guessed correctly on what types of information I would need to recover for the second one: https://gitlab.com/randall.mason/advent-of-code/blob/master/src/advent_of_code_2018/day03.clj

lilactown 2018-12-03T06:45:28.365600Z

Ok I'm ready to make a duplicates transducer now:grin:

lilactown 2018-12-03T06:46:01.366500Z

Second time it's been an "I wish I had that"

fellshard 2018-12-03T07:20:14.368100Z

I solved the first one in a horribly slow manner, then went back around with an idea I had and rejected the first go 'round and ended up being far more efficient.

fellshard 2018-12-03T07:20:39.368500Z

First time was brute-force squared, second time was brute-force linear 😛

fellshard 2018-12-03T07:41:09.369300Z

Oof. And looking at those solutions, I see some obvious places I was still overthinking it. I'm out of shape with Clojure 😅

niels 2018-12-03T08:01:40.369800Z

Peter Tseng is a machine

pesterhazy 2018-12-03T08:29:00.370800Z

I feel a little dirty about my solution https://github.com/pesterhazy/advent2018/blob/master/src/advent/puzzle03.clj#L38

borkdude 2018-12-03T08:29:52.371200Z

mutable array is perfect for this

pesterhazy 2018-12-03T08:33:48.371600Z

doesn't exactly translate into raw speed 🙂

Elapsed time: 16054.534362 msecs

helios 2018-12-03T08:51:05.372500Z

my part2 is slow as hell 😛

ihabunek 2018-12-03T09:00:52.373200Z

that's around 3 seconds for both parts, could probably speed it up by using a transient set

borkdude 2018-12-03T09:19:37.373700Z

The weird thing is that on Node part 2 takes less long than part 1…

=== Running clojure test 2018

Running tests in #{"src"}

Testing aoc.y2018.d03.borkdude
part-2 took 567.30943 msecs
part-1 took 60.775506 msecs

Ran 2 tests containing 2 assertions.
0 failures, 0 errors.

=== Running cljs test 2018

Testing aoc.y2018.d03.borkdude
part-1 took 6239.000000 msecs
part-2 took 1018.000000 msecs

Ran 2 tests containing 2 assertions.
0 failures, 0 errors.

borkdude 2018-12-03T09:21:24.374300Z

maybe it’s doing something very inefficient in part 1… maybe something to do with lazyiness

pesterhazy 2018-12-03T09:59:35.375500Z

Is there anyone doing AoC based on a different paradigm, like Prolog or APL?

borkdude 2018-12-03T10:20:45.376Z

@pesterhazy I know someone who does it in Postgres

borkdude 2018-12-03T10:22:59.376200Z

https://twitter.com/pg_xocolatl

❤️ 3
erwinrooijakkers 2018-12-03T10:58:28.377100Z

Hi @borkdude can we use reader conditionals in advent-of-cljc or does that defeat the purpose?

borkdude 2018-12-03T10:59:00.377800Z

@erwinrooijakkers you most definitely can. you can also add (cross platform) libraries

erwinrooijakkers 2018-12-03T10:59:16.378200Z

Thanks

borkdude 2018-12-03T10:59:20.378400Z

@erwinrooijakkers note that there are already two useful functions in aoc.utils

erwinrooijakkers 2018-12-03T11:01:33.378800Z

Aha

erwinrooijakkers 2018-12-03T11:01:34.379Z

🙂

borkdude 2018-12-03T11:01:42.379300Z

@erwinrooijakkers your tests are failing exactly on the functions I already provided in aoc.utils 🙂

borkdude 2018-12-03T11:01:53.379500Z

you just have to prefix them with u/

erwinrooijakkers 2018-12-03T11:02:28.379900Z

I see 🙂

erwinrooijakkers 2018-12-03T11:03:14.380300Z

Alright now back to work. Hope to do day 3 this evening.

erwinrooijakkers 2018-12-03T11:04:37.380500Z

Nice repository!

2018-12-03T11:38:08.380800Z

29 lines today but slow as hell 😄

2018-12-03T11:38:55.381700Z

I basically limited myself to what resources http://repl.it has so it’s easy to get a timeout once in a while, can’t be bothered to start a new lein project for AoC

borkdude 2018-12-03T11:54:34.382Z

@orestis fixed the FAIL output problem in cljs

borkdude 2018-12-03T11:55:43.382200Z

@erwinrooijakkers merged

benoit 2018-12-03T12:54:25.383200Z

My solution: https://github.com/benfle/advent-of-code-2018/blob/master/day3.clj As long as it is under a second I don't look at perf 🙂

2018-12-03T12:55:25.383700Z

mine is basically identical^

2018-12-03T12:55:37.383900Z

except

2018-12-03T12:56:31.384600Z

I used sets

2018-12-03T12:56:43.385100Z

so for the second part, I took a union of all overlaps

2018-12-03T12:57:04.385900Z

and then set/difference from every identifier

helios 2018-12-03T12:58:16.386700Z

@potetm interesting idea, i hadn't thought of that and did the brute-force approach first 😄

2018-12-03T12:58:32.387100Z

oh mine is def brute force

2018-12-03T12:58:50.387700Z

just get to talk about sets so I feel fancy

benoit 2018-12-03T12:59:22.388800Z

yeah at the end I tried to use sets for the list of claim ids. It seemed less performant when computing the surface area.

pesterhazy 2018-12-03T12:59:35.389300Z

I wonder why my solution is so much slower (>16s): https://github.com/pesterhazy/advent2018/blob/master/src/advent/puzzle03.clj#L38 - I naively thought that a mutable 2d Java Array would be faster

benoit 2018-12-03T13:00:04.390200Z

I also wondered if sets would be better for the fabric instead of vec of vec in case it was sparse but the perf seemed a bit worse too so I gave up perf improvements 🙂

borkdude 2018-12-03T13:00:52.391200Z

I probably could have made my parse function shorter by using @me1740’s (str/split s #"[ ,:x@#]") instead of multiple steps 🙂

🆒 1
2018-12-03T13:00:53.391300Z

ah, mine a vec of vec of sets

2018-12-03T13:01:02.391500Z

(instead of list in your case)

borkdude 2018-12-03T13:01:23.391800Z

my data set looks like a list of {:id id :coordinate [x y]}

benoit 2018-12-03T13:03:30.392300Z

@borkdude yeah I fully trusted the input to be well-formed 🙂

benoit 2018-12-03T13:03:45.392600Z

I usually don't do that in real life 🙂

helios 2018-12-03T13:05:17.393200Z

@borkdude I have done a single re-match and got {:x x :y y :w w :h h} 🙂

borkdude 2018-12-03T13:05:34.393600Z

re-find would probably also work?

helios 2018-12-03T13:05:42.393800Z

yeah i guess

benoit 2018-12-03T13:05:54.394200Z

@helios It was my first idea but I was too lazy to get the regexp right 🙂

borkdude 2018-12-03T13:05:54.394300Z

nice, I’m going to try that

helios 2018-12-03T13:06:47.395400Z

yeah i was thinking the regex would be a PITA to write but it turned out quite easy

helios 2018-12-03T13:08:02.396400Z

I also, in a sense, trusted the input to be well formed (same amount of spaces, etc)

helios 2018-12-03T13:08:17.397100Z

otherwise you would need to add just a lot more +? everywhere 😛

pesterhazy 2018-12-03T15:41:33.399600Z

@mfikes nice and concise

👍 1
borkdude 2018-12-03T15:56:07.400Z

funny timings. CLJ:

Testing aoc.y2018.d03.borkdude
part-2 took 967.53 msecs
part-1 took 60.77 msecs

Testing aoc.y2018.d03.mfikes
part-2 took 726.61 msecs
part-1 took 602.41 msecs
CLJS:
Testing aoc.y2018.d03.borkdude
part-1 took 6087.00 msecs
part-2 took 1843.00 msecs

Testing aoc.y2018.d03.mfikes
part-1 took 6375.00 msecs
part-2 took 6525.00 msecs

borkdude 2018-12-03T15:57:06.400500Z

CLJS seems to be 10x slower

mfikes 2018-12-03T15:57:18.400800Z

Yeah, I saw the same thing locally. I haven’t pinpointed what it is.

fellshard 2018-12-03T15:59:48.400900Z

Observation: The problem statement only lists that the canvas is at least 1000 inches per side. You're better off not pre-allocating the whole set of cells; that might help, dunno. Using atoms in your array won't be terribly useful, and will just cause overhead unless you're writing all your claims in parallel. As it is, everything's synchronous.

pesterhazy 2018-12-03T16:04:25.402300Z

I'm not using atoms in the array

fellshard 2018-12-03T16:08:07.402700Z

Noticed that after. Still probably not necessary for accumulation, though?

pesterhazy 2018-12-03T16:23:12.403800Z

yes, I'd have to replace the doseq's by for's I believe

pesterhazy 2018-12-03T16:23:30.404Z

combined with reduce

gklijs 2018-12-03T17:15:59.405300Z

part 2 took 26,02 ms (Java)

quoll 2018-12-03T17:16:37.406Z

I decided to use this one to practice a bit with core.matrix. I learned about some interesting gotchas, so I was happy with doing that.

borkdude 2018-12-03T17:20:49.407200Z

@gklijs nice!

gklijs 2018-12-03T17:23:31.407600Z

Spoiler

gklijs 2018-12-03T17:25:15.407700Z

I did a reduce and kept a set of all the id of 'patches' I added, then add the id to all the fields. But before I checked when one of the fields was already taken, in that case I would remove all the founds id's from the set.

borkdude 2018-12-03T17:35:10.408200Z

similar to what I did

borkdude 2018-12-03T17:35:42.408400Z

but this is more optimized 🙂

quoll 2018-12-03T17:37:23.409600Z

Basically what I did too

2018-12-03T17:37:24.409800Z

Spoiler

2018-12-03T17:37:32.409900Z

You can efficiently tell that two rects overlap when there is overlap in their x-extents and overlap in their y-extents. No need to enumerate all the points inside each rectangle. This also works in the continuous domain.

1
2018-12-03T17:38:24.410100Z

Also the regex is easier than it looks: #(re-seq #"\d+" %)

quoll 2018-12-03T17:39:05.410300Z

except, I added ids to a matrix (using assign! on a submatrix), and did the reduce as an ereduce over the submatrix

quoll 2018-12-03T17:41:11.410500Z

I thought about the overlaps that you mention, but don’t you then need to do O(n^2) rectangle comparisons?

2018-12-03T17:45:00.410700Z

Yep. It's a balance between O(n^2) rect comparisons vs O(n) rect processing steps times O(height*width) set insertions. If the rectangles are mostly small and you have many of them then the set approach will win.

2018-12-03T17:54:25.411100Z

Going live soon! Could def use some backup 😄 https://www.twitch.tv/timpote

👏 1
😎 3
2018-12-03T18:23:02.411800Z

There are probably optimizations that I'm missing in the set-based approach but it's currently 10x slower than my bounds-checking approach. 1400 ms for set intersection, 170 ms for O(n^2) bounds-checking.

andrew.sinclair 2018-12-03T18:24:39.412800Z

Is anybody going for leaderboard points? Hot tip, I won't be able to do tonights puzzle until tomorrow, so feel free to take the top spot on the adventofcode-clojurians leaderboard!

orestis 2018-12-03T19:35:12.414400Z

I decided to take it easy this year — no pressure to solve every day as soon as possible. Very busy at work, and I’m learning a new language in the evenings (human language, not computer language) so suddenly free time is not so plentiful as last year 🙂 Have fun!

🙂 4
borkdude 2018-12-03T19:49:00.414900Z

@orestis my statement on this year: https://twitter.com/borkdude/status/1069546247034466304 🙂

fellshard 2018-12-03T19:51:04.416300Z

I need the challenge to incentivize me, but I'm trying to stream this year in order to practice explaining things out loud and build my vocabulary for talking about solutions in Clojure, so the competitive edge is dulled. I've got a lot to learn 🙂

erwinrooijakkers 2018-12-03T19:55:18.416500Z

Nice

quoll 2018-12-03T20:07:59.421Z

Last year I focused on FP approaches. That made sense for some puzzles, and others were 50/50 as to whether keeping state would be helpful, but there were a handful of puzzles which cried out to be solved with mutable data structures. Those ones took some effort to stick to “pure” approaches. It was useful practice

pesterhazy 2018-12-03T20:11:57.423200Z

Barely anything is impossible to do in an FP way, except sometimes it’s hard to make it fast enough... I think

2018-12-03T20:12:29.423800Z

you’d be surprised at how fast it gets

☝️ 1
2018-12-03T20:12:35.424Z

and yeah, I haven’t found any barriers

2018-12-03T20:12:38.424200Z

except in my approaches

borkdude 2018-12-03T20:13:08.425Z

Right. In 2015 I encountered that problem and I needed mutable arrays. It was easier to solve that in Java or Scala but eventually I got it working Clojure just as fast: https://stackoverflow.com/questions/34153369/why-is-this-clojure-program-working-on-a-mutable-array-so-slow

borkdude 2018-12-03T20:13:30.426100Z

Then I thought: maybe there is something to Scala… but I never needed to do that kind of stuff in my daily work

pesterhazy 2018-12-03T20:13:32.426200Z

Especially given that the puzzles haven input->output shape

pesterhazy 2018-12-03T20:15:32.428200Z

@potetm I know pure approaches can be fast but the simplest solution is often not the fastest

quoll 2018-12-03T20:29:02.431100Z

I’m aware that everything can be done with pure functional programming, which is why I stuck to it. Sometimes it’s not the most elegant approach though. But forcing myself to stick to it often helped me identify elegance that wasn’t immediately apparent

quoll 2018-12-03T20:29:51.431800Z

And if all else fails, use a state monad 🤪

2018-12-03T20:35:16.434200Z

Day 02 Part 2 - The problem can be narrowed down using group-by on the first and second halves of the IDs. The subdivided problems are then small enough to quickly brute force with an O(n^2) comparison. I tried also doing the "delete column" approach to attack the subdivided problems, but the perf was about the same. Either way it's about 100x faster than the naive brute force approach.

2018-12-03T20:35:31.434300Z

(ns advent.scratch
  (:require [clojure.string :as str]))

;; Hybrid approach. Group the words by their first half and group them
;; by their second half. Perform a brute force O(n^2) search for
;; almost-duplicates in each group. Take the first pair of almost-
;; duplicates found and extract the common characters.
;;
;; Rationale: A pair of almost-duplicates will have their differing
;; character in either the first half or the second half, meaning
;; either their second half or their first half will be identical.
;; Grouping by first half and by second half guarantees that the
;; pair will end up in a group together. The grouping step also
;; drastically cuts down the number of pairings we need to consider.
;; Searching within the group is O(n^2)

(def day-02 (-&gt; (slurp "resources/day-02/input")
                (str/split-lines)))

(defn differences [x y]
  (filter #(apply distinct? %) (map list x y)))

(defn extract-common-chars
  [pair]
  (-&gt;&gt; pair
       (apply map list)
       (filter #(apply = %))
       (map first)
       (apply str)))

(defn find-almost-duplicates [ids]
  (for [lhs ids
        rhs ids
        :when (distinct? lhs rhs)]
    (when (-&gt; (differences lhs rhs)
              count
              (= 1))
      [lhs rhs])))

(defn in-twain [s]
  (let [mid (quot (count s) 2)]
    [(subs s 0 mid)
     (subs s mid)]))

(defn group-by-first-and-second-halves [coll]
  (concat (vals (group-by #(first (in-twain %)) coll))
          (vals (group-by #(second (in-twain %)) coll))))

(time (-&gt;&gt; day-02
           group-by-first-and-second-halves
           (filter #(&gt; (count %) 1))
           (map find-almost-duplicates)
           (some first)
           extract-common-chars)) ; 0.8 - 2 msecs

lilactown 2018-12-03T20:49:48.435500Z

I'm trying to solve today's problem in Rust and Rich's "Maybe Not" talk is echoing in my head as I try and figure out the correct sigils and incantations to make the type checker happy

adammiller 2018-12-03T20:52:13.437300Z

My problem is the sunk cost issue. I have a hard time not seeing my initial idea through even though I may realize there is a better way half way into it. On problem 3 today I thought it would be simple to convert 2d indexes into 1d array...and it was simple for the first part (if not a bit verbose) but was not terribly helpful to solve the 2nd part.

☝️ 1
adammiller 2018-12-03T20:53:55.438200Z

and then of course I saw @mfikes solutions which was half the length of mine! But I guess that's what this is great for, seeing how others approach the problems!

erwinrooijakkers 2018-12-03T21:11:04.440300Z

I use a one-dimensional vector and updating on index as well. I was happy to discover that the performance is about 25 times better than the other solutions 😄:

Testing aoc.y2018.d03.borkdude
part-2 took 805.32 msecs
part-1 took 113.23 msecs

Testing aoc.y2018.d03.iamdrowsy
part-2 took 971.44 msecs
part-1 took 80.25 msecs

Testing aoc.y2018.d03.mfikes
part-2 took 713.25 msecs
part-1 took 605.19 msecs

Testing aoc.y2018.d03.mrmcc3
part-2 took 818.67 msecs
part-1 took 0.43 msecs

Testing aoc.y2018.d03.transducer
part-2 took 15.80 msecs
part-1 took 21.30 msecs

👍 2
pesterhazy 2018-12-03T21:13:08.440600Z

Nice idea

gklijs 2018-12-03T21:33:01.442Z

Watching some solution, but so far I don't see anyone else using the 1000 square inch for the solution.

uosl 2018-12-04T20:37:24.529100Z

@quoll there's a link in the topic to a repo with a list of clojurians participating https://github.com/adventofcode-clojurians/adventofcode-clojurians

fellshard 2018-12-03T21:37:25.442600Z

1000 square inch is a specified minimum for the size, hence the caution, I think

fellshard 2018-12-03T21:38:12.443500Z

Plus given there's some relative sparseness to the rectangles, I think allocating an entire area for the entire expected space isn't as useful as could be hoped (though to be far it would be a one-shot allocation)

fellshard 2018-12-03T21:38:34.444500Z

a 1d array wouldn't be expandable correctly if you didn't know the size beforehand; a pass of the inputs could give you the max coords, though

gklijs 2018-12-03T21:38:53.445Z

it's not really clear, I also kind of cheated by checking there was no id of 0 (initial value of an int)

borkdude 2018-12-03T21:39:12.445400Z

@erwinrooijakkers Did you see my comment to your PR? > Doing “expensive” computations at top level is something I would like you to avoid, since this cuts of time from the test.

borkdude 2018-12-03T21:39:36.445900Z

your solution is likely to be faster because of that

erwinrooijakkers 2018-12-03T21:39:37.446Z

Ah I cheated? 😞

erwinrooijakkers 2018-12-03T21:40:12.446800Z

I calculate a grid with the counts that I reuse in the second one

borkdude 2018-12-03T21:40:27.447Z

Also from my comment: > If you want to re-use the same calculation from solution 1 in solution 2, then you can memoize or use a delay.

erwinrooijakkers 2018-12-03T21:40:43.447500Z

Okay

erwinrooijakkers 2018-12-03T21:42:12.448Z

Why is that allowed?

borkdude 2018-12-03T21:42:40.448400Z

@erwinrooijakkers because parsed is a function. the work is done within the test

erwinrooijakkers 2018-12-03T21:42:59.448700Z

Ah and it is not actually memoized between tests

erwinrooijakkers 2018-12-03T21:43:07.449Z

?

borkdude 2018-12-03T21:43:48.449600Z

it is, but at least the work is part of the tests.

erwinrooijakkers 2018-12-03T21:44:40.450Z

Ah I see

fellshard 2018-12-03T21:44:41.450100Z

That pre-processing work needs to show up in at least one test, basically

borkdude 2018-12-03T21:44:47.450300Z

right

erwinrooijakkers 2018-12-03T21:44:54.450600Z

Oh wait now I see

borkdude 2018-12-03T21:45:02.450900Z

also when you make an exception, the application won’t work at all anymore

erwinrooijakkers 2018-12-03T21:45:04.451200Z

I’ll fix it

fellshard 2018-12-03T21:45:12.451400Z

Might be good to use deterministic ordering of test execution so that folks' times are comparable

fellshard 2018-12-03T21:45:31.451900Z

(though I'm guessing you've already got that covered)

borkdude 2018-12-03T21:45:41.452100Z

I think it is deterministic, but the test runner reverses part 2 and then part 1

fellshard 2018-12-03T21:45:58.452400Z

Ah, cool

fellshard 2018-12-03T21:46:58.453500Z

I'll pipe mine through later, hopefully

borkdude 2018-12-03T21:48:22.454300Z

I’m using https://github.com/cognitect-labs/test-runner for the tests. you may be able to find out why it first does part-2 and then part-1

gklijs 2018-12-03T21:49:00.455300Z

I got about 0.25 ms and 1ms for the first and the second, but that's with some warm up interation, https://circleci.com/gh/gklijs/advent_of_code_2018/79 probably in the weekend I have time for a similar setup for clojure

mfikes 2018-12-03T21:53:19.458100Z

Perhaps the Advent of CLJC solutions should avoid defs with inits that calculate or otherwise cache things. It is really easy to make the solutions appear to take zero time otherwise.

borkdude 2018-12-03T21:55:23.458800Z

@mfikes we were just discussing that yeah. only top level functions, but memoizing is permitted

borkdude 2018-12-03T21:56:22.459700Z

and maybe top level lazy sequences for parsing the data. those don’t realize outside the tests either

mfikes 2018-12-03T21:57:25.461800Z

Yeah—a problem is that the second one to run benefits from the realizing done by the first. Hrm.

erwinrooijakkers 2018-12-03T21:57:39.462300Z

Yes thanks @borkdude I did in my latest force push 😉

borkdude 2018-12-03T21:58:41.463200Z

@mfikes I saw this pattern was used last year a lot: the output from part 1 served as input for part 2. I think it makes sense to memoize, because the build time on CI can go up a lot if we double these calculations?

borkdude 2018-12-03T22:00:57.464300Z

@mfikes the time is a nice gimmick, but the purpose is really to build a corpus to find errors in speculative or measure performance improvements in clj/cljs

mfikes 2018-12-03T22:01:09.464700Z

Being able to compare valid timings is nice :)

mfikes 2018-12-03T22:02:18.467100Z

I’ve always been focusing on clear, idiomatic code. But it is also nice to know how much slower that code is when compared to highly optimized solutions.

borkdude 2018-12-03T22:02:56.467900Z

@mfikes are you arguing for or against memoize?

2018-12-03T22:03:23.468400Z

@pesterhazy @quoll Apologies for my tone earlier. I shouldn’t have commented unless I was willing to really engage. I was in between things at the time and just threw a comment to the ether.

mfikes 2018-12-03T22:04:54.470200Z

I’m suggesting that, once a test starts, if anything has been calculated prior to it running, it really makes timing comparisons bogus

borkdude 2018-12-03T22:05:59.471100Z

@mfikes agreed. but can results from part-1 be used in part 2?

mfikes 2018-12-03T22:06:31.471900Z

Oh, yeah, that seems “fair” IMHO :)

borkdude 2018-12-03T22:06:58.472500Z

cool. I’ll add this to the README

quoll 2018-12-03T22:07:11.472900Z

I’ll just have to hassle you in HipChat

1
borkdude 2018-12-03T22:07:27.473800Z

when a test runs in 10ms when most of the solutions run in 200 or 300 ms it’s a smell 😉

borkdude 2018-12-03T22:07:35.474200Z

so then I check if this is the case

mfikes 2018-12-03T22:08:33.475600Z

An example of “cheating” would be to

(def xs (doall ,,,))

quoll 2018-12-03T22:09:40.477100Z

Oh, are people posting in some central place? I must not have scrolled back far enough in the Slack.

borkdude 2018-12-03T22:09:54.478Z

yes. so top level (def data (map parse-int input)) is ok, since it’s lazy. not ok when realized outside the tests

quoll 2018-12-03T22:10:37.478900Z

But I tried the 1000x1000 grid. It’s smaller than most images, so I didn’t see a problem with that approach

quoll 2018-12-03T22:11:04.479500Z

And it let me practice with core.matrix

pesterhazy 2018-12-03T22:19:09.479900Z

no worries

borkdude 2018-12-03T22:20:14.480300Z

@erwinrooijakkers your solution is still fast (although not as fast as measured before), congrats 🙂

😄 1
mfikes 2018-12-03T22:27:55.481100Z

Having said all this, ClojureScript was pretty slow on today’s problem.

borkdude 2018-12-03T22:33:16.481300Z

CLJ
Testing aoc.y2018.d03.borkdude
part-2 took 756.09 msecs
part-1 took 57.66 msecs

Testing aoc.y2018.d03.iamdrowsy
part-2 took 653.79 msecs
part-1 took 83.38 msecs

Testing aoc.y2018.d03.mfikes
part-2 took 673.82 msecs
part-1 took 552.37 msecs

Testing aoc.y2018.d03.mrmcc3
part-2 took 762.67 msecs
part-1 took 0.40 msecs

Testing aoc.y2018.d03.transducer
part-2 took 157.78 msecs
part-1 took 23.40 msecs

CLJS
Testing aoc.y2018.d03.borkdude
part-1 took 5555.00 msecs
part-2 took 1677.00 msecs

Testing aoc.y2018.d03.iamdrowsy
part-1 took 5439.00 msecs
part-2 took 638.00 msecs

Testing aoc.y2018.d03.mfikes
part-1 took 5314.00 msecs
part-2 took 5760.00 msecs

Testing aoc.y2018.d03.mrmcc3
part-1 took 2589.00 msecs
part-2 took 177.00 msecs

Testing aoc.y2018.d03.transducer
part-1 took 639.00 msecs
part-2 took 75.00 msecs

borkdude 2018-12-03T22:34:56.481900Z

about 4x slower roughly speaking

3Jane 2018-12-03T22:57:51.482700Z

this channel exists, yay! ❤️

4
✅ 3
3Jane 2018-12-03T23:03:17.483300Z

maybe not so yay XD