Change e letters to i in words: Difference between revisions
m
syntax highlighting fixup automation
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 19:
{{trans|Nim}}
<
V words_set = Set(words)
Line 26:
V new_word = word.replace(‘e’, ‘i’)
I new_word != word & new_word C words_set
print(word‘ -> ’new_word)</
{{out}}
Line 59:
=={{header|Ada}}==
<
with Ada.Strings.Fixed;
with Ada.Strings.Maps;
Line 99:
end;
end loop;
end Change_E_To_I;</
{{out}}
<pre>analyses -> analysis
Line 129:
=={{header|ALGOL 68}}==
<
# use the associative array in the Associate array/iteration task #
PR read "aArray.a68" PR
Line 186:
e := NEXT words
OD
FI</
{{out}}
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:
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.
<
use sorter : script "Custom Iterative Ternary Merge Sort" -- <https://macscripter.net/viewtopic.php?pid=194430#p194430>
use scripting additions
Line 278:
end task
task(6)</
{{output}}
<
===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.
<
use framework "Foundation"
use scripting additions
Line 348:
end task
task(6)</
===Functional===
Line 357:
and defining the list of twins as an intersection of sets.
<
Line 509:
set my text item delimiters to dlm
s
end unlines</
{{Out}}
<pre>analysis <- analyses
Line 540:
=={{header|Arturo}}==
<
loop words 'word [
Line 550:
if and? [contains? word "e"][contains? words iw] ->
print [word "=>" iw]
]</
{{out}}
Line 582:
=={{header|AutoHotkey}}==
<
oWord := []
for i, word in StrSplit(db, "`n", "`r")
Line 592:
result .= word . (StrLen(word) > 8 ? "`t" : "`t`t") . ": " StrReplace(word, "e", "i") "`n"
MsgBox, 262144, , % result</
{{out}}
<pre>analyses : analysis
Line 622:
=={{header|AWK}}==
<
# syntax: GAWK -f CHANGE_E_LETTERS_TO_I_IN_WORDS.AWK unixdict.txt
#
Line 649:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 681:
=={{header|C}}==
<
#include <stdio.h>
#include <stdlib.h>
Line 781:
free_dictionary(dictionary, size);
return EXIT_SUCCESS;
}</
{{out}}
Line 814:
=={{header|C++}}==
<
#include <cstdlib>
#include <fstream>
Line 850:
return EXIT_SUCCESS;
}</
{{out}}
Line 885:
{{libheader| System.SysUtils}}
{{libheader| System.Classes}}
<
program Change_e_letters_to_i_in_words;
Line 925:
readln;
end.</
{{out}}
<pre>analyses ──► analysis
Line 955:
=={{header|F_Sharp|F#}}==
<
// 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 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)
</syntaxhighlight>
{{out}}
<pre>
Line 991:
</pre>
=={{header|Factor}}==
<
io.files kernel literals math sequences splitting ;
Line 1,001:
[ dup "e" "i" replace ] map>alist
[ nip words sorted-member? ] assoc-filter ! binary search
[ "%-9s -> %s\n" printf ] assoc-each</
{{out}}
<pre>
Line 1,033:
=={{header|FreeBASIC}}==
<
type node
Line 1,093:
end if
curr = curr->nxt
wend</
{{out}}<pre>
analyses analysis
Line 1,123:
=={{header|Go}}==
<
import (
Line 1,161:
}
}
}</
{{out}}
Line 1,194:
=={{header|Haskell}}==
<
------ DICTIONARY WORDS TWINNED BY e -> i REPLACEMENT ----
Line 1,218:
main =
readFile "unixdict.txt"
>>= (mapM_ print . ieTwins)</
{{Out}}
<pre>("analyses","analysis")
Line 1,248:
=={{header|J}}==
<
analysis
atlantis
Line 1,274:
synopsis
victor
willis</
=={{header|JavaScript}}==
Line 1,283:
Here we use the ObjC interface of macOS ''JavaScript for Automation'' to define a '''readFile''' function.
<
"use strict";
Line 1,341:
// MAIN ---
return main();
})();</
{{Out}}
<pre>["analyses","analysis"]
Line 1,376:
For the sake of brevity, we confine attention to words longer than 6 characters.
<syntaxhighlight lang=jq>
def e2i($dict):
select(index("e"))
Line 1,389:
| e2i($dict)
| "\($w) → \(.)"
</syntaxhighlight>
Invocation: jq -n -rR -f e2i.jq unixdict.txt
{{out}}
Line 1,412:
=={{header|Julia}}==
See [[Alternade_words]] for the foreachword function.
<
foreachword("unixdict.txt", e2i, minlen=6, colwidth=23, numcols=4)
</
<pre>
Word source: unixdict.txt
Line 1,428:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
dict //= StringSplit[#, "\n"] &;
dict //= Select[StringLength /* GreaterThan[5]];
sel = Select[dict, StringContainsQ["e"]];
sel = Select[sel, MemberQ[dict, StringReplace[#, "e" -> "i"]] &];
{#, StringReplace[#, "e" -> "i"]} & /@ sel</
{{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>
=={{header|Nim}}==
<
# Build a set of words to speed up membership check.
Line 1,446:
let newWord = word.replace('e', 'i')
if newWord.len > 5 and newWord != word and newWord in wordSet:
echo word, " → ", newWord</
{{out}}
Line 1,477:
=={{header|Perl}}==
<
use strict; # https://rosettacode.org/wiki/Change_e_letters_to_i_in_words
Line 1,486:
my %i = map { tr/i/e/r => sprintf "%30s %s\n", tr/i/e/r, $_ }
grep !/e/, grep 5 <= length, $file =~ /^.*i.*$/gm;
print @i{ split ' ', $file };</
{{out}}
<pre>
Line 1,536:
=={{header|Phix}}==
<!--<
<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>
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: #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>
<!--</
{{out}}
<pre>
Line 1,551:
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<
main:-
Line 1,583:
replace(Ch1, Ch2, Chars1, Chars2).
replace(Ch1, Ch2, [Ch|Chars1], [Ch|Chars2]):-
replace(Ch1, Ch2, Chars1, Chars2).</
{{out}}
Line 1,619:
Needs Python 3.8 or above for the assignment operator in the list comprehension.
{{Works with|Python|3.8}}
<
Line 1,669:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre>('analyses', 'analysis')
Line 1,700:
=={{header|Quackery}}==
<
witheach [
dup nested
Line 1,727:
[ swap echo$ cr ]
else nip ]
drop</
{{out}}
Line 1,759:
=={{header|R}}==
<
changed <- chartr("e", "i", dict)
cbind(Before = dict, After = changed)[changed != dict & changed %in% dict & nchar(changed) > 5, ]</
{{out}}
<pre> Before After
Line 1,792:
=={{header|Raku}}==
<syntaxhighlight lang=raku
put %ei.grep( *.key.contains: 'e' ).grep({ %ei{.value}:exists }).sort.batch(4)».gist».fmt('%-22s').join: "\n";</
{{out}}
Line 1,810:
It also allows the minimum length to be specified on the command line (CL), as well as the old character (that is
<br>to be changed), the new character (that is to be changed into), and as well as the dictionary file identifier.
<
parse arg minL oldC newC iFID . /*obtain optional arguments from the CL*/
if minL=='' | minL=="," then minL= 6 /*Not specified? Then use the default.*/
Line 1,837:
say /*stick a fork in it, we're all done. */
say copies('─',30) finds " words found that were changed with " oldC '──►' ,
newC", and with a minimum length of " minL</
{{out|output|text= when using the default inputs:}}
<pre>
Line 1,873:
=={{header|Ring}}==
<
load "stdlib.ring"
Line 1,903:
see "done..." + nl
</syntaxhighlight>
{{out}}
<pre>
Line 1,938:
=={{header|Ruby}}==
<
words.each do |word|
next if word.size < 6
Line 1,946:
puts "#{word.ljust(10)} -> #{e2i}"
end
</syntaxhighlight>
{{out}}
<pre style="height: 30ex">analyses -> analysis
Line 1,977:
=={{header|Rust}}==
<
use std::fs::File;
use std::io::{self, BufRead};
Line 2,007:
Err(error) => eprintln!("{}", error),
}
}</
{{out}}
Line 2,040:
=={{header|Sidef}}==
<
if (!file.exists) {
Line 2,065:
printf("%2d: %20s <-> %s\n", ++count, word, changed)
}
}</
{{out}}
<pre>
Line 2,097:
=={{header|Swift}}==
<
func loadDictionary(path: String, minLength: Int) throws -> Set<String> {
Line 2,124:
} catch {
print(error.localizedDescription)
}</
{{out}}
Line 2,158:
=={{header|VBScript}}==
Run it in CScript.
<syntaxhighlight lang=vb>
with createobject("ADODB.Stream")
.charset ="UTF-8"
Line 2,186:
next
</syntaxhighlight>
{{out}}
<pre>
Line 2,220:
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
<
import "/sort" for Find
import "/fmt" for Fmt
Line 2,236:
}
}
}</
{{out}}
Line 2,269:
=={{header|XPL0}}==
<
int Dict(26000); \pointers to words (enough for unixdict.txt)
int DictSize; \actual number of pointers in Dict
Line 2,337:
DI:= DI+1;
until DI >= DictSize;
]</
{{out}}
|