langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,201 @@
/* NetRexx */
options replace format comments java crossref savelog symbols nobinary utf8
class RCBoxTheCompass
properties public constant
_FULL = '_FULL'
properties indirect
headings = Rexx
rosepoints = Rexx
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
method RCBoxTheCompass() public
setHeadings(makeHeadings)
setRosepoints(makeRosepoints)
return
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
method main(args = String[]) public static
box = RCBoxTheCompass()
cp = box.getCompassPoints
loop r_ = 1 to cp[0]
say cp[r_]
end r_
say
hx = box.getHeadingsReport(box.getHeadings)
loop r_ = 1 to hx[0]
say hx[r_]
end r_
say
return
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
method getDecimalAngle(degrees, minutes, seconds) public static returns Rexx
degrees = degrees * 10 % 10
minutes = minutes * 10 % 10
angle = degrees + (minutes / 60 + (seconds / 60 / 60))
return angle
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
method getDegreesMinutesSeconds(angle) public static returns Rexx
degrees = angle * 100 % 100
minutes = ((angle - degrees) * 60) * 100 % 100
seconds = ((((angle - degrees) * 60) - minutes) * 60) * 100 % 100
return degrees minutes seconds
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
method getHeadingsReport(bearings) public returns Rexx
r_ = 0
table = ''
r_ = r_ + 1; table[0] = r_; table[r_] = 'Idx' -
'Abbr' -
'Compass Point'.left(20) -
'Degrees'.right(10)
loop h_ = 1 to bearings[0]
heading = bearings[h_]
index = getRosepointIndex(heading)
parse getRosepoint(index) p_abbrev p_full
r_ = r_ + 1; table[0] = r_; table[r_] = index.right(3) -
p_abbrev.left(4) -
p_full.left(20) -
heading.format(6, 3).right(10)
end h_
return table
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
method getRosepointIndex(heading) public returns Rexx
one_pt = 360 / 32
hn = heading // 360
hi = hn % one_pt
if hn > hi * one_pt + one_pt / 2 then do
hi = hi + 1 -- greater than max range for this point; bump to next point
end
idx = hi // 32 + 1 -- add one to get index into rosepoints indexed string
return idx
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
method getRosepoint(index) public returns Rexx
rp = getRosepoints
return rp[index] rp[index, _FULL]
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
method makeRosepoints() private returns Rexx
p_ = 0
rp = ''
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'N'; rp[p_, _FULL] = 'North'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'NbE'; rp[p_, _FULL] = 'North by East'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'NNE'; rp[p_, _FULL] = 'North-Northeast'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'NEbn'; rp[p_, _FULL] = 'Northeast by North'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'NE'; rp[p_, _FULL] = 'Northeast'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'NEbE'; rp[p_, _FULL] = 'Northeast by East'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'ENE'; rp[p_, _FULL] = 'East-Northeast'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'EbN'; rp[p_, _FULL] = 'East by North'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'E'; rp[p_, _FULL] = 'East'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'EbS'; rp[p_, _FULL] = 'East by South'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'ESE'; rp[p_, _FULL] = 'East-Southeast'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'SEbE'; rp[p_, _FULL] = 'Southeast by East'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'SE'; rp[p_, _FULL] = 'Southeast'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'SEbS'; rp[p_, _FULL] = 'Southeast by South'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'SSE'; rp[p_, _FULL] = 'South-Southeast'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'SbE'; rp[p_, _FULL] = 'South by East'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'S'; rp[p_, _FULL] = 'South'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'SbW'; rp[p_, _FULL] = 'South by West'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'SSW'; rp[p_, _FULL] = 'South-Southwest'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'SWbS'; rp[p_, _FULL] = 'Southwest by South'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'SW'; rp[p_, _FULL] = 'Southwest'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'SWbW'; rp[p_, _FULL] = 'Southwest by West'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'WSW'; rp[p_, _FULL] = 'Southwest'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'WbS'; rp[p_, _FULL] = 'West by South'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'W'; rp[p_, _FULL] = 'West'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'WbN'; rp[p_, _FULL] = 'West by North'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'WNW'; rp[p_, _FULL] = 'West-Northwest'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'NWbW'; rp[p_, _FULL] = 'Northwest by West'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'NW'; rp[p_, _FULL] = 'Northwest'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'NWbN'; rp[p_, _FULL] = 'Northwest by North'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'NNW'; rp[p_, _FULL] = 'North-Northwest'
p_ = p_ + 1; rp[0] = p_; rp[p_] = 'NbW'; rp[p_, _FULL] = 'North by West'
return rp
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
method makeHeadings() private returns Rexx
hdg = ''
hdg[0] = 0
points = 32
loop i_ = 0 to points
heading = i_ * 360 / points
select case i_ // 3
when 1 then heading_h = heading + 5.62
when 2 then heading_h = heading - 5.62
otherwise heading_h = heading
end
ix = hdg[0] + 1; hdg[0] = ix; hdg[ix] = heading_h
end i_
return hdg
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
method getCompassPoints() public returns Rexx
r_ = 0
table = ''
r_ = r_ + 1; table[0] = r_; table[r_] = 'Idx' -
'Abbr' -
'Compass Point'.left(20) -
'Low (Deg.)'.right(10) -
'Mid (Deg.)'.right(10) -
'Hi (Deg.)'.right(10)
-- one point of the compass is 360 / 32 (11.25) degrees
-- using functions to calculate this just for fun
one_pt = 360 / 32
parse getDegreesMinutesSeconds(one_pt / 2) ad am as .
points = 32
loop h_ = 0 to points - 1
heading = h_ * 360 / points
hmin = heading - getDecimalAngle(ad, am, as)
hmax = heading + getDecimalAngle(ad, am, as)
if hmin < 0 then do
hmin = hmin + 360
end
if hmax >= 360 then do
hmax = hmax - 360
end
index = getRosepointIndex(heading)
parse getRosepoint(index) p_abbrev p_full
r_ = r_ + 1; table[0] = r_; table[r_] = index.right(3) -
p_abbrev.left(4) -
p_full.left(20) -
hmin.format(6, 3).right(10) -
heading.format(6, 3).right(10) -
hmax.format(6, 3).right(10)
end h_
return table

View file

@ -0,0 +1,34 @@
class BoxCompass {
function : Main(args : String[]) ~ Nil {
points := [
"North ", "North by east ", "North-northeast ",
"Northeast by north", "Northeast ", "Northeast by east ", "East-northeast ",
"East by north ", "East ", "East by south ", "East-southeast ",
"Southeast by east ", "Southeast ", "Southeast by south", "South-southeast ",
"South by east ", "South ", "South by west ", "South-southwest ",
"Southwest by south", "Southwest ", "Southwest by west ", "West-southwest ",
"West by south ", "West ", "West by north ", "West-northwest ",
"Northwest by west ", "Northwest ", "Northwest by north", "North-northwest ",
"North by west " ];
for(i := 0; i<= 32; i += 1;) {
heading := i * 11.25;
select(i % 3) {
label 1: {
heading += 5.62;
}
label 2: {
heading -= 5.62;
}
};
IO.Console->Print((i % 32) + 1)->Print('\t')->Print(points[GetPoint(heading)])
->Print('\t')->PrintLine(heading);
};
}
function : GetPoint(degrees : Float) ~ Int {
return (degrees / 11.25 + 0.5)->Floor()->As(Int) % 32;
}
}

View file

@ -0,0 +1,7 @@
box(x)={["North","North by east","North-northeast","Northeast by north","Northeast",
"Northeast by east","East-northeast","East by north","East","East by south","East-southeast",
"Southeast by east","Southeast","Southeast by south","South-southeast","South by east","South",
"South by west","South-southwest","Southwest by south","Southwest","Southwest by west","West-southwest",
"West by south","West","West by north","West-northwest","Northwest by west","Northwest",
"Northwest by north","North-northwest","North by west"][round(x*4/45)%32+1]};
for(i=0,32,print(i%32+1" "box(x=i*11.25+if(i%3==1,5.62,if(i%3==2,-5.62)))" "x))

View file

@ -0,0 +1,37 @@
program BoxTheCompass(output);
function compasspoint(angle: real): string;
const
points: array [1..32] of string =
('North ', 'North by east ', 'North-northeast ', 'Northeast by north',
'Northeast ', 'Northeast by east ', 'East-northeast ', 'East by north ',
'East ', 'East by south ', 'East-southeast ', 'Southeast by east ',
'Southeast ', 'Southeast by south', 'South-southeast ', 'South by east ',
'South ', 'South by west ', 'South-southwest ', 'Southwest by south',
'Southwest ', 'Southwest by west ', 'West-southwest ', 'West by south ',
'West ', 'West by north ', 'West-northwest ', 'Northwest by west ',
'Northwest ', 'Northwest by north', 'North-northwest ', 'North by west '
);
var
index: integer;
begin
index := round (angle / 11.25);
index := index mod 32 + 1;
compasspoint := points[index];
end;
var
i: integer;
heading: real;
begin
for i := 0 to 32 do
begin
heading := i * 11.25;
case (i mod 3) of
1: heading := heading + 5.62;
2: heading := heading - 5.62;
end;
writeln((i mod 32) + 1:2, ' ', compasspoint(heading), ' ', heading:8:4);
end;
end.

