@racket192 has joined the channel
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.
Thanks @spdegabrielle
Good luck!
I was hoping to see more solutions published here, so I could refine my newb solutions! Four stars so far.
I believe matthew butterick is publishing his solutions
I’ll try find the link.
brb
(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)))
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!
Also this is pretty brute force. Couldn’t think of a quicker way to solve it though.
@Leo Laporte <https://github.com/mbutterick/aoc-racket/tree/master/2019>
Ah, Matthew’s solution is helpful. Function composition to the rescue. Thanks!
(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)))
FYI, you want to use the constant 100, which will loops from 0 to 99
If you use 99 it will loop from 0 to 98
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.
spoilers :smile:
For day 7 I haven’t wanted to deal with continunation based coroutines so I’ve now written a cooperative scheduler.
@samdphillips, did you publish your solution somewhere? I don’t know what cooperative scheduler means and I would love to learn.
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.
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.
(ACTUALLY, I’m not adding a yield in the output instruction because it looks to be working good enough now.)
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.
Thanks for the explanation
I did something very incorrect (and specifically called out in the problem statement) and it worked in part one.
(of day 7)