Alternade words: Difference between revisions

m
m (Minor edit to Java code)
m (→‎{{header|Wren}}: Minor tidy)
 
(40 intermediate revisions by 28 users not shown)
Line 21:
{{Template:Strings}}
<br><br>
 
=={{header|11l}}==
{{trans|Nim}}
 
<syntaxhighlight lang="11l">F alternating_words(word)
V r = [‘’, ‘’]
L(c) word
r[L.index [&] 1] ‘’= c
R r
 
V words = Set(File(‘unixdict.txt’).read().split("\n"))
 
[String] result
L(word) words
I word.len >= 6
V alt_words = alternating_words(word)
I alt_words[0] C words & alt_words[1] C words
result.append(word.rjust(8)‘ → ’alt_words[0]‘ ’alt_words[1])
result.sort()
L(line) result
V i = L.index
print((‘#2:’.format(i + 1))‘ ’line)</syntaxhighlight>
 
{{out}}
<pre>
1: accost → acs cot
2: accuse → acs cue
3: afield → ail fed
4: agleam → ala gem
5: alcott → act lot
6: allele → all lee
7: allied → ale lid
8: alpert → apr let
9: apport → apr pot
10: assist → ass sit
11: battle → btl ate
12: blaine → ban lie
13: brenda → bed rna
14: choose → cos hoe
15: choosy → cos hoy
16: claire → car lie
17: effete → eft fee
18: fabric → fbi arc
19: fealty → fat ely
20: fluent → fun let
21: friend → fin red
22: george → gog ere
23: inroad → ira nod
24: israel → ire sal
25: jaunty → jut any
26: joanne → jan one
27: lounge → lug one
28: oriole → oil roe
29: oswald → owl sad
30: parrot → pro art
31: peoria → poi era
32: pierre → per ire
33: poodle → pol ode
34: pounce → puc one
35: racial → rca ail
36: realty → rat ely
37: sordid → sri odd
38: sprain → sri pan
39: strain → sri tan
40: strait → sri tat
41: sturdy → sud try
42: sweaty → set way
43: tattle → ttl ate
44: though → tog huh
45: triode → tid roe
46: triune → tin rue
47: troupe → top rue
48: truant → tun rat
49: twirly → til wry
50: ambient → abet min
51: annette → ante net
52: ariadne → aide ran
53: collude → clue old
54: forwent → fret own
55: spatial → sail pta
56: theorem → term hoe
57: throaty → tray hot
58: calliope → clip aloe
</pre>
 
=={{header|Ada}}==
<syntaxhighlight lang="ada">with Ada.Text_Io;
with Ada.Containers.Indefinite_Ordered_Maps;
 
procedure Alternade_Words is
use Ada.Text_Io;
 
package String_Maps is
new Ada.Containers.Indefinite_Ordered_Maps (Key_Type => String,
Element_Type => String);
 
function Get_Odd (Word : String) return String is
Odd : String (1 .. (Word'Length + 1) / 2);
begin
for Index in Odd'Range loop
Odd (Index) := Word (1 + 2 * (Index - 1));
end loop;
return Odd;
end Get_Odd;
 
function Get_Even (Word : String) return String is
Even : String (1 .. Word'Length / 2);
begin
for Index in Even'Range loop
Even (Index) := Word (1 + 1 + 2 * (Index - 1));
end loop;
return Even;
end Get_Even;
 
Filename : constant String := "unixdict.txt";
Words : String_Maps.Map;
File : File_Type;
begin
Open (File, In_File, Filename);
while not End_Of_File (File) loop
declare
Word : constant String := Get_Line (File);
begin
Words.Insert (Word, Word);
end;
end loop;
Close (File);
 
for Word of Words loop
declare
Odd : constant String := Get_Odd (Word);
Even : constant String := Get_Even (Word);
begin
if
Word'Length >= 6 and then
Words.Contains (Odd) and then
Words.Contains (Even)
then
Put (Word);
Set_Col (15); Put (Odd);
Set_Col (25); Put (Even);
New_Line;
end if;
end;
end loop;
end Alternade_Words;</syntaxhighlight>
{{out}}
<pre style="height: 45ex">accost acs cot
accuse acs cue
afield ail fed
agleam ala gem
alcott act lot
allele all lee
allied ale lid
alpert apr let
ambient abet min
annette ante net
apport apr pot
ariadne aide ran
assist ass sit
battle btl ate
blaine ban lie
brenda bed rna
calliope clip aloe
choose cos hoe
choosy cos hoy
claire car lie
collude clue old
effete eft fee
fabric fbi arc
fealty fat ely
fluent fun let
forwent fret own
friend fin red
george gog ere
inroad ira nod
israel ire sal
jaunty jut any
joanne jan one
lounge lug one
oriole oil roe
oswald owl sad
parrot pro art
peoria poi era
pierre per ire
poodle pol ode
pounce puc one
racial rca ail
realty rat ely
sordid sri odd
spatial sail pta
sprain sri pan
strain sri tan
strait sri tat
sturdy sud try
sweaty set way
tattle ttl ate
theorem term hoe
though tog huh
throaty tray hot
triode tid roe
triune tin rue
troupe top rue
truant tun rat
twirly til wry</pre>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
<langsyntaxhighlight lang="algol68"># find alternade words in a list of words #
# use the associative array in the Associate array/iteration task #
PR read "aArray.a68" PR
Line 93 ⟶ 298:
OD
FI
</syntaxhighlight>
</lang>
{{out}}
Note - the alternade words as output by this program are not sorted, the output shown here has been sorted for ease of comparison with the output of the other samples.
Line 160 ⟶ 365:
{{works with|Dyalog APL}}
 
<langsyntaxhighlight APLlang="apl">alternade←{
⍺←6
parts←{(⊂k/⍵),⊂(~k←2|⍳≢⍵)/⍵}
Line 166 ⟶ 371:
long←(⍺≤≢¨words)/words
↑(⊂,parts)¨(∧/∘check∘parts¨long)/long
}</langsyntaxhighlight>
 
{{out}}
Line 232 ⟶ 437:
=={{header|AppleScript}}==
 
<syntaxhighlight lang="applescript">use AppleScript version "2.3.1" -- OS X 10.9 (Mavericks) or later
<lang applescript>(*
use sorter : script ¬
Now takes the number of subwords per alternade as a parameter.
"Custom Iterative Ternary Merge Sort" --<www.macscripter.net/t/timsort-and-nigsort/71383/3>
Extracted texts are validated against the words in the input list.
*)
 
use AppleScript version "2.3.1" -- OS X 10.9 (Mavericks) or later
use sorter : script "Custom Iterative Ternary Merge Sort" --<https://macscripter.net/viewtopic.php?pid=194430#p194430>
use scripting additions
 
on binarySearch(v, theList, l, r)
on alternades(inputList, subwordsPerAlternade, minAlternadeLength, outputType)
script o
-- Script object through which to reference potentially long lists for speed.
property lst : theList
-- Also contains a by-length comparison handler for the custom sort and a finishing-off handler for the final output.
end script
repeat until (l = r)
set m to (l + r) div 2
if (o's lst's item m < v) then
set l to m + 1
else
set r to m
end if
end repeat
if (o's lst's item l = v) then return l
return 0
end binarySearch
 
on join(lst, delim)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
set txt to lst as text
set AppleScript's text item delimiters to astid
return txt
end join
 
on alternades(inputList, subsPerAlternade, minAlternadeLen, outputType)
script o
property wordList : inputList's items
property validSubwordssearchRanges : {}
property output : {}
-- Custom comparison handler for the sort.
on isGreater(a, b)
returnset (a'slenA lengthto > ba's length)
set lenB to b's length
if (lenA = lenB) then return (a > b)
return (lenA > lenB)
end isGreater
on finish()
if (outputType is text) then set output to join(output, linefeed)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set output to output as text
set AppleScript's text item delimiters to astid
end if
return output
end finish
end script
(* Check the input and marshal it for a less slow search. *)
set wordCount to (count o's wordList)
if (wordCount < subwordsPerAlternadesubsPerAlternade) then return o's finish()
-- Sort the wordsword list ascending by length, lexically within lengths.
tell sorter to sort(o's wordList, 1, wordCount, {comparer:o})
-- GetDeduce the lengthmaximum ofpossible the"subword" longestlength and deducefrom the maximum possible length of athe subwordlongest word.
set maxWordLengthmaxWordLen to lengtho's ofwordList's end of o's wordListlength
if (maxWordLengthmaxWordLen < minAlternadeLengthminAlternadeLen) then return o's finish()
set maxSubLen to (maxWordLen + subsPerAlternade - 1) div subsPerAlternade
set characterInterval to subwordsPerAlternade
-- Give the searchRanges list that many slots.
set maxSubwordLength to (maxWordLength + characterInterval - 1) div characterInterval
repeat maxSubLen times
-- Build a list containing maxSubwordLength lists.
set end of o's searchRanges to missing value
repeat maxSubwordLength times
set end of o's validSubwords to {}
end repeat
-- PopulateFor theeach relevantword listslength soin wordlist that's asuitable listfor witha indexsubword, n contains allset the input words withsame-numbered nslot characters.in
-- AlsosearchRanges findto the wordListrange indexindices at whichof the firstwordList wordrange withcovering minAlternadeLengththe orwords moreof charactersthat occurslength.
-- Also find the index in wordList of the first word whose length ≥ minAlternadeLen.
set minSubwordLength to minAlternadeLength div characterInterval
set startIndexminSubLen to missingminAlternadeLen valuediv subsPerAlternade
set minAltLenStart to 1
repeat with w from 1 to wordCount
set thisWordi to item w of o's wordList1
set currentLength to o's set wordLength towordList's thisWordbeginning's length
repeat with j from 2 to wordCount
if (wordLength ≥ minSubwordLength) then
set wordLen to o's wordList's item j's length
if (wordLength ≤ maxSubwordLength) then
if (wordLen > currentLength) then
set end of item wordLength of o's validSubwords to thisWord
if ((wordLengthcurrentLengthminAlternadeLengthminSubLen) and (startIndexcurrentLength is missing valuemaxSubLen)) then set startIndex to w
set o's searchRanges's item currentLength to {i, j - 1}
else if (wordLength ≥ minAlternadeLength) then
if (startIndexwordLen is missing valueminAlternadeLen) then set startIndex to w
exit repeat if (minAltLenStart = 1) then
set minAltLenStart to j
else if (wordLen > maxSubLen) then
exit repeat
end if
end if
end if
set i to j
set currentLength to wordLen
end if
end repeat
(*-- Extract "subwords"subtexts from those words whichhaving have minAlternadeLengthminAlternadeLen or more characters and checksee if themthey againstmatch
-- words from the wordssame-length ranges in validSubwords,wordList. appendingAppend any hit infohits to the output in either text or the default record form. *)
if (outputType is text) then set end of o's output to ""
set astid to AppleScript's text item delimiters
repeat with w from minAltLenStart to wordCount -- Per long-enough word.
set AppleScript's text item delimiters to {tab & tab}
set thisWord to o's wordList's item w
repeat with w from startIndex to wordCount -- Per long-enough word in wordList
set thisWordwordLen to item w of othisWord's wordListlength
set wordLengthfoundSubs to thisWord's length{}
setrepeat foundSubwordswith s from 1 to {}subsPerAlternade -- Per subword.
set sub to thisWord's character s
repeat with s from 1 to subwordsPerAlternade -- Per subword extracted from it.
repeat with c from (s + subsPerAlternade) to wordLen by subsPerAlternade -- Per chr.
set thisSubword to character s of thisWord
repeat with c from (sset + characterInterval)sub to wordLengthsub by& characterInterval -- PerthisWord's character involved.c
set thisSubword to thisSubword & character c of thisWord
end repeat
ifset (itemrange (thisSubwordto o's length)searchRanges's ofitem o(sub's validSubwords contains thisSubwordlength) then
if ((range = missing setvalue) endor of foundSubwords to thisSubword¬
(binarySearch(sub, o's wordList, range's beginning, range's end) = 0)) then ¬
else
exit repeat
set end ifof foundSubs to sub
end repeat
if ((count foundSubwordsfoundSubs) = subwordsPerAlternadesubsPerAlternade) then
if (outputType is text) then
set beginning of foundSubwordsfoundSubs to thisWord & ":"
set end of o's output to foundSubwordsjoin(foundSubs, astab text& tab)
else
set end of o's output to {alternade:thisWord, subwordssubs:foundSubwordsfoundSubs}
end if
end if
end repeat
set AppleScript's text item delimiters to astid
return o's finish()
Line 331 ⟶ 557:
-- Task code:
local wordFile, wordList
set wordFile to ((path to desktop as text) & "www.rosettacode.org:unixdict.txt") as «class furl»
set wordList to words of (read wordFile as «class utf8»)
-- Return two-word alternades of 6 or more characters. Result inas text form(as opposed to list).
return alternades(wordList, 2, 6, text)</langsyntaxhighlight>
 
{{output}}
<syntaxhighlight lang="applescript">"
<pre>accost: acs cot
accost: acs cot
accuse: acs cue
accuse: acs cue
afield: ail fed
afield: ail fed
agleam: ala gem
agleam: ala gem
alcott: act lot
alcott: act lot
allele: all lee
allele: all lee
allied: ale lid
allied: ale lid
alpert: apr let
alpert: apr let
apport: apr pot
apport: apr pot
assist: ass sit
assist: ass sit
battle: btl ate
battle: btl ate
blaine: ban lie
blaine: ban lie
brenda: bed rna
brenda: bed rna
choose: cos hoe
choose: cos hoe
choosy: cos hoy
choosy: cos hoy
claire: car lie
claire: car lie
effete: eft fee
effete: eft fee
fabric: fbi arc
fabric: fbi arc
fealty: fat ely
fealty: fat ely
fluent: fun let
fluent: fun let
friend: fin red
friend: fin red
george: gog ere
george: gog ere
inroad: ira nod
inroad: ira nod
israel: ire sal
israel: ire sal
jaunty: jut any
jaunty: jut any
joanne: jan one
joanne: jan one
lounge: lug one
lounge: lug one
oriole: oil roe
oriole: oil roe
oswald: owl sad
oswald: owl sad
parrot: pro art
parrot: pro art
peoria: poi era
peoria: poi era
pierre: per ire
pierre: per ire
poodle: pol ode
poodle: pol ode
pounce: puc one
pounce: puc one
racial: rca ail
racial: rca ail
realty: rat ely
realty: rat ely
sordid: sri odd
sordid: sri odd
sprain: sri pan
sprain: sri pan
strain: sri tan
strain: sri tan
strait: sri tat
strait: sri tat
sturdy: sud try
sturdy: sud try
sweaty: set way
sweaty: set way
tattle: ttl ate
tattle: ttl ate
though: tog huh
though: tog huh
triode: tid roe
triode: tid roe
triune: tin rue
triune: tin rue
troupe: top rue
troupe: top rue
truant: tun rat
truant: tun rat
twirly: til wry
twirly: til wry
ambient: abet min
ambient: abet min
annette: ante net
annette: ante net
ariadne: aide ran
ariadne: aide ran
collude: clue old
collude: clue old
forwent: fret own
forwent: fret own
spatial: sail pta
spatial: sail pta
theorem: term hoe
theorem: term hoe
throaty: tray hot
throaty: tray hot
calliope: clip aloe</pre>
calliope: clip aloe"</syntaxhighlight>
 
=={{header|Arturo}}==
Another example call:
<syntaxhighlight lang="rebol">words: map read.lines relative "unixdict.txt" => strip
 
loop words 'word [
<lang applescript>-- Return three-word alternades of 10 or more characters. Result as a list of records.
sw: new size word
return alternades(wordList, 3, 10, list)</lang>
if 6 > sw ->
continue
 
dec 'sw
 
alt1: join map select 0..sw => odd? 'x -> word\[x]
alt2: join map select 0..sw => even? 'x -> word\[x]
 
if and? [contains? words alt1][contains? words alt2] ->
print [word "=>" alt1 alt2]
]</syntaxhighlight>
 
{{out}}
 
<pre>accost => cot acs
accuse => cue acs
afield => fed ail
agleam => gem ala
alcott => lot act
allele => lee all
allied => lid ale
alpert => let apr
ambient => min abet
annette => net ante
apport => pot apr
ariadne => ran aide
assist => sit ass
battle => ate btl
blaine => lie ban
brenda => rna bed
calliope => aloe clip
choose => hoe cos
choosy => hoy cos
claire => lie car
collude => old clue
effete => fee eft
fabric => arc fbi
fealty => ely fat
fluent => let fun
forwent => own fret
friend => red fin
george => ere gog
inroad => nod ira
israel => sal ire
jaunty => any jut
joanne => one jan
lounge => one lug
oriole => roe oil
oswald => sad owl
parrot => art pro
peoria => era poi
pierre => ire per
poodle => ode pol
pounce => one puc
racial => ail rca
realty => ely rat
sordid => odd sri
spatial => pta sail
sprain => pan sri
strain => tan sri
strait => tat sri
sturdy => try sud
sweaty => way set
tattle => ate ttl
theorem => hoe term
though => huh tog
throaty => hot tray
triode => roe tid
triune => rue tin
troupe => rue top
truant => rat tun
twirly => wry til</pre>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">FileRead, db, % A_Desktop "\unixdict.txt"
words := [], sixWords := []
 
for i, w in StrSplit(db, "`n", "`r")
if (StrLen(w) >= 6)
sixWords[w] := true
else
Words[w] := true
 
for w in sixWords
{
w1 := w2 := ""
for j, letter in StrSplit(w)
if Mod(j, 2)
w1 .= letter
else
w2 .= letter
 
if words[w1] && words[w2]
result .= w "`t-> " w1 " " w2 "`n"
}
MsgBox % result</syntaxhighlight>
{{out}}
<pre style="height: 45ex">accost -> acs cot
accuse -> acs cue
afield -> ail fed
agleam -> ala gem
alcott -> act lot
allele -> all lee
allied -> ale lid
alpert -> apr let
ambient -> abet min
annette -> ante net
apport -> apr pot
ariadne -> aide ran
assist -> ass sit
battle -> btl ate
blaine -> ban lie
brenda -> bed rna
calliope -> clip aloe
choose -> cos hoe
choosy -> cos hoy
claire -> car lie
collude -> clue old
effete -> eft fee
fabric -> fbi arc
fealty -> fat ely
fluent -> fun let
forwent -> fret own
friend -> fin red
george -> gog ere
inroad -> ira nod
israel -> ire sal
jaunty -> jut any
joanne -> jan one
lounge -> lug one
oriole -> oil roe
oswald -> owl sad
parrot -> pro art
peoria -> poi era
pierre -> per ire
poodle -> pol ode
pounce -> puc one
racial -> rca ail
realty -> rat ely
sordid -> sri odd
spatial -> sail pta
sprain -> sri pan
strain -> sri tan
strait -> sri tat
sturdy -> sud try
sweaty -> set way
tattle -> ttl ate
theorem -> term hoe
though -> tog huh
throaty -> tray hot
triode -> tid roe
triune -> tin rue
troupe -> top rue
truant -> tun rat
twirly -> til wry</pre>
 
{{output}}
<lang applescript>{{alternade:"benevolent", subwords:{"belt", "eve", "non"}}, {alternade:"rejuvenate", subwords:{"rune", "eva", "jet"}}}</lang>
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f ALTERNADE_WORDS.AWK unixdict.txt
#
Line 434 ⟶ 815:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 499 ⟶ 880:
=={{header|C}}==
 
<langsyntaxhighlight Clang="c">#include <stdio.h>
#include <string.h>
#include <stdlib.h>
Line 632 ⟶ 1,013:
scan_trie(root, check_alternade);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 697 ⟶ 1,078:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <cstdlib>
#include <fstream>
#include <iomanip>
Line 733 ⟶ 1,114:
}
return EXIT_SUCCESS;
}</langsyntaxhighlight>
 
{{out}}
Line 796 ⟶ 1,177:
twirly til wry
</pre>
 
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|Classes,StdCtrls,SysUtils}}
 
Delphi-style problem solving, using standard Delphi
controls like the TStringList, which greatly simplifies
the solution.
 
<syntaxhighlight lang="Delphi">
unit Alternade;
 
interface
 
uses Classes,StdCtrls,SysUtils;
 
procedure FindAlternadeWords(Memo: TMemo);
 
implementation
 
var Dict: TStringList; {List holds dictionary}
 
function GetAlts(S: string; var Alt1,Alt2: string): boolean;
{Grab Alternades from string and test if they are valid }
var I: integer;
begin
Alt1:='';
Alt2:='';
{Copy every other letter into different string}
for I:=1 to Length(S) do
if (I mod 2)=0 then Alt2:=Alt2+S[I]
else Alt1:=Alt1+S[I];
{Check if the two strings are in the dictionary}
Result:=(Dict.IndexOf(Alt1)>=0) and (Dict.IndexOf(Alt2)>=0);
end;
 
procedure FindAlternadeWords(Memo: TMemo);
{test all words in the dictionary}
{And diplays the Alternade words in the Memo}
var I,Cnt: integer;
var Alt1,Alt2: string;
begin
Cnt:=0;
for I:=0 to Dict.Count-1 do
if (Length(Dict[I])>=6) and GetAlts(Dict[I], Alt1, Alt2) then
begin
Inc(Cnt);
Memo.Lines.Add(IntToStr(Cnt)+': '+Dict[I]+' '+Alt1+' '+Alt2);
end
end;
 
 
initialization
{Create/load dictionary}
Dict:=TStringList.Create;
Dict.LoadFromFile('unixdict.txt');
Dict.Sorted:=True;
finalization
Dict.Free;
end.
 
</syntaxhighlight>
 
{{out}}
<pre>
1: accost acs cot
2: accuse acs cue
3: afield ail fed
4: agleam ala gem
5: alcott act lot
6: allele all lee
7: allied ale lid
8: alpert apr let
9: ambient abet min
10: annette ante net
11: apport apr pot
12: ariadne aide ran
13: assist ass sit
14: battle btl ate
15: blaine ban lie
16: brenda bed rna
17: calliope clip aloe
18: choose cos hoe
19: choosy cos hoy
20: claire car lie
21: collude clue old
22: effete eft fee
23: fabric fbi arc
24: fealty fat ely
25: fluent fun let
26: forwent fret own
27: friend fin red
28: george gog ere
29: inroad ira nod
30: israel ire sal
31: jaunty jut any
32: joanne jan one
33: lounge lug one
34: oriole oil roe
35: oswald owl sad
36: parrot pro art
37: peoria poi era
38: pierre per ire
39: poodle pol ode
40: pounce puc one
41: racial rca ail
42: realty rat ely
43: sordid sri odd
44: spatial sail pta
45: sprain sri pan
46: strain sri tan
47: strait sri tat
48: sturdy sud try
49: sweaty set way
50: tattle ttl ate
51: theorem term hoe
52: though tog huh
53: throaty tray hot
54: triode tid roe
55: triune tin rue
56: troupe top rue
57: truant tun rat
58: twirly til wry
 
</pre>
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// Alternade words: Nigel Galloway. June 10th., 2021
let dict=seq{use n=System.IO.File.OpenText("unixdict.txt") in while not n.EndOfStream do yield n.ReadLine()}|>Seq.filter(fun n->n.Length>2)|>List.ofSeq
let fN g=let n=Seq.foldBack2(fun n g (z:char list [])->z.[g]<-n::z.[g]; z) g (let rec fN()=seq{yield![0;1]; yield! fN()} in fN())([|[];[]|]) in (n.[0],n.[1])
let fG(n,g)=let fN g=(Array.ofList>>System.String) g in let n,g=fN n,fN g in if List.contains n dict && List.contains g dict then Some(n,g) else None
dict|>Seq.filter(fun n->n.Length>5)|>Seq.iter(fun n->match (fN>>fG) n with Some(g,l)->printfn "%s -> %s * %s" n g l |_->())
</syntaxhighlight>
{{out}}
<pre>
accost -> acs * cot
accuse -> acs * cue
afield -> ail * fed
agleam -> ala * gem
alcott -> act * lot
allele -> all * lee
allied -> ale * lid
alpert -> apr * let
ambient -> abet * min
annette -> ante * net
apport -> apr * pot
ariadne -> aide * ran
assist -> ass * sit
battle -> btl * ate
blaine -> ban * lie
brenda -> bed * rna
calliope -> clip * aloe
choose -> cos * hoe
choosy -> cos * hoy
claire -> car * lie
collude -> clue * old
effete -> eft * fee
fabric -> fbi * arc
fealty -> fat * ely
fluent -> fun * let
forwent -> fret * own
friend -> fin * red
george -> gog * ere
inroad -> ira * nod
israel -> ire * sal
jaunty -> jut * any
joanne -> jan * one
lounge -> lug * one
oriole -> oil * roe
oswald -> owl * sad
parrot -> pro * art
peoria -> poi * era
pierre -> per * ire
poodle -> pol * ode
pounce -> puc * one
racial -> rca * ail
realty -> rat * ely
sordid -> sri * odd
spatial -> sail * pta
sprain -> sri * pan
strain -> sri * tan
strait -> sri * tat
sturdy -> sud * try
sweaty -> set * way
tattle -> ttl * ate
theorem -> term * hoe
though -> tog * huh
throaty -> tray * hot
triode -> tid * roe
triune -> tin * rue
troupe -> top * rue
truant -> tun * rat
twirly -> til * wry
</pre>
 
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: formatting io.encodings.ascii io.files kernel literals
math sequences sequences.extras sets strings ;
 
Line 815 ⟶ 1,393:
[ alternade? ] filter
[ length 5 > ] filter
[ dup subwords "%-8s %-4s %-4s\n" printf ] each</langsyntaxhighlight>
{{out}}
<pre style="height: 45ex">
Line 876 ⟶ 1,454:
truant tun rat
twirly til wry
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">#define DLEN 25104
 
function is_in(word() as string, s as string) as boolean
for i as uinteger = 1 to DLEN
if word(i)=s then return true
next i
return false
end function
 
dim as string word(1 to DLEN), alt(0 to 1)
dim as integer i, j
open "unixdict.txt" for input as #1
while not eof(1)
i+=1
line input #1, word(i)
wend
close #1
 
for i = 1 to DLEN
if len(word(i))<6 then continue for
alt(0) = ""
alt(1) = ""
for j = 1 to len(word(i))
alt(j mod 2) += mid(word(i),j, 1)
next j
if is_in(word(), alt(0)) and is_in(word(), alt(1)) then print word(i), alt(1), alt(0)
next i</syntaxhighlight>
{{out}}<pre>
accost acs cot
accuse acs cue
afield ail fed
agleam ala gem
alcott act lot
allele all lee
allied ale lid
alpert apr let
ambient abet min
annette ante net
apport apr pot
ariadne aide ran
assist ass sit
battle btl ate
blaine ban lie
brenda bed rna
calliope clip aloe
choose cos hoe
choosy cos hoy
claire car lie
collude clue old
effete eft fee
fabric fbi arc
fealty fat ely
fluent fun let
forwent fret own
friend fin red
george gog ere
inroad ira nod
israel ire sal
jaunty jut any
joanne jan one
lounge lug one
oriole oil roe
oswald owl sad
parrot pro art
peoria poi era
pierre per ire
poodle pol ode
pounce puc one
racial rca ail
realty rat ely
sordid sri odd
spatial sail pta
sprain sri pan
strain sri tan
strait sri tat
sturdy sud try
sweaty set way
tattle ttl ate
theorem term hoe
though tog huh
throaty tray hot
triode tid roe
triune tin rue
troupe top rue
truant tun rat
twirly til wry
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
 
#plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES}
 
local fn Words as CFArrayRef
CFURLRef url = fn URLWithString( @"https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt" )
CFStringRef string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
end fn = fn StringComponentsSeparatedByCharactersInSet( string, fn CharacterSetNewlineSet )
 
void local fn DoIt
text,,,,, 80
dispatchglobal
CFArrayRef words = fn Words
CFStringRef wd, wd1, wd2
long length, i
for wd in words
length = len(wd)
if ( length >= 6 )
wd1 = @"" : wd2 = @""
for i = 0 to length-1
if ( i mod 2 == 0 )
wd1 = fn StringByAppendingString( wd1, mid(wd,i,1) )
else
wd2 = fn StringByAppendingString( wd2, mid(wd,i,1) )
end if
next
if ( fn ArrayContainsObject( words, wd1 ) and fn ArrayContainsObject( words, wd2 ) )
dispatchmain
print wd,wd1,wd2
dispatchend
end if
end if
next
dispatchend
end fn
 
fn DoIt
 
HandleEvents
</syntaxhighlight>
 
{{out}}
<pre style="height:30ex">
accost acs cot
accuse acs cue
afield ail fed
agleam ala gem
alcott act lot
allele all lee
allied ale lid
alpert apr let
ambient abet min
annette ante net
apport apr pot
ariadne aide ran
assist ass sit
battle btl ate
blaine ban lie
brenda bed rna
calliope clip aloe
choose cos hoe
choosy cos hoy
claire car lie
collude clue old
effete eft fee
fabric fbi arc
fealty fat ely
fluent fun let
forwent fret own
friend fin red
george gog ere
inroad ira nod
israel ire sal
jaunty jut any
joanne jan one
lounge lug one
oriole oil roe
oswald owl sad
parrot pro art
peoria poi era
pierre per ire
poodle pol ode
pounce puc one
racial rca ail
realty rat ely
sordid sri odd
spatial sail pta
sprain sri pan
strain sri tan
strait sri tat
sturdy sud try
sweaty set way
tattle ttl ate
theorem term hoe
though tog huh
throaty tray hot
triode tid roe
triune tin rue
troupe top rue
truant tun rat
twirly til wry
</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 924 ⟶ 1,695:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 989 ⟶ 1,760:
58: twirly -> til wry
</pre>
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">import qualified Data.Set as S
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
 
-- Two words constructed from the alternating characters of a single word.
alt :: T.Text -> (T.Text, T.Text)
alt = T.foldl' (\(l, r) c -> (r `T.snoc` c, l)) (T.empty, T.empty)
 
-- The alternades of a list of words.
alternades :: S.Set T.Text -> [T.Text] -> [(T.Text, (T.Text, T.Text))]
alternades dict ws = filter (areMembers . snd) $ zip ws $ map alt ws
where areMembers (x, y) = S.member x dict && S.member y dict
 
main :: IO ()
main = TIO.interact $ \txt ->
let words' = map T.toLower $ T.lines txt
dict = S.fromList words'
in T.unlines $ map alterShow $ alternades dict $ filter longEnough words'
where longEnough = (>= 6) . T.length
alterShow (w, (x, y)) = T.unwords [w, x, y]</syntaxhighlight>
{{out}}
<pre>
$ alternade < unixdict.txt
accost cot acs
accuse cue acs
afield fed ail
agleam gem ala
alcott lot act
allele lee all
allied lid ale
alpert let apr
ambient abet min
annette ante net
apport pot apr
ariadne aide ran
assist sit ass
battle ate btl
blaine lie ban
brenda rna bed
calliope aloe clip
choose hoe cos
choosy hoy cos
claire lie car
collude clue old
effete fee eft
fabric arc fbi
fealty ely fat
fluent let fun
forwent fret own
friend red fin
george ere gog
inroad nod ira
israel sal ire
jaunty any jut
joanne one jan
lounge one lug
oriole roe oil
oswald sad owl
parrot art pro
peoria era poi
pierre ire per
poodle ode pol
pounce one puc
racial ail rca
realty ely rat
sordid odd sri
spatial sail pta
sprain pan sri
strain tan sri
strait tat sri
sturdy try sud
sweaty way set
tattle ate ttl
theorem term hoe
though huh tog
throaty tray hot
triode roe tid
triune rue tin
troupe rue top
truant rat tun
twirly wry til
</pre>
 
=={{header|J}}==
 
<syntaxhighlight lang="j"> words=: cutLF fread 'unixdict.txt'
alts=: <@deb"1@|:@(_2]\])@> ref=: (#~ 5<#@>) words
;:inv (ref,.alts) #~ alts */@e."1 words
accost acs cot
accuse acs cue
afield ail fed
agleam ala gem
alcott act lot
allele all lee
allied ale lid
alpert apr let
ambient abet min
annette ante net
apport apr pot
ariadne aide ran
assist ass sit
battle btl ate
blaine ban lie
brenda bed rna
calliope clip aloe
choose cos hoe
choosy cos hoy
claire car lie
collude clue old
effete eft fee
fabric fbi arc
fealty fat ely
fluent fun let
forwent fret own
friend fin red
george gog ere
inroad ira nod
israel ire sal
jaunty jut any
joanne jan one
lounge lug one
oriole oil roe
oswald owl sad
parrot pro art
peoria poi era
pierre per ire
poodle pol ode
pounce puc one
racial rca ail
realty rat ely
sordid sri odd
spatial sail pta
sprain sri pan
strain sri tan
strait sri tat
sturdy sud try
sweaty set way
tattle ttl ate
theorem term hoe
though tog huh
throaty tray hot
triode tid roe
triune tin rue
troupe top rue
truant tun rat
twirly til wry</syntaxhighlight>
 
=={{header|Java}}==
The 'userdict.txt' file is great, except it contains entries like 'mrs' and '1st'.<br />
<lang java>import java.io.*;
Testing a word for at least one vowel, and 'a-z' is necessary for this task.
import java.util.*;
<syntaxhighlight lang="java">
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Set;
import java.util.TreeSet;
 
public class AlternadeWords {
public static void main(Stringchar[] argsvowels = "aeiouy".toCharArray() {;
static String try {alphabet;
 
Set<String> dictionary = new TreeSet<>();
static {
try (BufferedReader reader = new BufferedReader(new FileReader("unixdict.txt"))) {
alphabet = String line"";
for (int index = 0; index < 26; while ((line = reader.readLine()) != nullindex++)
alphabet += (char) (index + dictionary.add(line'a');
}
 
StringBuilder word1 = new StringBuilder();
boolean alphabetic(String string) {
StringBuilder word2 = new StringBuilder();
for (Stringchar wordcharacter : dictionarystring.toCharArray()) {
if int length = word(!alphabet.lengthcontains(String.valueOf(character)));
ifreturn (length < 6)false;
}
return true;
}
 
boolean containsVowel(String string) {
for (char vowel : vowels) {
if (string.contains(String.valueOf(vowel)))
return true;
}
return false;
}
 
void alternateWords() throws IOException {
Set<String> dictionary = new TreeSet<>();
try (BufferedReader reader = new BufferedReader(new FileReader("unixdict.txt"))) {
String line;
while ((line = reader.readLine()) != null) {
if (!alphabetic(line) || !containsVowel(line))
continue;
word1dictionary.setLengthadd(0line);
word2.setLength(0);
for (int i = 0; i < length; i += 2) {
word1.append(word.charAt(i));
if (i + 1 < length)
word2.append(word.charAt(i + 1));
}
String w1 = word1.toString();
String w2 = word2.toString();
if (dictionary.contains(w1) && dictionary.contains(w2))
System.out.printf("%-10s%-6s%s\n", word, w1, w2);
}
} catch (Exception e) {
StringBuilder wordA = new e.printStackTraceStringBuilder();
StringBuilder wordB = new StringBuilder();
for (String word : dictionary) {
int length = word.length();
if (length < 6)
continue;
wordA.setLength(0);
wordB.setLength(0);
for (int index = 0; index < length; index += 2) {
wordA.append(word.charAt(index));
if (index + 1 < length)
wordB.append(word.charAt(index + 1));
}
if (dictionary.contains(wordA.toString()))
if (dictionary.contains(wordB.toString()))
System.out.printf("%-15s%5s %s%n", word, wordA, wordB);
}
}
}
}</lang>
</syntaxhighlight>
<pre>
accost acs cot
accuse acs cue
afield ail fed
agleam ala gem
alcott act lot
allele all lee
allied ale lid
alpert apr let
ambient abet min
annette ante net
apport apr pot
ariadne aide ran
assist ass sit
blaine ban lie
brenda bed rna
calliope clip aloe
choose cos hoe
choosy cos hoy
claire car lie
collude clue old
effete eft fee
fabric fbi arc
fealty fat ely
fluent fun let
forwent fret own
friend fin red
george gog ere
inroad ira nod
israel ire sal
jaunty jut any
joanne jan one
lounge lug one
oriole oil roe
oswald owl sad
parrot pro art
peoria poi era
pierre per ire
poodle pol ode
pounce puc one
racial rca ail
realty rat ely
sordid sri odd
spatial sail pta
sprain sri pan
strain sri tan
strait sri tat
sturdy sud try
sweaty set way
theorem term hoe
though tog huh
throaty tray hot
triode tid roe
triune tin rue
troupe top rue
truant tun rat
twirly til wry
</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
Note: For gojq, change `keys_unsorted` to `keys`. The results are unaffected.
<syntaxhighlight lang="jq">
# if the input is an alternade word relative to the keys of $dict,
# then emit [$even, $odd], else false.
def is_alternade($dict):
def seconds($start): [.[range($start;length;2)]];
explode
| [seconds(0,1)] | map(implode)
| if $dict[.[0]] and $dict[.[1]] then . else false end;
 
INDEX( inputs; . )
| . as $dict
| keys_unsorted[]
| select(length>5)
| . as $w
| is_alternade($dict)
| (select(.) // empty)
| "\($w) → \(.[0]) \(.[1])"
</syntaxhighlight>
Invocation: jq -n -rR -f alternade-words.jq unixdict.txt
{{out}}
<pre>
<pre style="height: 45ex">
accost acs cot
accuse acs cue
afield ail fed
agleam ala gem
alcott act lot
allele all lee
allied ale lid
alpert apr let
ambient abet min
annette ante net
apport apr pot
ariadne aide ran
assist ass sit
battle btl ate
blaine ban lie
brenda bed rna
calliope clip aloe
choose cos hoe
choosy cos hoy
claire car lie
collude clue old
effete eft fee
fabric fbi arc
fealty fat ely
fluent fun let
forwent fret own
friend fin red
george gog ere
inroad ira nod
israel ire sal
jaunty jut any
joanne jan one
lounge lug one
oriole oil roe
oswald owl sad
parrot pro art
peoria poi era
pierre per ire
poodle pol ode
pounce puc one
racial rca ail
realty rat ely
sordid sri odd
spatial sail pta
sprain sri pan
strain sri tan
strait sri tat
sturdy sud try
sweaty set way
tattle ttl ate
theorem term hoe
though tog huh
throaty tray hot
triode tid roe
triune tin rue
troupe top rue
truant tun rat
twirly til wry
</pre>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">function foreachword(wordfile::String, condition::Function; minlen = 0, colwidth = 15, numcols = 6, toshow = 0)
println("Word source: $wordfile\n")
words = split(read(wordfile, String), r"\s+")
Line 1,110 ⟶ 2,141:
foreachword("unixdict.txt", isalternade, minlen = 6, numcols=1)
 
</langsyntaxhighlight>{{out}}
<pre>
Word source: unixdict.txt
Line 1,172 ⟶ 2,203:
truant : tun, rat
twirly : til, wry
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">dic = Once[Import["https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt"]];
dic = StringSplit[dic, "\n"];
largerthansix = Select[dic, StringLength /* GreaterEqualThan[6]];
smallerthansix = Select[dic, StringLength /* LessEqualThan[5]];
ClearAll[AlternadeQ]
AlternadeQ[w_String, words_List] := Module[{chars, ws, c1, c2},
chars = Characters[w];
c1 = StringJoin@chars[[1 ;; ;; 2]];
c2 = StringJoin@chars[[2 ;; ;; 2]];
If[MemberQ[words, c1] \[And] MemberQ[words, c2], w -> {c1, c2}, {}]
]
all = DeleteCases[Table[AlternadeQ[w, smallerthansix], {w, largerthansix}], {}];
all // Column</syntaxhighlight>
{{out}}
<pre>accost->{acs,cot}
accuse->{acs,cue}
afield->{ail,fed}
agleam->{ala,gem}
alcott->{act,lot}
allele->{all,lee}
allied->{ale,lid}
alpert->{apr,let}
ambient->{abet,min}
annette->{ante,net}
apport->{apr,pot}
ariadne->{aide,ran}
assist->{ass,sit}
battle->{btl,ate}
blaine->{ban,lie}
brenda->{bed,rna}
calliope->{clip,aloe}
choose->{cos,hoe}
choosy->{cos,hoy}
claire->{car,lie}
collude->{clue,old}
effete->{eft,fee}
fabric->{fbi,arc}
fealty->{fat,ely}
fluent->{fun,let}
forwent->{fret,own}
friend->{fin,red}
george->{gog,ere}
inroad->{ira,nod}
israel->{ire,sal}
jaunty->{jut,any}
joanne->{jan,one}
lounge->{lug,one}
oriole->{oil,roe}
oswald->{owl,sad}
parrot->{pro,art}
peoria->{poi,era}
pierre->{per,ire}
poodle->{pol,ode}
pounce->{puc,one}
racial->{rca,ail}
realty->{rat,ely}
sordid->{sri,odd}
spatial->{sail,pta}
sprain->{sri,pan}
strain->{sri,tan}
strait->{sri,tat}
sturdy->{sud,try}
sweaty->{set,way}
tattle->{ttl,ate}
theorem->{term,hoe}
though->{tog,huh}
throaty->{tray,hot}
triode->{tid,roe}
triune->{tin,rue}
troupe->{top,rue}
truant->{tun,rat}
twirly->{til,wry}</pre>
 
=={{header|MiniScript}}==
This implementation is for use with the [http://miniscript.org/MiniMicro Mini Micro] version of MiniScript. The command-line version does not include a HTTP library. Modify the declaration of wordList object to use the file class to read a local copy of the word list file.
<syntaxhighlight lang="miniscript">
alternateLetters = function(word, ix)
if ix != 0 then ix = 1
altWord = ""
for i in range(ix, word.len - 1, 2)
altWord += word[i]
end for
return altWord
end function
 
wordList = http.get("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt").split(char(10))
ctr = 0
for word in wordList
if word.len > 5 then
word1 = alternateLetters(word, 0)
word2 = alternateLetters(word, 1)
if wordList.indexOf(word1) != null and wordList.indexOf(word2) != null then
ctr += 1
print [ctr, word, char(18), word1, word2].join(" ")
end if
end if
end for
</syntaxhighlight>
{{out}}
<pre>
1 accost : acs cot
2 accuse : acs cue
3 afield : ail fed
4 agleam : ala gem
5 alcott : act lot
6 allele : all lee
7 allied : ale lid
8 alpert : apr let
9 ambient : abet min
10 annette : ante net
11 apport : apr pot
12 ariadne : aide ran
13 assist : ass sit
14 battle : btl ate
15 blaine : ban lie
16 brenda : bed rna
17 calliope : clip aloe
18 choose : cos hoe
19 choosy : cos hoy
20 claire : car lie
21 collude : clue old
22 effete : eft fee
23 fabric : fbi arc
24 fealty : fat ely
25 fluent : fun let
26 forwent : fret own
27 friend : fin red
28 george : gog ere
29 inroad : ira nod
30 israel : ire sal
31 jaunty : jut any
32 joanne : jan one
33 lounge : lug one
34 oriole : oil roe
35 oswald : owl sad
36 parrot : pro art
37 peoria : poi era
38 pierre : per ire
39 poodle : pol ode
40 pounce : puc one
41 racial : rca ail
42 realty : rat ely
43 sordid : sri odd
44 spatial : sail pta
45 sprain : sri pan
46 strain : sri tan
47 strait : sri tat
48 sturdy : sud try
49 sweaty : set way
50 tattle : ttl ate
51 theorem : term hoe
52 though : tog huh
53 throaty : tray hot
54 triode : tid roe
55 triune : tin rue
56 troupe : top rue
57 truant : tun rat
58 twirly : til wry
</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">import algorithm, sets, strutils, sugar
 
proc alternatingWords(word: string): array[2, string] =
## Return the candidate alternating words of a word.
for i, c in word:
result[i and 1].add c
 
let words = collect(HashSet, for word in "unixdict.txt".lines: {word})
 
var result: seq[string]
for word in words:
if word.len >= 6:
let altWords = alternatingWords(word)
if altWords[0] in words and altWords[1] in words:
result.add word.align(8) & " → $1 $2" % altWords
result.sort()
for i, line in result: echo ($(i+1)).align(2), ": ", line</syntaxhighlight>
 
{{out}}
<pre> 1: accost → acs cot
2: accuse → acs cue
3: afield → ail fed
4: agleam → ala gem
5: alcott → act lot
6: allele → all lee
7: allied → ale lid
8: alpert → apr let
9: apport → apr pot
10: assist → ass sit
11: battle → btl ate
12: blaine → ban lie
13: brenda → bed rna
14: choose → cos hoe
15: choosy → cos hoy
16: claire → car lie
17: effete → eft fee
18: fabric → fbi arc
19: fealty → fat ely
20: fluent → fun let
21: friend → fin red
22: george → gog ere
23: inroad → ira nod
24: israel → ire sal
25: jaunty → jut any
26: joanne → jan one
27: lounge → lug one
28: oriole → oil roe
29: oswald → owl sad
30: parrot → pro art
31: peoria → poi era
32: pierre → per ire
33: poodle → pol ode
34: pounce → puc one
35: racial → rca ail
36: realty → rat ely
37: sordid → sri odd
38: sprain → sri pan
39: strain → sri tan
40: strait → sri tat
41: sturdy → sud try
42: sweaty → set way
43: tattle → ttl ate
44: though → tog huh
45: triode → tid roe
46: triune → tin rue
47: troupe → top rue
48: truant → tun rat
49: twirly → til wry
50: ambient → abet min
51: annette → ante net
52: ariadne → aide ran
53: collude → clue old
54: forwent → fret own
55: spatial → sail pta
56: theorem → term hoe
57: throaty → tray hot
58: calliope → clip aloe</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">module StrSet = Set.Make(String)
 
let seq_lines ch =
let rec repeat () =
match input_line ch with
| s -> Seq.Cons (s, repeat)
| exception End_of_file -> Nil
in repeat
 
let min_len l s =
l <= String.length s
 
let get_alternade set s =
let s0 = String.init (succ (String.length s) lsr 1) (fun i -> s.[i + i])
and s1 = String.init (String.length s lsr 1) (fun i -> s.[i + succ i]) in
if StrSet.mem s0 set && StrSet.mem s1 set
then Some (Printf.sprintf "%s | %s %s" s s0 s1) else None
 
let () =
let set = seq_lines stdin |> Seq.filter (min_len 3) |> StrSet.of_seq in
StrSet.to_seq set |> Seq.filter (min_len 6)
|> Seq.filter_map (get_alternade set) |> Seq.iter print_endline</syntaxhighlight>
{{out}}
<pre style="max-height:20em">
accost | acs cot
accuse | acs cue
afield | ail fed
agleam | ala gem
alcott | act lot
allele | all lee
allied | ale lid
alpert | apr let
ambient | abet min
annette | ante net
apport | apr pot
ariadne | aide ran
assist | ass sit
battle | btl ate
blaine | ban lie
brenda | bed rna
calliope | clip aloe
choose | cos hoe
choosy | cos hoy
claire | car lie
collude | clue old
effete | eft fee
fabric | fbi arc
fealty | fat ely
fluent | fun let
forwent | fret own
friend | fin red
george | gog ere
inroad | ira nod
israel | ire sal
jaunty | jut any
joanne | jan one
lounge | lug one
oriole | oil roe
oswald | owl sad
parrot | pro art
peoria | poi era
pierre | per ire
poodle | pol ode
pounce | puc one
racial | rca ail
realty | rat ely
sordid | sri odd
spatial | sail pta
sprain | sri pan
strain | sri tan
strait | sri tat
sturdy | sud try
sweaty | set way
tattle | ttl ate
theorem | term hoe
though | tog huh
throaty | tray hot
triode | tid roe
triune | tin rue
troupe | top rue
truant | tun rat
twirly | til wry
</pre>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict;
Line 1,187 ⟶ 2,543:
my $odd = s/.(.?)/$1/gr;
$words{$even} && $words{$odd} and print "$_ => [ $even $odd ]\n";
}</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">object</span> <span style="color: #000000;">words</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_text</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"demo/unixdict.txt"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">GT_LF_STRIPPED</span><span style="color: #0000FF;">)</span>
<span style="color: #008080004080;">ifsequence</span> <span style="color: #008080000000;">notwords</span> <span style="color: #0040800000FF;">sequence=</span><span style="color: #0000FF;">(</span><span style="color: #0000007060A8;">wordsunix_dict</span><span style="color: #0000FF;">()</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">crash</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"unixdict.txt error, download from http://www.puzzlers.org/pub/wordlists/unixdict.txt"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">minlens</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #000000;">11</span><span style="color: #0000FF;">,</span><span style="color: #000000;">12</span><span style="color: #0000FF;">,</span><span style="color: #000000;">12</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #000000;">6</span> <span style="color: #008080;">do</span>
Line 1,203 ⟶ 2,557:
<span style="color: #004080;">sequence</span> <span style="color: #000000;">sn</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">word</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #000000004080;">sninteger</span> <span style="color: #0000FF000000;">[ndx</span><span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">j</span><span style="color: #0000FF;">-</span><span style="color: #0000007060A8;">1mod</span><span style="color: #0000FF;">,(</span><span style="color: #000000;">nj</span><span style="color: #0000FF;">)+-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">],</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">wordn</span><span style="color: #0000FF;">[)+</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]1</span>
<span style="color: #000000;">sn</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ndx</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">word</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">n</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">binary_search</span><span style="color: #0000FF;">(</span><span style="color: #000000;">sn</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">],</span><span style="color: #000000;">words</span><span style="color: #0000FF;">)<</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">n</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">sn</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">prepend</span><span style="color: #0000FF;">(</span><span style="color: #000000;">sn</span><span style="color: #0000FF;">,</span><span style="color: #000000;">word</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">sn</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #000000;">sq_gt</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #000000;">binary_search</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">sn</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">words</span><span style="color: #0000FF;">}}),</span><span style="color: #000000;">0</span><span style="color: #0000FF;">))=</span><span style="color: #000000;">n</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">prepend</span><span style="color: #0000FF;">(</span><span style="color: #000000;">sn</span><span style="color: #0000FF;">,</span><span style="color: #000000;">word</span><span style="color: #0000FF;">))</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</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;">"\nEvery %s letter of length&gt;=%d:\n"</span><span style="color: #0000FF;">,{</span><span style="color: #0000007060A8;">ordinal</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">),</span><span style="color: #000000;">minlens</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">]})</span>
<span style="color: #7060A8;">pp</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"alternade words found"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">),{</span><span style="color: #004600;">pp_Nest</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,244 ⟶ 2,603:
{{`aristotelean`, `at`, `re`, `il`, `se`, `ta`, `on`},
{`warehouseman`, `wu`, `as`, `re`, `em`, `ha`, `on`}}
</pre>
 
=={{header|Picat}}==
{{works with|Picat}}
<syntaxhighlight lang="picat">
split_word(Word) = Words =>
N = len(Word),
W1 = [Word[I]: I in 1..N, I mod 2 == 1],
W2 = [Word[I]: I in 1..N, I mod 2 == 0],
Words = {W1, W2}.
 
main(Args) =>
File = Args[1],
Reader = open(File),
Dict = new_set(25104, []),
while (not at_end_of_stream(Reader))
Word = read_line(Reader),
put(Dict, Word),
end,
DictWords = keys(Dict),
LongWords = [Long: Long in DictWords, len(Long) >= 6],
LongSorted = sort(LongWords),
foreach (Word in LongSorted)
Words = split_word(Word),
if (has_key(Dict, Words[1]), has_key(Dict, Words[2])) then
printf("%w = %w + %w\n", Word, Words[1], Words[2])
end
end,
close(Reader).
</syntaxhighlight>
{{out}}
<pre style="height: 45ex">
accost = acs + cot
accuse = acs + cue
afield = ail + fed
agleam = ala + gem
alcott = act + lot
allele = all + lee
allied = ale + lid
alpert = apr + let
ambient = abet + min
annette = ante + net
apport = apr + pot
ariadne = aide + ran
assist = ass + sit
battle = btl + ate
blaine = ban + lie
brenda = bed + rna
calliope = clip + aloe
choose = cos + hoe
choosy = cos + hoy
claire = car + lie
collude = clue + old
effete = eft + fee
fabric = fbi + arc
fealty = fat + ely
fluent = fun + let
forwent = fret + own
friend = fin + red
george = gog + ere
inroad = ira + nod
israel = ire + sal
jaunty = jut + any
joanne = jan + one
lounge = lug + one
oriole = oil + roe
oswald = owl + sad
parrot = pro + art
peoria = poi + era
pierre = per + ire
poodle = pol + ode
pounce = puc + one
racial = rca + ail
realty = rat + ely
sordid = sri + odd
spatial = sail + pta
sprain = sri + pan
strain = sri + tan
strait = sri + tat
sturdy = sud + try
sweaty = set + way
tattle = ttl + ate
theorem = term + hoe
though = tog + huh
throaty = tray + hot
triode = tid + roe
triune = tin + rue
troupe = top + rue
truant = tun + rat
twirly = til + wry
</pre>
 
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<langsyntaxhighlight lang="prolog">:- dynamic dictionary_word/1.
 
main:-
Line 1,288 ⟶ 2,737:
odd_even_chars([Ch], [Ch], []):-!.
odd_even_chars([Ch1, Ch2|Chars], [Ch1|Chars1], [Ch2|Chars2]):-
odd_even_chars(Chars, Chars1, Chars2).</langsyntaxhighlight>
 
{{out}}
Line 1,354 ⟶ 2,803:
=={{header|Python}}==
 
<langsyntaxhighlight lang="python">WORDFILE = 'unixdict.txt'
MINLEN = 6
 
Line 1,419 ⟶ 2,868:
odd = word[1::2]
if even in words and odd in words:
print(word, even, odd)</langsyntaxhighlight>
 
{{out}}
Line 1,484 ⟶ 2,933:
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ stack ] is sift.test ( --> s )
protect sift.test
 
Line 1,519 ⟶ 2,968:
else [ drop 2drop ] ]
dict release</langsyntaxhighlight>
 
{{out}}
Line 1,576 ⟶ 3,025:
though tog huh
throaty tray hot
triode tid roe
triune tin rue
troupe top rue
truant tun rat
twirly til wry</pre>
 
 
A more straightforward approach:
 
<syntaxhighlight lang="quackery"> [ [] [] rot witheach [ join swap ] ] is unzip ( [ --> [ [ )
 
[ $ "rosetta/unixdict.txt" sharefile
drop nest$
[] swap witheach
[ [ nested join ]
else drop ] ] constant is unixdict ( --> [ )
 
unixdict witheach
[ dup size 6 < iff
drop done
dup unzip
unixdict find
unixdict found iff
[ unixdict find
unixdict found iff
[ dup echo$ sp
unzip echo$ sp
echo$ cr ]
else drop ]
else 2drop ]</syntaxhighlight>
 
{{out}}
 
<pre style="height: 30ex">accost acs cot
accuse acs cue
afield ail fed
agleam ala gem
alcott act lot
allele all lee
allied ale lid
alpert apr let
ambient min abet
annette net ante
apport apr pot
ariadne ran aide
assist ass sit
battle btl ate
blaine ban lie
brenda bed rna
calliope clip aloe
choose cos hoe
choosy cos hoy
claire car lie
collude old clue
effete eft fee
fabric fbi arc
fealty fat ely
fluent fun let
forwent own fret
friend fin red
george gog ere
inroad ira nod
israel ire sal
jaunty jut any
joanne jan one
lounge lug one
oriole oil roe
oswald owl sad
parrot pro art
peoria poi era
pierre per ire
poodle pol ode
pounce puc one
racial rca ail
realty rat ely
sordid sri odd
spatial pta sail
sprain sri pan
strain sri tan
strait sri tat
sturdy sud try
sweaty set way
tattle ttl ate
theorem hoe term
though tog huh
throaty hot tray
triode tid roe
triune tin rue
Line 1,584 ⟶ 3,119:
=={{header|Raku}}==
 
<syntaxhighlight lang="raku" perl6line>unit sub MAIN ($file = 'unixdict.txt', :$min = 6);
 
my %words = $file.IO.slurp.words.map: * => 1;
Line 1,603 ⟶ 3,138:
.say for @alternades > 10
?? (flat @alternades.head(5), '...', @alternades.tail(5))
!! @alternades;</langsyntaxhighlight>
{{out}}
<pre>58 alternades longer than 5 characters found in unixdict.txt:
Line 1,624 ⟶ 3,159:
 
It also allows the minimum length to be specified on the command line (CL) as well as the dictionary file identifier.
<langsyntaxhighlight lang="rexx">/*REXX program finds all the caseless alternade words (within an identified dictionary).*/
parse arg minL iFID . /*obtain optional arguments from the CL*/
if minL=='' | minL=="," then minL= 6 /*Not specified? Then use the default.*/
Line 1,650 ⟶ 3,185:
end /*j*/
/*stick a fork in it, we're all done. */
say copies('─',30) finds ' alternade words found with a minimum length of ' minL</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 1,716 ⟶ 3,251:
</pre>
 
===Versionversion 2===
This REXX version only handles the case (lowercase) of the dictionary being used, &nbsp; in this case, &nbsp; only lowercase words.
 
Independently developed at the same time as version 1 :-)
<langsyntaxhighlight lang="rexx">/* REXX */
fid='d:\unix.txt'
cnt.=0 /* cnt.n -> words of lenghtlength n */
ww.=0 /* ww.* the words to be analyzed */
w.=0 /* w.word = 1 if word is in unix.txt */
Line 1,750 ⟶ 3,287:
Exit
split: Procedure
/* split the word inointo components */
Parse Arg w
s.=''
Line 1,758 ⟶ 3,295:
s.v=s.v||vv
End
Return s.u s.v</langsyntaxhighlight>
Output:
<pre>D:\>rexx alternade
Line 1,827 ⟶ 3,364:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
 
Line 1,855 ⟶ 3,392:
next
see "done..." + nl
</syntaxhighlight>
</lang>
Output:
<pre>
Line 2,093 ⟶ 3,630:
 
done...
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">words = File.open("unixdict.txt").map(&:chomp)
 
res = words.filter_map do |word|
next if word.size < 6
splitted = word.each_char.partition.with_index{|_,i| i.even? }.map(&:join)
next unless splitted.all?{|split| words.bsearch{|w| split <=> w} }
"#{word}: #{splitted.join(", ")}"
end
 
puts res
</syntaxhighlight>
{{out}}
<pre style="height: 30ex">accost: acs, cot
accuse: acs, cue
afield: ail, fed
agleam: ala, gem
alcott: act, lot
allele: all, lee
allied: ale, lid
alpert: apr, let
ambient: abet, min
annette: ante, net
apport: apr, pot
ariadne: aide, ran
assist: ass, sit
battle: btl, ate
blaine: ban, lie
brenda: bed, rna
calliope: clip, aloe
choose: cos, hoe
choosy: cos, hoy
claire: car, lie
collude: clue, old
effete: eft, fee
fabric: fbi, arc
fealty: fat, ely
fluent: fun, let
forwent: fret, own
friend: fin, red
george: gog, ere
inroad: ira, nod
israel: ire, sal
jaunty: jut, any
joanne: jan, one
lounge: lug, one
oriole: oil, roe
oswald: owl, sad
parrot: pro, art
peoria: poi, era
pierre: per, ire
poodle: pol, ode
pounce: puc, one
racial: rca, ail
realty: rat, ely
sordid: sri, odd
spatial: sail, pta
sprain: sri, pan
strain: sri, tan
strait: sri, tat
sturdy: sud, try
sweaty: set, way
tattle: ttl, ate
theorem: term, hoe
though: tog, huh
throaty: tray, hot
triode: tid, roe
triune: tin, rue
troupe: top, rue
truant: tun, rat
twirly: til, wry
</pre>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">use std::collections::BTreeSet;
use std::fs::File;
use std::io::{self, BufRead};
Line 2,132 ⟶ 3,742:
Err(error) => eprintln!("{}", error),
}
}</langsyntaxhighlight>
 
{{out}}
Line 2,197 ⟶ 3,807:
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">import Foundation
 
func loadDictionary(_ path: String) throws -> Set<String> {
Line 2,235 ⟶ 3,845:
} catch {
print(error.localizedDescription)
}</langsyntaxhighlight>
 
{{out}}
Line 2,298 ⟶ 3,908:
twirly til wry
</pre>
 
=={{header|Tcl}}==
<syntaxhighlight lang="tcl">set unixdict [dict create]
foreach word [read [open unixdict.txt]] {
dict set unixdict $word {}
}
 
proc is_alt_word word {
global unixdict
for {set i 0} {$i < [string length $word]} {incr i} {
append [expr {$i % 2 ? "odd" : "even"}] [string index $word $i]
}
if {[dict exists $unixdict $even] && [dict exists $unixdict $odd]} {
return [list $even $odd]
}
}
 
foreach word [dict keys $unixdict] {
if {[string length $word] >= 6 && [set oddeven [is_alt_word $word]] ne ""} {
puts "$word $oddeven"
}
}</syntaxhighlight>
{{out}}
<pre>$ tclsh alternate_words.tcl | column -t
accost acs cot
accuse acs cue
afield ail fed
agleam ala gem
alcott act lot
allele all lee
allied ale lid
alpert apr let
ambient abet min
annette ante net
apport apr pot
ariadne aide ran
assist ass sit
battle btl ate
blaine ban lie
brenda bed rna
calliope clip aloe
choose cos hoe
choosy cos hoy
claire car lie
collude clue old
effete eft fee
fabric fbi arc
fealty fat ely
fluent fun let
forwent fret own
friend fin red
george gog ere
inroad ira nod
israel ire sal
jaunty jut any
joanne jan one
lounge lug one
oriole oil roe
oswald owl sad
parrot pro art
peoria poi era
pierre per ire
poodle pol ode
pounce puc one
racial rca ail
realty rat ely
sordid sri odd
spatial sail pta
sprain sri pan
strain sri tan
strait sri tat
sturdy sud try
sweaty set way
tattle ttl ate
theorem term hoe
though tog huh
throaty tray hot
triode tid roe
triune tin rue
troupe top rue
truant tun rat
twirly til wry</pre>
 
=={{header|V (Vlang)}}==
{{trans|go}}
<syntaxhighlight lang="v (vlang)">import os
 
fn main() {
bwords := os.read_lines('unixdict.txt')?//bytes.Fields(b)
mut dict := map[string]bool{}
mut words := bwords.clone()
for bword in bwords {
dict[bword] = true
}
println("'unixdict.txt' contains the following alternades of length 6 or more:\n")
mut count := 0
for word in words {
if word.len < 6 {
continue
}
mut w1 := ""
mut w2 := ""
for i, c in word {
if i%2 == 0 {
w1 += c.ascii_str()
} else {
w2 += c.ascii_str()
}
}
ok1 := w1 in dict
ok2 := w2 in dict
if ok1 && ok2 {
count++
println("${count:2}: ${word:-8} -> ${w1:-4} ${w2:-4}")
}
}
}</syntaxhighlight>
{{out}}
<pre>Same as Go entry</pre>
 
=={{header|Wren}}==
{{libheader|Wren-set}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "io" for File
import "./set" for Set
import "./fmt" for Fmt
 
var wordList = "unixdict.txt" // local copy
Line 2,330 ⟶ 4,059:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 2,397 ⟶ 4,126:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">string 0; \use zero-terminated strings
int Dict(26000); \pointers to words (enough for unixdict.txt)
int DictSize; \actual number of pointers in Dict
Line 2,464 ⟶ 4,193:
DI:= DI+1;
until DI >= DictSize;
]</langsyntaxhighlight>
 
{{out}}
Line 2,527 ⟶ 4,256:
58 twirly til wry
</pre>
 
 
{{omit from|6502 Assembly|unixdict.txt is much larger than the CPU's address space.}}
{{omit from|8080 Assembly|See 6502 Assembly.}}
{{omit from|Z80 Assembly|See 6502 Assembly.}}
9,476

edits