Jump to content

Change e letters to i in words: Difference between revisions

Added Vim Script solution
(add SETL)
(Added Vim Script solution)
 
Line 2,326:
welles -> willis
</pre>
 
=={{header|Vim Script}}==
 
In Vim, a [https://vimhelp.org/eval.txt.html#Dictionary dictionary] is an associative array with the entries not stored in a specific order. So, for this task, the output is put into a [https://vimhelp.org/eval.txt.html#List list], which enables it to be sorted with the builtin [https://vimhelp.org/builtin.txt.html#sort%28%29 sort()] function and output to the end of the current buffer. If only the unsorted words identified were wanted, the list-related lines could be omitted and one [https://vimhelp.org/builtin.txt.html#append%28%29 append] line used to ouput the matches (within the second 'for' loop). Although the problem does not say the output must be sorted, it's been done to allow for easier comparison of the output with other solutions.
 
<syntaxhighlight lang="vim">
let s:word_dict = {}
for word in readfile('unixdict.txt')
if strlen(word) > 5
let s:word_dict[word] = substitute(word, 'e', 'i', 'g')
endif
endfor
let s:word_list = []
for [key, value] in items(s:word_dict)
if key != value && s:word_dict->has_key(value)
call add(s:word_list, value .. " <- " .. key)
endif
endfor
call append(line('$'), sort(s:word_list))
</syntaxhighlight>
 
{{out}}
<pre>
analysis <- analyses
atlantis <- atlantes
billow <- bellow
briton <- breton
clinch <- clench
convict <- convect
crisis <- crises
diagnosis <- diagnoses
francis <- frances
galatia <- galatea
hardin <- harden
hickman <- heckman
infant <- enfant
inflict <- inflect
iniquity <- inequity
inquiry <- enquiry
jacobian <- jacobean
martin <- marten
moduli <- module
pigging <- pegging
psychosis <- psychoses
rabbit <- rabbet
stirling <- sterling
synopsis <- synopses
victor <- vector
willis <- welles
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-sort}}
40

edits

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