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
st3fan 2020-12-10T01:20:30.011500Z

Totally over-thinking this one

➕ 2
fingertoe 2020-12-10T06:19:38.014200Z

Kinda quiet in here tonight? 😉

👋 1
2020-12-10T06:22:06.014600Z

Good morning

😁 1
2020-12-10T06:22:48.015400Z

I am sure people will start to be VERY DYNAMIC very soon. … or never (<- hidden joke there)

😆 1
plexus 2020-12-10T09:04:30.024600Z

I had to google "dynamic programming", seems this is basically just divide and conquer algorithms? it's not confusing at all that this has nothing to do with dynamic programming languages or dynamic bindings

2020-12-10T18:17:24.085200Z

It is a "divide and reuse" way of doing. I guess the "dynamic" part is the non-constant cost of calculating things when memoized.

2020-12-10T06:24:41.015500Z

My solutions for today https://github.com/green-coder/advent-of-code-2020/blob/master/src/aoc/day_10.clj

🎉 2
2020-12-10T06:27:52.016300Z

And mine, definitely wanna clean up it https://github.com/zelark/AoC-2020/blob/master/src/zelark/aoc_2020/day_10.clj

🎉 2
mchampine 2020-12-10T06:38:17.017Z

Updated w/ part 2. Note: I found an interesting pattern. Looking a the diffs pattern (first and last value with moving window of 3) you can simply count the number of runs of 2's. Runs of 3 = 7, runs of 2 = 4, runs of 1 = 2, then take the product.

;; part 1
(let [jolts (sort (concat input [0 (+ 3 (apply max input))]))
      diffs (map (fn [[a b]] (- b a)) (partition 2 1 jolts))]
  (apply * (vals (select-keys (frequencies diffs) [1 3]))))
;; =&gt; 1690

