September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -2,7 +2,7 @@ When two or more words are composed of the same characters, but in a different o
{{task heading}}
Using the word list at   http://www.puzzlers.org/pub/wordlists/unixdict.txt,
Using the word list at   http://wiki.puzzlers.org/pub/wordlists/unixdict.txt,
<br>find the sets of words that share the same characters that contain the most words in them.
{{task heading|Related tasks}}

View file

@ -1,36 +1,37 @@
import system'routines.
import system'io.
import system'collections.
import extensions.
import extensions'routines.
import extensions'text.
import system'routines;
import system'io;
import system'collections;
import extensions;
import extensions'routines;
import extensions'text;
extension op
{
T<literal> normalized
= self toArray; ascendant; summarize(StringWriter new).
string normalized()
= self.toArray().ascendant().summarize(new StringWriter());
}
public program
[
auto aDictionary := Map<literal,object>().
File new("unixdict.txt"); forEachLine(:aWord)
[
var s := aWord.
var aKey := aWord normalized.
var anItem := aDictionary[aKey].
if (nil == anItem)
[
anItem := ArrayList new.
aDictionary[aKey] := anItem.
].
public program()
{
auto dictionary := new Map<string,object>();
anItem append:aWord.
].
File.assign("unixdict.txt").forEachLine:(word)
{
var key := word.normalized();
var item := dictionary[key];
if (nil == item)
{
item := new ArrayList();
dictionary[key] := item
};
aDictionary values;
sort(:aFormer:aLater)( aFormer item2; length > aLater item2; length );
top:20; forEach(:aPair)[ console printLine(aPair item2) ].
item.append:word
};
console readChar
]
dictionary.Values
.sort:(former,later => former.Item2.Length > later.Item2.Length )
.top:20
.forEach:(pair){ console.printLine(pair.Item2) };
console.readChar()
}

View file

@ -1,15 +1,12 @@
use LWP::Simple;
use List::Util qw(max);
use List::Util 'max';
my @words = split(' ', get('http://www.puzzlers.org/pub/wordlists/unixdict.txt'));
my @words = split "\n", do { local( @ARGV, $/ ) = ( 'unixdict.txt' ); <> };
my %anagram;
foreach my $word (@words) {
push @{ $anagram{join('', sort(split(//, $word)))} }, $word;
for my $word (@words) {
push @{ $anagram{join '', sort split '', $word} }, $word;
}
my $count = max(map {scalar @$_} values %anagram);
foreach my $ana (values %anagram) {
if (@$ana >= $count) {
print "@$ana\n";
}
for my $ana (values %anagram) {
print "@$ana\n" if @$ana == $count;
}

View file

@ -1,7 +1,3 @@
use LWP::Simple;
for (split ' ' => get 'http://www.puzzlers.org/pub/wordlists/unixdict.txt')
{push @{$anagram{ join '' => sort split // }}, $_}
push @{$anagram{ join '' => sort split '' }}, $_ for @words;
$max > @$_ or $max = @$_ for values %anagram;
@$_ >= $max and print "@$_\n" for values %anagram;
@$_ == $max and print "@$_\n" for values %anagram;

View file

@ -1,5 +1,5 @@
$c = New-Object Net.WebClient
$words = -split ($c.DownloadString('http://www.puzzlers.org/pub/wordlists/unixdict.txt'))
$words = -split ($c.DownloadString('http://wiki.puzzlers.org/pub/wordlists/unixdict.txt'))
$top_anagrams = $words `
| ForEach-Object {
$_ | Add-Member -PassThru NoteProperty Characters `

View file

@ -0,0 +1,43 @@
$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

@ -0,0 +1,26 @@
import java.util.Map;
void setup() {
String[] words = loadStrings("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt");
topAnagrams(words);
}
void topAnagrams (String[] words){
HashMap<String, StringList> anagrams = new HashMap<String, StringList>();
int maxcount = 0;
for (String word : words) {
char[] chars = word.toCharArray();
chars = sort(chars);
String key = new String(chars);
if (!anagrams.containsKey(key)) {
anagrams.put(key, new StringList());
}
anagrams.get(key).append(word);
maxcount = max(maxcount, anagrams.get(key).size());
}
for (StringList ana : anagrams.values()) {
if (ana.size() >= maxcount) {
println(ana);
}
}
}

View file

@ -0,0 +1,111 @@
'''Largest anagram groups found in list of words.'''
from os.path import expanduser
from itertools import groupby
from operator import eq
# main :: IO ()
def main():
'''Largest anagram groups in local unixdict.txt'''
print(unlines(
largestAnagramGroups(
lines(readFile('unixdict.txt'))
)
))
# largestAnagramGroups :: [String] -> [[String]]
def largestAnagramGroups(ws):
'''A list of the anagram groups of
of the largest size found in a
given list of words.
'''
# wordChars :: String -> (String, String)
def wordChars(w):
'''A word paired with its
AZ sorted characters
'''
return (''.join(sorted(w)), w)
groups = list(map(
compose(list)(snd),
groupby(
sorted(
map(wordChars, ws),
key=fst
),
key=fst
)
))
intMax = max(map(len, groups))
return list(map(
compose(unwords)(curry(map)(snd)),
filter(compose(curry(eq)(intMax))(len), groups)
))
# GENERIC -------------------------------------------------
# compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
def compose(g):
'''Right to left function composition.'''
return lambda f: lambda x: g(f(x))
# curry :: ((a, b) -> c) -> a -> b -> c
def curry(f):
'''A curried function derived
from an uncurried function.'''
return lambda a: lambda b: f(a, b)
# fst :: (a, b) -> a
def fst(tpl):
'''First member of a pair.'''
return tpl[0]
# lines :: String -> [String]
def lines(s):
'''A list of strings,
(containing no newline characters)
derived from a single new-line delimited string.'''
return s.splitlines()
# from os.path import expanduser
# readFile :: FilePath -> IO String
def readFile(fp):
'''The contents of any file at the path
derived by expanding any ~ in fp.'''
with open(expanduser(fp), 'r', encoding='utf-8') as f:
return f.read()
# snd :: (a, b) -> b
def snd(tpl):
'''Second member of a pair.'''
return tpl[1]
# unlines :: [String] -> String
def unlines(xs):
'''A single string derived by the intercalation
of a list of strings with the newline character.'''
return '\n'.join(xs)
# unwords :: [String] -> String
def unwords(xs):
'''A space-separated string derived from
a list of words.'''
return ' '.join(xs)
# MAIN ---
if __name__ == '__main__':
main()