Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,7 +1,7 @@
When two or more words are composed of the same characters, but in a different order, they are called [[wp:Anagram|anagrams]].
;Task
Using the word list at   http://wiki.puzzlers.org/pub/wordlists/unixdict.txt,
Using the word list at   http://wiki.puzzlers.org/pub/wordlists/unixdict.txt or [https://raw.githubusercontent.com/thundergnat/rc-run/refs/heads/master/rc/resources/unixdict.txt here],
<br>find the sets of words that share the same characters that contain the most words in them.
;Related tasks

View file

@ -1,69 +0,0 @@
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Indefinite_Ordered_Maps;
with Ada.Containers.Indefinite_Ordered_Sets;
procedure Words_Of_Equal_Characters is
package Set_Of_Words is new Ada.Containers.Indefinite_Ordered_Sets (String);
use Ada.Containers, Set_Of_Words;
package Anagrams is new Ada.Containers.Indefinite_Ordered_Maps (String, Set);
use Anagrams;
File : File_Type;
Result : Map;
Max : Count_Type := 1;
procedure Put (Position : Anagrams.Cursor) is
First : Boolean := True;
List : Set renames Element (Position);
procedure Put (Position : Set_Of_Words.Cursor) is
begin
if First then
First := False;
else
Put (',');
end if;
Put (Element (Position));
end Put;
begin
if List.Length = Max then
Iterate (List, Put'Access);
New_Line;
end if;
end Put;
begin
Open (File, In_File, "unixdict.txt");
loop
declare
Word : constant String := Get_Line (File);
Key : String (Word'Range) := (others => Character'Last);
List : Set;
Position : Anagrams.Cursor;
begin
for I in Word'Range loop
for J in Word'Range loop
if Key (J) > Word (I) then
Key (J + 1..I) := Key (J..I - 1);
Key (J) := Word (I);
exit;
end if;
end loop;
end loop;
Position := Find (Result, Key);
if Has_Element (Position) then
List := Element (Position);
Insert (List, Word);
Replace_Element (Result, Position, List);
else
Insert (List, Word);
Include (Result, Key, List);
end if;
Max := Count_Type'Max (Max, Length (List));
end;
end loop;
exception
when End_Error =>
Iterate (Result, Put'Access);
Close (File);
end Words_Of_Equal_Characters;

View file

@ -5,7 +5,7 @@ anagrams: #[]
loop wordset 'word [
anagram: sort to [:char] word
unless key? anagrams anagram ->
anagrams\[anagram]: new []
anagrams\[anagram]: []
anagrams\[anagram]: anagrams\[anagram] ++ word
]

View file

@ -1,243 +0,0 @@
*> TECTONICS
*> wget http://wiki.puzzlers.org/pub/wordlists/unixdict.txt
*> or visit https://sourceforge.net/projects/souptonuts/files
*> or snag ftp://ftp.openwall.com/pub/wordlists/all.gz
*> for a 5 million all language word file (a few phrases)
*> cobc -xj anagrams.cob [-DMOSTWORDS -DMOREWORDS -DALLWORDS]
*> ***************************************************************
identification division.
program-id. anagrams.
environment division.
configuration section.
repository.
function all intrinsic.
input-output section.
file-control.
select words-in
assign to wordfile
organization is line sequential
status is words-status
.
REPLACE ==:LETTERS:== BY ==42==.
data division.
file section.
fd words-in record is varying from 1 to :LETTERS: characters
depending on word-length.
01 word-record.
05 word-data pic x occurs 0 to :LETTERS: times
depending on word-length.
working-storage section.
>>IF ALLWORDS DEFINED
01 wordfile constant as "/usr/local/share/dict/all.words".
01 max-words constant as 4802100.
>>ELSE-IF MOSTWORDS DEFINED
01 wordfile constant as "/usr/local/share/dict/linux.words".
01 max-words constant as 628000.
>>ELSE-IF MOREWORDS DEFINED
01 wordfile constant as "/usr/share/dict/words".
01 max-words constant as 100000.
>>ELSE
01 wordfile constant as "unixdict.txt".
01 max-words constant as 26000.
>>END-IF
*> The 5 million word file needs to restrict the word length
>>IF ALLWORDS DEFINED
01 max-letters constant as 26.
>>ELSE
01 max-letters constant as :LETTERS:.
>>END-IF
01 word-length pic 99 comp-5.
01 words-status pic xx.
88 ok-status values '00' thru '09'.
88 eof-status value '10'.
*> sortable word by letter table
01 letter-index usage index.
01 letter-table.
05 letters occurs 1 to max-letters times
depending on word-length
ascending key letter
indexed by letter-index.
10 letter pic x.
*> table of words
01 sorted-index usage index.
01 word-table.
05 word-list occurs 0 to max-words times
depending on word-tally
ascending key sorted-word
indexed by sorted-index.
10 match-count pic 999 comp-5.
10 this-word pic x(max-letters).
10 sorted-word pic x(max-letters).
01 sorted-display pic x(10).
01 interest-table.
05 interest-list pic 9(8) comp-5
occurs 0 to max-words times
depending on interest-tally.
01 outer pic 9(8) comp-5.
01 inner pic 9(8) comp-5.
01 starter pic 9(8) comp-5.
01 ender pic 9(8) comp-5.
01 word-tally pic 9(8) comp-5.
01 interest-tally pic 9(8) comp-5.
01 tally-display pic zz,zzz,zz9.
01 most-matches pic 99 comp-5.
01 matches pic 99 comp-5.
01 match-display pic z9.
*> timing display
01 time-stamp.
05 filler pic x(11).
05 timer-hours pic 99.
05 filler pic x.
05 timer-minutes pic 99.
05 filler pic x.
05 timer-seconds pic 99.
05 filler pic x.
05 timer-subsec pic v9(6).
01 timer-elapsed pic 9(6)v9(6).
01 timer-value pic 9(6)v9(6).
01 timer-display pic zzz,zz9.9(6).
*> ***************************************************************
procedure division.
main-routine.
>>IF ALLWORDS DEFINED
display "** Words limited to " max-letters " letters **"
>>END-IF
perform show-time
perform load-words
perform find-most
perform display-result
perform show-time
goback
.
*> ***************************************************************
load-words.
open input words-in
if not ok-status then
display "error opening " wordfile upon syserr
move 1 to return-code
goback
end-if
perform until exit
read words-in
if eof-status then exit perform end-if
if not ok-status then
display wordfile " read error: " words-status upon syserr
end-if
if word-length equal zero then exit perform cycle end-if
>>IF ALLWORDS DEFINED
move min(word-length, max-letters) to word-length
>>END-IF
add 1 to word-tally
move word-record to this-word(word-tally) letter-table
sort letters ascending key letter
move letter-table to sorted-word(word-tally)
end-perform
move word-tally to tally-display
display trim(tally-display) " words" with no advancing
close words-in
if not ok-status then
display "error closing " wordfile upon syserr
move 1 to return-code
end-if
*> sort word list by anagram check field
sort word-list ascending key sorted-word
.
*> first entry in a list will end up with highest match count
find-most.
perform varying outer from 1 by 1 until outer > word-tally
move 1 to matches
add 1 to outer giving starter
perform varying inner from starter by 1
until sorted-word(inner) not equal sorted-word(outer)
add 1 to matches
end-perform
if matches > most-matches then
move matches to most-matches
initialize interest-table all to value
move 0 to interest-tally
end-if
move matches to match-count(outer)
if matches = most-matches then
add 1 to interest-tally
move outer to interest-list(interest-tally)
end-if
end-perform
.
*> only display the words with the most anagrams
display-result.
move interest-tally to tally-display
move most-matches to match-display
display ", most anagrams: " trim(match-display)
", with " trim(tally-display) " set" with no advancing
if interest-tally not equal 1 then
display "s" with no advancing
end-if
display " of interest"
perform varying outer from 1 by 1 until outer > interest-tally
move sorted-word(interest-list(outer)) to sorted-display
display sorted-display
" [" trim(this-word(interest-list(outer)))
with no advancing
add 1 to interest-list(outer) giving starter
add most-matches to interest-list(outer) giving ender
perform varying inner from starter by 1
until inner = ender
display ", " trim(this-word(inner))
with no advancing
end-perform
display "]"
end-perform
.
*> elapsed time
show-time.
move formatted-current-date("YYYY-MM-DDThh:mm:ss.ssssss")
to time-stamp
compute timer-value = timer-hours * 3600 + timer-minutes * 60
+ timer-seconds + timer-subsec
if timer-elapsed = 0 then
display time-stamp
move timer-value to timer-elapsed
else
if timer-value < timer-elapsed then
add 86400 to timer-value
end-if
subtract timer-elapsed from timer-value
move timer-value to timer-display
display time-stamp ", " trim(timer-display) " seconds"
end-if
.
end program anagrams.

View file

@ -13,7 +13,7 @@ extension op
= self.toArray().ascendant().summarize(new StringWriter());
}
public program()
public Program()
{
var start := Now;

View file

@ -1,87 +0,0 @@
(defun code-letters (str)
"Sort STR into alphabetized list of individual letters."
(sort (split-string str "" t) #'string<))
(defun code-letters-to-string (str)
"Sort STR alphabetically and combine into one string."
(apply #'concat (code-letters str)))
(defun remove-periods (str)
"Remove periods (full stops) from STR."
(string-replace "." "" str))
(defun list-pair (str)
"Create paired list from STR, STR (unchanged) and alphabetized order of STR."
;; Remove periods from alphabetized order to make regex matching easier
(let ((letter-list (remove-periods (code-letters-to-string str))))
(list letter-list str)))
(defun pair-up (words)
"Make list of lists of paired words, one alphabetized one original."
(let ((paired-list)
(temp-pair))
(dolist (word words)
(setq temp-pair (list-pair word))
(push temp-pair paired-list))
paired-list))
(defun create-list-of-numbers (my-list)
"Create list of numbers from MY-LIST."
(let ((list-of-numbers))
(dolist (one-pair my-list)
(push (car one-pair) list-of-numbers))
list-of-numbers))
(defun get-largest-number (my-list)
"Find largest number in MY-LIST."
(let ((list-of-numbers))
(setq list-of-numbers (create-list-of-numbers my-list))
(apply #'max list-of-numbers)))
(defun make-list-matching-words (coded-word-and-original number-and-code-pair)
"List original words whose code matches code in NUMBER-AND-CODE-PAIR."
(dolist (word-pair coded-word-and-original)
;; test if coded word in CODED-WORD-AND-ORIGINAL matches
;; coded word in NUMBER-AND-CODE-PAIR
(when (string= (nth 0 word-pair) (nth 1 number-and-code-pair))
;; insert the original word
(insert (format "%s " (nth 1 word-pair)))))
(insert "\n"))
(defun count-anagrams ()
"Count the number of anagrams in file wordlist.txt"
(let ((coded-word-and-original)
(just-coded-words)
(unique-coded-words)
(count-and-code)
(number-of-anagrams)
(largest-number))
;; Path below needs to be adapted to individual case
(find-file "~/Documents/Elisp/wordlist.txt")
(beginning-of-buffer)
;; create list of lists of coded words and originals
(setq coded-word-and-original (pair-up (split-string (buffer-string) "\n")))
(find-file "temp-all-coded")
(erase-buffer)
(dolist (number-and-code-pair coded-word-and-original)
;; make list of just the coded words
(push (nth 0 number-and-code-pair) just-coded-words))
(dolist (one-word just-coded-words)
;; write list of coded words to buffer for later processing
(insert (format "%s\n" one-word)))
;; create a list of coded words with no repetitions
(setq unique-coded-words (seq-uniq just-coded-words))
(dolist (one-code unique-coded-words)
(find-file "temp-all-coded")
(beginning-of-buffer)
;; count the number of times ONE-CODE appears in buffer
(setq number-of-anagrams (how-many (format "^%s$" one-code)))
(if (>= number-of-anagrams 1) ; eliminate "words" of zero length
(push (list number-of-anagrams one-code) count-and-code)))
(find-file "anagram-listing")
(erase-buffer)
(setq largest-number (get-largest-number count-and-code))
(dolist (number-and-code-pair count-and-code)
;; when the number in NUMBER-AND-CODE-PAIR = largest number of anagrams
(when (= (nth 0 number-and-code-pair) largest-number)
(make-list-matching-words coded-word-and-original number-and-code-pair)))))

View file

@ -1,74 +0,0 @@
(defun code-letters (str)
"Sort STR into alphabetized list of individual letters."
(sort (split-string str "" t) #'string<))
(defun code-letters-to-string (str)
"Sort STR alphabetically and combine into one string."
(apply #'concat (code-letters str)))
(defun add-to-hash (key value table)
"If KEY exists, add VALUE to list of values.
If KEY does not exist, associate value with KEY."
(let ((current-values))
(if (gethash key table)
(progn
(setq current-values (gethash key table))
(setq current-values (push value current-values))
(puthash key current-values table))
(puthash key (list value) table))))
(defun create-list-of-numbers (hash-table)
"Create a list of numbers from HASH-TABLE."
(let ((current-number)
(list-of-numbers))
(setq list-of-numbers (list)) ; omit?
(maphash (lambda (key value)
(setq current-number (car (gethash key hash-table)))
(push current-number list-of-numbers))
hash-table)
list-of-numbers))
(defun find-largest-number-in-hash (hash-table)
"Find largest number in HASH-TABLE."
(let ((list-of-numbers))
(setq list-of-numbers (create-list-of-numbers hash-table))
(apply #'max list-of-numbers)))
(defun find-longest-lists-of-anagrams (&optional file)
"Find the set(s) of largest number of anagrams in file wordlist.txt"
(let ((largest-number)
(hash-key)
(dictionary-table (make-hash-table :test 'equal)))
;; Path and filename below needs to be adapted to individual case if
;; FILE is *not* passed to this function
(with-temp-buffer
(insert-file-contents (or file "~/Documents/Elisp/wordlist.txt"))
(beginning-of-buffer)
;; set up hash table with key and word(s)
;; key = letters of word, but with letters in
;; alphabetical order. Create list word(s) associated
;; with key.
(dolist (current-word (split-string (buffer-string) "\n"))
(setq hash-key (code-letters-to-string current-word))
(add-to-hash hash-key current-word dictionary-table))
;; Count number of anagram words
(maphash (lambda (key value)
"Add number of anagram words to VALUE."
(add-to-hash key (length (gethash key dictionary-table)) dictionary-table))
dictionary-table)
;; find the size of the largest list(s) of anagrams
(setq largest-number (find-largest-number-in-hash dictionary-table)))
;; set up empty buffer to show results
(with-current-buffer (pop-to-buffer "anagram-listing")
(erase-buffer)
;; show results
(maphash (lambda (key value)
"Display longest lists of anagrams."
(when (= largest-number (car (gethash key dictionary-table)))
(mapc
(lambda (element)
"Insert ELEMENT followed by one space in buffer."
(insert (format "%s " element)))
(cdr (gethash key dictionary-table)))
(insert "\n")))
dictionary-table))))

View file

@ -1,49 +0,0 @@
include sort.e
function compare_keys(sequence a, sequence b)
return compare(a[1],b[1])
end function
constant fn = open("unixdict.txt","r")
sequence words, anagrams
object word
words = {}
while 1 do
word = gets(fn)
if atom(word) then
exit
end if
word = word[1..$-1] -- truncate new-line character
words = append(words, {sort(word), word})
end while
close(fn)
integer maxlen
maxlen = 0
words = custom_sort(routine_id("compare_keys"), words)
anagrams = {words[1]}
for i = 2 to length(words) do
if equal(anagrams[$][1],words[i][1]) then
anagrams[$] = append(anagrams[$], words[i][2])
elsif length(anagrams[$]) = 2 then
anagrams[$] = words[i]
else
if length(anagrams[$]) > maxlen then
maxlen = length(anagrams[$])
end if
anagrams = append(anagrams, words[i])
end if
end for
if length(anagrams[$]) = 2 then
anagrams = anagrams[1..$-1]
end if
for i = 1 to length(anagrams) do
if length(anagrams[i]) = maxlen then
for j = 2 to length(anagrams[i]) do
puts(1,anagrams[i][j])
puts(1,' ')
end for
puts(1,"\n")
end if
end for

View file

@ -1,13 +0,0 @@
$c = New-Object Net.WebClient
$words = -split ($c.DownloadString('http://wiki.puzzlers.org/pub/wordlists/unixdict.txt'))
$top_anagrams = $words `
| ForEach-Object {
$_ | Add-Member -PassThru NoteProperty Characters `
(-join (([char[]] $_) | Sort-Object))
} `
| Group-Object Characters `
| Group-Object Count `
| Sort-Object Count `
| Select-Object -First 1
$top_anagrams.Group | ForEach-Object { $_.Group -join ', ' }

View file

@ -1,43 +0,0 @@
$Timer = [System.Diagnostics.Stopwatch]::StartNew()
$uri = 'http://wiki.puzzlers.org/pub/wordlists/unixdict.txt'
$words = -split [Net.WebClient]::new().DownloadString($uri)
$anagrams = @{}
$maxAnagramCount = 0
foreach ($w in $words)
{
# Sort the characters in the word into alphabetical order
$chars=[char[]]$w
[array]::sort($chars)
$orderedChars = [string]::Join('', $chars)
# If no anagrams list for these chars, make one
if (-not $anagrams.ContainsKey($orderedChars))
{
$anagrams[$orderedChars] = [Collections.Generic.List[String]]::new()
}
# Add current word as an anagram of these chars,
# in a way which keeps the list available
($list = $anagrams[$orderedChars]).Add($w)
# Keep running score of max number of anagrams seen
if ($list.Count -gt $maxAnagramCount)
{
$maxAnagramCount = $list.Count
}
}
foreach ($entry in $anagrams.GetEnumerator())
{
if ($entry.Value.Count -eq $maxAnagramCount)
{
[string]::join('', $entry.Value)
}
}

View file

@ -1,70 +0,0 @@
Const adInteger = 3
Const adVarChar = 200
function charcnt(s,ch)
charcnt=0
for i=1 to len(s)
if mid(s,i,1)=ch then charcnt=charcnt+1
next
end function
set fso=createobject("Scripting.Filesystemobject")
dim a(122)
sfn=WScript.ScriptFullName
sfn= Left(sfn, InStrRev(sfn, "\"))
set f=fso.opentextfile(sfn & "unixdict.txt",1)
'words to dictionnary using acronym as key
set d=createobject("Scripting.Dictionary")
while not f.AtEndOfStream
erase a :cnt=0
s=trim(f.readline)
'tally chars
for i=1 to len(s)
n=asc(mid(s,i,1))
a(n)=a(n)+1
next
'build the anagram
k=""
for i= 48 to 122
if a(i) then k=k & string(a(i),chr(i))
next
'add to dict
if d.exists(k) then
b=d(k)
d(k)=b & " " & s
else
d(k)=s
end if
wend
'copy dictionnary to recorset to be able to sort it .Add nr of items as a new field
Set rs = CreateObject("ADODB.Recordset")
rs.Fields.Append "anag", adVarChar, 30
rs.Fields.Append "items", adInteger
rs.Fields.Append "words", adVarChar, 200
rs.open
for each k in d.keys
rs.addnew
rs("anag")=k
s=d(k)
rs("words")=s
rs("items")=charcnt(s," ")+1
rs.update
next
d.removeall
'do the query
rs.sort="items DESC, anag ASC"
rs.movefirst
it=rs("items")
while rs("items")=it
wscript.echo rs("items") & " (" &rs("anag") & ") " & rs("words")
rs.movenext
wend
rs.close