A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
22
Task/Box-the-compass/Groovy/box-the-compass.groovy
Normal file
22
Task/Box-the-compass/Groovy/box-the-compass.groovy
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
def asCompassPoint(angle) {
|
||||
def cardinalDirections = ["north", "east", "south", "west"]
|
||||
|
||||
int index = Math.floor(angle / 11.25 + 0.5)
|
||||
int cardinalIndex = (index / 8)
|
||||
|
||||
def c1 = cardinalDirections[cardinalIndex % 4]
|
||||
def c2 = cardinalDirections[(cardinalIndex + 1) % 4]
|
||||
def c3 = (cardinalIndex == 0 || cardinalIndex == 2) ? "$c1$c2" : "$c2$c1"
|
||||
|
||||
def point = [
|
||||
"$c1", "$c1 by $c2", "$c1-$c3", "$c3 by $c1", "$c3", "$c3 by $c2", "$c2-$c3", "$c2 by $c1"
|
||||
][index % 8]
|
||||
point.substring(0, 1).toUpperCase() + point.substring(1)
|
||||
}
|
||||
Number.metaClass.asCompassPoint = { asCompassPoint(delegate) }
|
||||
|
||||
[0.0, 16.87, 16.88, 33.75, 50.62, 50.63, 67.5, 84.37, 84.38, 101.25, 118.12, 118.13, 135.0, 151.87, 151.88, 168.75,
|
||||
185.62, 185.63, 202.5, 219.37, 219.38, 236.25, 253.12, 253.13, 270.0, 286.87, 286.88, 303.75, 320.62, 320.63, 337.5,
|
||||
354.37, 354.38].eachWithIndex { angle, index ->
|
||||
println "${(index % 32) + 1}".padRight(3) + "${angle.asCompassPoint().padLeft(20)} $angle\u00b0"
|
||||
}
|
||||
26
Task/Box-the-compass/Icon/box-the-compass.icon
Normal file
26
Task/Box-the-compass/Icon/box-the-compass.icon
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
link strings,numbers
|
||||
|
||||
procedure main()
|
||||
|
||||
every heading := 11.25 * (i := 0 to 32) do {
|
||||
case i%3 of {
|
||||
1: heading +:= 5.62
|
||||
2: heading -:= 5.62
|
||||
}
|
||||
write(right(i+1,3)," ",left(direction(heading),20)," ",fix(heading,,7,2))
|
||||
}
|
||||
end
|
||||
|
||||
procedure direction(d) # compass heading given +/- degrees
|
||||
static dirs
|
||||
initial {
|
||||
every put(dirs := [],
|
||||
replacem(!["N","NbE","N-NE","NEbN","NE","NEbE","E-NE","EbN",
|
||||
"E","EbS","E-SE","SEbE","SE","SEbS","S-SE","SbE",
|
||||
"S","SbW","S-SW","SWbS","SW","SWbW","W-SW","WbS",
|
||||
"W","WbN","W-NW","NWbW","NW","NWbN","N-NW","NbW"],
|
||||
"N","north","E","east","W","west","S","south","b"," by "))
|
||||
}
|
||||
|
||||
return dirs[round(((((d%360)+360)%360)/11.25)%32 + 1)]
|
||||
end
|
||||
8
Task/Box-the-compass/J/box-the-compass-1.j
Normal file
8
Task/Box-the-compass/J/box-the-compass-1.j
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
require'strings'
|
||||
subs=: 'N,north,S,south,E,east,W,west,b, by ,'
|
||||
dirs=: subs (toupper@{., }.)@rplc~L:1 0&(<;._2) 0 :0 -. ' ',LF
|
||||
N,NbE,N-NE,NEbN,NE,NEbE,E-NE,EbN,E,EbS,E-SE,SEbE,SE,SEbS,S-SE,SbE,
|
||||
S,SbW,S-SW,SWbS,SW,SWbW,W-SW,WbS,W,WbN,W-NW,NWbW,NW,NWbN,N-NW,NbW,
|
||||
)
|
||||
indice=: 32 | 0.5 <.@+ %&11.25
|
||||
deg2pnt=: dirs {~ indice
|
||||
6
Task/Box-the-compass/J/box-the-compass-2.j
Normal file
6
Task/Box-the-compass/J/box-the-compass-2.j
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
i.10
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
deg2pnt i.10
|
||||
┌─────┬─────┬─────┬─────┬─────┬─────┬─────────────┬─────────────┬─────────────┬─────────────┐
|
||||
│North│North│North│North│North│North│North by east│North by east│North by east│North by east│
|
||||
└─────┴─────┴─────┴─────┴─────┴─────┴─────────────┴─────────────┴─────────────┴─────────────┘
|
||||
34
Task/Box-the-compass/J/box-the-compass-3.j
Normal file
34
Task/Box-the-compass/J/box-the-compass-3.j
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
(":@>:@indice,.' ',.>@deg2pnt,.' ',.":@,.)(*&11.25 + 5.62 * 0 1 _1 {~ 3&|) i.33
|
||||
1 North 0
|
||||
2 North by east 16.87
|
||||
3 North-northeast 16.88
|
||||
4 Northeast by north 33.75
|
||||
5 Northeast 50.62
|
||||
6 Northeast by east 50.63
|
||||
7 East-northeast 67.5
|
||||
8 East by north 84.37
|
||||
9 East 84.38
|
||||
10 East by south 101.25
|
||||
11 East-southeast 118.12
|
||||
12 Southeast by east 118.13
|
||||
13 Southeast 135
|
||||
14 Southeast by south 151.87
|
||||
15 South-southeast 151.88
|
||||
16 South by east 168.75
|
||||
17 South 185.62
|
||||
18 South by west 185.63
|
||||
19 South-southwest 202.5
|
||||
20 Southwest by south 219.37
|
||||
21 Southwest 219.38
|
||||
22 Southwest by west 236.25
|
||||
23 West-southwest 253.12
|
||||
24 West by south 253.13
|
||||
25 West 270
|
||||
26 West by north 286.87
|
||||
27 West-northwest 286.88
|
||||
28 Northwest by west 303.75
|
||||
29 Northwest 320.62
|
||||
30 Northwest by north 320.63
|
||||
31 North-northwest 337.5
|
||||
32 North by west 354.37
|
||||
1 North 354.38
|
||||
16
Task/Box-the-compass/K/box-the-compass-1.k
Normal file
16
Task/Box-the-compass/K/box-the-compass-1.k
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
d:("N;Nbe;N-ne;Nebn;Ne;Nebe;E-ne;Ebn;")
|
||||
d,:("E;Ebs;E-se;Sebe;Se;Sebs;S-se;Sbe;")
|
||||
d,:("S;Sbw;S-sw;Swbs;Sw;Swbw;W-sw;Wbs;")
|
||||
d,:("W;Wbn;W-nw;Nwbw;Nw;Nwbn;N-nw;Nbw;N")
|
||||
|
||||
split:{1_'(&x=y)_ x:y,x}
|
||||
dd:split[d;";"]
|
||||
|
||||
/ lookup table
|
||||
s1:"NEWSnewsb-"
|
||||
s2:("North";"East";"West";"South";"north";"east";"west";"south";" by ";"-")
|
||||
c:.({`$x}'s1),'{`$x}'s2 / create the dictionary
|
||||
cc:{,/{$c[`$$x]}'x} / lookup function
|
||||
|
||||
/ calculate the degrees
|
||||
f:{m:x!3;(11.25*x)+:[1=m;+5.62;2=m;-5.62;0]}
|
||||
34
Task/Box-the-compass/K/box-the-compass-2.k
Normal file
34
Task/Box-the-compass/K/box-the-compass-2.k
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
`0:{((2$(1+x!32))," ",(-19$cc@dd[x]),(6.2$f@x))}'!#dd
|
||||
1 North 0.00
|
||||
2 North by east 16.87
|
||||
3 North-northeast 16.88
|
||||
4 Northeast by north 33.75
|
||||
5 Northeast 50.62
|
||||
6 Northeast by east 50.63
|
||||
7 East-northeast 67.50
|
||||
8 East by north 84.37
|
||||
9 East 84.38
|
||||
10 East by south 101.25
|
||||
11 East-southeast 118.12
|
||||
12 Southeast by east 118.13
|
||||
13 Southeast 135.00
|
||||
14 Southeast by south 151.87
|
||||
15 South-southeast 151.88
|
||||
16 South by east 168.75
|
||||
17 South 185.62
|
||||
18 South by west 185.63
|
||||
19 South-southwest 202.50
|
||||
20 Southwest by south 219.37
|
||||
21 Southwest 219.38
|
||||
22 Southwest by west 236.25
|
||||
23 West-southwest 253.12
|
||||
24 West by south 253.13
|
||||
25 West 270.00
|
||||
26 West by north 286.87
|
||||
27 West-northwest 286.88
|
||||
28 Northwest by west 303.75
|
||||
29 Northwest 320.62
|
||||
30 Northwest by north 320.63
|
||||
31 North-northwest 337.50
|
||||
32 North by west 354.37
|
||||
1 North 354.38
|
||||
34
Task/Box-the-compass/Liberty-BASIC/box-the-compass.liberty
Normal file
34
Task/Box-the-compass/Liberty-BASIC/box-the-compass.liberty
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
dim point$( 32)
|
||||
|
||||
for i =1 to 32
|
||||
read d$: point$( i) =d$
|
||||
next i
|
||||
|
||||
for i = 0 to 32
|
||||
heading = i *11.25
|
||||
if ( i mod 3) =1 then
|
||||
heading = heading +5.62
|
||||
else
|
||||
if ( i mod 3) =2 then heading = heading -5.62
|
||||
end if
|
||||
ind = i mod 32 +1
|
||||
print ind, compasspoint$( heading), heading
|
||||
next i
|
||||
|
||||
end
|
||||
|
||||
function compasspoint$( h)
|
||||
x = h /11.25 +1.5
|
||||
if (x >=33.0) then x =x -32.0
|
||||
compasspoint$ = point$( int( x))
|
||||
end function
|
||||
|
||||
data "North ", "North by east ", "North-northeast "
|
||||
data "Northeast by north", "Northeast ", "Northeast by east ", "East-northeast "
|
||||
data "East by north ", "East ", "East by south ", "East-southeast "
|
||||
data "Southeast by east ", "Southeast ", "Southeast by south", "South-southeast "
|
||||
data "South by east ", "South ", "South by west ", "South-southwest "
|
||||
data "Southwest by south", "Southwest ", "Southwest by west ", "West-southwest "
|
||||
data "West by south ", "West ", "West by north ", "West-northwest "
|
||||
data "Northwest by west ", "Northwest ", "Northwest by north", "North-northwest "
|
||||
data "North by west
|
||||
64
Task/Box-the-compass/Logo/box-the-compass.logo
Normal file
64
Task/Box-the-compass/Logo/box-the-compass.logo
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
; List of abbreviated compass point labels
|
||||
make "compass_points [ N NbE N-NE NEbN NE NEbE E-NE EbN
|
||||
E EbS E-SE SEbE SE SEbS S-SE SbE
|
||||
S SbW S-SW SWbS SW SWbW W-SW WbS
|
||||
W WbN W-NW NWbW NW NWbN N-NW NbW ]
|
||||
|
||||
; List of angles to test
|
||||
make "test_angles [ 0.00 16.87 16.88 33.75 50.62 50.63 67.50
|
||||
84.37 84.38 101.25 118.12 118.13 135.00 151.87
|
||||
151.88 168.75 185.62 185.63 202.50 219.37 219.38
|
||||
236.25 253.12 253.13 270.00 286.87 286.88 303.75
|
||||
320.62 320.63 337.50 354.37 354.38 ]
|
||||
|
||||
; make comparisons case-sensitive
|
||||
make "caseignoredp "false
|
||||
|
||||
; String utilities: search and replace
|
||||
to replace_in :src :from :to
|
||||
output map [ ifelse equalp ? :from [:to] [?] ] :src
|
||||
end
|
||||
|
||||
; pad with spaces
|
||||
to pad :string :length
|
||||
output cascade [lessp :length count ?] [word ? "\ ] :string
|
||||
end
|
||||
|
||||
; capitalize first letter
|
||||
to capitalize :string
|
||||
output word (uppercase first :string) butfirst :string
|
||||
end
|
||||
|
||||
; convert compass point abbreviation to full text of label
|
||||
to expand_point :abbr
|
||||
foreach [[N north] [E east] [S south] [W west] [b \ by\ ]] [
|
||||
make "abbr replace_in :abbr (first ?) (last ?)
|
||||
]
|
||||
output capitalize :abbr
|
||||
end
|
||||
|
||||
; modulus function that returns 1..N instead of 0..N-1
|
||||
to adjusted_modulo :n :d
|
||||
output sum 1 modulo (difference :n 1) :d
|
||||
end
|
||||
|
||||
; convert a compass angle from degrees into a box index (1..32)
|
||||
to compass_point :degrees
|
||||
make "degrees modulo :degrees 360
|
||||
output adjusted_modulo (sum 1 int quotient (sum :degrees 5.625) 11.25) 32
|
||||
end
|
||||
|
||||
; Now output the table of test data
|
||||
print (sentence (pad "Degrees 7) "\| (pad "Closest\ Point 18) "\| "Index )
|
||||
foreach :test_angles [
|
||||
local "index
|
||||
make "index compass_point ?
|
||||
local "abbr
|
||||
make "abbr item :index :compass_points
|
||||
local "label
|
||||
make "label expand_point :abbr
|
||||
print (sentence (form ? 7 2) "\| (pad :label 18) "\| (form :index 2 0) )
|
||||
]
|
||||
|
||||
; and exit
|
||||
bye
|
||||
34
Task/Box-the-compass/MUMPS/box-the-compass.mumps
Normal file
34
Task/Box-the-compass/MUMPS/box-the-compass.mumps
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
BOXING(DEGREE)
|
||||
;This takes in a degree heading, nominally from 0 to 360, and returns the compass point name.
|
||||
QUIT:((DEGREE<0)||(DEGREE>360)) "land lubber can't read a compass"
|
||||
NEW DIRS,UNP,UNPACK,SEP,DIR,DOS,D,DS,I,F
|
||||
SET DIRS="N^NbE^N-NE^NEbN^NE^NEbE^E-NE^EbN^E^EbS^E-SE^SEbE^SE^SEbS^S-SE^SbE^"
|
||||
SET DIRS=DIRS_"S^SbW^S-SW^SWbS^SW^SWbW^W-SW^WbS^W^WbN^W-NW^NWbW^NW^NWbN^N-NW^NbW"
|
||||
SET UNP="NESWb"
|
||||
SET UNPACK="north^east^south^west^ by "
|
||||
SET SEP=360/$LENGTH(DIRS,"^")
|
||||
SET DIR=(DEGREE/SEP)+1.5
|
||||
SET DIR=$SELECT((DIR>33):DIR-32,1:DIR)
|
||||
SET DOS=$NUMBER(DIR-.5,0)
|
||||
SET D=$PIECE(DIRS,"^",DIR)
|
||||
SET DS=""
|
||||
FOR I=1:1:$LENGTH(D) DO
|
||||
. SET F=$FIND(UNP,$EXTRACT(D,I)) SET DS=DS_$SELECT((F>0):$PIECE(UNPACK,"^",F-1),1:$E(D,I))
|
||||
KILL DIRS,UNP,UNPACK,SEP,DIR,D,I,F
|
||||
QUIT DOS_"^"_DS
|
||||
|
||||
BOXWRITE
|
||||
NEW POINTS,UP,LO,DIR,P,X
|
||||
SET POINTS="0.0,16.87,16.88,33.75,50.62,50.63,67.5,84.37,84.38,101.25,118.12,118.13,135.0,151.87,"
|
||||
SET POINTS=POINTS_"151.88,168.75,185.62,185.63,202.5,219.37,219.38,236.25,253.12,253.13,270.0,286.87,"
|
||||
SET POINTS=POINTS_"286.88,303.75,320.62,320.63,337.5,354.37,354.38"
|
||||
SET UP="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
SET LO="abcdefghijklmnopqrstuvwxyz"
|
||||
FOR P=1:1:$LENGTH(POINTS,",") DO
|
||||
. SET X=$$BOXING($PIECE(POINTS,",",P))
|
||||
. ;Capitalize the initial letter of the direction
|
||||
. SET DIR=$PIECE(X,"^",2)
|
||||
. SET DIR=$TRANSLATE($EXTRACT(DIR,1),LO,UP)_$EXTRACT(DIR,2,$LENGTH(DIR))
|
||||
. WRITE $PIECE(X,"^"),?5,DIR,?40,$JUSTIFY($PIECE(POINTS,",",P),10,2),!
|
||||
KILL POINTS,UP,LO,DIR,P,X
|
||||
QUIT
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Map[List[Part[#,1], dirs[[Part[#,1]]], ToString@Part[#,2]<>"°"]&,
|
||||
Map[{Floor[Mod[ #+5.625 , 360]/11.25]+1,#}&,input] ]//TableForm
|
||||
Loading…
Add table
Add a link
Reference in a new issue