Day 25: Minor refactoring.
This commit is contained in:
parent
1ce429e5a0
commit
86a9bec9d3
115
src/25.rkt
115
src/25.rkt
|
@ -32,17 +32,11 @@
|
||||||
(if (empty? inputs) st
|
(if (empty? inputs) st
|
||||||
(type-case state st
|
(type-case state st
|
||||||
[in (resume)
|
[in (resume)
|
||||||
(resume-with-inputs (resume (first inputs)) (rest inputs))]
|
|
||||||
[else (error "Unexpected program state.")])))
|
|
||||||
|
|
||||||
(define (resume-with-inputs* st inputs)
|
|
||||||
(if (empty? inputs) st
|
(if (empty? inputs) st
|
||||||
(type-case state st
|
(resume-with-inputs (resume (first inputs)) (rest inputs)))]
|
||||||
[in (resume)
|
|
||||||
(if (empty? inputs) st
|
|
||||||
(resume-with-inputs* (resume (first inputs)) (rest inputs)))]
|
|
||||||
[out (value resume)
|
[out (value resume)
|
||||||
(resume-with-inputs* (resume) inputs)]
|
#;(display (integer->char value))
|
||||||
|
(resume-with-inputs (resume) inputs)]
|
||||||
[halt (_) (error "Unexpected program state.")])))
|
[halt (_) (error "Unexpected program state.")])))
|
||||||
|
|
||||||
(define (play st)
|
(define (play st)
|
||||||
|
@ -66,76 +60,57 @@
|
||||||
(loop st output)])]
|
(loop st output)])]
|
||||||
[halt (_) (display (ascii->string (reverse output)))])))
|
[halt (_) (display (ascii->string (reverse output)))])))
|
||||||
|
|
||||||
|
(define drop-mouse (drop* '(mouse)))
|
||||||
|
(define drop-pointer (drop* '(pointer)))
|
||||||
|
(define drop-monolith (drop* '(monolith)))
|
||||||
|
(define drop-ration (drop* '(food ration)))
|
||||||
|
(define drop-slsb (drop* '(space law space brochure)))
|
||||||
|
(define drop-sand (drop* '(sand)))
|
||||||
|
(define drop-asterisk (drop* '(asterisk)))
|
||||||
|
(define drop-mutex (drop* '(mutex)))
|
||||||
|
(define take-mouse (take* '(mouse)))
|
||||||
|
(define take-pointer (take* '(pointer)))
|
||||||
|
(define take-monolith (take* '(monolith)))
|
||||||
|
(define take-ration (take* '(food ration)))
|
||||||
|
(define take-slsb (take* '(space law space brochure)))
|
||||||
|
(define take-sand (take* '(sand)))
|
||||||
|
(define take-asterisk (take* '(asterisk)))
|
||||||
|
(define take-mutex (take* '(mutex)))
|
||||||
|
|
||||||
|
;; Some other locations we don't need to explore:
|
||||||
|
;; - quarters: east of storage
|
||||||
|
;; - holodeck: east of hallway
|
||||||
|
;; - gift wrapping: east of kitchen
|
||||||
|
;; - passage: south of gift wrapping
|
||||||
|
;; Some items we should not take:
|
||||||
|
;; - lava: in sick bay
|
||||||
|
;; - electromagnet: in gift wrapping
|
||||||
|
;; - escape pod: in holodeck
|
||||||
|
;; - photons: in engineering
|
||||||
(define (goto-checkpoint)
|
(define (goto-checkpoint)
|
||||||
(let ([commands
|
(let ([commands
|
||||||
(append
|
(append
|
||||||
north
|
north ;; hallway
|
||||||
(take* '(mouse))
|
|
||||||
north
|
|
||||||
(take* '(pointer))
|
|
||||||
south
|
|
||||||
south
|
|
||||||
west
|
|
||||||
(take* '(monolith))
|
|
||||||
north
|
|
||||||
west
|
|
||||||
(take* '(food ration))
|
|
||||||
south
|
|
||||||
(take* '(space law space brochure))
|
|
||||||
north
|
|
||||||
east
|
|
||||||
south
|
|
||||||
south
|
|
||||||
(take* '(sand))
|
|
||||||
south
|
|
||||||
west
|
|
||||||
(take* '(asterisk))
|
|
||||||
south
|
|
||||||
(take* '(mutex))
|
|
||||||
north
|
|
||||||
east
|
|
||||||
north
|
|
||||||
north
|
|
||||||
east
|
|
||||||
south
|
|
||||||
south
|
|
||||||
west
|
|
||||||
south
|
|
||||||
inv)])
|
|
||||||
(resume-with-inputs* (exec input) commands)))
|
|
||||||
|
|
||||||
(define-values (drop-mouse
|
|
||||||
drop-pointer
|
|
||||||
drop-monolith
|
|
||||||
drop-ration
|
|
||||||
drop-slsb
|
|
||||||
drop-sand
|
|
||||||
drop-asterisk
|
|
||||||
drop-mutex
|
|
||||||
take-mouse
|
take-mouse
|
||||||
|
north ;; kitchen
|
||||||
take-pointer
|
take-pointer
|
||||||
|
south south west ;; hallway, hull, stable
|
||||||
take-monolith
|
take-monolith
|
||||||
|
north west ;; sick bay, observatory
|
||||||
take-ration
|
take-ration
|
||||||
|
south ;; hot chocolate fountain
|
||||||
take-slsb
|
take-slsb
|
||||||
|
north east south south ;; observatory, sick bay, stable, navigation
|
||||||
take-sand
|
take-sand
|
||||||
|
south west ;; corridor, maintenance
|
||||||
take-asterisk
|
take-asterisk
|
||||||
take-mutex)
|
south ;; storage
|
||||||
(values (drop* '(mouse))
|
take-mutex
|
||||||
(drop* '(pointer))
|
;; maintenance, corridor, navigation, stable, hull,
|
||||||
(drop* '(monolith))
|
;; arcade, laboratory, engineering, checkpoint
|
||||||
(drop* '(food ration))
|
north east north north east south south west south
|
||||||
(drop* '(space law space brochure))
|
inv)])
|
||||||
(drop* '(sand))
|
(resume-with-inputs (exec input) commands)))
|
||||||
(drop* '(asterisk))
|
|
||||||
(drop* '(mutex))
|
|
||||||
(take* '(mouse))
|
|
||||||
(take* '(pointer))
|
|
||||||
(take* '(monolith))
|
|
||||||
(take* '(food ration))
|
|
||||||
(take* '(space law space brochure))
|
|
||||||
(take* '(sand))
|
|
||||||
(take* '(asterisk))
|
|
||||||
(take* '(mutex))))
|
|
||||||
|
|
||||||
(define drop-all
|
(define drop-all
|
||||||
(append drop-mouse
|
(append drop-mouse
|
||||||
|
@ -164,7 +139,7 @@
|
||||||
(let/cc k
|
(let/cc k
|
||||||
(for ([combo item-combinations])
|
(for ([combo item-combinations])
|
||||||
(let* ([commands (append drop-all combo east)]
|
(let* ([commands (append drop-all combo east)]
|
||||||
[st* (resume-with-inputs* st commands)])
|
[st* (resume-with-inputs st commands)])
|
||||||
(let loop ([st st*]
|
(let loop ([st st*]
|
||||||
[output '()])
|
[output '()])
|
||||||
(type-case state st
|
(type-case state st
|
||||||
|
|
Loading…
Reference in New Issue