Change e letters to i in words: Difference between revisions

m
Automated syntax highlighting fixup (second round - minor fixes)
m (syntax highlighting fixup automation)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 1:
{{Draft task}}
{{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.}}
;Task:
Use the dictionary   [https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt unixdict.txt]
Line 15 ⟶ 12:
{{Template:Strings}}
<br><br>
 
=={{header|11l}}==
{{trans|Nim}}
 
<syntaxhighlight lang="11l">V words = File(‘unixdict.txt’).read().split("\n")
V words_set = Set(words)
 
Line 57 ⟶ 53:
welles -> willis
</pre>
 
=={{header|Ada}}==
<syntaxhighlight lang=Ada"ada">with Ada.Text_Io;
with Ada.Strings.Fixed;
with Ada.Strings.Maps;
Line 127 ⟶ 122:
vector -> victor
welles -> willis</pre>
 
=={{header|ALGOL 68}}==
<syntaxhighlight lang="algol68"># find words where replacing "e" with "i" results in another word #
# use the associative array in the Associate array/iteration task #
PR read "aArray.a68" PR
Line 217 ⟶ 211:
welles -> willis
</pre>
 
=={{header|AppleScript}}==
===Core language only===
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.
 
<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 scripting additions
Line 281 ⟶ 274:
 
{{output}}
<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===
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.
 
<syntaxhighlight lang="applescript">use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
use scripting additions
Line 357 ⟶ 350:
and defining the list of twins as an intersection of sets.
 
<syntaxhighlight lang="applescript">use framework "Foundation"
 
 
Line 537 ⟶ 530:
victor <- vector
willis <- welles</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">words: map read.lines relative "unixdict.txt" => strip
 
loop words 'word [
Line 580 ⟶ 572:
vector => victor
welles => willis</pre>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang=AutoHotkey"autohotkey">FileRead, db, % A_Desktop "\unixdict.txt"
oWord := []
for i, word in StrSplit(db, "`n", "`r")
Line 620 ⟶ 611:
vector : victor
welles : willis</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang=AWK"awk">
# syntax: GAWK -f CHANGE_E_LETTERS_TO_I_IN_WORDS.AWK unixdict.txt
#
Line 679 ⟶ 669:
welles willis
</pre>
 
=={{header|C}}==
<syntaxhighlight lang="c">#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
Line 812 ⟶ 801:
26. welles -> willis
</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <algorithm>
#include <cstdlib>
#include <fstream>
Line 881 ⟶ 869:
26. welles -> willis
</pre>
 
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{libheader| System.Classes}}
<syntaxhighlight lang=Delphi"delphi">
program Change_e_letters_to_i_in_words;
 
Line 953 ⟶ 940:
vector ──► victor
welles ──► willis</pre>
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// 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)
Line 991 ⟶ 977:
</pre>
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: assocs binary-search formatting io.encodings.ascii
io.files kernel literals math sequences splitting ;
 
Line 1,031 ⟶ 1,017:
welles -> willis
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">#define NULL 0
 
type node
Line 1,121 ⟶ 1,106:
vector victor
welles willis</pre>
 
=={{header|Go}}==
<syntaxhighlight lang="go">package main
 
