racket192
2019-12-8 16:20:34

@racket192 has joined the channel


spdegabrielle
2019-12-8 17:08:19

Welcome @racket192 :smiley: Please use the Leaderboard Key: 22197-a7a01707 to join the Racket leaderboard on https://adventofcode.com/ Solutions in ANY Racket Language; #lang(too many to list),  languages that target other architectures (FPGA,6510) and derivatives like RacketScript, Pyret & Urlang. Hackett is ok. See https://racket-lang.org for info about Racket languages, documentation etc. Languages used so for have included standard Racket, Rosette, and Rebellion.


racket192
2019-12-8 17:08:44

Thanks @spdegabrielle


spdegabrielle
2019-12-8 17:09:11

Good luck!


racket192
2019-12-8 17:09:24

I was hoping to see more solutions published here, so I could refine my newb solutions! Four stars so far.


spdegabrielle
2019-12-8 17:09:58

I believe matthew butterick is publishing his solutions


spdegabrielle
2019-12-8 17:10:11

I’ll try find the link.


spdegabrielle
2019-12-8 17:10:12

brb


racket192
2019-12-8 17:11:46

(define final-answer 19690720)

(for* ([noun 99] [verb 99]) (define v (vector-copy GAP)) (vector-set! v 1 noun) (vector-set! v 2 verb) #:final (equal? (vector-ref (run-program v) 0) final-answer) (printf "The solution to 2.2 is ~a\n" (+ (* 100 noun) verb)))


racket192
2019-12-8 17:12:34

For Day 2, Problem 2: The for* prints out every try until the final solution. I’d love a way to just see the final answer!


racket192
2019-12-8 17:13:17

Also this is pretty brute force. Couldn’t think of a quicker way to solve it though.


spdegabrielle
2019-12-8 17:20:53

@Leo Laporte <https://github.com/mbutterick/aoc-racket/tree/master/2019>


racket192
2019-12-8 17:25:01

Ah, Matthew’s solution is helpful. Function composition to the rescue. Thanks!


racket192
2019-12-8 17:34:57

(define final-answer 19690720)

(define (try-this noun verb) (local [(define v (vector-copy GAP))] (vector-set! v 1 noun) (vector-set! v 2 verb) (vector-ref (run-program v) 0)))

(for* ([noun 99] [verb 99] #:when (equal? (try-this noun verb) final-answer)) (printf "The solution to 2.2 is ~a\n" (+ (* 100 noun) verb)))


sorawee
2019-12-8 19:07:58

FYI, you want to use the constant 100, which will loops from 0 to 99


sorawee
2019-12-8 19:08:17

If you use 99 it will loop from 0 to 98


sorawee
2019-12-8 19:23:04

For part 2, my previous solution uses Rosette to generate constraints and then solve them. I now switch to the brute force solution though since I want to share the intcode implementation with other days and Rosette doesn’t work well with continuation voodoo like generator.


samdphillips
2019-12-8 20:54:50

spoilers :smile:


samdphillips
2019-12-8 21:04:09

For day 7 I haven’t wanted to deal with continunation based coroutines so I’ve now written a cooperative scheduler.


wanderley.guimaraes
2019-12-8 22:17:59

@samdphillips, did you publish your solution somewhere? I don’t know what cooperative scheduler means and I would love to learn.


samdphillips
2019-12-8 22:55:20

It’s in my github aoc repo. It’s not quite done yet.

https://github.com/samdphillips/aoc-2019/blob/master/07.rkt

In a multithread/process concurrent (not parallel) environment the scheduler is the bit of code that decides which process runs next. In a cooperative system the processes run for as long as they like and “yield” to the scheduler to allow other processes to run.

In a preemptive environment the scheduler pauses the processes and switches the tasks.


samdphillips
2019-12-8 22:56:43

In my setup whenever and input instruction is processed if there is no input it goes into a wait state and lets the scheduler run. Also when an output instruction is processed the intcode machine yields.


samdphillips
2019-12-8 23:16:51

(ACTUALLY, I’m not adding a yield in the output instruction because it looks to be working good enough now.)


wanderley.guimaraes
2019-12-9 01:37:04

I see .. my solution is similar to yours (but more ugly). I have a main loop that runs until all machines are halted. For each iteration, I feed one machine with the output of its feeder if the machine is waiting for input and the other has output available.


wanderley.guimaraes
2019-12-9 01:37:18

Thanks for the explanation


samdphillips
2019-12-9 01:58:19

I did something very incorrect (and specifically called out in the problem statement) and it worked in part one.


samdphillips
2019-12-9 01:58:36

(of day 7)