Skip to content

Instantly share code, notes, and snippets.

@whitequark
Created March 17, 2020 06:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whitequark/70a7fa946f517e46686c3f80814abc9b to your computer and use it in GitHub Desktop.
Save whitequark/70a7fa946f517e46686c3f80814abc9b to your computer and use it in GitHub Desktop.
#lang rosette/safe
(require rosette/lib/angelic
(only-in racket/base syntax->datum))
(define-syntax-rule (define-distinct v x ...)
(begin
(define x v) ...
(assert (distinct? x ...))))
(define-syntax-rule (list-choices x ... sol)
(list (list (evaluate x sol) (syntax->datum #'x)) ...))
(define houses '(1 2 3 4 5))
(define (left-of? h1 h2) (= (+ h1 1) h2))
(define (right-of? h1 h2) (= h1 (+ h2 1)))
(define (adjacent? h1 h2) (or (right-of? h1 h2) (left-of? h1 h2)))
(define-distinct (choose* 1 2 3 4 5) poet editor critic writer journalist)
(define-distinct (choose* 1 2 3 4 5) red blue green white yellow)
(define-distinct (choose* 1 2 3 4 5) bicycle motorcycle pedestrian car)
(define-distinct (choose* 1 2 3 4 5) bullfinch tit canary parrot magpie)
(define-distinct (choose* 1 2 3 4 5) milk cacao tea coffee tomato-juice)
(define solution
(solve
(begin
(assert (eq? poet bicycle))
(assert (eq? editor red))
(assert (eq? critic 1))
(assert (adjacent? critic blue))
(assert (eq? motorcycle 3))
(assert (right-of? green white))
(assert (eq? green pedestrian))
(assert (eq? milk bullfinch))
(assert (adjacent? cacao tit))
(assert (eq? yellow tea))
(assert (adjacent? canary tea))
(assert (eq? writer coffee))
(assert (eq? car tomato-juice))
(assert (eq? journalist parrot)))))
(define magpie-in (evaluate magpie solution))
(assoc magpie-in (list-choices poet editor critic writer journalist solution)) ; '(5 writer)
(second (assoc magpie-in (list-choices red blue green white yellow solution))) ; 'green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment