Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,66 @@
with Ada.Text_IO;
procedure Box_The_Compass is
type Degrees is digits 5 range 0.00 .. 359.99;
type Index_Type is mod 32;
function Long_Name(Short: String) return String is
function Char_To_Name(Char: Character) return String is
begin
case Char is
when 'N' | 'n' => return Char & "orth";
when 'S' | 's' => return Char & "outh";
when 'E' | 'e' => return Char & "ast";
when 'W' | 'w' => return Char & "est";
when 'b' => return " by ";
when '-' => return "-";
when others => raise Constraint_Error;
end case;
end Char_To_Name;
begin
if Short'Length = 0 or else Short(Short'First)=' ' then
return "";
else
return Char_To_Name(Short(Short'First))
& Long_Name(Short(Short'First+1 .. Short'Last));
end if;
end Long_Name;
procedure Put_Line(Angle: Degrees) is
function Index(D: Degrees) return Index_Type is
begin
return Index_Type(Integer(Degrees'Rounding(D/11.25)) mod 32);
end Index;
I: Integer := Integer(Index(Angle))+1;
package DIO is new Ada.Text_IO.Float_IO(Degrees);
Abbr: constant array(Index_Type) of String(1 .. 4)
:= ("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 ");
begin
DIO.Put(Angle, Fore => 3, Aft => 2, Exp => 0); -- format "zzx.xx"
Ada.Text_IO.Put(" |");
if I <= 9 then
Ada.Text_IO.Put(" ");
end if;
Ada.Text_IO.Put_Line(" " & Integer'Image(I) & " | "
& Long_Name(Abbr(Index(Angle))));
end Put_Line;
Difference: constant array(0..2) of Degrees'Base
:= (0=> 0.0, 1=> +5.62, 2=> - 5.62);
begin
Ada.Text_IO.Put_Line(" angle | box | compass point");
Ada.Text_IO.Put_Line(" ---------------------------------");
for I in 0 .. 32 loop
Put_Line(Degrees(Degrees'Base(I) * 11.25 + Difference(I mod 3)));
end loop;
end Box_The_Compass;

View file

@ -0,0 +1,18 @@
Local $avArray[33] = [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]
For $i = 0 To UBound($avArray) - 1
Boxing_the_compass($avArray[$i])
Next
Func Boxing_the_compass($Degree)
Local $namearray[33] = ["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"]
ConsoleWrite(StringFormat("%-2s", Mod(Floor($Degree / 11.25 + 0.5), 32)) & " : " & _
StringFormat("%-20s", $namearray[Mod(Floor($Degree / 11.25 + 0.5), 32)]) & " : " & $Degree & @CRLF)
EndFunc ;==>Boxing_the_compass

View file

@ -0,0 +1,67 @@
identification division.
program-id. box-compass.
data division.
working-storage section.
01 point pic 99.
01 degrees usage float-short.
01 degrees-rounded pic 999v99.
01 show-degrees pic zz9.99.
01 box pic z9.
01 fudge pic 9.
01 compass pic x(4).
01 compass-point pic x(18).
01 shortform pic x.
01 short-names.
05 short-name pic x(4) occurs 33 times.
01 overlay.
05 value "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 ".
procedure division.
display "Index Compass point Degree"
move overlay to short-names.
perform varying point from 0 by 1 until point > 32
compute box = function mod(point 32) + 1
compute degrees = point * 11.25
compute fudge = function mod(point 3)
evaluate fudge
when equal 1
add 5.62 to degrees
when equal 2
subtract 5.62 from degrees
end-evaluate
compute degrees-rounded rounded = degrees
move degrees-rounded to show-degrees
inspect show-degrees replacing trailing '00' by '0 '
inspect show-degrees replacing trailing '50' by '5 '
move short-name(point + 1) to compass
move spaces to compass-point
display space box space space space with no advancing
perform varying tally from 1 by 1 until tally > 4
move compass(tally:1) to shortform
move function concatenate(function trim(compass-point),
function substitute(shortform,
"N", "North",
"E", "East",
"S", "South",
"W", "West",
"b", " byZ",
"-", "-"))
to compass-point
end-perform
move function substitute(compass-point, "Z", " ")
to compass-point
move function lower-case(compass-point) to compass-point
move function upper-case(compass-point(1:1))
to compass-point(1:1)
display compass-point space show-degrees
end-perform
goback.

View file

@ -0,0 +1,23 @@
constant names = {"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"}
function deg2ind(atom degree)
return remainder(floor(degree*32/360+.5),32)+1
end function
sequence degrees
degrees = {}
for i = 0 to 32 do
degrees &= i*11.25 + 5.62*(remainder(i+1,3)-1)
end for
integer j
for i = 1 to length(degrees) do
j = deg2ind(degrees[i])
printf(1, "%6.2f %2d %-22s\n", {degrees[i], j, names[j]})
end for

View file

@ -0,0 +1,63 @@
local fmt = require "fmt"
---'cpx' returns integer index from 1 to 32 corresponding to compass point.
-- Input heading h is in degrees.
local function cpx(h)
local x = math.floor(h /11.25 + 0.5) % 32
if x < 0 then x += 32 end
return x + 1
end
-- Printable compass points.
local compass_point = {
"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"
}
-- Function required by task.
local function degrees_to_compass_point(h) return compass_point[cpx(h)] end
local r = {
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
}
print("Index Compass point Degree")
local i = 0
for r as h do
local index = i % 32 + 1
local d = degrees_to_compass_point(h)
fmt.print("%4d %-19s %7.2f°", index, d, h)
i += 1
end

View file

@ -0,0 +1,16 @@
function Convert-DegreeToDirection ( [double]$Degree )
{
$Directions = @( 'n','n by e','n-ne','ne by n','ne','ne by e','e-ne','e by n',
'e','e by s','e-se','se by e','se','se by s','s-se','s by e',
's','s by w','s-sw','sw by s','sw','sw by w','w-sw','w by s',
'w','w by n','w-nw','nw by w','nw','nw by n','n-nw','n by w',
'n'
).Replace( 's', 'south' ).Replace( 'e', 'east' ).Replace( 'n', 'north' ).Replace( 'w', 'west' )
$Directions[[math]::floor(( $Degree % 360 ) / 11.25 + 0.5 )]
}
$x = 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
$x | % { Convert-DegreeToDirection -Degree $_ }

View file

@ -0,0 +1,23 @@
function Convert-DegreeToDirection ( [double]$Degree, [int]$Points )
{
$Directions = @( 'n','n by e','n-ne','ne by n','ne','ne by e','e-ne','e by n',
'e','e by s','e-se','se by e','se','se by s','s-se','s by e',
's','s by w','s-sw','sw by s','sw','sw by w','w-sw','w by s',
'w','w by n','w-nw','nw by w','nw','nw by n','n-nw','n by w',
'n'
).Replace( 's', 'south' ).Replace( 'e', 'east' ).Replace( 'n', 'north' ).Replace( 'w', 'west' )
$Directions[[math]::floor((( $Degree % 360 ) * $Points / 360 + 0.5 )) * 32 / $Points ]
}
$x = 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
$Values = @()
ForEach ( $Degree in $X ) { $Values += [pscustomobject]@{ Degree = $Degree
32 = ( Convert-DegreeToDirection -Degree $Degree -Points 32 )
16 = ( Convert-DegreeToDirection -Degree $Degree -Points 16 )
8 = ( Convert-DegreeToDirection -Degree $Degree -Points 8 )
4 = ( Convert-DegreeToDirection -Degree $Degree -Points 4 ) } }
$Values | Format-Table

View file

@ -0,0 +1,107 @@
Rebol [
title: "Rosetta code: Box the compass"
file: %Box_the_compass.r3
url: https://rosettacode.org/wiki/Box_the_compass
needs: 3.10.0 ;; or something like that
]
form-angle: func[
"Format the angle as a string with at least one decimal and pad to 2 decimals"
angle [decimal!]
][
angle: form round/to angle 0.01
pad/with find/last angle #"." 3 #"0" ;; ensure two digits after the decimal point
append angle #"°" ;; add the degree symbol
]
compass: context [
points: none
make-points: function [/verbose][
out: copy []
;; Define a character set for the four main directions
main-dir: charset "NESW"
;; 32-wind compass notation (with quarter winds and by-points)
words: [
N NbE NNE NEbN NE NEbE ENE EbN E EbS ESE SEbE SE SEbS SSE
SbE S SbW SSW SWbS SW SWbW WSW WbS W WbN WNW NWbW NW NWbN NNW NbW N
]
;; Replacement map from shorthand characters to full words (and spacing)
replacement: #[
#"N" "north"
#"b" " by "
#"S" "south"
#"E" "east"
#"W" "west"
]
i: 0 ;; index of the current compass point (0..32)
foreach word words [
;; Compute heading angle:
;; Each step is 11.25°, with offsets of +5.62, 0.0, or -5.62 for the 1/3 sub-steps.
heading: i * 11.25 + (pickz [0.0 5.62 -5.62] i % 3)
;; Start with the symbolic label (e.g., "NEbE") as a mutable string
text: to string! word
;; Insert a hyphen after the first main direction if followed by two more main directions
;; (e.g., "NEbE" -> "N-EbE")
parse text [1 main-dir ahead 2 main-dir insert "-"]
;; Expand shorthand letters to full words using the replacement table:
;; - Replace N/S/E/W with north/south/east/west
;; - Replace 'b' with " by "
parse text [any [p: change skip (any [replacement/(p/1) p/1])]]
;; Capitalize first letter of the expanded label (e.g., "north by east" -> "North by east")
uppercase/part text 1
if verbose [
;; Print three columns:
;; - Ordinal index within 32-wind cycle (1..32)
;; - Formatted angle
;; - Expanded textual compass point
print [
pad (i % 32 + 1) -3
pad form-angle heading -7
pad form word 5
text
]
]
repend out [heading word text]
++ i
]
new-line/skip out true 3
out
]
nearest-text: function [
"Returns the nearest compass point text for a given angle."
angle [number! integer! decimal!]
][
;; :lazily build the points table if not already built
unless points [points: make-points]
;; Normalize query angle into [0,360)
angle: angle % 360.0
if angle < 0 [angle: angle + 360.0]
best-diff: 1e9
;; Walk triples: angle word text
foreach [deg wrd txt] points [
;; Compute minimal circular difference
diff: abs deg - angle
if diff < best-diff [
best-diff: diff
best: txt ;; remember the text for the closest heading
]
]
best
]
]
;; Print all angle texts
compass/make-points/verbose
print "^/Resolve texts for random angles:"
random/seed 1
loop 5 [
angle: random 360.0
print [
pad form-angle angle -7
compass/nearest-text angle
]
]

View file

@ -0,0 +1,21 @@
const names = ["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 degrees = [f32(0), 16.87, 16.88, 33.75, 50.62, 50.63,
67.5, 84.37, 84.38, 101.25, 118.12, 118.13, 135, 151.87, 151.88, 168.75,
185.62, 185.63, 202.5, 219.37, 219.38, 236.25, 253.12, 253.13, 270,
286.87, 286.88, 303.75, 320.62, 320.63, 337.5, 354.37, 354.38]
fn main() {
for idx, degree in degrees {
mut jdx := if idx >= 32 {idx - 31} else {idx + 1}
println("${jdx:2} ${names[jdx]:-18} ${degree:6.2f}")
}
}