Jump to content

Anadromes: Difference between revisions

m
Automated syntax highlighting fixup (second round - minor fixes)
m (syntax highlighting fixup automation)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 25:
So you will need to use another compiler under Windows.<br>
As in the Wren sample, the words are quicksorted so binary searching can be used to find the reversed words.
<syntaxhighlight lang="algol68">BEGIN # find some anadromes: words that whwn reversed are also words #
# in-place quick sort an array of strings #
PROC s quicksort = ( REF[]STRING a, INT lb, ub )VOID:
Line 144:
 
=={{header|AppleScript}}==
<syntaxhighlight lang="applescript">use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
use scripting additions
Line 192:
 
{{output}}
<syntaxhighlight lang="applescript">"amaroid <--> diorama
degener <--> reneged
deifier <--> reified
Line 211:
 
=={{header|AWK}}==
<syntaxhighlight lang=AWK"awk">
# syntax: GAWK -f ANADROMES.AWK WORDS.TXT
#
Line 269:
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <algorithm>
#include <cstdlib>
#include <fstream>
Line 322:
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// Anadromes. Nigel Galloway: June 26th., 2022
let words=seq{use n=System.IO.File.OpenText("words.txt") in while not n.EndOfStream do yield n.ReadLine()}|>Seq.filter(fun n->6<(Seq.length n))|>Seq.map(fun n->n.ToCharArray())|>Set.ofSeq
Line 329:
=={{header|Factor}}==
{{works with|Factor|0.99 2022-04-03}}
<syntaxhighlight lang="factor">USING: assocs grouping hash-sets io.encodings.ascii io.files
kernel math prettyprint sequences sets sets.extras ;
 
Line 358:
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">import qualified Data.Set as S
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
Line 418:
Anyways, the basic approach here is to identify a canonical key for each word, look for paired keys and organize the words based on those keys:
 
<syntaxhighlight lang=J"j">words=: cutLF fread 'words.txt'
canon=: {.@/:~@(,:|.) each words
akeys=: (~. #~ 2 = #/.~) canon
Line 427:
This gives us:
 
<syntaxhighlight lang=J"j"> pairs
┌────────┬────────┐
│amaroid │diorama │
Line 465:
 
=={{header|Julia}}==
<syntaxhighlight lang="ruby">function anadromes(minsize, csense = true, fname = "words.txt")
words = Set(filter(w -> length(w) >= minsize, split((csense ? identity : lowercase)(read(fname, String)), r"\s+")))
found = [(w, reverse(w)) for w in words if (r = reverse(w)) in words && w < r]
Line 530:
 
=={{header|Perl}}==
<syntaxhighlight lang="perl">use strict;
use warnings;
 
Line 561:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">m</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #004600;">JS</span><span style="color: #0000FF;">?</span><span style="color: #000000;">5</span><span style="color: #0000FF;">:</span><span style="color: #000000;">7</span><span style="color: #0000FF;">)</span>
Line 606:
 
=={{header|Raku}}==
<syntaxhighlight lang=perl6"raku" line>my @words = 'words.txt'.IO.slurp.words.grep: *.chars > 6;
 
my %words = @words.pairs.invert;
Line 631:
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">use std::collections::BTreeSet;
use std::fs::File;
use std::io::{self, BufRead};
Line 683:
 
=={{header|Seed7}}==
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const func boolean: binarySearch (in array string: haystack, in string: needle) is func
Line 750:
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var S = Hash()
 
File('words.txt').open_r.each {|word|
Line 785:
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascript">import "io" for File
import "./sort" for Sort, Find
import "./fmt" for Fmt
10,351

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.