This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,19 @@
USING: fry grouping io io.encodings.utf8 io.files kernel math
math.order sequences unicode.case ;
IN: ordered-words
CONSTANT: dict-file "vocab:ordered-words/unixdict.txt"
: word-list ( -- seq )
dict-file utf8 file-lines ;
: ordered-word? ( word -- ? )
>lower 2 <clumps> [ first2 <= ] all? ;
: filter-longest-words ( seq -- seq' )
dup [ length ] [ max ] map-reduce
'[ length _ = ] filter ;
: main ( -- )
word-list [ ordered-word? ] filter
filter-longest-words [ print ] each ;

View file

@ -0,0 +1,30 @@
class Main
{
public static Bool ordered (Str word)
{
word.chars.all |Int c, Int i -> Bool|
{
(i == (word.size-1) || c <= word.chars[i+1])
}
}
public static Void main ()
{
Str[] words := [,]
File(`unixdict.txt`).eachLine |Str word|
{
if (ordered(word))
{
if (words.isEmpty || words.first.size < word.size)
{ // reset the list
words = [word]
}
else if (words.size >= 1 && words.first.size == word.size)
{ // add word to existing ones
words.add (word)
}
}
}
echo (words.join (" "))
}
}

View file

@ -0,0 +1,9 @@
def isOrdered = { word -> def letters = word as List; letters == ([] + letters).sort() }
assert isOrdered('abbey')
assert !isOrdered('cat')
def dictUrl = new URL('http://www.puzzlers.org/pub/wordlists/unixdict.txt')
def orderedWords = dictUrl.readLines().findAll { isOrdered(it) }
def owMax = orderedWords*.size().max()
orderedWords.findAll { it.size() == owMax }.each { println it }

View file

@ -0,0 +1,10 @@
link strings
procedure main(A)
f := open(\A[1]) | stop("Give dictionary file name on command line")
every (maxLen := 0, maxLen <= *(w := !f), w == csort(w)) do {
if maxLen <:= *w then maxList := [] #discard any shorter sorted words
put(maxList, w)
}
every write(!\maxList)
end

View file

@ -0,0 +1,5 @@
require'web/gethttp'
dict=: gethttp'http://www.puzzlers.org/pub/wordlists/unixdict.txt'
oWords=: (#~ ] = /:~L:0) <;._2 dict-.CR
;:inv (#~ (= >./)@:(#@>))oWords
abbott accent accept access accost almost bellow billow biopsy chilly choosy choppy effort floppy glossy knotty

View file

@ -0,0 +1,17 @@
w@&d=|/d:#:'w:d@&&/'{~x<y}':'d:0:"unixdict.txt"
("abbott"
"accent"
"accept"
"access"
"accost"
"almost"
"bellow"
"billow"
"biopsy"
"chilly"
"choosy"
"choppy"
"effort"
"floppy"
"glossy"
"knotty")

View file

@ -0,0 +1,37 @@
: >string-index
"" split
"&'0123456789abcdefghijklmnopqrstuvwxyz" "" split
swap index collapse ;
: chars "" split length swap drop ;
: cr "\n" . ;
: nip swap drop ;
: ordered?
dup grade subscript != '+ reduce if 0 else -1 then ;
: filtering
[] '_ set
0 do read
2dup chars
<=
if dup >string-index ordered?
if 2dup chars
<
if nip dup chars swap
[] '_ set
then
_ swap append '_ set
'. . # progress dot
else drop
then
else drop
then
eof if break then loop
cr _ . cr
;
: ordered-words
'< 'unixdict.txt open 'fh set
fh fin filtering fh close ;
ordered-words

View file

@ -0,0 +1,33 @@
'Ordered wordsFrom Rosetta Code
open "unixdict.txt" for input as #1
'this is not normal DOS/Windows file.
'It LF delimited, not CR LF
'So Line input would not work.
lf$=chr$(10)
curLen=0
wordList$=""
while not(eof(#1))
a$=inputto$(#1, lf$)
'now, check word
flag = 1
c$ = left$(a$,1)
for i = 2 to len(a$)
d$ = mid$(a$,i,1)
if c$>d$ then flag=0: exit for
c$=d$
next
'ckecked, proceed if ordered word
if flag then
if curLen=len(a$) then
wordList$=wordList$+" "+a$
else
if curLen<len(a$) then
curLen=len(a$)
wordList$=a$
end if
end if
end if
wend
close #1
print wordList$

View file

@ -0,0 +1,5 @@
Module[{max,
data = Select[Import["http://www.puzzlers.org/pub/wordlists/unixdict.txt", "List"],
OrderedQ[Characters[#]] &]},
max = Max[StringLength /@ data];
Select[data, StringLength[#] == max &]]

View file

@ -0,0 +1,3 @@
maxWords[language_String] := Module[{max,data = Select[DictionaryLookup[{language, "*"}],OrderedQ[Characters[#]] &]},
max = Max[StringLength /@ data];
Select[data, StringLength[#] == max &]]