Box the compass: Difference between revisions

m
(Added R (Arrrr!) version)
Line 5,927:
 
<lang R>
# Build a table of directions
pts <- data.frame(
des = c("N", "NxE", "NNE", "NExN", "NE", "NExE", "ENE", "ExN",
Line 5,938 ⟶ 5,939:
heading <- Vectorize(function(deg) {
res <- pts
# Calculate the absolute difference between each
# point on the table and the function input
res$diff <- abs(res$deg - deg)
# Sort the table by abs difference, return the first
res <- res[order(res$diff), ]
res[1,]$des[1]
Line 6,007 ⟶ 6,011:
[1] TRUE
</pre>
 
 
 
=={{header|Racket}}==