Anonymous user
Three word location: Difference between revisions
→{{header|Symsyn}}
No edit summary |
|||
Line 831:
<pre>
W18497 W11324 W01322
latitude = 28.3852 longitude = -81.5638
</pre>
Using Real Words
<lang Symsyn>
| Three Word Location - convert latitude and longitude to three words
lat : 28.3852
lon : -81.5638
| Build real word array of the first 28126 words of 8
| or less characters from list of 69905 words sorted alphabetically
| at http://www-personal.umich.edu/~jlawler/wordlist.
| There are 36282 words of 8 or less characters here.
opentext 'LargeWordList.txt' wf
if ioresult <> 0
stop
endif
if i <= 28125
[wf] $s
if ioresult <> 0
go closefile
endif
#$s wsz
if wsz <= 8
+ $s $wordarray
(8-wsz) wsz
+ ' ' $wordarray wsz
+ i
endif
goif
endif
closefile close wf
| make latitude and longitude positive integers
{lat * 10000 + 900000} ilat
{lon * 10000 + 1800000} ilon
| build 43 bit integer containing latitude (21 bits) and longitude (22 bits)
ilat latlon
shl latlon 22
+ ilon latlon
| isolate most significant 15 bits for word 1 index
| next 14 bits for word 2 index
| next 14 bits for word 3 index
latlon:42:15 w1
latlon:27:14 w2
latlon:13:14 w3
| fetch each word from word array
(w1*8+1) w1
$wordarray.w1 $w1 8
(w2*8+1) w2
$wordarray.w2 $w2 8
(w3*8+1) w3
$wordarray.w3 $w3 8
| display words
"$w1 ' ' $w2 ' ' $w3" []
| reverse the procedure
| look up each word
call bsearch 0 28125 $w1
result w1index
call bsearch 0 28125 $w2
result w2index
call bsearch 0 28125 $w3
result w3index
| build the latlon integer from the word indexes
w1index latlon
shl latlon 14
+ w2index latlon
shl latlon 14
+ w3index latlon
| isolate the latitude and longitude
latlon:21:22 ilon
latlon:42:21 ilat
| convert back to floating point values
{(ilon - 1800000) / 10000} lon
{(ilat - 900000) / 10000} lat
| display values
"'latitude = ' lat ' longitude = ' lon" []
stop
bsearch
param L H $word
if L <= H
((L + H) shr 1) M
(M*8+1) I
$wordarray.I $w 8
if $w > $word
- 1 M H
else
if $w < $word
+ 1 M L
else
return M
endif
endif
goif
endif
return -1
</lang>
{{Output}}
<pre>
ling everyone amoral
latitude = 28.3852 longitude = -81.5638
</pre>
|