Skip to content

Instantly share code, notes, and snippets.

@laszlokorte
Created October 31, 2012 17:31
Show Gist options
  • Save laszlokorte/3988514 to your computer and use it in GitHub Desktop.
Save laszlokorte/3988514 to your computer and use it in GitHub Desktop.
#lang racket
(define (helper dir1 dir2 sub)
(cond
[(= sub 1) dir1]
[(= (modulo sub 4) 0) (string-append "b" dir1)]
[(= (modulo sub 2) 0) (string-append "b" dir2)]
))
(define directions "NESESWNW")
(define (degree->cardinal degree)
(define step (+ (floor (/ degree (/ 360 32))) 1))
(define sub (+ (modulo (- step 1) 8) 1))
(define quarter (inexact->exact(floor (/ degree 90))))
(helper
(substring directions (modulo (* 2 quarter) 7) (modulo (+ (* 2 quarter) 1) 8))
(substring directions (modulo (+ (* 2 quarter) 1) 7) (modulo (+ (* 2 quarter) 2) 8)) sub)
)
#lang racket
(define (helper dir1 dir2 sub)
(cond
[(= sub 1) dir1]
[(= (modulo sub 4) 0) (string-append "b" dir1)]
[(= (modulo sub 2) 0) (string-append "b" dir2)]
))
(define directions "NESESWNW")
(define (degree->cardinal degree)
(define step (+ (floor (/ degree (/ 360 32))) 1))
(define sub (+ (modulo (- step 1) 8) 1))
(define quarter (inexact->exact(floor (/ degree 90))))
(helper
(substring directions (modulo (* 2 quarter) 7) (modulo (+ (* 2 quarter) 1) 8))
(substring directions (modulo (+ (* 2 quarter) 1) 7) (modulo (+ (* 2 quarter) 2) 8)) sub)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment