Change e letters to i in words: Difference between revisions
m (→{{header|Phix}}: please make it stop) |
(Add Factor) |
||
Line 9: | Line 9: | ||
The length of any word shown should have a length <big>'''> 5</big>. |
The length of any word shown should have a length <big>'''> 5</big>. |
||
=={{header|Factor}}== |
|||
<lang factor>USING: assocs binary-search formatting io.encodings.ascii |
|||
io.files kernel literals math sequences splitting ; |
|||
CONSTANT: words $[ "unixdict.txt" ascii file-lines ] |
|||
words |
|||
[ length 5 > ] filter |
|||
[ CHAR: e swap member? ] filter |
|||
[ dup "e" "i" replace ] map>alist |
|||
[ nip words sorted-member? ] assoc-filter ! binary search |
|||
[ "%-9s -> %s\n" printf ] assoc-each</lang> |
|||
{{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|Julia}}== |
=={{header|Julia}}== |
Revision as of 19:47, 12 February 2021
- Task
Use the dictionary unixdict.txt
Change letters e to i in words.
If changed word in dictionary show it here on this page.
The length of any word shown should have a length > 5.
Factor
<lang factor>USING: assocs binary-search formatting io.encodings.ascii io.files kernel literals math sequences splitting ;
CONSTANT: words $[ "unixdict.txt" ascii file-lines ]
words [ length 5 > ] filter [ CHAR: e swap member? ] filter [ dup "e" "i" replace ] map>alist [ nip words sorted-member? ] assoc-filter ! binary search [ "%-9s -> %s\n" printf ] assoc-each</lang>
- Output:
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
Julia
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; "") foreachword("unixdict.txt", e2i, minlen=6, colwidth=23, numcols=4)
</lang>
- Output:
Word source: unixdict.txt 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
Phix
Please make it stop. <lang Phix>sequence words = get_text("demo/unixdict.txt",GT_LF_STRIPPED) function chei(string word) return substitute(word,"e","i") end function function cheti(string word) return length(word)>5 and find('e',word) and find(chei(word),words) end function sequence chetie = filter(words,cheti), chetei = columnize({chetie,apply(chetie,chei)}) printf(1,"%d words: %v\n",{length(chetei),shorten(chetei,"",2)})</lang>
- Output:
26 words: {{"analyses","analysis"},{"atlantes","atlantis"},"...",{"vector","victor"},{"welles","willis"}}
Raku
<lang perl6>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>
- Output:
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
Ring
<lang ring> load "stdlib.ring"
cStr = read("unixdict.txt") wordList = str2list(cStr) num = 0
see "working..." + nl see "Words are:" + nl
ln = len(wordList) for n = ln to 1 step -1
if len(wordList[n]) < 6 del(wordList,n) ok
next
for n = 1 to len(wordList)
ind = substr(wordList[n],"e") if ind > 0 str = substr(wordList[n],"e","i") indstr = find(wordList,str) if indstr > 0 num = num + 1 see "" + num + ". " + wordList[n] + " => " + str + nl ok ok
next
see "done..." + nl </lang>
- Output:
working... Words are: 1. analyses => analysis 2. atlantes => atlantis 3. bellow => billow 4. breton => briton 5. clench => clinch 6. convect => convict 7. crises => crisis 8. diagnoses => diagnosis 9. enfant => infant 10. enquiry => inquiry 11. frances => francis 12. galatea => galatia 13. harden => hardin 14. heckman => hickman 15. inequity => iniquity 16. inflect => inflict 17. jacobean => jacobian 18. marten => martin 19. module => moduli 20. pegging => pigging 21. psychoses => psychosis 22. rabbet => rabbit 23. sterling => stirling 24. synopses => synopsis 25. vector => victor 26. welles => willis done...
Wren
<lang ecmascript>import "io" for File import "/sort" for Find import "/fmt" for Fmt
var wordList = "unixdict.txt" // local copy var count = 0 var words = File.read(wordList).trimEnd().split("\n").
where { |w| w.count > 5 }.toList
for (word in words) {
if (word.contains("e")) { var repl = word.replace("e", "i") if (Find.first(words, repl) >= 0) { // binary search count = count + 1 Fmt.print("$2d: $-9s -> $s", count, word, repl) } }
}</lang>
- Output:
1: analyses -> analysis 2: atlantes -> atlantis 3: bellow -> billow 4: breton -> briton 5: clench -> clinch 6: convect -> convict 7: crises -> crisis 8: diagnoses -> diagnosis 9: enfant -> infant 10: enquiry -> inquiry 11: frances -> francis 12: galatea -> galatia 13: harden -> hardin 14: heckman -> hickman 15: inequity -> iniquity 16: inflect -> inflict 17: jacobean -> jacobian 18: marten -> martin 19: module -> moduli 20: pegging -> pigging 21: psychoses -> psychosis 22: rabbet -> rabbit 23: sterling -> stirling 24: synopses -> synopsis 25: vector -> victor 26: welles -> willis