caente
2020-12-12 22:49:09

@caente has left the channel


badkins
2020-12-13 00:56:29

Yeah, that was a great tip! I worked pretty hard on trying to exploit the similarity between parts for <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day12.rkt|Day 12>, but I didn’t quite get to where I wanted.


me1890
2020-12-13 05:35:08

I’m kind of surprised how few people have solved todays so far…


haskal
2020-12-13 06:14:16

racket really had the import solution for today lol


haskal
2020-12-13 06:14:37

thank you racket :blue_heart:


me1890
2020-12-13 06:18:50

yup! :smile:


me1890
2020-12-13 06:19:10

I removed my second message becuase i figured it was a little too spoilery


notjack
2020-12-13 07:30:09

spoilers for day 12 solution in thread


notjack
2020-12-13 07:30:56

I cannot fucking believe I didn’t realize solve-chinese is in the standard distribution until after I implemented my solution


me1890
2020-12-13 07:31:19

oh no


me1890
2020-12-13 07:34:02

I learned about about CRT in my intro to discrete mathematics class earlier this semester, so i’m glad there was one problem where it was a little easier for me to get a high score. That being said, i was aware of solve-chinese after having looked through math/number-theory from other day’s problems. I would not want to implement it myself, it was a big enough pain in class.


notjack
2020-12-13 07:34:56

it was pretty dang painful implementing myself


notjack
2020-12-13 07:35:10

however now I’m playing around with something neat


notjack
2020-12-13 07:35:32

I made a congruence-equation? struct &gt; (congruence-equation 13 5) x = 3 (mod 5)


me1890
2020-12-13 07:36:25

why’s that? you needed to do some other modification with them?


me1890
2020-12-13 07:37:18

wait, nvm. I’m dumb.


me1890
2020-12-13 07:37:28

you said it was for implementing it yourself


notjack
2020-12-13 07:38:25

tweaked the printing: &gt; (congruence 13 5) #&lt;congruence: x = 3 (mod 5)&gt;


me1890
2020-12-13 07:38:39

very nice


me1890
2020-12-13 07:38:50

(it bugs me a little that you aren’t using ≡ though)


notjack
2020-12-13 07:38:54

oh I just made them because I like the idea of having a solve-chinese function that takes a Listof Congruence instead of two lists


notjack
2020-12-13 07:39:02

you know what? you’re right. one sec.


notjack
2020-12-13 07:39:22

&gt; (congruence 13 5) #&lt;congruence: x ≡ 3 (mod 5)&gt;


me1890
2020-12-13 07:39:36

thanks :slightly_smiling_face:


notjack
2020-12-13 07:39:49

thanks for saving me from having to google the ≡ character to copy paste it :p


me1890
2020-12-13 07:39:53

that does sound nicer than the two lists thing


me1890
2020-12-13 07:41:18

I made a for/lists loop to make my two lists, which isn’t the nicest, but it works. I will try your Listof Congruence approach tomorrow, it sounds nicer.


notjack
2020-12-13 07:41:36

I’m tweaking it slightly now


notjack
2020-12-13 07:44:09

Made a solve-congruences function that takes a Sequenceof Congruence


notjack
2020-12-13 07:44:27

(define (solve-congruences congruences) (define descending-congruence-list (transduce congruences (sorting #:key congruence-remainder #:descending? #true) #:into into-list)) (define remainders (map congruence-remainder descending-congruence-list)) (define moduli (map congruence-modulus descending-congruence-list)) (solve-chinese remainders moduli))


me1890
2020-12-13 07:46:55

Are there performance benefits to sorting the list?


notjack
2020-12-13 07:48:42

only if solve-chinese is implemented with a sieve, which now that I think about it, it probably isn’t


notjack
2020-12-13 07:49:55

uh… I have no idea what algorithm this is (define (solve-chinese as ns) (unless (andmap positive? ns) (raise-argument-error 'solve-chinese "(Listof Positive-Integer)" 1 as ns)) ; the ns should be coprime (let* ([n (apply * ns)] [cs (map (λ: ([ni : Integer]) (quotient n ni)) ns)] [ds (map modular-inverse cs ns)] [es (cast ds (make-predicate (Listof Integer)))]) (cast (modulo (apply + (map * as cs es)) n) natural?)))


me1890
2020-12-13 07:50:45

I didn’t sort my list and it seems to work fine for me (<2ms for the whole day)


notjack
2020-12-13 07:51:31

since there were only a handful of congruences in the input problem for today it probably didn’t matter, I just did it because the wiki article on the sieve algorithm said it was a good idea


notjack
2020-12-13 07:51:40

I’m gonna remove it from this one though since there’s not a sieve in sight


notjack
2020-12-13 07:52:22

(define (solve-congruences congruences) (define congruence-list (sequence-&gt;list congruences)) (define remainders (map congruence-remainder congruence-list)) (define moduli (map congruence-modulus congruence-list)) (solve-chinese remainders moduli))


me1890
2020-12-13 07:58:16

Definitely a cleaner solution than mine, thanks for sharing! I should be getting to bed for tonight though, good luck on tomorrow’s problems!