Box the compass: Difference between revisions
→{{header|UNIX Shell}}: sed-based capitalize() doesn't work on BSD/OS X, which also doesn't have bash 4 and its ${param^}.
(→{{header|Nim}}: Solution that matches the task) |
(→{{header|UNIX Shell}}: sed-based capitalize() doesn't work on BSD/OS X, which also doesn't have bash 4 and its ${param^}.) |
||
Line 6,542:
{{trans|Logo}}
Requires the standard POSIX bc(1)
<lang sh># List of abbreviated compass point labels
Line 6,557:
320.62 320.63 337.50 354.37 354.38 )
printf '%s%s\n' "$(tr a-z A-Z <<<"${1:0:1}")" "${1:1}"
▲function capitalize {
}
# convert compass point abbreviation to full text of label
function expand_point {
local label=
set -- N north E east S south W west b " by "
while (( $# )); do
label=
shift 2
done
Line 6,581 ⟶ 6,579:
# convert a compass angle from degrees into a box index (1..32)
function compass_point {
# use bc or dc depending on what's on the system
#amod $(dc <<<"$1 5.625 + 11.25 / 1 + p") 32
amod $(bc <<<"($1 + 5.625) / 11.25 + 1") 32
|