way too little info to comment
post a gist w/ the 2 versions + the method used to time?
@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: https://gist.github.com/cellularmitosis/269d593919a7337219f8df7c5a5df648
@jasonpepas you might want to use quot instead of Math/floor. I had the same, but quot is easier.
https://github.com/RutledgePaulV/aoc2019/blob/master/src/aoc2019/day2.clj
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. 😁
@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.
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
@fellshard that is very cool
My second puzzle: https://github.com/pesterhazy/advent2019/tree/master/src/advent
I have a feeling that Intcode will stay with us for a while
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 😄
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..
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
https://github.com/tschady/advent-of-code/blob/master/src/aoc/2019/d02.clj
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?
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:And mine https://github.com/genmeblog/advent-of-code-2019/blob/master/src/advent_of_code_2019/day02.clj
Mine for day 1 and 2: https://github.com/ChrisBlom/advent-of-code/tree/master/src/adventofcode/2019
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.
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.
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
7. (not (nil? x))
can be substituted with (seq x)
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
(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)
Also consider using destructuring on op-seq, and case
rather than (if (== ...)). = should usually be favoured over ==.
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.
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.
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.
As long as we're sharing repos: https://github.com/rjray/advent-2019-clojure
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.