Three word location: Difference between revisions

m
(→‎{{header|Raku}}: Make word indexing routine user overridable, demo)
m (→‎{{header|Julia}}: bit twiddles)
Line 168:
 
=={{header|Julia}}==
Direct translation from the SymSyn example given by the task creator., though note that idiomatic Julia would usually code this as two small encode() and decode() functions.
<lang julia>
# Three Word Location - convert latitude and longitude to three words
Line 187:
# next 14 bits for word 2 index
# next 14 bits for word 3 index
W1 = (LATLON >> 28) & 0xefff0x7fff
W2 = (LATLON >> 14) & 0x7fff0x3fff
W3 = LATLON & 0x7fff0x3fff
 
# fetch each word from word array
Line 241:
end
i = (Int(lat * 10000 + 900000) << 22) | Int(lon * 10000 + 1800000)
return map(x -> arr[x + 1], [(i >> 28) & 0xefff0x7fff, (i >> 14) & 0x7fff0x3fff, i & 0x7fff0x3fff])
end
 
4,105

edits