
Oh, the leaderboard is in order of how soon you post your answer - I guess I’m doomed to the bottom since I’ll probably be doing these late in the day :)

Doesn’t change the level of fun though.

honestly if you consistently do them every day I’m sure you’ll be ahead of most people regardless of what time during the day you do them

@winny your Day 1 solution is pretty amazing IMO ! https://github.com/winny-/aoc/blob/master/2020/01/day01.rkt

Might miss some solutions in a different input file, but the concision is incredible :)

Thanks. :-) Part two takes awhile due to duplicate work, but i gave myself only 15 minutes to write it

Just out of curiosity, have you spent much time w/ Haskell or ML’s ?

Yes, some… sml and scala in school. Ocaml and haskell for fun/hacking on code

But really racket is my first exposure to fp, besides learning list processing stuff in python list comprehensions and .net LINQ

I need to get more comfortable with folds, etc. I felt pretty good about the following: (define (ascending-permutations n lst)
(cond [ (null? lst) '() ]
[ (= n 1) (map (λ (e) (list e)) lst) ]
[ else (append (foldr (λ (e result) (cons (cons (car lst) e) result))
'()
(ascending-permutations (sub1 n) (cdr lst)))
(ascending-permutations n (cdr lst))) ]))
but had to think about it for a while, and that’s only part of a solution vs. your one line complete solution :)

Coming from Assembler/C/C++ in the old days, it’s hard for me to not consider efficiency, but sometimes, a concise, readable solution is best, even if a bit slower.

@winny I just noticed you could probably just apply *
instead of that first fold: (apply * (for/first ([c (combinations (port->list) 2)] #:when (= 2020 (foldl + 0 c))) c))

Pretty amazing that Racket can solve Day 1 Part 1 in one line like that - thanks for the inspiration!

Goof catch! I’m always shy with apply. We know the list length is very short, so it’s probably similar time cost yet less verbosity. If it was very long list, apply might use a good amount of memory.

For every concise solution I wrote, I’ve probably deleted twice as many very verbose and wordy solutions… Keep playing with list processing and fp, and it’ll become very comfortable and intuitive in no time! I learn new stuff about fp every time i exercise this style too, so it keeps me engaged.

Folds can be handy, but it does seem like list comprehensions are more readable (eye of the beholder I suppose): cartesian [] = []
cartesian [x] = [[e] \| e <- x]
cartesian (x:xs) = [ x' : rest \| x' <- x, rest <- cartesian xs ]
vs. cartesian [] = []
cartesian [x] = map (\ e -> [e]) x
cartesian (x:xs) = foldr (\ x' result ->
(foldr (\ tc l -> (x':tc):l) result tailCross)) [] x
where tailCross = cartesian xs