Change e letters to i in words: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 19: Line 19:
{{trans|Nim}}
{{trans|Nim}}


<lang 11l>V words = File(‘unixdict.txt’).read().split("\n")
<syntaxhighlight lang=11l>V words = File(‘unixdict.txt’).read().split("\n")
V words_set = Set(words)
V words_set = Set(words)


Line 26: Line 26:
V new_word = word.replace(‘e’, ‘i’)
V new_word = word.replace(‘e’, ‘i’)
I new_word != word & new_word C words_set
I new_word != word & new_word C words_set
print(word‘ -> ’new_word)</lang>
print(word‘ -> ’new_word)</syntaxhighlight>


{{out}}
{{out}}
Line 59: Line 59:


=={{header|Ada}}==
=={{header|Ada}}==
<lang Ada>with Ada.Text_Io;
<syntaxhighlight lang=Ada>with Ada.Text_Io;
with Ada.Strings.Fixed;
with Ada.Strings.Fixed;
with Ada.Strings.Maps;
with Ada.Strings.Maps;
Line 99: Line 99:
end;
end;
end loop;
end loop;
end Change_E_To_I;</lang>
end Change_E_To_I;</syntaxhighlight>
{{out}}
{{out}}
<pre>analyses -> analysis
<pre>analyses -> analysis
Line 129: Line 129:


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
<lang algol68># find words where replacing "e" with "i" results in another word #
<syntaxhighlight lang=algol68># find words where replacing "e" with "i" results in another word #
# use the associative array in the Associate array/iteration task #
# use the associative array in the Associate array/iteration task #
PR read "aArray.a68" PR
PR read "aArray.a68" PR
Line 186: Line 186:
e := NEXT words
e := NEXT words
OD
OD
FI</lang>
FI</syntaxhighlight>
{{out}}
{{out}}
Note, the associative array is not traversed in lexicographical order, the output here has been sorted for ease of comparison with other samples.
Note, the associative array is not traversed in lexicographical order, the output here has been sorted for ease of comparison with other samples.
Line 222: Line 222:
Because of the huge size of the original word list and the number of changed words to check, it's nearly 100 times as fast to ensure the list is sorted and to use a binary search handler as it is to use the language's built-in '''is in''' command! (1.17 seconds instead of 110 on my current machine.) A further, lesser but interesting optimisation is to work through the sorted list in reverse, storing possible "i" word candidates encountered before getting to any "e" words from which they can be derived. Changed "e" words then only need to be checked against this smaller collection.
Because of the huge size of the original word list and the number of changed words to check, it's nearly 100 times as fast to ensure the list is sorted and to use a binary search handler as it is to use the language's built-in '''is in''' command! (1.17 seconds instead of 110 on my current machine.) A further, lesser but interesting optimisation is to work through the sorted list in reverse, storing possible "i" word candidates encountered before getting to any "e" words from which they can be derived. Changed "e" words then only need to be checked against this smaller collection.


<lang applescript>use AppleScript version "2.3.1" -- Mac OS X 10.9 (Mavericks) or later.
<syntaxhighlight lang=applescript>use AppleScript version "2.3.1" -- Mac OS X 10.9 (Mavericks) or later.
use sorter : script "Custom Iterative Ternary Merge Sort" -- <https://macscripter.net/viewtopic.php?pid=194430#p194430>
use sorter : script "Custom Iterative Ternary Merge Sort" -- <https://macscripter.net/viewtopic.php?pid=194430#p194430>
use scripting additions
use scripting additions
Line 278: Line 278:
end task
end task


task(6)</lang>
task(6)</syntaxhighlight>


{{output}}
{{output}}
<lang applescript>{{"analyses", "analysis"}, {"atlantes", "atlantis"}, {"bellow", "billow"}, {"breton", "briton"}, {"clench", "clinch"}, {"convect", "convict"}, {"crises", "crisis"}, {"diagnoses", "diagnosis"}, {"enfant", "infant"}, {"enquiry", "inquiry"}, {"frances", "francis"}, {"galatea", "galatia"}, {"harden", "hardin"}, {"heckman", "hickman"}, {"inequity", "iniquity"}, {"inflect", "inflict"}, {"jacobean", "jacobian"}, {"marten", "martin"}, {"module", "moduli"}, {"pegging", "pigging"}, {"psychoses", "psychosis"}, {"rabbet", "rabbit"}, {"sterling", "stirling"}, {"synopses", "synopsis"}, {"vector", "victor"}, {"welles", "willis"}}</lang>
<syntaxhighlight lang=applescript>{{"analyses", "analysis"}, {"atlantes", "atlantis"}, {"bellow", "billow"}, {"breton", "briton"}, {"clench", "clinch"}, {"convect", "convict"}, {"crises", "crisis"}, {"diagnoses", "diagnosis"}, {"enfant", "infant"}, {"enquiry", "inquiry"}, {"frances", "francis"}, {"galatea", "galatia"}, {"harden", "hardin"}, {"heckman", "hickman"}, {"inequity", "iniquity"}, {"inflect", "inflict"}, {"jacobean", "jacobian"}, {"marten", "martin"}, {"module", "moduli"}, {"pegging", "pigging"}, {"psychoses", "psychosis"}, {"rabbet", "rabbit"}, {"sterling", "stirling"}, {"synopses", "synopsis"}, {"vector", "victor"}, {"welles", "willis"}}</syntaxhighlight>


===AppleScriptObjC===
===AppleScriptObjC===
The Foundation framework has very fast array filters, but reducing the checklist size and checking with the same binary search handler as above are also effective. This version takes about 0.37 seconds. As above, the case-sensitivity and sorting arrangements are superfluous with unixdict.txt, but are included for interest. Same result.
The Foundation framework has very fast array filters, but reducing the checklist size and checking with the same binary search handler as above are also effective. This version takes about 0.37 seconds. As above, the case-sensitivity and sorting arrangements are superfluous with unixdict.txt, but are included for interest. Same result.


<lang applescript>use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
<syntaxhighlight lang=applescript>use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
use framework "Foundation"
use scripting additions
use scripting additions
Line 348: Line 348:
end task
end task


task(6)</lang>
task(6)</syntaxhighlight>


===Functional===
===Functional===
Line 357: Line 357:
and defining the list of twins as an intersection of sets.
and defining the list of twins as an intersection of sets.


<lang applescript>use framework "Foundation"
<syntaxhighlight lang=applescript>use framework "Foundation"




Line 509: Line 509:
set my text item delimiters to dlm
set my text item delimiters to dlm
s
s
end unlines</lang>
end unlines</syntaxhighlight>
{{Out}}
{{Out}}
<pre>analysis <- analyses
<pre>analysis <- analyses
Line 540: Line 540:
=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>words: map read.lines relative "unixdict.txt" => strip
<syntaxhighlight lang=rebol>words: map read.lines relative "unixdict.txt" => strip


loop words 'word [
loop words 'word [
Line 550: Line 550:
if and? [contains? word "e"][contains? words iw] ->
if and? [contains? word "e"][contains? words iw] ->
print [word "=>" iw]
print [word "=>" iw]
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 582: Line 582:


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang AutoHotkey>FileRead, db, % A_Desktop "\unixdict.txt"
<syntaxhighlight lang=AutoHotkey>FileRead, db, % A_Desktop "\unixdict.txt"
oWord := []
oWord := []
for i, word in StrSplit(db, "`n", "`r")
for i, word in StrSplit(db, "`n", "`r")
Line 592: Line 592:
result .= word . (StrLen(word) > 8 ? "`t" : "`t`t") . ": " StrReplace(word, "e", "i") "`n"
result .= word . (StrLen(word) > 8 ? "`t" : "`t`t") . ": " StrReplace(word, "e", "i") "`n"


MsgBox, 262144, , % result</lang>
MsgBox, 262144, , % result</syntaxhighlight>
{{out}}
{{out}}
<pre>analyses : analysis
<pre>analyses : analysis
Line 622: Line 622:


=={{header|AWK}}==
=={{header|AWK}}==
<lang AWK>
<syntaxhighlight lang=AWK>
# syntax: GAWK -f CHANGE_E_LETTERS_TO_I_IN_WORDS.AWK unixdict.txt
# syntax: GAWK -f CHANGE_E_LETTERS_TO_I_IN_WORDS.AWK unixdict.txt
#
#
Line 649: Line 649:
exit(0)
exit(0)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 681: Line 681:


=={{header|C}}==
=={{header|C}}==
<lang c>#include <stdbool.h>
<syntaxhighlight lang=c>#include <stdbool.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
Line 781: Line 781:
free_dictionary(dictionary, size);
free_dictionary(dictionary, size);
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 814: Line 814:


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <algorithm>
<syntaxhighlight lang=cpp>#include <algorithm>
#include <cstdlib>
#include <cstdlib>
#include <fstream>
#include <fstream>
Line 850: Line 850:


return EXIT_SUCCESS;
return EXIT_SUCCESS;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 885: Line 885:
{{libheader| System.SysUtils}}
{{libheader| System.SysUtils}}
{{libheader| System.Classes}}
{{libheader| System.Classes}}
<lang Delphi>
<syntaxhighlight lang=Delphi>
program Change_e_letters_to_i_in_words;
program Change_e_letters_to_i_in_words;


Line 925: Line 925:


readln;
readln;
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>analyses ──► analysis
<pre>analyses ──► analysis
Line 955: Line 955:


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>
<syntaxhighlight lang=fsharp>
// Change 'e' to 'i' in words. Nigel Galloway: February 18th., 2021
// Change 'e' to 'i' in words. Nigel Galloway: February 18th., 2021
let g=[|use n=System.IO.File.OpenText("unixdict.txt") in while not n.EndOfStream do yield n.ReadLine()|]|>Array.filter(fun n->n.Length>5)
let g=[|use n=System.IO.File.OpenText("unixdict.txt") in while not n.EndOfStream do yield n.ReadLine()|]|>Array.filter(fun n->n.Length>5)
let fN g=(g,(Seq.map(fun n->if n='e' then 'i' else n)>>Array.ofSeq>>System.String)g)
let fN g=(g,(Seq.map(fun n->if n='e' then 'i' else n)>>Array.ofSeq>>System.String)g)
g|>Array.filter(Seq.contains 'e')|>Array.map fN|>Array.filter(fun(_,n)-> Array.contains n g)|>Array.iter(fun(n,g)->printfn "%s -> %s" n g)
g|>Array.filter(Seq.contains 'e')|>Array.map fN|>Array.filter(fun(_,n)-> Array.contains n g)|>Array.iter(fun(n,g)->printfn "%s -> %s" n g)
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 991: Line 991:
</pre>
</pre>
=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: assocs binary-search formatting io.encodings.ascii
<syntaxhighlight lang=factor>USING: assocs binary-search formatting io.encodings.ascii
io.files kernel literals math sequences splitting ;
io.files kernel literals math sequences splitting ;


Line 1,001: Line 1,001:
[ dup "e" "i" replace ] map>alist
[ dup "e" "i" replace ] map>alist
[ nip words sorted-member? ] assoc-filter ! binary search
[ nip words sorted-member? ] assoc-filter ! binary search
[ "%-9s -> %s\n" printf ] assoc-each</lang>
[ "%-9s -> %s\n" printf ] assoc-each</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,033: Line 1,033:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>#define NULL 0
<syntaxhighlight lang=freebasic>#define NULL 0


type node
type node
Line 1,093: Line 1,093:
end if
end if
curr = curr->nxt
curr = curr->nxt
wend</lang>
wend</syntaxhighlight>
{{out}}<pre>
{{out}}<pre>
analyses analysis
analyses analysis
Line 1,123: Line 1,123:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang=go>package main


import (
import (
Line 1,161: Line 1,161:
}
}
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,194: Line 1,194:


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import qualified Data.Set as S
<syntaxhighlight lang=haskell>import qualified Data.Set as S


