Geohash: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Minor tidy)
(added RPL)
Line 977: Line 977:
geo-encoded: tv1ypk4
geo-encoded: tv1ypk4
geo-decoded: 29.202347 ± 6.866e-04, 81.532974 ± 6.866e-04
geo-decoded: 29.202347 ± 6.866e-04, 81.532974 ± 6.866e-04
</pre>

=={{header|RPL}}==
{{trans|Python}}
{{works with|HP|48}}

« ROT ROT DUP ∑LIST 2 /
ROT OVER <
ROT OVER 1 + 4 ROLL PUT
ROT SL ROT NOT R→B OR
» '<span style="color:blue">BISECT</span>' STO <span style="color:grey">''@ ( val (mn,mx) bits → (a,b) bits )''</span>
« "0123456789bcdefghjkmnpqrstuvwxyz" "" → coord pre ch32 hash
« { -90 90 } { -180 180 } #0
0 pre 5 * 1 - FOR j
'''IF''' j 2 MOD '''THEN'''
coord 1 GET 4 ROLL ROT <span style="color:blue">BISECT</span> ROT SWAP
'''ELSE'''
coord 2 GET ROT ROT <span style="color:blue">BISECT</span>
'''END'''
'''NEXT'''
1 pre '''START'''
ch32 OVER #31d AND B→R 1 + DUP SUB
'hash' STO+ 32 /
'''NEXT'''
3 DROPN hash
» » '<span style="color:blue">→GEOH</span>' STO <span style="color:grey">''@ ( { lat long } pre → "geohash" )''</span>
« "0123456789bcdefghjkmnpqrstuvwxyz" "" → hash ch32
« "" BIN
1 hash SIZE '''FOR''' j
ch32 hash j DUP SUB POS
1 - 32 + R→B →STR 4 OVER SIZE 1 - SUB +
'''NEXT'''
'hash' STO
{ {-90,90} {-180,180} }
1 hash SIZE '''FOR''' j
j 2 MOD 1 + DUP2 GET
hash j DUP SUB "0" == 1 +
OVER ∑LIST 2 / PUT PUT
'''NEXT'''
» » '<span style="color:blue">GEOH→</span>' STO <span style="color:grey">''@ ( "geohash" → { { latmin latmax } { longmin longmax ) }''</span>

{ 51.433718 -0.214126 } 2 <span style="color:blue">GEOH→</span>
{ 51.433718 -0.214126 } 9 <span style="color:blue">GEOH→</span>
{ 57.649110 10.407440 } 11 <span style="color:blue">GEOH→</span>
{{out}}
<pre>
3: "gc"
2: "gcpuxe0rj"
1: "u4pruydqqvj"
</pre>
RPL floating-point numbers have only 12 significant digits, which could explain the error in the second case.

"gc" <span style="color:blue">GEOH→</span>
"gcpue5hp4" <span style="color:blue">GEOH→</span>
"u4pruydqqvj" <span style="color:blue">GEOH→</span>
{{out}}
<pre>
3: { { 50.625 56.25 } { -11.25 0 } }
2: { { 51.4336967465 51.433739662 } { -.21414756775 -.214104652406 } }
1: { { 57.6491099595 57.649111301 } { 10.4074390233 10.4074403644 } }
</pre>
</pre>