;; part 2
(defn adapter-combos [inp]
  (-&gt;&gt; (sort (concat inp [0 (+ 3 (apply max inp))]))
       (partition 3 1)
       (map (fn [[a _ c]] (- c a)))
       (partition-by identity)
       (keep {'(2 2 2) 7 '(2 2) 4 '(2) 2})
       (reduce *)))

(adapter-combos input)
;; =&gt; 5289227976704

rjray 2020-12-10T07:25:24.019300Z

Crap... almost 2 1/2 hours and I can't get a solution for part 2 that takes less than forever...

👍 1
☝️ 2
pez 2020-12-10T07:53:40.019900Z

No real idea about how to think about step 2. Step1 seemed like this to me:

(-&gt;&gt; input
       (parse)
       (sort)
       (cons 0)
       (#(concat % [(+ 3 (last %))]))
       (partition 2 1)
       (map #(- (second %) (first %)))
       (frequencies)
       (vals)
       (apply *))

👍 1
plexus 2020-12-10T08:26:23.022900Z

Spent about an hour on this one, and same deal. The second demo input takes ~25ms for part2, but no end in sight with the real input. Might have to crack out visualvm and do some profiling.

plexus 2020-12-10T08:30:13.023400Z

It's that time of the year where I'm starting to wonder why I'm wasting my time on this...

😁 2
2020-12-10T08:56:35.024Z

man, top solver had solution for part 2 solved in 2:19

🤯 2
2020-12-10T09:23:16.026600Z

btw during reclojure I saw someone fire up a nice graph genreated from the profiler output

2020-12-10T09:24:10.027300Z

anyone knows how it can be done? I used to love to generate these graphs with Python and https://github.com/gak/pycallgraph

2020-12-10T09:25:12.027800Z

something like https://github.com/jstepien/flames maybe but I think it was a different one

oxalorg (Mitesh) 2020-12-10T09:29:05.028100Z

Oh wow didn't know you could check the stats! Thanks, it took me 26 minutes 🙈

solf 2020-12-10T09:59:25.031400Z

@andrea.crotti probably this one: https://github.com/clojure-goes-fast/clj-async-profiler

Björn Ebbinghaus 2020-12-10T10:25:35.035900Z

Don’t forget your old friend memoize. That takes the naive approach straight to O(n).

plexus 2020-12-10T10:46:59.037Z

I don't see how my solution benefits from memoize, it's not doing anything multiple times

plexus 2020-12-10T10:47:27.037200Z

well, not 100% true, but still 🙂

plexus 2020-12-10T13:09:59.040900Z

alright, got a solution now

🎉 1
2020-12-10T14:31:31.045200Z

The best solution I’ve seen today. Only one thing I could add to it is simplifying of the part 1 by reverting map’s arguments. [Spoiler inside]

2
🤯 1
2020-12-11T09:14:57.128200Z

I'm having trouble wrapping my head around this solution for part 2. Anyone care to explain the logic behind it?

2020-12-12T11:05:04.182500Z

@gjsugiyama The key here is a reverse order of adapters. We start with a map with just the end adapter, which means there is only one way to reach the end. Then, on each iteration we count ways for the next adapter based on cnts map and previous calculations. And so on, until we reach opposite end of reverse sequence of adapters. At the end, we get a result hold under 0 key. Actually, the idea is pretty simple and elegant.

🙏 1
2020-12-10T14:31:57.045300Z

(-&gt;&gt; (frequencies (map - (rest adapters) adapters)) vals (apply *))

👍 1
misha 2020-12-10T14:34:21.046200Z

p2:
"Elapsed time: 0.39624 msecs"
=&gt; 19208 (test input)
 
"Elapsed time: 9.720333 msecs"
=&gt; 96717311574016

Lars Nilsson 2020-12-10T15:08:17.050200Z

Was trying to come up with some clever solution, but in the end gave up and memoized results.

Lars Nilsson 2020-12-10T15:08:53.050600Z

Side-effect of my accomplishment is code that hurts my eyes.

Average-user 2020-12-10T15:18:47.051600Z

Forgot about aoc this year. Just remembered yesterday. Finally caught up !

👍 3
🏃 3
pez 2020-12-10T15:33:22.053500Z

Shiny gold stars does that to ya! 😃

Lars Nilsson 2020-12-10T15:37:59.053800Z

Is that why I'm looking at completing a backlog of AoC years?

Mno 2020-12-10T16:27:11.056300Z

I found an odd… pattern? in the results of day 10 part 2 . The results will only have prime factors of 2 and 7… I’ve been trying to figure out why.. and if I could leverage that into a different solution.

2020-12-12T21:39:39.208500Z

here is my (probably not too Clojurey) version, but hopefully with clear enough comments to explain the logic. https://github.com/jeff303/advent-of-code-2020/blob/master/src/advent_of_code/day10.clj#L41-L73

2020-12-10T16:45:07.057400Z

jeez it's getting hard even to understand the assignment

2020-12-10T16:45:31.058Z

I have to fire up all the neurons even to understand the instructions

➕ 1
🙏 1
Average-user 2020-12-10T16:45:33.058300Z

Check out https://www.reddit.com/r/adventofcode/comments/ka9pc3/2020_day_10_part_2_suspicious_factorisation/ post in reddit, unless you don't want any spilers

tws 2020-12-10T16:46:11.059Z

@hobosarefriends it’s because a run of 4 ones has 7 combos, a run of 3 ones has 4 combos, and a run of 2 ones has 2 combos.

tws 2020-12-10T16:46:31.059200Z

my input didn’t have more than run of 4

Average-user 2020-12-10T16:47:01.059400Z

Yep, it depends upon the length of runs, but I think is not that simple to get the exponents anyway

tws 2020-12-10T16:47:43.059600Z

my solution (almost there) may show that. it’s a variant of a change-making problem

Average-user 2020-12-10T16:50:27.059800Z

Kind of, I guess. But in this case there is an O(n) solution, so clearly not the general one

Mno 2020-12-10T16:50:28.060Z

I can’t say I understand it yet, but thanks a lot for the info guys

roelof 2020-12-10T17:20:06.061200Z

Just learning clojure and I wonder if the first 3 days can easiliy be done in clojure

2020-12-10T17:24:19.061700Z

an interesting stats today

🤪 2
2020-12-10T17:26:32.062Z

depends what you mean by easily

2020-12-10T17:26:58.062300Z

if you have never done clojure it might take a while but the algoriths to use are quite simple

2020-12-10T17:26:59.062500Z

There is a couple guys who recorded videos. You can learn from them a lot.

2020-12-10T17:27:25.062700Z

https://youtu.be/9ITiZ88sljA

2020-12-10T17:27:34.062900Z

yeah but you should try by yourself first maybe

2020-12-10T17:28:11.063100Z

and https://youtu.be/Vp8RbO7l6eg

Mno 2020-12-10T17:28:48.063900Z

part 2… it’s definitely not easy, I’d guess because the puzzle doesn’t hint at the solution so directly?

2020-12-10T17:29:49.064Z

My thinking is, but I'm having trouble implementing it.. Spoiliers ahead if this works* Find partitions where smallest number in partition is within 3 of biggest. either the partition will have 4 numbers in it, or the partition will have 3 numbers in it (or less) Partitions with 4 will have 4 combos. Partitions with 3 will have 2 combos. Multiply all theses partitions combo counts together. It works for the smaller test but not the bigger one. Or my code is guff. 😕 Am I on the right track or should I give up with this line of thinking?

Mno 2020-12-10T17:35:46.064800Z

make sure you have the beginning and ending pieces there

2020-12-10T17:36:25.065Z

you mean the starting (0) and ending + 3, does this makes a difference?

2020-12-10T17:36:34.065200Z

damn, thought i could ignore that

Mno 2020-12-10T17:36:55.065400Z

it does for this because you’re adding a 1 and 3 to the total

Lars Nilsson 2020-12-10T17:37:19.065600Z

A lot of the very early problems rely on using things like regular expressions, generating sequences using for and range, map and filter or sequences. Having a handle on things like that will take you past several problems.

Mno 2020-12-10T17:39:49.065900Z

I dunno how to explain it, because I don’t really understand it, but I did make it work by checking the number of consecutive 1 jumps and mapping:

{:dual-consecutive-1s 2
 :trip-consecutive-1s 4
 :quad-consecutive-1s 7}

Mno 2020-12-10T17:40:43.066800Z

and so in the beginning if you omit the 0 to 1 jump you’re missing a consecutive 1 from the beginning. I suppose the 3 jump at the end can be ignored

markw 2020-12-10T17:40:54.067100Z

I saw part 2 and was like.. oh that’s easy, i’ll just generate permutations for everything +3 from current, drop the count of that from the remaining sequence, and concat all the results to what i’ve found so far and recurse

2020-12-10T17:41:03.067500Z

yes, you are correct. The 0 at the start definitely makes a difference!

markw 2020-12-10T17:41:03.067700Z

Yeah that didn’t work

markw 2020-12-10T17:41:17.068100Z

then I thought.. oh that’s easy, I’ll just do a depth first search and track the paths.

markw 2020-12-10T17:41:25.068400Z

That also didn’t work… I think you can see where this is going

Average-user 2020-12-10T17:45:40.071400Z

I also tried working out all the paths, and went to buy bread (I do these in the morning). When I got back, it (obviously) had not finished, and just then I came up with the good one 🙂

markw 2020-12-10T17:46:13.071800Z

I guess my first indication should have been when using the second test input took like 5 seconds to count the valid paths

Lars Nilsson 2020-12-10T17:47:43.072300Z

My clue was the word "trillions".

markw 2020-12-10T17:47:59.072700Z

well it’s only trillions if you generate all permutations up front I think

markw 2020-12-10T17:48:13.073Z

or that’s how i interpreted it late last night

markw 2020-12-10T17:54:46.075Z

hmm actually, if you assume an upper bound for the branching factor of 3 (can be 1, 2, or 3 higher), then wouldn’t the possible paths be count of input ^ 3?

roelof 2020-12-10T17:56:42.075600Z

oops I hate regexes

roelof 2020-12-10T17:57:07.075800Z

range, map and filyer I already learned

roelof 2020-12-10T17:57:16.076Z

but now how to read from a file

Lars Nilsson 2020-12-10T17:59:01.076200Z

(slurp filename), or (line-seq (reader filename)) is fairly suitable. The first gets the whole content into a string, the second generates a sequence of lines (using reader from the http://clojure.java.io namespace).

roelof 2020-12-10T17:59:49.076400Z

I see , I think first learn more and get more familiar with clojure

Lars Nilsson 2020-12-10T18:01:27.076600Z

(map #(Long/parseLong %) (line-seq (reader filename))) would be a common way of getting a sequence of integers out of lines of integers in a file.

Lars Nilsson 2020-12-10T18:03:01.077600Z

Wouldn't it be 3^input?

tws 2020-12-10T18:03:07.077700Z

spoiler, but my solution goes along these lines: https://github.com/tschady/advent-of-code/blob/master/src/aoc/2020/d10.clj

tws 2020-12-10T18:03:21.078Z

relevant bit:

(defn permuted-partition-count
  "Returns the number of different ways a sequence can be carved up
  into segments of length 1,2, or 3"
  [xs]
  (-&gt;&gt; (combo/partitions xs :min 1 :max 3)
       (map (comp count combo/permutations))
       (reduce +)))

markw 2020-12-10T18:03:30.078300Z

oops sorry yes that’s what i meant

Lars Nilsson 2020-12-10T18:03:40.078600Z

3^100 is a big number..

markw 2020-12-10T18:03:43.078700Z

so basically a very big number

markw 2020-12-10T18:03:58.079100Z

yeah you know it’s a problem when there is an ‘e’ in the google rsults

markw 2020-12-10T18:04:56.079600Z

even being generous and assuming a branching factor of 2, that’s 2.1 billion paths for the second test input

markw 2020-12-10T18:05:07.079800Z

so much for search

Average-user 2020-12-10T18:06:32.079900Z

> I see , I think first learn more and get more familiar with clojure Doing AoC was for me, a good way to learn a language (in my case was Prolog)

Average-user 2020-12-10T18:08:29.081100Z

Is there any goo way to work a clojure file without creating a whole project? This year I'm doing days in different languages. And I don't want to create a whole project for single days

kpav 2020-12-10T18:09:13.081400Z

You could use a deps.edn file

kpav 2020-12-10T18:09:49.082200Z

also, as far as I know, you can just create a .clj file, im not aware of any need to create a whole project for it

👍 1
kpav 2020-12-10T18:10:14.082600Z

I am still learning though so take that with a grain of salt!

Average-user 2020-12-10T18:12:15.082800Z

Yup you can. But working with it gets kind of awkward. For example, I work with emacs-cider, and refuses to cider-jack-in (run the repl) correctly

kpav 2020-12-10T18:13:18.083Z

ah yeah, in that case try with a deps.edn file, i have a project with that and cider-jack-in seems to work fine

Average-user 2020-12-10T18:14:08.083200Z

Anything special in deps.edn ? Mine still fails

2020-12-10T18:14:32.083600Z

touch hw.clj                             
echo "(println \"Hello world\")" &gt; hw.clj
clj hw.clj                               
WARNING: When invoking clojure.main, use -M
Hello world

Lars Nilsson 2020-12-10T18:17:04.085100Z

I (like a lot of people, I imagine) have a project for all the days, and one file per day with a different namespace ( (ns aoc2020.day01) for example)

mchampine 2020-12-10T18:17:35.085400Z

Ah, I discovered the powers of 7, 4 and 2 pattern independently and used it for my part 2: Runs in “Elapsed time: 0.5174 msecs”

;; part 2
(defn adapter-combos [inp]
  (-&gt;&gt; (sort (concat inp [0 (+ 3 (apply max inp))]))
       (partition 3 1)
       (map (fn [[a _ c]] (- c a)))
       (partition-by identity)
       (keep {'(2 2 2) 7 '(2 2) 4 '(2) 2})
       (reduce *)))

(adapter-combos input)
;; =&gt; 5289227976704

kpav 2020-12-10T18:17:37.085600Z

I think you might just need {:deps}? heres the documentation https://clojure.org/guides/deps_and_cli

👍 1
2020-12-10T18:18:43.085800Z

at least you have to have {:paths [“src”]}, that’s enough to start

2020-12-10T18:19:37.086100Z

an example: https://github.com/zelark/AoC-2020/blob/master/deps.edn

Average-user 2020-12-10T18:21:49.086700Z

Thanks, Is now working

🙌 2
roelof 2020-12-10T18:49:27.087800Z

thanks both

2020-12-10T20:43:41.089500Z

glad its not just me!

2020-12-10T20:47:10.090300Z

I must be missing something obvious but why are the intervals between any 2 adapters today either 1 or 3. Why not 2?

Average-user 2020-12-11T13:32:58.130700Z

It is not hard actually. So suppose values for t(1),t(2), and t(3) are correct. And you wanna know how many ways are there to get to the fourth place in a run of ones, then since the fourth must be preceded by one of the previous three, there must be t(1) + t(2) + t(3) options. And so on an so on

pez 2020-12-11T16:34:00.142900Z

I think that what it means for the solution is about what I have there. Of course, it's solving the special case where there are no gaps off 2 in the input.

R.A. Porter 2020-12-10T20:49:19.090600Z

That’s just the way the Institute of Elvish Electrical Engineers spec’d them, I guess.

😁 1
pez 2020-12-10T20:50:52.090800Z

Not sure, but I “misunderstood” the description such that this was the case and based my solution on it. 😃

2020-12-10T20:51:50.091Z

yeah, i just realised i think my solution totally breaks if any 2 adapters were seperated by 2 (and not 1 or 3)

pez 2020-12-10T20:53:35.091200Z

Mine certainly will produce the wrong answer then. But I think it is quite small adaption needed,

Average-user 2020-12-10T21:02:51.091500Z

How do they fail? Are working with prime factorization? Or am I missing something?

2020-12-10T21:04:24.091700Z

I look for partitions that are like [4 5 6 7], and then find the ways through those partitions find the product of those, plus the count of the partitions that dont result in a branching.

✅ 1
2020-12-10T21:06:31.092100Z

so if in the 1st test input if the adapters were 1 4 5 6 8 10, my code would split it into [4 5 6] and I'd lose a branching multiplier

Average-user 2020-12-10T21:06:52.092300Z

what woul return to [1 3 5]?

2020-12-10T21:07:21.092500Z

1

2020-12-10T21:08:14.092700Z

[0 1 4 5 6 8 10] ;=> 2, where it should be 3

2020-12-10T21:09:05.092900Z

I got lucky my assumption held in the actual real data to pass 😄

Average-user 2020-12-10T21:09:26.093100Z

The input being [1 4 5 6 8 10]? Because we were supposed to add 0 ourselves right?

2020-12-10T21:09:33.093300Z

yes

Average-user 2020-12-10T21:09:49.093500Z

Mhh, yes I think I understand what the problem is

2020-12-10T21:09:50.093700Z

I ignored adding the final value, it changes nothing

2020-12-10T21:10:02.093900Z

since its + 3, it can't affect branching

Average-user 2020-12-10T21:10:20.094100Z

yeah right

Average-user 2020-12-10T21:10:50.094300Z

Mine I think it works with differences of two

Average-user 2020-12-10T21:11:09.094500Z

But I'm not so sure anymore haha

pez 2020-12-10T21:11:09.094700Z

My solution does not split or anything like that. Instead it finds sprees of distances 1, calculates (inc (combinations n 2)) on the length of these sprees and then multiplies them. This only works if there are no distances 2. But I think that I could adapt it for those as well.

pez 2020-12-10T21:11:39.094900Z

So, basically some math on part 1.

Average-user 2020-12-10T21:13:38.095100Z

Could you elaborate? I thought there was no close formula (even under the assumption that the there are no differences of 2)

pez 2020-12-10T21:16:43.095600Z

Translated that into:

(def ! 
  (memoize (fn [n]
             (reduce *' (range 1 (inc n))))))

(def combinations 
  (memoize (fn [n r]
             (if (= 1 n)
               0
               (let [n! (! n)
                     r! (! r)
                     r-n! (! (- n r))]
                 (/ n! (* r! r-n!)))))))

Average-user 2020-12-10T21:19:59.096Z

Thanks, I'll have a look at it. Though combinations of two can be calculated with n(n-1)/2, since r is constant in your application you don't need that complicated algorithm

pez 2020-12-10T21:24:36.096600Z

Oh, I struggled hard to see that connection. Very nice! I’ll throw criterium on this simpler one and see it gains me execution time as well.

Average-user 2020-12-10T21:29:05.096800Z

I really don't understand why your solution works 😂 But nicely done. Can you prove that it does what it should?

Average-user 2020-12-10T21:29:30.097Z

Ore give me an insight?

pez 2020-12-10T21:31:45.097200Z

So, about the same performance, but I take the simplification! 😃

Evaluation count : 4242 in 6 samples of 707 calls.
             Execution time mean : 145,779817 µs
    Execution time std-deviation : 4,846516 µs
   Execution time lower quantile : 141,316390 µs ( 2,5%)
   Execution time upper quantile : 152,683197 µs (97,5%)
                   Overhead used : 6,391737 ns

pez 2020-12-10T21:32:35.097400Z

I can’t really prove it, but I can tell you how I arrived at it…

Average-user 2020-12-10T21:37:53.097600Z

If you check, the lengths of runs of 1s are alel numbers between 1 and 20 (at least in my input) so yeah, not gonna change performance.

Average-user 2020-12-10T21:38:38.097800Z

And I think I'm understanding why it works now Thanks!

pez 2020-12-10T21:40:01.098Z

Let’s look at my part 1 solution:

(-&gt;&gt; input
       (parse)
       (sort)
       (cons 0)
       (#(concat % [(+ 3 (last %))]))
       (partition 2 1)
       (map (fn [[a b]] (- b a)))
       (frequencies)
       (vals)
       (apply *))
For the larger input example, after the (map (fn [[a b]] (- b a))) step I have:
(1 1 1 1 3 1 1 1 1 3 3 1 1 1 3 1 1 3 3 1 1 1 1 3 1 3 3 1 1 1 1 3)
So, to me those strings of 1s looked like “bidges”. For the shorter sprees it was easy to reason “I can remove none of them, this one, this one, those two…” and so on. There was a pattern to it and my daughter helped me see what the pattern was about. Then I googled it a bit and it seemed like the 2-combinations + 1 was the answer. I tried it and, boom.

pez 2020-12-10T21:40:52.098200Z

Pasting my part 2 here as well, for comleteness:

(-&gt;&gt; input
       parse
       (sort)
       (cons 0)
       (#(concat % [(+ 3 (last %))]))
       (partition 2 1)
       (map (fn [[a b]] (- b a)))
       (partition-by identity)
       (keep #(seq (filter #{1} %)))
       (map count)
       (map #(inc (combinations % 2)))
       (apply *)))

Average-user 2020-12-10T21:53:29.098800Z

I think your solution does not always work. Even if there are no differences of two: Try it on [1,2,3,4,5,8,9] for example. I think you are going to get 11. Where the real aswwer should be 13

pez 2020-12-10T21:57:06.099200Z

Haha, yes. it produces 11. Can you elaborate?

Average-user 2020-12-10T21:57:06.099400Z

Not that if you get to 4 or 5, you only have one way to proceed. Since 4 must go to 5. And 5 must go to 8 which must go to 9. So we can count 4 and 5 as leaves. And you get a tree with 13 leaves:

pez 2020-12-10T21:58:43.099800Z

So, my solution breaks at runs &gt; 4?

Average-user 2020-12-10T21:59:54.100Z

I thought so. But, my input has runs of 7 and it works on my input. So I'm not completely aware of whats going on

pez 2020-12-10T22:02:37.100200Z

This that the last 1 near a 3 couldn’t be removed was a thing that I and my daughter saw when we were looking at it. We didn’t draw a tree of it (thankfully, maybe) but we reasoned our way towards that, like you did there before you drew the tree.

pez 2020-12-10T22:04:07.100400Z

Does your input have runs of 5?

Average-user 2020-12-10T22:04:34.100600Z

just {1,2,4,7}

pez 2020-12-10T22:07:53.100900Z

Mine has 1,2,3,4… quite strange.

Average-user 2020-12-10T22:09:22.101100Z

No no, I lied sorry

Average-user 2020-12-10T22:09:39.101300Z

It does have runs of at most 4, there it is. I was looking at the wrong output

Average-user 2020-12-10T22:10:23.101500Z

haha. yes with runs of <= 4 it works as you found the formula so it fitted that pattern

pez 2020-12-10T22:20:23.101800Z

So then there might be a formula that works past 4, I guess. I just fitted 2-combinations + 1 onto the table we plotted, my daughter and I.

Average-user 2020-12-10T22:22:29.102300Z

Yup. That would be my guess too. About another formula I'm not too sure. That's why was suspicious in the first place. A lot of this combinatorial problems have no, or very hard to find closed formula

pez 2020-12-10T22:24:01.102500Z

Sometimes it helps not knowing much math.

Average-user 2020-12-10T22:24:23.102700Z

hahaha, yup.

pez 2020-12-10T22:25:38.102900Z

It bothers me to know end that there wouldn’t be a formula solution to it, though.

Average-user 2020-12-10T22:28:28.103100Z

You can still try to find one! I don't know if definitively does not exist. But yeah, probably not gonna be easy.🦜

pez 2020-12-10T22:29:13.103300Z

I’m no Ramanujan for sure.

rfisher 2020-12-10T22:30:46.104300Z

Part 2 feels like it requires some knowledge of mathematics which I do not have. Presumably some aspect of combinatorics.

pez 2020-12-10T22:32:33.106Z

@rob156 It might seem like that. And it helped me gather my shiny gold stars thinking it did. But I’ve just learnt (the thread above your post) that I had the math wrong. Haha.

Average-user 2020-12-10T22:33:21.106100Z

On reddit I saw solutions using "Tribonacci" numbers. Which are a generalization of fibonacci numbers. And fibonacci numbers have closed formulas (although using irrationals). So there might be one, but again, probably involving irrationals

rfisher 2020-12-10T22:34:20.106600Z

Hmm.... I'll keep thinking then!

pez 2020-12-10T22:36:57.106700Z

Interesting. My daughter and I was “seeing” fibbonacci sequences a while, but then when we blinked they were gone. 😃

pez 2020-12-10T22:38:08.106900Z

I have this feeling that some day soon the AoC challenge will involve runs > 4 and that I was supposed to walk into that trap.

🦜 1
pez 2020-12-10T22:43:48.107200Z

I se 1, 2, 4, 7, 13 in that tribonacci sequence, hmmm.

Average-user 2020-12-10T22:45:54.107800Z

Yup, that must be it

2020-12-10T22:46:08.108300Z

is there a typo on day 10, part 2, the longer sample input? here: https://adventofcode.com/2020/day/10 “In this larger example, in a chain that uses all of the adapters, there are `22` differences of 1 jolt and `10` differences of 3 jolts.” I think there are actually 9 differences of 3 jolts. I counted by hand (and also my code came up with that, which of course may not be bug free)

pez 2020-12-10T22:47:15.108400Z

(defn tribonacci [a b c]
  (lazy-seq (cons a (tribonacci b c (+' a b c)))))
According to stackoverflow.

❤️ 1
Average-user 2020-12-10T22:48:11.109200Z

Maybe you are not counting the max element + 3 you must add

2020-12-10T22:48:49.109500Z

ah, good catch. I somehow missed that. thanks, @lucaspolymeris!

🦜 1
pez 2020-12-10T23:04:53.110Z

That would make a solution I am still unable to prove to be:

(defn tribonacci [a b c]
  (lazy-seq (cons a (tribonacci b c (+' a b c)))))

(def run-lenght-&gt;paths
  (memoize (fn [n]
             (nth (tribonacci 1 2 4) (dec n)))))

(quick-bench
 (-&gt;&gt; parsed-input
      (sort)
      (cons 0)
      (#(concat % [(+ 3 (last %))]))
      (partition 2 1)
      (map (fn [[a b]] (- b a)))
      (partition-by identity)
      (keep #(seq (filter #{1} %)))
      (map count)
      (map run-lenght-&gt;paths)
      (apply *)) ; =&gt; 24179327893504
 )
; Evaluation count : 3990 in 6 samples of 665 calls.
;              Execution time mean : 150,040247 µs
;     Execution time std-deviation : 5,732067 µs
;    Execution time lower quantile : 143,768069 µs ( 2,5%)
;    Execution time upper quantile : 157,965810 µs (97,5%)
;                    Overhead used : 6,391737 ns