Skip to content

Instantly share code, notes, and snippets.

@Glorp
Created August 15, 2022 21:44
Show Gist options
  • Save Glorp/b97d348f00659b5f614854f3ac52875d to your computer and use it in GitHub Desktop.
Save Glorp/b97d348f00659b5f614854f3ac52875d to your computer and use it in GitHub Desktop.
#lang racket
(define start '(0 3 3 3 0 1))
(define a '(3 2 1 1 0 0))
(define b '(0 0 1 0 1 0))
(define c '(-1 1 -2 1 -2 1))
(define d '(1 1 1 0 3 1))
(define e '(-2 +2 0 -2 +2 -2))
(define (0? l)
(andmap (λ (x) (= x 0)) l))
(define (use state thing)
(map (λ (a b) (modulo (+ a b) 4)) state thing))
(define (try-stuff state path as bs cs ds es)
(cond [(0? state) (printf "~a~n" path)]
[else (when (< 0 as)
(try-stuff (use state a) (cons 'a path) (- as 1) bs cs ds es))
(when (< 0 bs)
(try-stuff (use state b) (cons 'b path) as (- bs 1) cs ds es))
(when (< 0 cs)
(try-stuff (use state c) (cons 'c path) as bs (- cs 1) ds es))
(when (< 0 ds)
(try-stuff (use state d) (cons 'd path) as bs cs (- ds 1) es))
(when (< 0 es)
(try-stuff (use state e) (cons 'e path) as bs cs ds (- es 1)))]))
(try-stuff start '() 3 3 3 3 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment