Changeable 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 18:
* [[Levenshtein distance]]
<br><br>
 
=={{header|11l}}==
{{trans|Nim}}
{{trans|Go}}
 
<syntaxhighlight lang="11l">V words = File(‘unixdict.txt’).read().split("\n").filter(word -> word.len > 11)
 
F hamming_dist(word1, word2)
Line 81 ⟶ 80:
Found 52 changeable words.
</pre>
 
=={{header|Ada}}==
<syntaxhighlight lang=Ada"ada">with Ada.Text_Io;
with Ada.Strings.Fixed;
with Ada.Containers.Indefinite_Vectors;
Line 164 ⟶ 162:
upperclassman <-> upperclassmen
</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">wordset: map read.lines relative "unixdict.txt" => strip
 
wordset: select wordset 'word -> 12 =< size word
Line 212 ⟶ 209:
underclassman - underclassmen
upperclassman - upperclassmen</pre>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang=AutoHotkey"autohotkey">FileRead, db, % A_Desktop "\unixdict.txt"
oWord := [], Found := []
for i, word in StrSplit(db, "`n", "`r")
Line 263 ⟶ 259:
underclassman <-> underclassmen
upperclassman <-> upperclassmen</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang=AWK"awk">
# syntax: GAWK -f CHANGEABLE_WORDS.AWK unixdict.txt
#
Line 370 ⟶ 365:
=={{header|C}}==
{{trans|Go}}
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Line 513 ⟶ 508:
52: upperclassmen -> upperclassman
</pre>
 
=={{header|C++}}==
{{trans|Go}}
<syntaxhighlight lang="cpp">#include <cstdlib>
#include <fstream>
#include <iomanip>
Line 621 ⟶ 615:
52: upperclassmen -> upperclassman
</pre>
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// 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 661 ⟶ 654:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<syntaxhighlight lang="factor">USING: assocs combinators.short-circuit formatting
io.encodings.ascii io.files kernel math math.combinatorics
math.distances sequences ;
Line 701 ⟶ 694:
upperclassman <-> upperclassmen
</pre>
 
=={{header|FreeBASIC}}==
Brute force method, reuses some code from [[Odd_words#FreeBASIC]].
<syntaxhighlight lang="freebasic">
#define NULL 0
 
Line 815 ⟶ 807:
upperclassman ---> upperclassmen
upperclassmen ---> upperclassman</pre>
 
=={{header|Go}}==
{{trans|Wren}}
<syntaxhighlight lang="go">package main
 
import (
Line 928 ⟶ 919:
52: upperclassmen -> upperclassman
</pre>
 
=={{header|J}}==
<syntaxhighlight lang=J"j"> ;:inv ({~ ~.@($ /:~"1@#: I.@,)@(1=+/ .~: ::0:&>/~))(#~ 11<#@>) cutLF fread'unixdict.txt'
aristotelean aristotelian
claustrophobia claustrophobic
Line 957 ⟶ 947:
underclassman underclassmen
upperclassman upperclassmen</syntaxhighlight>
 
=={{header|Java}}==
{{trans|Go}}
<syntaxhighlight lang="java">import java.io.*;
import java.util.*;
 
Line 1,061 ⟶ 1,050:
52: upperclassmen -> upperclassman
</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<syntaxhighlight lang="jq"># Emit a stream of words "greater than" the input word that differ by just one character.
def changeable_to($dict):
. as $w
Line 1,111 ⟶ 1,099:
upperclassman <=> upperclassmen
</pre>
 
=={{header|Julia}}==
See [[Alternade_words#Julia]] for the foreachword function.
<syntaxhighlight lang="julia">const alts = Set{String}()
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,148 ⟶ 1,135:
underclassman <=> underclassmen upperclassman <=> upperclassmen
</pre>
 
=={{header|Nim}}==
Using the standard module <code>std/editdistance</code> to get the distance between two words.
<syntaxhighlight lang=Nim"nim">import std/editdistance, sugar
 
# Build list of words with length >= 12.
Line 1,202 ⟶ 1,188:
 
Found 52 changeable words.</pre>
 
=={{header|Perl}}==
<syntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict;
Line 1,249 ⟶ 1,234:
underclassman <-> underclassmen
upperclassman <-> upperclassmen
</pre> =={{header|Perl}}==
<syntaxhighlight lang="perl">#!/usr/bin/perl
 
=={{header|Perl}}==
<syntaxhighlight lang=perl>#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Changeable_words
Line 1,290 ⟶ 1,273:
26: upperclassman <-> upperclassmen
</pre>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<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,321 ⟶ 1,303:
upperclassman <=> upperclassmen
</pre>
 
=={{header|Prolog}}==
{{works with|SWI Prolog}}
{{trans|Go}}
<syntaxhighlight lang="prolog">:- dynamic dictionary_word/1.
 
main:-
Line 1,433 ⟶ 1,414:
52: upperclassmen -> upperclassman
</pre>
 
=={{header|Python}}==
 
<syntaxhighlight lang="python">from collections import defaultdict, Counter
 
 
Line 1,512 ⟶ 1,492:
underclassman From underclassmen
upperclassman From upperclassmen</pre>
 
=={{header|Raku}}==
Sorensen-Dice is very fast to calculate similarities but isn't great for detecting small changes. Levenshtein is great for detecting small changes but isn't very fast.
 
Get the best of both worlds by doing an initial filter with Sorensen, then get exact results with Levenshtein.
<syntaxhighlight lang="raku" line>use Text::Levenshtein;
use Text::Sorensen :sorensen;
 
Line 1,563 ⟶ 1,542:
25: underclassman <-> underclassmen
26: upperclassman <-> upperclassmen</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,569 ⟶ 1,547:
 
It also allows the minimum length to be specified on the command line (CL) as well as the dictionary file identifier.
<syntaxhighlight lang="rexx">/*REXX program finds changeable words (within an identified dict.), changing any letter.*/
parse arg minL iFID . /*obtain optional arguments from the CL*/
if minL=='' | minL=="," then minL= 12 /*Not specified? Then use the default.*/
Line 1,663 ⟶ 1,641:
────────────────────────────── 52 changeable words found with a minimum length of 12
</pre>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
cStr = read("unixdict.txt")
wordList = str2list(cStr)
Line 1,760 ⟶ 1,737:
done...
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">words = File.open("unixdict.txt").readlines.map(&:chomp).select{|w| w.size > 11 }
 
size_groups = words.group_by(&:size).sort.map(&:last)
Line 1,803 ⟶ 1,779:
=={{header|Sidef}}==
{{trans|Perl}}
<syntaxhighlight lang="ruby">var file = File("unixdict.txt")
 
if (!file.exists) {
Line 1,861 ⟶ 1,837:
26: upperclassman <-> upperclassmen
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-fmt}}
Using the Hamming Distance between two equal length strings which needs to be 1 here:
<syntaxhighlight lang="ecmascript">import "io" for File
import "/fmt" for Fmt
 
Line 1,954 ⟶ 1,929:
52: upperclassmen -> upperclassman
</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
10,333

edits