This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # adventofcode (47)
- # announcements (7)
- # aws (1)
- # babashka (52)
- # beginners (80)
- # boot (3)
- # calva (19)
- # cider (9)
- # cljs-dev (1)
- # clojure (48)
- # clojure-brasil (1)
- # clojure-dev (27)
- # clojure-europe (3)
- # clojure-madison (3)
- # clojure-nl (29)
- # clojure-spec (11)
- # clojure-sweden (1)
- # clojure-uk (49)
- # clojurescript (66)
- # core-async (20)
- # cryogen (4)
- # cursive (13)
- # data-science (7)
- # datomic (5)
- # emacs (30)
- # figwheel-main (11)
- # fulcro (15)
- # graphql (8)
- # jobs (5)
- # joker (17)
- # lambdaisland (1)
- # leiningen (2)
- # malli (2)
- # off-topic (5)
- # pathom (22)
- # re-frame (12)
- # reagent (29)
- # reitit (2)
- # ring (10)
- # shadow-cljs (57)
- # specter (3)
- # tools-deps (22)
- # vim (5)
- # xtdb (7)
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.
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. 😁
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
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 😄
after some testing I noticed that if I change is constant if I bump the "noun" variable
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..
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.
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))))
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
Mine for day 1 and 2: https://github.com/ChrisBlom/advent-of-code/tree/master/src/adventofcode/2019
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.
def should go outside your
let inside your functions.
for can be combined into one. This way you can avoid
(nth seq 0) equals
4. I think in this task
subvec is not necessary.
5. Instead of
vector use just
(into (vector) map ...) can be substituted with
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.
(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))))))
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 ==.
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.
(get  1) => nil (nth  1) Execution error (IndexOutOfBoundsException) ( 1) Execution error (IndexOutOfBoundsException)