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
2019-12-02T00:37:44.048600Z

way too little info to comment

2019-12-02T00:38:01.048800Z

post a gist w/ the 2 versions + the method used to time?

2019-12-02T02:16:31.049600Z

@potetm Are you doing your videos this year?

2019-12-02T02:55:08.050400Z

If I do, it’ll have to be after the advent season 😕

2019-12-02T02:55:15.050700Z

too busy at the moment

pepas 2019-12-02T03:57:26.051600Z

hey folks, I’m very new to clojure. decided to go through the advent of code stuff to get some practice! here’s day 1: https://gist.github.com/cellularmitosis/269d593919a7337219f8df7c5a5df648

mpcjanssen 2019-12-02T04:59:53.053Z

@jasonpepas you might want to use quot instead of Math/floor. I had the same, but quot is easier.

👍 1
😎 1
Jett Durham 2019-12-02T06:40:54.057600Z

I suppose I ought to share my repo, given my current slot in the leaderboard 😅 https://github.com/thejettdurham/advent-of-code-2019-clj I’m a Senior Frontend Engineer working in React(+Native) by day, and wannabe Clojurist by night. I don’t have formal CS training, so Advent of Code gives me the opportunity to help fill in those gaps in the fundamentals. 😁

fingertoe 2019-12-02T07:19:05.059400Z

@mpcjanssen @jasonpepas I used int instead of quot or Math/floor without any problem.. Seemed to coerce a ratio to it’s next lowest integer.

mpcjanssen 2019-12-02T07:57:54.061500Z

What I like about the iterate based solutions is that they clearly separate the step function between states and the terminating condition. This is great for debugging.

👌 1
fellshard 2019-12-02T08:38:40.063200Z

Trying to focus a bit differently this year. I'm solving for speed first, then focusing on visualizing the problem/solution. This has a side-effect of encouraging me to find CLJC solutions for rapid porting to the Quil sketch host. http://www.quil.info/sketches/show/0622589e4acd61f73d86eff09064deff308553905d58dfc10448cf244ce9fa24 http://www.quil.info/sketches/show/d804ff390bc3f0bf59ba151699b5930e82158efc95765b5c81f188eec0e648a3

👍 3
mpcjanssen 2019-12-02T08:45:59.063600Z

@fellshard that is very cool

pesterhazy 2019-12-02T09:18:55.063900Z

My second puzzle: https://github.com/pesterhazy/advent2019/tree/master/src/advent

pesterhazy 2019-12-02T09:23:44.064500Z

I have a feeling that Intcode will stay with us for a while

karlis 2019-12-02T10:31:52.065700Z

my solutions for the day: https://github.com/skazhy/advent/blob/master/src/advent/2019/day2.clj second one took two coffees to figure out without bruteforcing 😄

❤️ 1
fingertoe 2019-12-02T10:33:57.067500Z

My solution: https://github.com/jreighley/aoc2019/blob/master/src/aoc/aoc2.clj I suspect my handling of the 99 op code passed my tests but needs some further thought Not used to the mutation risk..

2019-12-02T11:49:54.068200Z

Can you explain? Why is the output linear in the noun variable?

karlis 2019-12-02T12:51:56.068700Z

after some testing I noticed that if I change is constant if I bump the "noun" variable

dpsutton 2019-12-02T13:59:12.070200Z

is there a mistake in day2 examples? 1,1,1,4,99,5,6,0,99 becomes 30,1,1,4,2,5,6,0,99 it highlights the 30 and the 2 as new values. but there can only be one single instruction run because position 5--the second opcode-- is a 99 and the machine halts?

rutledgepaulv 2019-12-02T14:11:50.070700Z

the first step is to replace 99 with 2. add registers 1 and register 2 and put into register 4 (5th position)

dpsutton 2019-12-02T14:15:38.072500Z

thanks. i did a partition-by 4 rather than allowing for dynamic instructions. part 1 still worked 🙂

misha 2019-12-02T14:26:31.074700Z

I assoced to (state res-idx) rather than to res-idx and part 1 worked too. I wonder if that was a deliberate trap or unintentional.

