Created
October 31, 2012 17:31
-
-
Save laszlokorte/3988514 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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