popa.bogdanp
2020-12-1 09:49:42

@popa.bogdanp has joined the channel


badkins
2020-12-1 14:32:14

@badkins has joined the channel


badkins
2020-12-1 16:59:28

I have a question about Day 1 Part 2. I’ll put it in a thread to avoid spoilers.


badkins
2020-12-1 16:59:58

Did anyone generalize to N, or did you just modify your solution for 2 to work specifically for 3?


badkins
2020-12-1 17:13:51

I’ve added a <https://github.com/lojic/LearningRacket/tree/master/advent-of-code–2020|Advent of Code 2020 directory> to my <https://github.com/lojic/LearningRacket|Learning Racket repo>


johnmwise
2020-12-1 17:14:07

@johnmwise has joined the channel


samdphillips
2020-12-1 17:18:08

I adapted mine. Now that I squint generalizing it shouldn’t be too hard.


badkins
2020-12-1 17:20:28

I had to think a bit harder than I should have to create find-n - seems like a perfect problem for lisps.


badkins
2020-12-1 17:28:08

I’m not super pleased with the end result, so if anyone comes up with a more elegant find-n, let me know: https://github.com/lojic/LearningRacket/blob/09b032f0ae7edcbb493954eec4e0bc53a417e24f/advent-of-code-2020/day1b.rkt#L28-L48



popa.bogdanp
2020-12-1 20:20:42

samdphillips
2020-12-1 20:32:02

I’m scared, and intrigued, to see what you have cooked up.


badkins
2020-12-1 21:16:33

Looking at Racket’s cartesian-product: (define (cartesian-product . ls) (define (cp-2 as bs) (for*/list ([i (in-list as)] [j (in-list bs)]) (cons i j))) (foldr cp-2 (list (list)) ls)) I’m pretty sure there is something similarly elegant that combines elements in a way needed for this task.


badkins
2020-12-1 21:17:13

I’m fine with not short circuiting - probably better to find all solutions anyway.



badkins
2020-12-1 22:11:34

Ok, I feel more comfortable with the following solution to a slightly different problem: (define (ascending-permutations lst n) (reverse (let loop ([ lst lst ][ n n ][ stack '() ][ result '() ]) (if (= n 0) (cons (reverse stack) result) (if (null? lst) result (let ([ ans (loop (cdr lst) (sub1 n) (cons (car lst) stack) result) ]) (loop (cdr lst) n stack ans))))))) Produces all the “ascending permutations” - I’m really not sure what to call them.


badkins
2020-12-1 22:12:17

Maybe making this into a generator would do the job.


badkins
2020-12-1 22:18:53

Hmm… no need for the ans variable: (define (ascending-permutations lst n) (reverse (let loop ([ lst lst ][ n n ][ stack '() ][ result '() ]) (if (= n 0) (cons (reverse stack) result) (if (null? lst) result (loop (cdr lst) n stack (loop (cdr lst) (sub1 n) (cons (car lst) stack) result)))))))


eeide
2020-12-2 01:16:54

@eeide has joined the channel