Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -1,9 +1,9 @@
import std.stdio, std.algorithm, std.range, std.string, std.exception;
import std.stdio, std.algorithm, std.string, std.exception, std.file;
void main() {
string[][const ubyte[]] an;
foreach (w; "unixdict.txt".File.byLine(KeepTerminator.no))
an[w.dup.representation.sort().release.assumeUnique] ~= w.idup;
string[][ubyte[]] an;
foreach (w; "unixdict.txt".readText.splitLines)
an[w.dup.representation.sort().release.assumeUnique] ~= w;
immutable m = an.byValue.map!q{ a.length }.reduce!max;
writefln("%(%s\n%)", an.byValue.filter!(ws => ws.length == m));
}

View file

@ -1,13 +1,14 @@
#define system.
#define system'collections.
#define extensions'text.
#define system'routines.
#define extensions.
#define extensions'text.
// --- Normalized ---
#symbol Normalized = &&:aLiteral
#symbol Normalized = (:aLiteral)
[
^ Summing new:(String new) foreach:(arrayControl sort:(stringControl toArray:aLiteral)) Literal.
^ Summing new:(String new) foreach:(arrayControl sort:(literalControl toArray:aLiteral)) literal.
].
// --- Program ---
@ -16,20 +17,20 @@
[
#var aDictionary := Dictionary new.
textFileControl forEachLine:"unixdict.txt" &do: &&:aWord
textFileControl forEachLine:"unixdict.txt" &do: aWord
[
#var aKey := Normalized eval:aWord.
#var anItem := aDictionary @ aKey.
#var aKey := Normalized:aWord.
#var anItem := aDictionary getAt &key:aKey.
nil == anItem ?
[
anItem := List new.
aDictionary setAt:aKey:anItem.
aDictionary set &key:aKey &value:anItem.
].
anItem += aWord.
].
listControl sort:aDictionary &with: &&:aFormer:aLater [ aFormer Value Count > aLater Value Count ].
listControl sort:aDictionary &with: (:aFormer:aLater) [ aFormer value length > aLater value length ].
listControl foreach:aDictionary &top:20 &do: &&:aPair [ console writeLine:(ListPresenter new:(aPair Value)) ].
controlEx foreach:aDictionary &top:20 &do: aPair [ consoleEx writeLine:(aPair value) ].
].

View file

@ -1,22 +1,30 @@
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"sort"
"strings"
)
func main() {
b, err := ioutil.ReadFile("unixdict.txt")
r, err := http.Get("http://www.puzzlers.org/pub/wordlists/unixdict.txt")
if err != nil {
fmt.Println(err)
return
}
b, err := ioutil.ReadAll(r.Body)
r.Body.Close()
if err != nil {
fmt.Println(err)
return
}
var ma int
m := make(map[string][]string)
for _, word := range strings.Split(string(b), "\n") {
bs := byteSlice(word)
var bs byteSlice
m := make(map[string][][]byte)
for _, word := range bytes.Fields(b) {
bs = append(bs[:0], byteSlice(word)...)
sort.Sort(bs)
k := string(bs)
a := append(m[k], word)
@ -27,13 +35,13 @@ func main() {
}
for _, a := range m {
if len(a) == ma {
fmt.Println(a)
fmt.Printf("%s\n", a)
}
}
}
type byteSlice []byte
func (b byteSlice) Len() int { return len(b) }
func (b byteSlice) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
func (b byteSlice) Len() int { return len(b) }
func (b byteSlice) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
func (b byteSlice) Less(i, j int) bool { return b[i] < b[j] }

View file

@ -0,0 +1,52 @@
import tables
proc sort(s: string): string =
var
i,j: int
t: char
result = s
for i in 0 .. result.len - 1:
j = i
t = result[j]
while(j > 0) and (result[j - 1] > t):
result[j] = result[j - 1]
dec(j)
result[j] = t
# end sort
proc maxCount(an: TTable[string,seq[string]]): int =
result = 0
for v in an.values:
if v.len > result:
result = v.len
#end maxCount
proc showAnagrams(s: seq[string]) =
for v in s:
write(stdout,v)
write(stdout," ")
writeln(stdout,"")
#end showAnagrams
proc processFile: TTable[string,seq[string]] =
var
fd: TFile
sline,line: string
result = initTable[string,seq[string]]()
if Open(fd,"unixdict.txt"):
while not EndOfFile(fd):
line = fd.readLine()
sline = sort(line)
if result.hasKey(sline):
result[sline] = result[sline] & line
else:
result[sline] = @[line]
var
anagrams:TTable[string,seq[string]] = processFile()
max = anagrams.maxCount
for v in anagrams.values:
if v.len == max: showAnagrams(v)

View file

@ -23,7 +23,7 @@ let () =
try Hashtbl.find h k
with Not_found -> []
in
Hashtbl.add h k (w::l);
Hashtbl.replace h k (w::l);
done with End_of_file -> ();
let n = Hashtbl.fold (fun _ lw n -> max n (List.length lw)) h 0 in
Hashtbl.iter (fun _ lw ->

View file

@ -1,14 +1,4 @@
require 'open-uri'
anagram = nil
open('http://www.puzzlers.org/pub/wordlists/unixdict.txt') do |f|
anagram = f.read.split.group_by {|s| s.each_char.sort}
end
count = anagram.each_value.map {|ana| ana.length}.max
anagram.each_value do |ana|
if ana.length >= count
p ana
end
end
anagrams = open('http://www.puzzlers.org/pub/wordlists/unixdict.txt'){|f| f.read.split.group_by{|w| w.each_char.sort} }
anagrams.values.group_by(&:size).max.last.each{|group| puts group.join(", ") }