misha 2019-12-02T16:01:59.075900Z

(def enum-pairs
  (letfn [(pairs [i] (map (fn [j] [j (- i j)]) (range (inc i))))]
    (mapcat pairs (range))))
wtf :opieop:

2019-12-02T19:54:21.077100Z

Mine for day 1 and 2: https://github.com/ChrisBlom/advent-of-code/tree/master/src/adventofcode/2019

👍 1
genmeblog 2019-12-02T20:44:27.077500Z

Looks like (quite not optimal) list comprehension. I would use for here. Especially when we know that > Each of the two input values will be between 0 and 99, inclusive.

Alex Jackson 2019-12-02T21:02:03.080100Z

Hi all, I'm using aoc to learn me some clojure this year. here's my solution for day 2: https://github.com/jacksonal/advent-of-code-2019/blob/master/src/advent_of_code_2019/day2.clj any comments or criticisms welcome. I've never written a line of clojure outside of messing around in the REPL a little bit. I especially struggled with figuring out how to best use (for) although it sounds like there is a non-brute force solution.

genmeblog 2019-12-02T21:11:55.080300Z

Hi Alex. Some use of language comments. 1. def should go outside your defn. Use let inside your functions. 2. for can be combined into one. This way you can avoid flatten 3. (nth seq 0) equals first 4. I think in this task subvec is not necessary. 5. Instead of vector use just [] 6. (into (vector) map ...) can be substituted with mapv

👍 1
genmeblog 2019-12-02T21:12:56.080600Z

7. (not (nil? x)) can be substituted with (seq x)

Alex Jackson 2019-12-02T21:13:42.080800Z

ah cool these language comments are great. thank you

fingertoe 2019-12-02T21:14:10.081Z

Nice looking code. The only serious “Beginner” hallmark that I see is the user of the def inside of the int-compute function. It’s pretty rare to see a def within a defn — usually we use let bindings in that spot. I think most folks would use the def on it’s own to slurp the input data, then pass that as an arg to the int-compute.

tws 2019-12-02T21:14:35.081200Z

:let and :when in the for loop can help clear it up

👍 2
tws 2019-12-02T21:15:20.081500Z

(defn part-2 [input]
  (let [magic-output 19690720]
    (first (for [noun  (range 100)
                 verb  (range 100)
                 :let  [tape (run-tape input noun verb)]
                 :when (= magic-output (first tape))]
             (+ verb (* 100 noun))))))

genmeblog 2019-12-02T21:15:44.081700Z

Also, since a lot of code is already around, take a look at it.

genmeblog 2019-12-02T21:19:13.081900Z

8. One more advice (nth vector k) can be replaced by (vector k) eg. ([0 1 2 3 4] 3)

👍 1
val_waeselynck 2019-12-02T21:38:34.082100Z

Also consider using destructuring on op-seq, and case rather than (if (== ...)). = should usually be favoured over ==.

val_waeselynck 2019-12-02T21:41:47.082400Z

https://clojurians.slack.com/archives/C0GLTDB2T/p1575321553081900?thread_ts=1575320523.080100&cid=C0GLTDB2T Some consider this bad practice though. It's clever, but may be overly general, obscuring the type of vector and increasing the risk of breakage.

val_waeselynck 2019-12-02T21:43:23.082700Z

https://tonsky.me/blog/readable-clojure/

👍 2
genmeblog 2019-12-02T21:56:16.083200Z

Yes, yes, in general you're right. But in this case, when code is short and vector type is used consciously it can be helpful.

💯 1
genmeblog 2019-12-02T22:00:46.083400Z

Anyway. In contests like this plenty of performance tricks will be used to make algorithms efficient enough. Some of such ticks can be considered bad style.

rjray 2019-12-02T22:06:55.084200Z

As long as we're sharing repos: https://github.com/rjray/advent-2019-clojure

fingertoe 2019-12-02T22:57:40.084400Z

It’s sorta Greek to us Clojurists, but mutability causes that 99 to be replaced by a 2.

fingertoe 2019-12-02T23:01:03.084600Z

I am pretty sure by code didn’t think that through either.