------ DICTIONARY WORDS TWINNED BY e -> i REPLACEMENT ----
------ DICTIONARY WORDS TWINNED BY e -> i REPLACEMENT ----
Line 1,218: Line 1,218:
main =
main =
readFile "unixdict.txt"
readFile "unixdict.txt"
>>= (mapM_ print . ieTwins)</lang>
>>= (mapM_ print . ieTwins)</syntaxhighlight>
{{Out}}
{{Out}}
<pre>("analyses","analysis")
<pre>("analyses","analysis")
Line 1,248: Line 1,248:


=={{header|J}}==
=={{header|J}}==
<lang J> >(([-.-.)rplc&'ei'&.>@(#~ ('e'&e. * 5<#)@>)) cutLF fread 'unixdict.txt'
<syntaxhighlight lang=J> >(([-.-.)rplc&'ei'&.>@(#~ ('e'&e. * 5<#)@>)) cutLF fread 'unixdict.txt'
analysis
analysis
atlantis
atlantis
Line 1,274: Line 1,274:
synopsis
synopsis
victor
victor
willis</lang>
willis</syntaxhighlight>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
Line 1,283: Line 1,283:
Here we use the ObjC interface of macOS ''JavaScript for Automation'' to define a '''readFile''' function.
Here we use the ObjC interface of macOS ''JavaScript for Automation'' to define a '''readFile''' function.


<lang javascript>(() => {
<syntaxhighlight lang=javascript>(() => {
"use strict";
"use strict";
Line 1,341: Line 1,341:
// MAIN ---
// MAIN ---
return main();
return main();
})();</lang>
})();</syntaxhighlight>
{{Out}}
{{Out}}
<pre>["analyses","analysis"]
<pre>["analyses","analysis"]
Line 1,376: Line 1,376:
For the sake of brevity, we confine attention to words longer than 6 characters.
For the sake of brevity, we confine attention to words longer than 6 characters.


<syntaxhighlight lang=jq>
<lang jq>
def e2i($dict):
def e2i($dict):
select(index("e"))
select(index("e"))
Line 1,389: Line 1,389:
| e2i($dict)
| e2i($dict)
| "\($w) → \(.)"
| "\($w) → \(.)"
</syntaxhighlight>
</lang>
Invocation: jq -n -rR -f e2i.jq unixdict.txt
Invocation: jq -n -rR -f e2i.jq unixdict.txt
{{out}}
{{out}}
Line 1,412: Line 1,412:
=={{header|Julia}}==
=={{header|Julia}}==
See [[Alternade_words]] for the foreachword function.
See [[Alternade_words]] for the foreachword function.
<lang julia>e2i(w, d) = (if 'e' in w s = replace(w, "e" => "i"); haskey(d, s) && return "$w => $s" end; "")
<syntaxhighlight lang=julia>e2i(w, d) = (if 'e' in w s = replace(w, "e" => "i"); haskey(d, s) && return "$w => $s" end; "")
foreachword("unixdict.txt", e2i, minlen=6, colwidth=23, numcols=4)
foreachword("unixdict.txt", e2i, minlen=6, colwidth=23, numcols=4)
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
Word source: unixdict.txt
Word source: unixdict.txt
Line 1,428: Line 1,428:


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>dict = Once[Import["https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt"]];
<syntaxhighlight lang=Mathematica>dict = Once[Import["https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt"]];
dict //= StringSplit[#, "\n"] &;
dict //= StringSplit[#, "\n"] &;
dict //= Select[StringLength /* GreaterThan[5]];
dict //= Select[StringLength /* GreaterThan[5]];
sel = Select[dict, StringContainsQ["e"]];
sel = Select[dict, StringContainsQ["e"]];
sel = Select[sel, MemberQ[dict, StringReplace[#, "e" -> "i"]] &];
sel = Select[sel, MemberQ[dict, StringReplace[#, "e" -> "i"]] &];
{#, StringReplace[#, "e" -> "i"]} & /@ sel</lang>
{#, StringReplace[#, "e" -> "i"]} & /@ sel</syntaxhighlight>
{{out}}
{{out}}
<pre>{{analyses,analysis},{atlantes,atlantis},{bellow,billow},{breton,briton},{clench,clinch},{convect,convict},{crises,crisis},{diagnoses,diagnosis},{enfant,infant},{enquiry,inquiry},{frances,francis},{galatea,galatia},{harden,hardin},{heckman,hickman},{inequity,iniquity},{inflect,inflict},{jacobean,jacobian},{marten,martin},{module,moduli},{pegging,pigging},{psychoses,psychosis},{rabbet,rabbit},{sterling,stirling},{synopses,synopsis},{vector,victor},{welles,willis}}</pre>
<pre>{{analyses,analysis},{atlantes,atlantis},{bellow,billow},{breton,briton},{clench,clinch},{convect,convict},{crises,crisis},{diagnoses,diagnosis},{enfant,infant},{enquiry,inquiry},{frances,francis},{galatea,galatia},{harden,hardin},{heckman,hickman},{inequity,iniquity},{inflect,inflict},{jacobean,jacobian},{marten,martin},{module,moduli},{pegging,pigging},{psychoses,psychosis},{rabbet,rabbit},{sterling,stirling},{synopses,synopsis},{vector,victor},{welles,willis}}</pre>


=={{header|Nim}}==
=={{header|Nim}}==
<lang Nim>import sets, strutils, sugar
<syntaxhighlight lang=Nim>import sets, strutils, sugar


# Build a set of words to speed up membership check.
# Build a set of words to speed up membership check.
Line 1,446: Line 1,446:
let newWord = word.replace('e', 'i')
let newWord = word.replace('e', 'i')
if newWord.len > 5 and newWord != word and newWord in wordSet:
if newWord.len > 5 and newWord != word and newWord in wordSet:
echo word, " → ", newWord</lang>
echo word, " → ", newWord</syntaxhighlight>


{{out}}
{{out}}
Line 1,477: Line 1,477:


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>#!/usr/bin/perl
<syntaxhighlight lang=perl>#!/usr/bin/perl


use strict; # https://rosettacode.org/wiki/Change_e_letters_to_i_in_words
use strict; # https://rosettacode.org/wiki/Change_e_letters_to_i_in_words
Line 1,486: Line 1,486:
my %i = map { tr/i/e/r => sprintf "%30s %s\n", tr/i/e/r, $_ }
my %i = map { tr/i/e/r => sprintf "%30s %s\n", tr/i/e/r, $_ }
grep !/e/, grep 5 <= length, $file =~ /^.*i.*$/gm;
grep !/e/, grep 5 <= length, $file =~ /^.*i.*$/gm;
print @i{ split ' ', $file };</lang>
print @i{ split ' ', $file };</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,536: Line 1,536:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">words</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">unix_dict</span><span style="color: #0000FF;">()</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">words</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">unix_dict</span><span style="color: #0000FF;">()</span>
Line 1,543: Line 1,543:
<span style="color: #004080;">sequence</span> <span style="color: #000000;">chetie</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #000000;">words</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cheti</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">chetei</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">({</span><span style="color: #000000;">chetie</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #000000;">chetie</span><span style="color: #0000FF;">,</span><span style="color: #000000;">chei</span><span style="color: #0000FF;">)})</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">chetie</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #000000;">words</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cheti</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">chetei</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">({</span><span style="color: #000000;">chetie</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #000000;">chetie</span><span style="color: #0000FF;">,</span><span style="color: #000000;">chei</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;">"%d words: %v\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">chetei</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">chetei</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</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;">"%d words: %v\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">chetei</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">chetei</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)})</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 1,551: Line 1,551:
=={{header|Prolog}}==
=={{header|Prolog}}==
{{works with|SWI Prolog}}
{{works with|SWI Prolog}}
<lang prolog>:- dynamic dictionary_word/1.
<syntaxhighlight lang=prolog>:- dynamic dictionary_word/1.


main:-
main:-
Line 1,583: Line 1,583:
replace(Ch1, Ch2, Chars1, Chars2).
replace(Ch1, Ch2, Chars1, Chars2).
replace(Ch1, Ch2, [Ch|Chars1], [Ch|Chars2]):-
replace(Ch1, Ch2, [Ch|Chars1], [Ch|Chars2]):-
replace(Ch1, Ch2, Chars1, Chars2).</lang>
replace(Ch1, Ch2, Chars1, Chars2).</syntaxhighlight>


{{out}}
{{out}}
Line 1,619: Line 1,619:
Needs Python 3.8 or above for the assignment operator in the list comprehension.
Needs Python 3.8 or above for the assignment operator in the list comprehension.
{{Works with|Python|3.8}}
{{Works with|Python|3.8}}
<lang python>'''Dictionary words twinned by (e -> i) replacement'''
<syntaxhighlight lang=python>'''Dictionary words twinned by (e -> i) replacement'''




Line 1,669: Line 1,669:
# MAIN ---
# MAIN ---
if __name__ == '__main__':
if __name__ == '__main__':
main()</lang>
main()</syntaxhighlight>
{{Out}}
{{Out}}
<pre>('analyses', 'analysis')
<pre>('analyses', 'analysis')
Line 1,700: Line 1,700:
=={{header|Quackery}}==
=={{header|Quackery}}==


<lang Quackery> [ [] swap ]'[ swap
<syntaxhighlight lang=Quackery> [ [] swap ]'[ swap
witheach [
witheach [
dup nested
dup nested
Line 1,727: Line 1,727:
[ swap echo$ cr ]
[ swap echo$ cr ]
else nip ]
else nip ]
drop</lang>
drop</syntaxhighlight>


{{out}}
{{out}}
Line 1,759: Line 1,759:


=={{header|R}}==
=={{header|R}}==
<lang rsplus>dict <- scan("https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt", what = character())
<syntaxhighlight lang=rsplus>dict <- scan("https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt", what = character())
changed <- chartr("e", "i", dict)
changed <- chartr("e", "i", dict)
cbind(Before = dict, After = changed)[changed != dict & changed %in% dict & nchar(changed) > 5, ]</lang>
cbind(Before = dict, After = changed)[changed != dict & changed %in% dict & nchar(changed) > 5, ]</syntaxhighlight>
{{out}}
{{out}}
<pre> Before After
<pre> Before After
Line 1,792: Line 1,792:


=={{header|Raku}}==
=={{header|Raku}}==
<lang perl6>my %ei = 'unixdict.txt'.IO.words.grep({ .chars > 5 and /<[ie]>/ }).map: { $_ => .subst('e', 'i', :g) };
<syntaxhighlight lang=raku line>my %ei = 'unixdict.txt'.IO.words.grep({ .chars > 5 and /<[ie]>/ }).map: { $_ => .subst('e', 'i', :g) };
put %ei.grep( *.key.contains: 'e' ).grep({ %ei{.value}:exists }).sort.batch(4)».gist».fmt('%-22s').join: "\n";</lang>
put %ei.grep( *.key.contains: 'e' ).grep({ %ei{.value}:exists }).sort.batch(4)».gist».fmt('%-22s').join: "\n";</syntaxhighlight>


{{out}}
{{out}}
Line 1,810: Line 1,810:
It also allows the minimum length to be specified on the command line (CL), &nbsp; as well as the old character &nbsp; (that is
It also allows the minimum length to be specified on the command line (CL), &nbsp; as well as the old character &nbsp; (that is
<br>to be changed), &nbsp; the new character &nbsp; (that is to be changed into), &nbsp; and as well as the dictionary file identifier.
<br>to be changed), &nbsp; the new character &nbsp; (that is to be changed into), &nbsp; and as well as the dictionary file identifier.
<lang rexx>/*REXX pgm finds words with changed letter E──►I and is a word (in a specified dict).*/
<syntaxhighlight lang=rexx>/*REXX pgm finds words with changed letter E──►I and is a word (in a specified dict).*/
parse arg minL oldC newC iFID . /*obtain optional arguments from the CL*/
parse arg minL oldC newC iFID . /*obtain optional arguments from the CL*/
if minL=='' | minL=="," then minL= 6 /*Not specified? Then use the default.*/
if minL=='' | minL=="," then minL= 6 /*Not specified? Then use the default.*/
Line 1,837: Line 1,837:
say /*stick a fork in it, we're all done. */
say /*stick a fork in it, we're all done. */
say copies('─',30) finds " words found that were changed with " oldC '──►' ,
say copies('─',30) finds " words found that were changed with " oldC '──►' ,
newC", and with a minimum length of " minL</lang>
newC", and with a minimum length of " minL</syntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>
Line 1,873: Line 1,873:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang=ring>
load "stdlib.ring"
load "stdlib.ring"


Line 1,903: Line 1,903:


see "done..." + nl
see "done..." + nl
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,938: Line 1,938:


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>words = File.readlines("unixdict.txt").map(&:chomp)
<syntaxhighlight lang=ruby>words = File.readlines("unixdict.txt").map(&:chomp)
words.each do |word|
words.each do |word|
next if word.size < 6
next if word.size < 6
Line 1,946: Line 1,946:
puts "#{word.ljust(10)} -> #{e2i}"
puts "#{word.ljust(10)} -> #{e2i}"
end
end
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre style="height: 30ex">analyses -> analysis
<pre style="height: 30ex">analyses -> analysis
Line 1,977: Line 1,977:


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>use std::collections::BTreeSet;
<syntaxhighlight lang=rust>use std::collections::BTreeSet;
use std::fs::File;
use std::fs::File;
use std::io::{self, BufRead};
use std::io::{self, BufRead};
Line 2,007: Line 2,007:
Err(error) => eprintln!("{}", error),
Err(error) => eprintln!("{}", error),
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,040: Line 2,040:


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>var file = File("unixdict.txt")
<syntaxhighlight lang=ruby>var file = File("unixdict.txt")


if (!file.exists) {
if (!file.exists) {
Line 2,065: Line 2,065:
printf("%2d: %20s <-> %s\n", ++count, word, changed)
printf("%2d: %20s <-> %s\n", ++count, word, changed)
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,097: Line 2,097:


=={{header|Swift}}==
=={{header|Swift}}==
<lang swift>import Foundation
<syntaxhighlight lang=swift>import Foundation


func loadDictionary(path: String, minLength: Int) throws -> Set<String> {
func loadDictionary(path: String, minLength: Int) throws -> Set<String> {
Line 2,124: Line 2,124:
} catch {
} catch {
print(error.localizedDescription)
print(error.localizedDescription)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,158: Line 2,158:
=={{header|VBScript}}==
=={{header|VBScript}}==
Run it in CScript.
Run it in CScript.
<syntaxhighlight lang=vb>
<lang vb>
with createobject("ADODB.Stream")
with createobject("ADODB.Stream")
.charset ="UTF-8"
.charset ="UTF-8"
Line 2,186: Line 2,186:
next
next


</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,220: Line 2,220:
{{libheader|Wren-sort}}
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "io" for File
<syntaxhighlight lang=ecmascript>import "io" for File
import "/sort" for Find
import "/sort" for Find
import "/fmt" for Fmt
import "/fmt" for Fmt
Line 2,236: Line 2,236:
}
}
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,269: Line 2,269:


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>string 0; \use zero-terminated strings
<syntaxhighlight lang=XPL0>string 0; \use zero-terminated strings
int Dict(26000); \pointers to words (enough for unixdict.txt)
int Dict(26000); \pointers to words (enough for unixdict.txt)
int DictSize; \actual number of pointers in Dict
int DictSize; \actual number of pointers in Dict
Line 2,337: Line 2,337:
DI:= DI+1;
DI:= DI+1;
until DI >= DictSize;
until DI >= DictSize;
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}