Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (use srfi-1);;a hacky way to get emacs to recognize chicken files
- (define DIRECTIONS
- '((R . 4) (R . 5) (L . 5) (L . 5) (L . 3) (R . 2) (R . 1) (R . 1) (L . 5)
- (R . 5) (R . 2) (L . 1) (L . 3) (L . 4) (R . 3) (L . 1) (L . 1) (R . 2)
- (R . 3) (R . 3) (R . 1) (L . 3) (L . 5) (R . 3) (R . 1) (L . 1) (R . 1)
- (R . 2) (L . 1) (L . 4) (L . 5) (R . 4) (R . 2) (L . 192) (R . 5) (L . 2)
- (R . 53) (R . 1) (L . 5) (R . 73) (R . 5) (L . 5) (R . 186) (L . 3) (L . 2)
- (R . 1) (R . 3) (L . 3) (L . 3) (R . 1) (L . 4) (L . 2) (R . 3) (L . 5)
- (R . 4) (R . 3) (R . 1) (L . 1) (R . 5) (R . 2) (R . 1) (R . 1) (R . 1)
- (R . 3) (R . 2) (L . 1) (R . 5) (R . 1) (L . 5) (R . 2) (L . 2) (L . 4)
- (R . 3) (L . 1) (R . 4) (L . 5) (R . 4) (R . 3) (L . 5) (L . 3) (R . 4)
- (R . 2) (L . 5) (L . 5) (R . 2) (R . 3) (R . 5) (R . 4) (R . 2) (R . 1)
- (L . 1) (L . 5) (L . 2) (L . 3) (L . 4) (L . 5) (L . 4) (L . 5) (L . 1)
- (R . 3) (R . 4) (R . 5) (R . 3) (L . 5) (L . 4) (L . 3) (L . 1) (L . 4)
- (R . 2) (R . 5) (R . 5) (R . 4) (L . 2) (L . 4) (R . 3) (R . 1) (L . 2)
- (R . 5) (L . 5) (R . 1) (R . 1) (L . 1) (L . 5) (L . 5) (L . 2) (L . 1)
- (R . 5) (R . 2) (L . 4) (L . 1) (R . 4) (R . 3) (L . 3) (R . 1) (R . 5)
- (L . 1) (L . 4) (R . 2) (L . 3) (R . 5) (R . 3) (R . 1) (L . 3)))
- (define (rotdir-l dir)
- ;;dir is a cons cell: (x . y)
- (if (= (car dir) 0)
- (cons (- (cdr dir)) 0)
- (cons (cdr dir) (car dir))))
- (define (rotdir-r dir)
- (if (= (cdr dir) 0)
- (cons 0 (- (car dir)))
- (cons (cdr dir) (car dir))))
- (define (add-to-point p dir n)
- ;;I am way prouder of this than I should be
- (cons (+ (car p)
- (* (car dir) n))
- (+ (cdr p)
- (* (cdr dir) n))))
- (define (new-direction curdir rsym)
- ((if (equal? rsym 'R) rotdir-r rotdir-l) curdir))
- (define (range from to)
- (let loop ((from from)
- (to ((if (< from to) - +) to 1))
- (lst '()))
- (if (= from to)
- (cons to lst)
- (loop from ((if (< from to) - +) to 1) (cons to lst)))))
- (define (path-to from to)
- (if (= (car to) (car from))
- (map (lambda (x) (cons (car to) x)) (range (cdr from) (cdr to)))
- (map (lambda (x) (cons x (cdr to))) (range (car from) (car to)))))
- (define (get-path dirlist initdr)
- ;;returns a list of all locations traversed. The car is the final location
- (let loop ((dirlist dirlist)
- (dir initdr)
- (curloc '(0 . 0))
- (visited '()))
- (cond ((null? dirlist) (append (path-to curloc (car visited)) visited))
- (else (let ((newdir (new-direction dir (caar dirlist))))
- (loop (cdr dirlist) newdir
- (add-to-point curloc newdir (cdar dirlist))
- (if (null? visited)
- (list curloc)
- (append (path-to curloc (car visited))
- visited))))))))
- (define (find-first-intersec locs)
- ;;you have to REVERSE the output of get-path before you put it in here.
- (let loop ((locs locs)
- (visited '()))
- (cond
- ((null? locs) #f)
- ((member (car locs) visited) (car locs))
- (else (loop (cdr locs) (cons (car locs) visited))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement