Anonymous user
Box the compass: Difference between revisions
→{{header|Julia}}: Updated for Julia 1.2
(→{{header|Julia}}: Updated for Julia 1.2) |
|||
Line 3,012:
=={{header|Julia}}==
{{works with|Julia|
{{trans|Python}}
<lang julia>
majors = ("north", "east", "south", "ovest", "north", "east", "south", "ovest")▼
quart1 = ("N", "N by E", "N-NE", "NE by N", "NE", "NE by E", "E-NE", "E by N")▼
function degree2compasspoint(d::Float64)
d = (d % 360) + 360/64▼
majorindex, minor = divrem(d, 90)▼
quarter2 = map(p -> replace(p, "NE" => "EN"), quarter1)
majorindex += 1▼
minorindex += 1▼
p1, p2 = majors[majorindex:majorindex+1]▼
if p1 in ("north", "south"); q = quart1▼
return titlecase(replace(replace(q[minorindex], 'N', p1), 'E', p2))▼
end
for i in 0:32
d = i * 11.25
▲ @printf("%2i %-17s %10.2f°\n", n, degree2compasspoint(d), d)
end</lang>
Line 3,042:
<pre> 1 North 0.00°
2 North By East 16.87°
3 North-
4 Northeast By North 33.75°
5 Northeast 50.62°
6 Northeast By East 50.63°
7 East-
8 East By North 84.37°
9 East 84.38°
10 East By South 101.25°
11 East-
12
13
14
15 South-
16 South By East 168.75°
17 South 185.62°
18 South By
19 South-
20
21
22
23
24
25
26
27
28
29
30
31 North-
32 North By
1 North 354.38°</pre>
|