Three word location: Difference between revisions

→‎{{header|Raku}}: Add a Raku example
(→‎{{header|Raku}}: Add a Raku example)
Line 276:
latitude = -81.5638 longitude = 28.3852
</pre>
 
=={{header|Raku}}==
{{works with|Rakudo|2020.07}}
In large part due to the complete lack of specification, reference implementation, or guidance from the task creator, came up with my own bespoke synthetic word list.
 
Words always consist of a series of consonant/vowel pairs. Uses a cut down alphabet to reduce possible confusion from overlapping pronunciation.
 
Some letters with overlapping pronunciation are removed: c: confusable with k or s, g: overlaps with j, x: overlaps with z, q: just because, v: similar to w and we have way more than enough characters anyway.
 
As it is, with this alphabet we can form 512000 different 6 character "words"; 28126 is a drop in the bucket. (We end up with an awful lot of "words" starting with b)
 
We don't bother to pre-calculate and store them though, just generate them on the fly.
 
Official pronunciation guide:
 
* a - long a (say may day)
* e - long e (he me see)
* i - long i (hi sigh die)
* o - long o (go so low)
* u - long u (due boo moo)
 
<lang perl6># 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;
my $exp = @synth.elems;
 
sub synth (Int $v) { @synth[$v.polymod($exp xx *).reverse || 0].join }
 
sub thnys (Str $v) { sum %htnys{$v.comb(2).reverse} Z* 1, $exp, $exp**2 }
 
 
# ENCODE / DECODE
sub w-encode ( Rat(Real) $lat, Rat(Real) $lon ) {
$_ = (($lat + 90) * 10000).round.fmt('%021b') ~ (($lon + 180) * 10000).round.fmt('%022b');
(:2(.substr(0,15)), :2(.substr(15,14)),:2(.substr(29)))».&synth
}
 
sub w-decode ( *@words ) {
my $bin = (@words».&thnys Z, <0 1 1>).map({.[0].fmt('%015b').substr(.[1])}).join;
(:2($bin.substr(0,21))/10000) - 90, (:2($bin.substr(21))/10000) - 180
}
 
 
# TESTING
for 51.4337, -0.2141, # Wimbledon
21.2596,-157.8117, # Diamond Head crater
-55.9652, -67.2256, # Monumento Cabo De Hornos
59.3586, 24.7447, # Lake Raku
29.2021, 81.5324, # Village Raku
28.3852, -81.5638 # Walt Disney World
-> $lat, $lon {
my @words = w-encode $lat, $lon;
printf "Coordinates: %s, %s\n To 3-word: %-20s\n And back: %s, %s\n\n",
$lat, $lon, @words.Str, w-decode(@words);
}</lang>
{{out}}
<pre>Coordinates: 51.4337, -0.2141
To 3-word: bomehu bupa beyabo
And back: 51.4337, -0.2141
 
Coordinates: 21.2596, -157.8117
To 3-word: bisiju tufo belefe
And back: 21.2596, -157.8117
 
Coordinates: -55.9652, -67.2256
To 3-word: wemi biliwo bifali
And back: -55.9652, -67.2256
 
Coordinates: 59.3586, 24.7447
To 3-word: boresi sufi bimiye
And back: 59.3586, 24.7447
 
Coordinates: 29.2021, 81.5324
To 3-word: biyiwa wuha bepoko
And back: 29.2021, 81.5324
 
Coordinates: 28.3852, -81.5638
To 3-word: biyehi betenu heni
And back: 28.3852, -81.5638</pre>
 
 
=={{header|Symsyn}}==
10,333

edits