Fork me on GitHub

@potetm Are you doing your videos this year?


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


too busy at the moment


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:


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

👍 1
😎 1
Jett Durham06:12:54

I suppose I ought to share my repo, given my current slot in the leaderboard 😅 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. 😁


@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.


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

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.

👍 3

@fellshard that is very cool


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


my solutions for the day: second one took two coffees to figure out without bruteforcing 😄

❤️ 1

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


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


My solution: I suspect my handling of the 99 op code passed my tests but needs some further thought Not used to the mutation risk..


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?


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


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


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


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


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.


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


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.


it is lazy infinite positive quarter of a xy plane. Sweet, but yeah, ranges are known, so for is more readable and sufficient here


I wasn't sure if those values where necessarily bounded. But yeah.

Alex Jackson21:12:03

Hi all, I'm using aoc to learn me some clojure this year. here's my solution for day 2: 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.


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

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

Alex Jackson21:12:42

ah cool these language comments are great. thank you


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.


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

👍 2

(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))))))


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


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

👍 1

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

val_waeselynck21:12:47;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.


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

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.


(get [] 1)
=> nil
(nth [] 1)
Execution error (IndexOutOfBoundsException) 
([] 1)
Execution error (IndexOutOfBoundsException)