Geohash: Difference between revisions

m
→‎{{header|J}}: slight efficiency gain and an observation about rounding
(J first draft, without extra credit)
m (→‎{{header|J}}: slight efficiency gain and an observation about rounding)
Line 350:
 
geohash=: {{
bits=. 53*x
x{.gdigits{~_5 #.\,|:|.(bits#2)#:<.(2^bits)*(y+90 180)%180 360
}}</syntaxhighlight>
 
Note that the test cases suggest that rounding should never be used when generating a geohash. This guarantees that a short geohash is always a prefix of a longer geohash for the same location.
Caution: this implementation may have issues with rounding. But it works fine for the available test cases.
 
<syntaxhighlight lang=J> 2 geohash 51.433718 _0.214126
6,962

edits