RosettaCodeData/Task/Box-the-compass/Phix/box-the-compass-1.phix
2026-02-01 16:33:20 -08:00

46 lines
1.7 KiB
Text

with javascript_semantics
function get225(integer d, string p1, string p2, string p4)
string p3 = p1&'-'&lower(p2)
p2 &= " by "&lower(p1)
p1 &= " by "&lower(p4)
if d then
return {p1,p3,p2} -- eg {North by east,North-northeast,Northeast by north}
else
return {p2,p3,p1} -- eg {Northeast by east,East-northeast,East by north}
end if
end function
function get45(sequence res, integer d, string p1, string p2)
string p3
res = append(res,p1) -- North/East/South/West
if d then
p3 = p1&lower(p2) -- Northeast/Southwest
else
p3 = p2&lower(p1) -- Southeast/Northwest
end if
res &= get225(1,p1,p3,p2) -- eg get225(1,North,Northeast,East)
-- -> {North by east,North-northeast,Northeast by north}
res = append(res,p3) -- Northeast/Southeast/Southwest/Northwest
res &= get225(0,p2,p3,p1) -- eg get225(0,East,Northeast,North)
-- -> {Northeast by east,East-northeast,East by north}
return res
end function
function get90(sequence points)
sequence res = {}
for i=1 to length(points) do
res = get45(res,remainder(i,2),points[i],points[remainder(i,4)+1])
end for -- ie get45(1,North,East)
-- get45(0,East,South)
-- get45(1,South,West)
-- get45(0,West,North)
return res
end function
constant compass_points = get90({"North","East","South","West"})
for i=1 to 33 do
atom test_point = (i-1)*11.25 + 5.62*(remainder(i,3)-1)
integer compass_point = remainder(floor(test_point*32/360+0.5),32)+1
printf(1, "%2d %-22s %6.2f\n", {compass_point, compass_points[compass_point], test_point})
end for