Changeable words: Difference between revisions
m
syntax highlighting fixup automation
(J) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 23:
{{trans|Go}}
<
F hamming_dist(word1, word2)
Line 46:
count += 2
print("\nFound "count‘ changeable words.’)</
{{out}}
Line 83:
=={{header|Ada}}==
<
with Ada.Strings.Fixed;
with Ada.Containers.Indefinite_Vectors;
Line 134:
end loop;
end loop;
end Changeable;</
{{out}}
<pre>
Line 167:
=={{header|Arturo}}==
<
wordset: select wordset 'word -> 12 =< size word
Line 182:
loop unique results 'result ->
print join.with:" - " result</
{{out}}
Line 214:
=={{header|AutoHotkey}}==
<
oWord := [], Found := []
for i, word in StrSplit(db, "`n", "`r")
Line 235:
num++
return (StrLen(s1) - num = 1)
}</
{{out}}
<pre>aristotelean <-> aristotelian
Line 265:
=={{header|AWK}}==
<
# syntax: GAWK -f CHANGEABLE_WORDS.AWK unixdict.txt
#
Line 312:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 370:
=={{header|C}}==
{{trans|Go}}
<
#include <stdlib.h>
#include <string.h>
Line 455:
free(dictionary);
return EXIT_SUCCESS;
}</
{{out}}
Line 516:
=={{header|C++}}==
{{trans|Go}}
<
#include <fstream>
#include <iomanip>
Line 563:
}
return EXIT_SUCCESS;
}</
{{out}}
Line 623:
=={{header|F_Sharp|F#}}==
<
// Changeable words: Nigel Galloway. June 14th., 2021
let fN g=Seq.fold2(fun z n g->z+if n=g then 0 else 1) 0 g
Line 629:
seq{use n=System.IO.File.OpenText("unixdict.txt") in while not n.EndOfStream do yield n.ReadLine()}|>Seq.filter(fun n->n.Length>11)
|>List.ofSeq|>List.groupBy(fun n->n.Length)|>Seq.collect(fun(_,n)->fG [] n)|>Seq.iter(fun(n,g)->printfn "%s <=> %s" n g)
</syntaxhighlight>
{{out}}
<pre>
Line 661:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<
io.encodings.ascii io.files kernel math math.combinatorics
math.distances sequences ;
Line 671:
[ length 11 > ] filter
2 [ first2 changeable? ] filter-combinations
[ "%s <-> %s\n" printf ] assoc-each</
{{out}}
<pre>
Line 704:
=={{header|FreeBASIC}}==
Brute force method, reuses some code from [[Odd_words#FreeBASIC]].
<
#define NULL 0
Line 760:
next i
curr = curr->nxt
wend</
{{out}}
<pre>
Line 818:
=={{header|Go}}==
{{trans|Wren}}
<
import (
Line 870:
}
}
}</
{{out}}
Line 930:
=={{header|J}}==
<
aristotelean aristotelian
claustrophobia claustrophobic
Line 956:
spectroscope spectroscopy
underclassman underclassmen
upperclassman upperclassmen</
=={{header|Java}}==
{{trans|Go}}
<
import java.util.*;
Line 1,003:
return count;
}
}</
{{out}}
Line 1,065:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<
def changeable_to($dict):
. as $w
Line 1,080:
| . as $w
| [changeable_to($dict)] | unique[]
| "\($w) <=> \(.)"</
Invocation: jq -n -rR -f changeable-words.jq unixdict.txt
{{out}}
Line 1,114:
=={{header|Julia}}==
See [[Alternade_words#Julia]] for the foreachword function.
<
function ischangeable(w, d)
alternatives = [w[1:p[1]-1] * p[2] * w[p[1]+1:end] for p in Iterators.product(1:length(w), 'a':'z')]
Line 1,130:
foreachword("unixdict.txt", ischangeable, minlen = 12, colwidth=40, numcols=2)
</
<pre>
Word source: unixdict.txt
Line 1,151:
=={{header|Nim}}==
Using the standard module <code>std/editdistance</code> to get the distance between two words.
<
# Build list of words with length >= 12.
Line 1,169:
inc count, 2
echo "\nFound ", count, " changeable words."</
{{out}}
Line 1,204:
=={{header|Perl}}==
<
use strict;
Line 1,220:
}
push @{ $words[length] }, $_;
}</
{{out}}
<pre>
Line 1,252:
=={{header|Perl}}==
<
use strict; # https://rosettacode.org/wiki/Changeable_words
Line 1,260:
my $count = 0;
printf "%3d: %15s <-> %s\n", ++$count, $1, $4
while /^ ((\N*)\N(\N*)) \n(?=.*^ (\2\N\3) \n)/gmsx;</
{{out}}
<pre>
Line 1,292:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">changeable</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">b</span><span style="color: #0000FF;">)</span>
Line 1,309:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</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 changeable words found:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)})</span>
<!--</
{{out}}
<pre>
Line 1,325:
{{works with|SWI Prolog}}
{{trans|Go}}
<
main:-
Line 1,375:
Count1 is Count + 1,
Count1 < 2,
hamming_distance(Chars1, Chars2, Dist, Count1).</
{{out}}
Line 1,436:
=={{header|Python}}==
<
Line 1,474:
print(f"\n{len(cwords)} words that are from changing a char from other words:")
for v in sorted(cwords):
print(f" {v[0]:12} From {', '.join(v[1:])}")</
{{out}}
Line 1,517:
Get the best of both worlds by doing an initial filter with Sorensen, then get exact results with Levenshtein.
<syntaxhighlight lang=raku
use Text::Sorensen :sorensen;
Line 1,535:
%skip{$_}++ for @sorensens[@levenshtein];
": {$this.fmt('%14s')} <-> ", @sorensens[@levenshtein].join: ', ';
}</
{{out}}
<pre> 1: aristotelean <-> aristotelian
Line 1,569:
It also allows the minimum length to be specified on the command line (CL) as well as the dictionary file identifier.
<
parse arg minL iFID . /*obtain optional arguments from the CL*/
if minL=='' | minL=="," then minL= 12 /*Not specified? Then use the default.*/
Line 1,605:
#= # - 1 /*adjust word count because of DO loop.*/
say copies('─', 30) # "words ("n 'usable words) in the dictionary file: ' iFID
return</
{{out|output|text= when using the default inputs:}}
<pre>
Line 1,665:
=={{header|Ring}}==
<
cStr = read("unixdict.txt")
wordList = str2list(cStr)
Line 1,701:
see "done..." + nl
</syntaxhighlight>
Output:
<pre>
Line 1,762:
=={{header|Ruby}}==
<
size_groups = words.group_by(&:size).sort.map(&:last)
Line 1,771:
puts "Found #{res.size} changeable word pairs:"
res.each{|w1, w2|puts "#{w1} - #{w2}" }
</syntaxhighlight>
{{out}}
<pre>Found 26 changeable word pairs:
Line 1,803:
=={{header|Sidef}}==
{{trans|Perl}}
<
if (!file.exists) {
Line 1,831:
}
bucket{len} << word
}</
{{out}}
<pre>
Line 1,865:
{{libheader|Wren-fmt}}
Using the Hamming Distance between two equal length strings which needs to be 1 here:
<
import "/fmt" for Fmt
Line 1,896:
}
}
}</
{{out}}
Line 1,956:
=={{header|XPL0}}==
<
int Dict(26000); \pointers to words (enough for unixdict.txt)
int DictSize; \actual number of pointers in Dict
Line 2,029:
DI:= DI+1;
until DI >= DictSize;
]</
{{out}}
|