Three word location: Difference between revisions
m
syntax highlighting fixup automation
(J) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 32:
===Index words===
When the words are index-based as in the task description, it's not necessary to generate all 28126.
<
-- "Convert" the coordinates to positive integers by adding enough degrees to ensure positive results,
-- multiplying by enough to left shift by four decimal places, and rounding.
Line 63:
set threeWords to locationToWords(location)
set checkLocation to wordsToLocation(threeWords)
return {location, threeWords, checkLocation}</
{{output}}
<
===Actual words===
<
script o
property wordList : listOfWords
Line 128:
set threeWords to locationToWords(location, o's wordList)
set checkLocation to wordsToLocation(threeWords, o's wordList)
return {location, threeWords, checkLocation}</
{{output}}
<
=={{header|AutoHotkey}}==
Conversion based on Wren<br>
WordList From link suggested by Symsyn
<
FileRead, wordList, % A_Temp "\wordlist.txt"
Line 186:
return [(ilat-900000)/10000, (ilon-1800000)/10000]
}
;-----------------------------------------------</
{{out}}
<pre>LL = 28.3852, -81.5638
Line 195:
=={{header|C}}==
{{trans|Go}}
<
#include <stdlib.h>
Line 253:
printf(" latitude = %0.4f, longitude = %0.4f\n", lat, lon);
return 0;
}</
{{out}}
Line 270:
{{libheader| System.SysUtils}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
program Three_word_location;
Line 416:
end.
</syntaxhighlight>
{{out}}
Line 433:
=={{header|FreeBASIC}}==
{{trans|Nim}}
<
Dim As Double lat = 28.3852, longi = -81.5638
Print Using " latitude = &, longitude = &"; lat; longi
Line 468:
Print !"\nAfter reversing the procedure:"
Print Using " latitude = &, longitude = &"; lat; longi
Sleep</
{{out}}
<pre>Igual que la entrada de Nim</pre>
Line 475:
{{trans|Wren}}
Though no need for big integers as we have int64 built in.
<
import (
Line 530:
fmt.Println("\nAfter reversing the procedure:")
fmt.Printf(" latitude = %0.4f, longitude = %0.4f\n", lat, lon)
}</
{{out}}
Line 546:
=={{header|J}}==
To take full advantage of the bit space, I think we should use 11650.8444 for the multiplier (2^21 - log2 180), but that's not what was asked for here.<
colw=: {{ _90 _180+1e_4*21({.,&#.}.);(15 14 14#&.>2)#:&.>wordlist i.;:y }}</
With <code>wordlist=: ('W',}.@":)&.> 1e5+i.3e4</code>
<
W18497 W11324 W01322
colw wloc 28.3852 _81.5638
28.3852 _81.5638</
With <code>wordlist=: cutLF CR-.~fread 'wordlist'</code> based on the file 'wordlist' from http://www-personal.umich.edu/~jlawler/wordlist <
diplotene chamomile aeroplanist
colw wloc 28.3852 _81.5638
28.3852 _81.5638</
=={{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.
<
# Three Word Location - convert latitude and longitude to three words
LAT = 28.3852
Line 613:
# display values
println("latitude = $lat longitude = $lon")
</
<pre>
W18497 W11324 W01322
Line 620:
=== Idiomatic version with scrambling===
<
const LAT = 28.3852
Line 661:
lat, lon = threeworddecode(words..., 12345678)
println("latitude = $lat longitude = $lon")
</
<pre>
W18497 W11324 W01322
Line 673:
=={{header|Kotlin}}==
{{trans|Go}}
<
return "W%05d".format(w)
}
Line 724:
println("After reversing the procedure:")
println(" latitude = %.4f, longitude = %.4f".format(lat, lon))
}</
{{out}}
<pre>Starting figures:
Line 737:
=={{header|Lua}}==
{{trans|C}}
<
return string.format("W%05d", w)
end
Line 790:
-- and print the results
print("After reversing the procedure:")
print(string.format(" latitude = %0.4f, longitude = %0.4f", lat, lon))</
{{out}}
<pre>Starting figures:
Line 803:
=={{header|Nim}}==
{{trans|Go}}
<
func toWord(w: int64): string = &"W{w:05}"
Line 852:
# Print the results.
echo "\nAfter reversing the procedure:"
echo &" latitude = {lat:0.4f}, longitude = {long:0.4f}"</
{{out}}
Line 866:
=={{header|Perl}}==
{{trans|Raku}}
<
use warnings;
use feature 'say';
Line 923:
printf "Coordinates: %s, %s (%s)\n To Index: %s\n To 3-word: %s\nFrom 3-word: %s, %s\n From Index: %s, %s\n\n",
$lat, $lon, $description, join(' ',@index), join(' ',@words), w_decode(\@words), w_decode(\@index, sub { shift() });
}</
{{out}}
<pre>Coordinates: 51.4337, -0.2141 (Wimbledon)
Line 963:
=={{header|Phix}}==
{{trans|Go}}
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Three_word_location.exw
Line 1,022:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\nAfter reversing the procedure:\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" latitude = %0.4f, longitude = %0.4f\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">lat</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">lon</span><span style="color: #0000FF;">})</span>
<!--</
{{out}}
<pre>
Line 1,056:
* u - long u (due boo moo)
<syntaxhighlight lang="raku"
my @synth = flat < b d f h j k l m n p r s t w y z > X~ < a e i o u >;
my %htnys = @synth.antipairs;
Line 1,091:
printf "Coordinates: %s, %s\n To Index: %s\n To 3-word: %s\nFrom 3-word: %s, %s\n From Index: %s, %s\n\n",
$lat, $lon, @index.Str, @words.Str, w-decode(@words), w-decode @index, :f( { $_ } );
}</
{{out}}
Line 1,158:
10 times better accuracy in the same three, 6-letter word space.
<syntaxhighlight lang="raku"
my @synth = flat < b d f j k n p r s t w > X~ < a e i o u >;
my %htnys = @synth.antipairs;
Line 1,193:
printf "Coordinates: %s, %s\n To Index: %s\n To 3-word: %s\nFrom 3-word: %s, %s\n\n",
$lat, $lon, w-encode($lat, $lon, :f({$_})).Str, @words.Str, w-decode(@words);
}</
{{out}}
<pre>Coordinates: 51.43372, -0.21412
Line 1,226:
=={{header|Symsyn}}==
<syntaxhighlight lang="symsyn">
| Three Word Location - convert latitude and longitude to three words
Line 1,337:
return -1
</syntaxhighlight>
{{out}}
<pre>
Line 1,346:
Using Real Words
<syntaxhighlight lang="symsyn">
| Three Word Location - convert latitude and longitude to three words
Line 1,470:
return -1
</syntaxhighlight>
{{Output}}
Line 1,480:
=={{header|Vlang}}==
{{trans|Go}}
<
fn to_word(w i64) string { return 'W${w:05}' }
Line 1,530:
println("\nAfter reversing the procedure:")
println(" latitude = ${lat:.4}, longitude = ${lon:.4}")
}</
{{out}}
Line 1,550:
Note that bitwise operations are limited to 32-bit unsigned integers in Wren which isn't big enough here so we use BigInts instead.
<
import "/big" for BigInt
Line 1,596:
// and print the results
System.print("\nAfter reversing the procedure:")
Fmt.print(" latitude = $0.4f, longitude = $0.4f", lat, lon)</
{{out}}
|