View file

@ -0,0 +1,22 @@
sub point (Int $index) {
my $ix = $index % 32;
if $ix +& 1
{ "&point(($ix + 1) +& 28) by &point(((2 - ($ix +& 2)) * 4) + $ix +& 24)" }
elsif $ix +& 2
{ "&point(($ix + 2) +& 24)-&point(($ix +| 4) +& 28)" }
elsif $ix +& 4
{ "&point(($ix + 8) +& 16)&point(($ix +| 8) +& 24)" }
else
{ <north east south west>[$ix div 8]; }
}
sub test-angle ($ix) { $ix * 11.25 + (0, 5.62, -5.62)[ $ix % 3 ] }
sub angle-to-point($𝜽) { floor $𝜽 / 360 * 32 + 0.5 }
for 0 .. 32 -> $ix {
my $𝜽 = test-angle($ix);
printf " %2d %6.2f%s %s\n",
$ix % 32 + 1,
$𝜽, '°',
ucfirst point angle-to-point $𝜽;
}

View file

@ -0,0 +1,73 @@
DataSection
Data.s "N", "north", "E", "east", "W", "west", "S", "south", "b", " by " ;abbreviations, expansions
Data.s "N NbE N-NE NEbN NE NEbE E-NE EbN E EbS E-SE SEbE SE SEbS S-SE SbE" ;dirs
Data.s "S SbW S-SW SWbS SW SWbW W-SW WbS W WbN W-NW NWbW NW NWbN N-NW NbW"
EndDataSection
;initialize data
NewMap dirSubst.s()
Define i, abbr.s, expansion.s
For i = 1 To 5
Read.s abbr
Read.s expansion
dirSubst(abbr) = expansion
Next
Dim dirs.s(32)
Define j, s.s
For j = 0 To 1
Read.s s.s
For i = 0 To 15
abbr.s = StringField(s, i + 1, " ")
dirs(j * 16 + i) = abbr
Next
Next
;expand abbreviated compass point and capitalize
Procedure.s abbr2compassPoint(abbr.s)
Shared dirSubst()
Protected i, compassPoint.s, key.s
For i = 1 To Len(abbr)
key.s = Mid(abbr, i, 1)
If FindMapElement(dirSubst(), key)
compassPoint + dirSubst(key)
Else
compassPoint + key
EndIf
Next
ProcedureReturn UCase(Left(compassPoint, 1)) + Mid(compassPoint, 2)
EndProcedure
Procedure.s angle2compass(angle.f)
Shared dirs()
Static segment.f = 360.0 / 32 ;width of each compass segment
Protected dir
;work out which segment contains the compass angle
dir = Int((Mod(angle, 360) / segment) + 0.5)
;convert to a named direction
ProcedureReturn abbr2compassPoint(dirs(dir))
EndProcedure
;box the compass
If OpenConsole()
Define i, heading.f, index
For i = 0 To 32
heading = i * 11.25
If i % 3 = 1
heading + 5.62
EndIf
If i % 3 = 2
heading - 5.62
EndIf
index = i % 32 + 1
PrintN(RSet(Str(index), 2) + " " + LSet(angle2compass(heading), 18) + RSet(StrF(heading, 2), 7))
Next
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf

View file

@ -0,0 +1,37 @@
global direct$
dim direct$(22)
direct$(1) = "y" 'by
direct$(4) = "ast" 'East
direct$(13) = "orth" 'North
direct$(18) = "outh" 'Soutn
direct$(22) = "est" 'West
dim point$(32)
for i =1 to 32: read point$(i) :next i
html "<table border=1>"
for i = 0 to 32
hdng = i * 11.25
if (i mod 3) = 1 then
hdng = hdng +5.62
else
if (i mod 3) = 2 then hdng = hdng -5.62
end if
pointer = i mod 32 + 1
html "<TR><TD align=right>";pointer;"</td><td>";compas$(hdng);"</td><td>";hdng;"</td></tr>"
next i
html "</table>"
end
function compas$(hd)
x = hd /11.25 + 1.5
if (x >=33.0) then x =x -32.0
p$ = point$(int(x))
for i = 1 to len(p$)
compas$ = compas$ + mid$(p$,i,1) + direct$(max(asc(upper$(mid$(p$,i,1)))-65,0))
next i
end function
data "N","N b e","N-ne","Ne b n","Ne","Ne b e","E-ne","E b n","E","E b s","E-se"
data "Se b e","Se","Se b s","S-se","S b e","S","S b w","S-sw","Sw b s","Sw","Sw b w"
data "W-sw","W b s","W","W b n","W-nw","Nw b w","Nw","Nw b n","N-nw","N b w"

