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
Average-user 2018-12-25T02:05:57.090500Z

They are talking about day 9

2018-12-25T07:32:52.091Z

All done - hooray

1
3
misha 2018-12-25T07:40:50.091600Z

day 23 2 :harold:

2018-12-25T07:45:54.093500Z

Honestly, I lucked my way through that one at the repl. It’s the only one I’m not sure I could do from scratch again. I still don’t know what a correct algorithm is. 😞

misha 2018-12-25T07:55:03.094Z

I am reusing today's solution for 23/2 right now : )

misha 2018-12-25T07:55:42.094800Z

at this point I'll accept anything under 30minutes, will see how it goes

misha 2018-12-25T08:09:17.095300Z

out of 1000, 978 ranges intersect

Average-user 2018-12-25T15:22:41.097800Z

@norman Which algorithm for connected components did you use?

Average-user 2018-12-25T15:23:27.098100Z

(for Day25)

2018-12-25T15:27:22.098500Z

For search? Just a simple bfs https://github.com/orb/advent2018/blob/master/src/advent2018/day25.clj#L36

2018-12-25T15:29:40.099Z

I’m looking at ubergraph at the moment though https://github.com/Engelberg/ubergraph

2018-12-25T15:30:08.099800Z

That’s probably worth having in the toolbelt

Average-user 2018-12-25T15:36:26.100Z

my solution runs in 2s

Average-user 2018-12-25T15:38:08.100200Z

yours takes over a minute

2018-12-25T15:40:18.101600Z

Yeah. It was 1am when I got started. I’m really surprised it runs 🙂

2018-12-25T15:40:21.101900Z

at all

Average-user 2018-12-25T15:40:57.102800Z

(defn connected-with [x graph]
  (loop [gs graph, cs #{x}]
    (let [ng (mapcat #(get gs %) cs)]
      (if (empty? ng)
        [cs gs]          
        (recur (reduce dissoc gs cs) (reduce conj cs ng))))))

(defn find-connected
  "Graph should be a map from nodes to their neighbors"
  [graph]
  (loop [gs graph, ac #{}]
    (if (empty? gs)
      ac
      (let [[cs ngs] (connected-with (ffirst gs) gs)]
        (recur ngs (conj ac cs))))))
This is an algorithm to detect connected components of a graph that I came u with past year, since there also was a problem of finding connected components. Don't know how good is it. But I compared the time it takes with http://clj-me.cgrand.net/2013/03/18/tarjans-strongly-connected-components-algorithm/ . And there is almost no difference

2018-12-25T15:41:46.104Z

All the work in my solution is that nest for loop. O(n^2).

Average-user 2018-12-25T15:42:22.104700Z

I'm wondering if by some chance I accidentally implemented an already known connected components algorithm. Or something very similar