Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,13 +1,13 @@
import std.stdio, std.algorithm, std.range, std.string;
void main() {
import std.stdio, std.algorithm, std.range, std.string;
string[] result;
size_t maxLen;
foreach (string word; File("unixdict.txt").lines()) {
word = word.chomp();
immutable len = walkLength(word);
if (len < maxLen || !isSorted(word))
foreach (string word; "unixdict.txt".File.lines) {
word = word.chomp;
immutable len = word.walkLength;
if (len < maxLen || !word.isSorted)
continue;
if (len > maxLen) {
result = [word];
@ -16,5 +16,5 @@ void main() {
result ~= word;
}
writeln(result.join("\n"));
writefln("%-(%s\n%)", result);
}

View file

@ -1,5 +1,6 @@
void main() {
import std.stdio, std.algorithm, std.file, std.range;
string[] result;
size_t maxWalkLen;

View file

@ -1,6 +1,6 @@
import std.stdio, std.algorithm, std.range, std.file, std.string;
void main() {
import std.stdio, std.algorithm, std.range, std.file, std.string;
auto words = "unixdict.txt".readText.split.filter!isSorted;
immutable maxLen = words.map!q{a.length}.reduce!max;
writefln("%-(%s\n%)", words.filter!(w => w.length == maxLen));

View file

@ -1,17 +1,14 @@
import std.stdio, core.stdc.string, std.mmfile, std.algorithm;
const(char)[] findWord(const char[] s) pure nothrow @safe {
// return s.takeWhile!(c => c !in "\n\r");
const(char)[] findWord(const char[] s) pure nothrow @safe @nogc {
size_t wordEnd = 0;
while (wordEnd < s.length && s[wordEnd] != '\n'
&& s[wordEnd] != '\r')
while (wordEnd < s.length && s[wordEnd] != '\n' && s[wordEnd] != '\r')
wordEnd++;
return s[0 .. wordEnd];
}
void main() {
auto mmf = new MmFile("unixdict.txt",
MmFile.Mode.readCopyOnWrite, 0, null);
auto mmf = new MmFile("unixdict.txt", MmFile.Mode.readCopyOnWrite, 0, null);
auto txt = cast(char[])(mmf[]);
size_t maxLen = 0, outStart = 0;
@ -22,7 +19,7 @@ void main() {
const word = findWord(txt[wordStart .. $]);
wordStart += word.length;
if (word.length < maxLen || !word.isSorted())
if (word.length < maxLen || !word.isSorted)
continue;
if (word.length > maxLen) {
// Longer ordered word found, reset the out buffer.
@ -40,5 +37,5 @@ void main() {
txt[outStart++] = '\n'; // Words separator in out buffer.
}
write(txt[0 .. outStart]);
txt[0 .. outStart].write;
}

View file

@ -2,27 +2,26 @@
ifid = 'UNIXDICT.TXT' /*filename of the word dictionary*/
@.= /*placeholder for list of words. */
mL=0 /*maximum length of ordered words*/
call linein ifid,1,0 /*point to the first word in dict*/
/*(above)───in case file is open.*/
do j=1 while lines(ifid)\==0 /*keep reading until exhausted. */
call linein ifid, 1, 0 /*point to the first word in dict*/
/* [↑] in case the file is open.*/
do j=1 while lines(ifid)\==0 /*keep reading until exhausted. */
x=linein(ifid); w=length(x) /*get a word and also its length.*/
if w<mL then iterate /*if not long enough, ignore it. */
xU=x; upper xU /*create uppercase version of X.*/
if w<mL then iterate /*if not long enough, ignore it. */
xU=x; upper xU /*create uppercase version of X.*/
z=left(xU,1) /*now, see if the word is ordered*/
/*handle words of mixed case. */
do k=2 to w; _=substr(xU,k,1) /*process each letter in the word*/
if \datatype(_,'U') then iterate /*Not a letter? Then skip it. */
if _<z then iterate j /*is letter < than the previous ?*/
z=_ /*we have a newer current letter.*/
end /*k*/ /*(above) logic includes ≥ order.*/
/*handle words of mixed case.*/
do k=2 to w; _=substr(xU,k,1) /*process each letter in word*/
if \datatype(_,'U') then iterate /*Not a letter? Then skip it.*/
if _<z then iterate j /*is letter < than previous ?*/
z=_ /*have newer current letter. */
end /*k*/ /* [↑] logic includes≥order.*/
mL=w /*maybe define a new maximum len.*/
@.w=@.w x /*add orig. word to a word list.*/
end /*j*/
q=words(@.mL) /*just a handy-dandy var to have.*/
say q 'word's(q) "found (of length" mL')'; say /*show #words & length*/
do n=1 for q; say word(@.mL,n); end /*list all the words. */
#=words(@.mL) /*just a handy-dandy var to have.*/
say # 'word's(#) "found (of length" mL')'; say /*show #words & length*/
do n=1 for #; say word(@.mL,n); end /*list all the words. */
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────S subroutine────────────────────────*/
s: if arg(1)==1 then return ''; return 's' /*a simple pluralizer.*/

View file

@ -1,7 +1,7 @@
require 'open-uri'
ordered_words = open('http://www.puzzlers.org/pub/wordlists/unixdict.txt', 'r').select do |word|
word.chomp!
word.split( '' ).sort.join == word
word.strip!
word.chars.sort.join == word
end
grouped = ordered_words.group_by{ |word| word.size }