View file

@ -0,0 +1,24 @@
$ include "seed7_05.s7i";
include "float.s7i";
const array string: names is [] ("North", "North by east", "North-northeast", "Northeast by north",
"Northeast", "Northeast by east", "East-northeast", "East by north", "East", "East by south",
"East-southeast", "Southeast by east", "Southeast", "Southeast by south", "South-southeast",
"South by east", "South", "South by west", "South-southwest", "Southwest by south", "Southwest",
"Southwest by west", "West-southwest", "West by south", "West", "West by north", "West-northwest",
"Northwest by west", "Northwest", "Northwest by north", "North-northwest", "North by west", "North");
const proc: main is func
local
const array float: degrees is [] (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);
var integer: index is 0;
var integer: nameIndex is 0;
begin
for key index range degrees do
nameIndex := round(degrees[index] * 32.0 / 360.0);
writeln(succ(pred(index) rem 32) lpad 2 <& " " <& names[succ(nameIndex rem 32)] rpad 22 <&
degrees[index] digits 2 lpad 6);
end for;
end func;

View file

@ -0,0 +1,51 @@
# List of abbreviated compass point labels
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
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 )
# capitalize a string
function capitalize {
echo "$1" | sed 's/^./\U&/'
}
# convert compass point abbreviation to full text of label
function expand_point {
local label="$1"
set -- N north E east S south W west b " by "
while (( $# )); do
label="${label//$1/$2}"
shift 2
done
capitalize "$label"
}
# modulus function that returns 1..N instead of 0..N-1
function amod {
echo $(( ($1 - 1) % $2 + 1 ))
}
# convert a compass angle from degrees into a box index (1..32)
function compass_point {
#amod $(dc <<<"$1 5.625 + 11.25 / 1 + p") 32
amod $(bc <<<"($1 + 5.625) / 11.25 + 1") 32
}
# Now output the table of test data
header_format="%-7s | %-18s | %s\n"
row_format="%7.2f | %-18s | %2d\n"
printf "$header_format" "Degrees" "Closest Point" "Index"
for angle in ${test_angles[@]}; do
let index=$(compass_point $angle)
abbr=${compass_points[index-1]}
label="$(expand_point $abbr)"
printf "$row_format" $angle "$label" $index
done

View file

@ -0,0 +1,46 @@
Module BoxingTheCompass
Dim _points(32) As String
Sub Main()
BuildPoints()
Dim heading As Double = 0D
For i As Integer = 0 To 32
heading = i * 11.25
Select Case i Mod 3
Case 1
heading += 5.62
Case 2
heading -= 5.62
End Select
Console.WriteLine("{0,2}: {1,-18} {2,6:F2}°", (i Mod 32) + 1, InitialUpper(GetPoint(heading)), heading)
Next
End Sub
Private Sub BuildPoints()
Dim cardinal As String() = New String() {"north", "east", "south", "west"}
Dim pointDesc As String() = New String() {"1", "1 by 2", "1-C", "C by 1", "C", "C by 2", "2-C", "2 by 1"}
Dim str1, str2, strC As String
For i As Integer = 0 To 3
str1 = cardinal(i)
str2 = cardinal((i + 1) Mod 4)
strC = IIf(str1 = "north" Or str1 = "south", str1 & str2, str2 & str1)
For j As Integer = 0 To 7
_points(i * 8 + j) = pointDesc(j).Replace("1", str1).Replace("2", str2).Replace("C", strC)
Next
Next
End Sub
Private Function InitialUpper(ByVal s As String) As String
Return s.Substring(0, 1).ToUpper() & s.Substring(1)
End Function
Private Function GetPoint(ByVal Degrees As Double) As String
Dim testD As Double = (Degrees / 11.25) + 0.5
Return _points(CInt(Math.Floor(testD Mod 32)))
End Function
End Module