import (
Line 1,192 ⟶ 1,176:
26: welles -> willis
</pre>
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">import qualified Data.Set as S
 
------ DICTIONARY WORDS TWINNED BY e -> i REPLACEMENT ----
Line 1,246 ⟶ 1,229:
("vector","victor")
("welles","willis")</pre>
 
=={{header|J}}==
<syntaxhighlight lang=J"j"> >(([-.-.)rplc&'ei'&.>@(#~ ('e'&e. * 5<#)@>)) cutLF fread 'unixdict.txt'
analysis
atlantis
Line 1,275 ⟶ 1,257:
victor
willis</syntaxhighlight>
 
=={{header|JavaScript}}==
{{Works with| macOS}}
Line 1,283 ⟶ 1,264:
Here we use the ObjC interface of macOS ''JavaScript for Automation'' to define a '''readFile''' function.
 
<syntaxhighlight lang="javascript">(() => {
"use strict";
Line 1,369 ⟶ 1,350:
["vector","victor"]
["welles","willis"]</pre>
 
=={{header|jq}}==
{{works with|jq}}
Line 1,376 ⟶ 1,356:
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,409 ⟶ 1,389:
synopses → synopsis
</pre>
 
=={{header|Julia}}==
See [[Alternade_words]] for the foreachword function.
<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)
</syntaxhighlight>{{out}}
Line 1,426 ⟶ 1,405:
vector => victor welles => willis
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang=Mathematica"mathematica">dict = Once[Import["https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt"]];
dict //= StringSplit[#, "\n"] &;
dict //= Select[StringLength /* GreaterThan[5]];
Line 1,436 ⟶ 1,414:
{{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}}==
<syntaxhighlight lang=Nim"nim">import sets, strutils, sugar
 
# Build a set of words to speed up membership check.
Line 1,475 ⟶ 1,452:
vector → victor
welles → willis</pre>
 
=={{header|Perl}}==
<syntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Change_e_letters_to_i_in_words
Line 1,534 ⟶ 1,510:
wrest wrist
</pre>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<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,548 ⟶ 1,523:
26 words: {{"analyses","analysis"},{"atlantes","atlantis"},"...",{"vector","victor"},{"welles","willis"}}
</pre>
 
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<syntaxhighlight lang="prolog">:- dynamic dictionary_word/1.
 
main:-
Line 1,614 ⟶ 1,588:
welles -> willis
</pre>
 
 
=={{header|Python}}==
Needs Python 3.8 or above for the assignment operator in the list comprehension.
{{Works with|Python|3.8}}
<syntaxhighlight lang="python">'''Dictionary words twinned by (e -> i) replacement'''
 
 
Line 1,697 ⟶ 1,669:
('vector', 'victor')
('welles', 'willis')</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang=Quackery"quackery"> [ [] swap ]'[ swap
witheach [
dup nested
Line 1,757 ⟶ 1,728:
victor
willis</pre>
 
=={{header|R}}==
<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)
cbind(Before = dict, After = changed)[changed != dict & changed %in% dict & nchar(changed) > 5, ]</syntaxhighlight>
Line 1,790 ⟶ 1,760:
[25,] "vector" "victor"
[26,] "welles" "willis"</pre>
 
=={{header|Raku}}==
<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";</syntaxhighlight>
 
Line 1,803 ⟶ 1,772:
psychoses => psychosis rabbet => rabbit sterling => stirling synopses => synopsis
vector => victor welles => willis</pre>
 
=={{header|REXX}}==
This REXX version doesn't care what order the words in the dictionary are in, &nbsp; nor does it care what
Line 1,810 ⟶ 1,778:
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.
<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*/
if minL=='' | minL=="," then minL= 6 /*Not specified? Then use the default.*/
Line 1,871 ⟶ 1,839:
────────────────────────────── 26 words found that were changed with E ──► I, and with a minimum length of 6
</pre>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
load "stdlib.ring"
 
Line 1,936 ⟶ 1,903:
done...
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">words = File.readlines("unixdict.txt").map(&:chomp)
words.each do |word|
next if word.size < 6
Line 1,975 ⟶ 1,941:
welles -> willis
</pre>
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">use std::collections::BTreeSet;
use std::fs::File;
use std::io::{self, BufRead};
Line 2,038 ⟶ 2,003:
26. welles -> willis
</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var file = File("unixdict.txt")
 
if (!file.exists) {
Line 2,095 ⟶ 2,059:
26: welles <-> willis
</pre>
 
=={{header|Swift}}==
<syntaxhighlight lang="swift">import Foundation
 
func loadDictionary(path: String, minLength: Int) throws -> Set<String> {
Line 2,155 ⟶ 2,118:
26. welles -> willis
</pre>
 
=={{header|VBScript}}==
Run it in CScript.
<syntaxhighlight lang="vb">
with createobject("ADODB.Stream")
.charset ="UTF-8"
Line 2,216 ⟶ 2,178:
welles -> willis
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascript">import "io" for File
import "/sort" for Find
import "/fmt" for Fmt
Line 2,267 ⟶ 2,228:
26: welles -> willis
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang=XPL0"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,368 ⟶ 2,328:
welles -> willis
</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.}}
10,333

edits