Box the compass: Difference between revisions

add RPL
(→‎{{header|REXX}}: refurbished and extended the output)
(add RPL)
Line 6,621:
354.38 0 North
</pre>
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.9}}
{| class="wikitable" ≪
! RPL code
! Comment
|-
|
≪ { "north" "east" "south" "west" }
SWAP 8 / IP 1 + GET
LAST 1 + DUP 5 ≠ SWAP 1 IFTE GET
≫ '<span style="color:blue">I→QDT</span>' STO
≪ → pattern a b
≪ "" 1 pattern SIZE '''FOR''' j
pattern j DUP SUB
DUP "X" == a ROT DUP "Y" == b ROT IFTE IFTE
+ '''NEXT'''
≫ ≫ '<span style="color:blue">FILLXY</span>' STO
11.25 / 0.5 + FLOOR 32 MOD
{ "X" "X by Y" "X-XY" "XY by X"
"XY" "XY by Y" "Y-XY" "Y by X" "Y" }
OVER 8 MOD 1 + GET SWAP <span style="color:blue">I→QDT</span> <span style="color:blue">FILLXY</span>
≫ '<span style="color:blue">→HDG</span>' STO
|
<span style="color:blue">I→QDT</span> ''( index → "wind1" "wind2" )'' // index ∈ [0,31]
Get wind1
Get wind2
<span style="color:blue">FILLXY</span> ''( "pattern" "a" "b" → "string" ) ''
Initialize output string and loop
get jth character of pattern
replace "X" by "a" and "Y" by b
add to output string
<span style="color:blue">→HDG</span> ''( angle → "heading" )'' // angle in degreees
Convert angle into compass index
Naming patterns
Get pattern, get winds and convert into heading
|}
The demonstration has been limited to a few significant cases, due to the poor display capabilities of typical RPL devices (e.g. 4 x 22 characters on a HP-28S) :
≪ <span style="color:red">{ 0 16.87 16.88 33.75 50.62 354.37 354.38 } { } 1 3</span> PICK SIZE '''FOR''' j OVER j GET <span style="color:blue">→HDG</span> + '''NEXT''' SWAP DROP ≫ EVAL
 
{{out}}
<pre>
1: { "north" "north by east" "north-northeast" "northeast by north" "northeast" "north by west" "north" }
</pre>
 
=={{header|Ruby}}==
 
Line 6,682 ⟶ 6,737:
32 north by west 354.37
1 north 354.38</pre>
 
=={{header|Run BASIC}}==
<syntaxhighlight lang="runbasic">global direct$
1,150

edits