Three word location: Difference between revisions

m
syntax highlighting fixup automation
(J)
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.
<langsyntaxhighlight lang="applescript">on locationToWords({latitude, longitude})
-- "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}</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">{{28.3852, -81.5638}, {"W18497", "W11324", "W01322"}, {28.3852, -81.5638}}</langsyntaxhighlight>
 
===Actual words===
<langsyntaxhighlight lang="applescript">on locationToWords({latitude, longitude}, listOfWords)
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}</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">{{28.3852, -81.5638}, {"quote", "hygiene", "aristotelean"}, {28.3852, -81.5638}}</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
Conversion based on Wren<br>
WordList From link suggested by Symsyn
<langsyntaxhighlight AutoHotkeylang="autohotkey">URLDownloadToFile, http://www-personal.umich.edu/~jlawler/wordlist, % A_Temp "\wordlist.txt"
FileRead, wordList, % A_Temp "\wordlist.txt"
 
Line 186:
return [(ilat-900000)/10000, (ilon-1800000)/10000]
}
;-----------------------------------------------</langsyntaxhighlight>
{{out}}
<pre>LL = 28.3852, -81.5638
Line 195:
=={{header|C}}==
{{trans|Go}}
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
 
Line 253:
printf(" latitude = %0.4f, longitude = %0.4f\n", lat, lon);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 270:
{{libheader| System.SysUtils}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Three_word_location;
 
Line 416:
end.
 
</syntaxhighlight>
</lang>
 
{{out}}
Line 433:
=={{header|FreeBASIC}}==
{{trans|Nim}}
<langsyntaxhighlight lang="freebasic">Print "Starting figures:"
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</langsyntaxhighlight>
{{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.
<langsyntaxhighlight lang="go">package main
 
import (
Line 530:
fmt.Println("\nAfter reversing the procedure:")
fmt.Printf(" latitude = %0.4f, longitude = %0.4f\n", lat, lon)
}</langsyntaxhighlight>
 
{{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.<langsyntaxhighlight Jlang="j">wloc=: {{ ;:inv wordlist{~ (15 14 14#i.3)#./.;(21 22#&.>2) #:&.> <.0.5+10000*90 180+y }}
colw=: {{ _90 _180+1e_4*21({.,&#.}.);(15 14 14#&.>2)#:&.>wordlist i.;:y }}</langsyntaxhighlight>
 
With <code>wordlist=: ('W',}.@":)&.> 1e5+i.3e4</code>
 
<langsyntaxhighlight Jlang="j"> wloc 28.3852 _81.5638
W18497 W11324 W01322
colw wloc 28.3852 _81.5638
28.3852 _81.5638</langsyntaxhighlight>
 
With <code>wordlist=: cutLF CR-.~fread 'wordlist'</code> based on the file 'wordlist' from http://www-personal.umich.edu/~jlawler/wordlist <langsyntaxhighlight Jlang="j"> wloc 28.3852 _81.5638
diplotene chamomile aeroplanist
colw wloc 28.3852 _81.5638
28.3852 _81.5638</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="julia">
# Three Word Location - convert latitude and longitude to three words
LAT = 28.3852
Line 613:
# display values
println("latitude = $lat longitude = $lon")
</langsyntaxhighlight>{{out}}
<pre>
W18497 W11324 W01322
Line 620:
 
=== Idiomatic version with scrambling===
<langsyntaxhighlight lang="julia">using Random
 
const LAT = 28.3852
Line 661:
lat, lon = threeworddecode(words..., 12345678)
println("latitude = $lat longitude = $lon")
</langsyntaxhighlight>{{out}}
<pre>
W18497 W11324 W01322
Line 673:
=={{header|Kotlin}}==
{{trans|Go}}
<langsyntaxhighlight lang="scala">fun toWord(w: Long): String {
return "W%05d".format(w)
}
Line 724:
println("After reversing the procedure:")
println(" latitude = %.4f, longitude = %.4f".format(lat, lon))
}</langsyntaxhighlight>
{{out}}
<pre>Starting figures:
Line 737:
=={{header|Lua}}==
{{trans|C}}
<langsyntaxhighlight lang="lua">function toWord(w)
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))</langsyntaxhighlight>
{{out}}
<pre>Starting figures:
Line 803:
=={{header|Nim}}==
{{trans|Go}}
<langsyntaxhighlight Nimlang="nim">import strformat, strutils
 
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}"</langsyntaxhighlight>
 
{{out}}
Line 866:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use strict;
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() });
}</langsyntaxhighlight>
{{out}}
<pre>Coordinates: 51.4337, -0.2141 (Wimbledon)
Line 963:
=={{header|Phix}}==
{{trans|Go}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,056:
* u - long u (due boo moo)
 
<syntaxhighlight lang="raku" perl6line># SYNTHETICS HANDLING
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( { $_ } );
}</langsyntaxhighlight>
{{out}}
 
Line 1,158:
10 times better accuracy in the same three, 6-letter word space.
 
<syntaxhighlight lang="raku" perl6line># SYNTHETICS HANDLING
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);
}</langsyntaxhighlight>
{{out}}
<pre>Coordinates: 51.43372, -0.21412
Line 1,226:
 
=={{header|Symsyn}}==
<syntaxhighlight lang="symsyn">
<lang Symsyn>
| Three Word Location - convert latitude and longitude to three words
 
Line 1,337:
return -1
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,346:
Using Real Words
 
<syntaxhighlight lang="symsyn">
<lang Symsyn>
 
| Three Word Location - convert latitude and longitude to three words
Line 1,470:
return -1
 
</syntaxhighlight>
</lang>
 
{{Output}}
Line 1,480:
=={{header|Vlang}}==
{{trans|Go}}
<langsyntaxhighlight lang="go">import strconv
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}")
}</langsyntaxhighlight>
 
{{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.
<langsyntaxhighlight lang="ecmascript">import "/fmt" for Fmt
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)</langsyntaxhighlight>
 
{{out}}
10,327

edits