Anonymous user
Ordered words: Difference between revisions
m
Fix functional CL dict path
m (→{{header|J}}: unixdict.txt uses unix format -- no carriage returns) |
imported>GoulashAmateur m (Fix functional CL dict path) |
||
(25 intermediate revisions by 16 users not shown) | |||
Line 24:
{{trans|Python}}
<
V ordered = words.filter(word -> word == sorted(word
V maxlen = max(ordered, key' w -> w.len).len
V maxorderedwords = ordered.filter(word -> word.len == :maxlen)
print(maxorderedwords.join(‘ ’))</
{{out}}
<pre>
abbott accent accept access accost almost bellow billow biopsy chilly choosy choppy effort floppy glossy knotty
</pre>
=={{header|Acornsoft Lisp}}==
In <code>find-longest-ordered-words</code>, <code>len</code>, <code>word</code>, and <code>words</code> are used as local variables. <code>open</code> returns an integer as a file-handle. <code>chars</code> returns the number of characters in a symbol's name. <code>eq</code> can be used to compare numbers for equality.
<syntaxhighlight lang="lisp">
(defun longest-ordered-words ()
(find-longest-ordered-words
(open 'notes/unixdict!.txt t)))
(defun find-longest-ordered-words
(h (len . 0) (word) (words))
(loop
(until (eof h)
(close h)
words)
(setq word (readline h))
(cond ((lessp (chars word) len))
((not (ordered-p word)))
((eq (chars word) len)
(setq words (cons word words)))
(t
(setq len (chars word))
(setq words (list word))))))
(defun ordered-p (word)
(nondecreasing-p
(mapc ordinal (explode word))))
(defun nondecreasing-p (numbers)
(or (null numbers)
(null (cdr numbers))
(and (not (greaterp (car numbers) (cadr numbers)))
(nondecreasing-p (cdr numbers)))))
</syntaxhighlight>
{{Out}}
<code>(longest-ordered-words)</code> will return
<pre>
(knotty glossy floppy effort
choppy choosy chilly biopsy
billow bellow almost accost
access accept accent abbott)
</pre>
=={{header|Action!}}==
In the following solution the input file is loaded from H6 drive. Altirra emulator automatically converts CR/LF character from ASCII into 155 character in ATASCII charset used by Atari 8-bit computer when one from H6-H10 hard drive under DOS 2.5 is used.
<
BYTE FUNC IsOrderedWord(CHAR ARRAY word)
Line 93 ⟶ 138:
FindWords(fname,max)
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Ordered_words.png Screenshot from Atari 8-bit computer]
Line 104 ⟶ 149:
=={{header|Ada}}==
<syntaxhighlight lang="ada">
with Ada.Text_IO, Ada.Containers.Indefinite_Vectors;
use Ada.Text_IO;
Line 137 ⟶ 182:
Close (File);
end Ordered_Words;
</syntaxhighlight>
Output:
Line 158 ⟶ 203:
=={{header|Aime}}==
<
ordered(data s)
{
Line 196 ⟶ 241:
return 0;
}</
{{out}}
<pre>abbott
Line 217 ⟶ 262:
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}.
<
BEGIN
FOR i TO UPB s - 1 DO IF s[i] > s[i+1] THEN return false FI OD;
Line 261 ⟶ 306:
IF UPB words[i] = max length THEN print((words[i], newline)) FI
OD
FI</
{{out}}
<pre>Maximum length of ordered words: 6
Line 280 ⟶ 325:
glossy
knotty</pre>
=={{header|Amazing Hopper}}==
<syntaxhighlight lang="c">
#include <basico.h>
#define MAX_LINE 30
algoritmo
fd=0
word={}, result={}
old_word="",new_word=""
fijar separador (NULO)
abrir para leer("basica/unixdict.txt",fd)
iterar mientras ' no es fin de archivo (fd) '
usando 'MAX_LINE', leer línea desde(fd),
---copiar en 'old_word'---, separar para 'word '
word, ---retener--- ordenar esto,
encadenar en 'new_word'
new_word, meter según (#(old_word == new_word), result)
reiterar
cerrar archivo(fd)
result ---retener---, obtener largo ---retener---
obtener máximo valor, es mayor o igual?, replicar esto
compactar esto
fijar separador 'NL', luego imprime todo
terminar
</syntaxhighlight>
{{out}}
<pre>
abbott
accent
accept
access
accost
almost
bellow
billow
biopsy
chilly
choosy
choppy
effort
floppy
glossy
knotty
</pre>
=={{header|APL}}==
Works in NARS2000 APL; ("Objects" menu -> New, paste this in, save. Then run in the main session manager).
<
f←file_path ⎕NTIE 0 ⍝ open file
Line 296 ⟶ 398:
⍝ find max of word lengths, filter only words with that length
result←ordered_words/⍨lengths=⍨⌈/lengths←≢¨ordered_words
</syntaxhighlight>
The ordered character filter is a train which uses gradeup to say which order you would have to pick the characters, to put them in order. e.g. ⍋ 'zxy' is 2 3 1 because you'd have to pick the second character, then the third, then the first, to put them in order. If they are in order then the result is the integers 1 2 3 .. to the length of the word.
Line 312 ⟶ 414:
=={{header|AppleScript}}==
<
use sorter : script "Insertion sort" -- https://www.rosettacode.org/wiki/Sorting_algorithms/Insertion_sort#AppleScript.
use scripting additions
Line 354 ⟶ 456:
-- ignoring white space, punctuation and diacriticals
return longestOrderedWords(wordList)
--- end ignoring</
{{output}}
<
=={{header|Arturo}}==
<
w = join sort split w
Line 374 ⟶ 476:
maxl: get first ret 'l
print sort map select ret 'x -> maxl = x\l
'x -> x\w</
{{out}}
Line 384 ⟶ 486:
StringLower could be used. This script assumes a locally downloaded copy of the dictionary, but UrlDownloadToFile could be used.
The purpose of the GUI is simply to display a field where the user can copy the list. MsgBox could be used, or FileAppend.
<syntaxhighlight lang="autohotkey">
MaxLen=0
Loop, Read, UnixDict.txt ; Assigns A_LoopReadLine to each line of the file
Line 418 ⟶ 520:
GUIClose:
ExitApp
</syntaxhighlight>
Output:
<pre>abbott, accent, accept, access, accost, almost, bellow, billow, biopsy, chilly, choosy, choppy, effort, floppy, glossy, knotty</pre>
=={{header|AWK}}==
<
abc = "abcdefghijklmnopqrstuvwxyz"
}
Line 458 ⟶ 560:
for (i = 1; i <= best["count"]; i++)
print best[i]
}</
You must provide <tt>unixdict.txt</tt> as input.
Line 481 ⟶ 583:
=={{header|BaCon}}==
<
OPTION COLLAPSE TRUE
Line 501 ⟶ 603:
PRINT result$
</syntaxhighlight>
{{out}}
Line 529 ⟶ 631:
=={{header|BBC BASIC}}==
An optimisation is that the word isn't checked for being ordered unless it is at least as long as the current maximum.
<
IF dict%=0 ERROR 100, "Failed to open dictionary file"
Line 547 ⟶ 649:
CLOSE #dict%
PRINT list$
END</
'''Output:'''
<pre>
Line 573 ⟶ 675:
Memory usage isn't very efficient - the matching list is stored one word per line - so on a standard Befunge-93 interpreter there is an upper limit of 22 matches. This is not a problem for the unix dictionary, which only requires 16, but it's theoretically possible that other data sets could run out of space.
<
>0#v _$^#::\p04:<^+>#1^#\p01:p02*g02!`\g01:<@$ _ ,#!>#:<$<^<!:g03$<_^#!`\g00:+<
^<o>\30g2+p40g1+^0p00p03+1*g03!-g00 < < < < < <:>#$:#$00g#<\#<`#<!#<2#$0g#<*#<_</
{{out}}
Line 595 ⟶ 697:
knotty</pre>
=={{header|BQN}}==
<code>(↕∘≠≡⍋)</code> checks for an ordered word.
<code>¯1⊑(≠¨⊔⊢)</code> groups by length, and takes the last (longest length) group.
<syntaxhighlight lang="bqn"> words←•FLines "unixdict.txt"
¯1⊑(≠¨⊔⊢)(↕∘≠≡⍋)¨⊸/words
⟨ "abbott" "accent" "accept" "access" "accost" "almost" "bellow" "billow" "biopsy" "chilly" "choosy" "choppy" "effort" "floppy" "glossy" "knotty" ⟩</syntaxhighlight>
=={{header|Bracmat}}==
<
= bow result longestLength word character
. 0:?bow
Line 620 ⟶ 730:
| !result
)
& orderedWords$"unixdict.txt"</
<pre> knotty
glossy
Line 639 ⟶ 749:
=={{header|Burlesque}}==
<
{{Out}}
Line 661 ⟶ 771:
=={{header|C}}==
<
#include <string.h>
#include <stdio.h>
Line 743 ⟶ 853:
return EXIT_SUCCESS;
}</
Output:
<pre>abbott
Line 762 ⟶ 872:
knotty</pre>
Alternative version with dynamic array:
<
#include <string.h>
#include <stdio.h>
Line 848 ⟶ 958:
return EXIT_SUCCESS;
}</
===Mmap===
Shorter and potentially much faster version with <code>mmap (2)</code>. No stinky <code>malloc</code> or <code>scanf</code> calls.
<
#include <sys/mman.h>
#include <sys/types.h>
Line 904 ⟶ 1,014:
close(fd);
return 0;
}</
=={{header|C sharp|C#}}==
<
using System.Linq;
using System.Net;
Line 936 ⟶ 1,046:
return true;
}
}</
Output:
Line 943 ⟶ 1,053:
=={{header|C++}}==
<
#include <fstream>
#include <iostream>
Line 980 ⟶ 1,090:
}
std::copy(words.begin(), words.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
}</
Output:
<pre>
Line 1,003 ⟶ 1,113:
=={{header|Clojure}}==
<
(not-any? pos? (map compare coll (next coll))))
Line 1,017 ⟶ 1,127:
take-while-eqcount
(clojure.string/join ", ")
println))</
Output
<
=={{header|CLU}}==
<
last: char := '\000'
for c: char in string$chars(s) do
Line 1,065 ⟶ 1,175:
stream$putl(po, word)
end
end start_up</
{{out}}
<pre>accent
Line 1,084 ⟶ 1,194:
=={{header|COBOL}}==
<
PROGRAM-ID. ABC-WORDS.
Line 1,149 ⟶ 1,259:
IF LEN IS EQUAL TO MAXLEN, DISPLAY WORD.
DONE.
EXIT.</
{{out}}
<pre>abbott
Line 1,169 ⟶ 1,279:
=={{header|CoffeeScript}}==
<
ordered_word = (word) ->
for i in [0...word.length - 1]
Line 1,191 ⟶ 1,301:
dict_words = file_content.toString().split '\n'
show_longest_ordered_words dict_words, dict_file_name
</syntaxhighlight>
output
<syntaxhighlight lang="text">
> coffee ordered_words.coffee
Longest Ordered Words (source=unixdict.txt):
Line 1,212 ⟶ 1,322:
glossy
knotty
</syntaxhighlight>
=={{header|Common Lisp}}==
<
(reduce (lambda (prev curr)
(when (char> prev curr) (return-from orderedp nil))
Line 1,241 ⟶ 1,351:
("abbott" "accent" "accept" "access" "accost" "almost" "bellow" "billow"
"biopsy" "chilly" "choosy" "choppy" "effort" "floppy" "glossy" "knotty")
</syntaxhighlight>
Or in a more functional way:
<syntaxhighlight lang="lisp">(defun orderedp (word)
(apply #'char<= (coerce word 'list)))
(let* ((words (uiop:read-file-lines "unixdict.txt"))
(ordered (delete-if-not #'orderedp words))
(maxlen (apply #'max (mapcar #'length ordered)))
(result (delete-if-not (lambda (l) (= l maxlen)) ordered :key #'length)))
(format t "~{~A~^, ~}" result))</syntaxhighlight>
{{out}}
<pre>abbott, accent, accept, access, accost, almost, bellow, billow, biopsy, chilly, choosy, choppy, effort, floppy, glossy, knotty</pre>
=={{header|Cowgol}}==
Line 1,248 ⟶ 1,370:
of the ordered words it finds, and once to actually print the words.
<
include "strings.coh";
include "file.coh";
Line 1,330 ⟶ 1,452:
ForEachLine(&fcb, PrintMaxLenWord);
var foo := FCBClose(&fcb);</
{{out}}
Line 1,352 ⟶ 1,474:
=={{header|D}}==
===Simple Procedural Version===
<
import std.stdio, std.algorithm, std.range, std.string;
Line 1,371 ⟶ 1,493:
writefln("%-(%s\n%)", result);
}</
{{out}}
<pre>abbott
Line 1,392 ⟶ 1,514:
===Faster Procedural Version===
Faster, same output.
<
import std.stdio, std.algorithm, std.file, std.range;
Line 1,410 ⟶ 1,532:
writefln("%-(%s\n%)", result);
}</
===Functional Version===
Shorter, same output.
<
import std.stdio, std.algorithm, std.range, std.file, std.string;
Line 1,420 ⟶ 1,542:
immutable maxLen = words.map!q{a.length}.reduce!max;
writefln("%-(%s\n%)", words.filter!(w => w.length == maxLen));
}</
===Fastest Memory Mapped Version===
Lower level, much faster with large input files (about as fast as the memory mapped C version). The output is the same. It works only with ASCII texts, but unlike the C entry this is portable.
{{trans|C}}
<
const(char)[] findWord(const char[] s) pure nothrow @safe @nogc {
Line 1,465 ⟶ 1,587:
txt[0 .. outStart].write;
}</
=={{header|Delphi}}==
<syntaxhighlight lang="delphi">
program POrderedWords;
Line 1,523 ⟶ 1,645:
end;
end.
</syntaxhighlight>
Output: dictionary directly processed from the URL
<syntaxhighlight lang="delphi">
abbott accent accept access accost almost bellow billow biopsy chilly choosy choppy effort floppy glossy knotty
</syntaxhighlight>
=={{header|Draco}}==
<syntaxhighlight lang="draco">\util.g
proc nonrec is_ordered(*char str) bool:
while str* /= '\e' and str* <= (str+1)* do
str := str + 1
od;
str* = '\e' or (str+1)* = '\e'
corp
proc nonrec main() void:
[64]char buf;
*char str;
word length, max_length;
file(1024) dictfile;
channel input text dict;
str := &buf[0];
max_length := 0;
open(dict, dictfile, "unixdict.txt");
while readln(dict; str) do
if is_ordered(str) then
length := CharsLen(str);
if length > max_length then max_length := length fi
fi
od;
close(dict);
open(dict, dictfile, "unixdict.txt");
while readln(dict; str) do
if is_ordered(str) then
length := CharsLen(str);
if length = max_length then writeln(str) fi
fi
od;
close(dict)
corp</syntaxhighlight>
{{out}}
<pre>abbott
accent
accept
access
accost
almost
bellow
billow
biopsy
chilly
choosy
choppy
effort
floppy
glossy
knotty</pre>
=={{header|E}}==
{{trans|Python}}
<
def words := <http://www.puzzlers.org/pub/wordlists/unixdict.txt>.getText().split("\n")
Line 1,540 ⟶ 1,717:
def maxLen := accum 0 for word in ordered { _.max(word.size()) }
def maxOrderedWords := accum [] for word ? (word.size() <=> maxLen) in ordered { _.with(word) }
println(" ".rjoin(maxOrderedWords))</
One-pass procedural algorithm which avoids keeping the entire data set in memory:
<
for `@word$\n` ? (word.sort() <=> word) in <http://www.puzzlers.org/pub/wordlists/unixdict.txt> {
if (best.size() == 0) {
Line 1,554 ⟶ 1,731:
}
}
println(" ".rjoin(best.snapshot()))</
Output: <code>abbott accent accept access accost almost bellow billow biopsy chilly choosy
Line 1,560 ⟶ 1,737:
=={{header|EchoLisp}}==
<
(define (ordered? str)
(for/and ([i (in-range 1 (string-length str))])
Line 1,587 ⟶ 1,764:
;; english
→ (Adelops alloquy beefily begorry billowy egilops)
</syntaxhighlight>
=={{header|Elixir}}==
<
|> String.split
|> Enum.filter(fn word -> String.codepoints(word) |> Enum.sort |> Enum.join == word end)
Line 1,597 ⟶ 1,774:
|> elem(1)
|> Enum.sort
|> Enum.each(fn word -> IO.puts word end)</
{{out}}
Line 1,620 ⟶ 1,797:
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">
-module( ordered_words ).
Line 1,642 ⟶ 1,819:
words() -> anagrams_deranged:words_from_url( "http://www.puzzlers.org/pub/wordlists/unixdict.txt" ).
</syntaxhighlight>
{{out}}
<pre>
Line 1,652 ⟶ 1,829:
=={{header|Euphoria}}==
<
type ordered(sequence s)
Line 1,687 ⟶ 1,864:
close(fn)
pretty_print(1,words,{2})</
Output:
Line 1,710 ⟶ 1,887:
=={{header|F Sharp|F#}}==
<
open System.IO
Line 1,722 ⟶ 1,899:
|> Seq.head |> snd
longestOrderedWords() |> Seq.iter (printfn "%s")</
Output:
Line 1,744 ⟶ 1,921:
=={{header|Factor}}==
<
USING: grouping http.client io io.encodings.utf8 io.files
io.files.temp kernel math memoize sequences sequences.extras
Line 1,762 ⟶ 1,939:
word-list [ ordered-word? ] filter
all-longest [ print ] each ;
</syntaxhighlight>
Output: <pre>( scratchpad ) USING: ordered-words-main ;
Line 1,785 ⟶ 1,962:
=={{header|Fantom}}==
<
class Main
{
Line 1,816 ⟶ 1,993:
}
}
</syntaxhighlight>
Output:
Line 1,824 ⟶ 2,001:
=={{header|FBSL}}==
Downloads the list from puzzlers.org.
<
FUNCTION RESTfulGET(url)
Line 1,857 ⟶ 2,034:
RETURN TRUE
END FUNCTION
</syntaxhighlight>
Output
<pre> abbott accent accept access accost almost bellow billow biopsy chilly choosy choppy effort floppy glossy knotty
Line 1,867 ⟶ 2,044:
This program uses a string stack, which means that all matching words are stored on a stack.
The longest word ends up on the top of the stack.
<syntaxhighlight lang="forth">
include lib/stmstack.4th \ include string stack library
Line 1,911 ⟶ 2,088:
; \ open file, clear the stack, read file
\ read it back and close the file
ordered</
Since the longest word is on top of the stack, the only thing to be done is to pop
all words from the stack until a shorter word is encountered. Consequently, all
Line 1,934 ⟶ 2,111:
=={{header|Fortran}}==
<
!***************************************************************************************
module ordered_module
Line 2,048 ⟶ 2,225:
end program main
!****************************************************
</syntaxhighlight>
'''Output'''
Line 2,054 ⟶ 2,231:
=={{header|FreeBASIC}}==
<
Function isOrdered(s As Const String) As Boolean
Line 2,095 ⟶ 2,272:
Print
Print "Press any key to quit"
Sleep</
{{out}}
Line 2,120 ⟶ 2,297:
=={{header|Frink}}==
<
a = sort[select[lines[url], {|w| charList[w] == sort[charList[w]] } ], {|a,b| length[a] <=> length[b]}]
println[sort[select[a, {|w, longest| length[w] == longest}, length[last[a]]]]]</
{{out}}
<pre>
[abbott, accent, accept, access, accost, almost, bellow, billow, biopsy, chilly, choosy, choppy, effort, floppy, glossy, knotty]
</pre>
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
#plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES}
local fn Words as CFArrayRef
CFURLRef url = fn URLWithString( @"https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt" )
CFStringRef string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
end fn = fn StringComponentsSeparatedByCharactersInSet( string, fn CharacterSetNewlineSet )
local fn IsOrderedWord( string as CFStringRef ) as BOOL
BOOL flag = YES
long i
unichar chr, prevChr = 0
for i = 0 to len(string) - 1
chr = fn StringCharacterAtIndex( string, i )
if ( chr < prevChr )
flag = NO : break
end if
prevChr = chr
next
end fn = flag
void local fn DoIt
CFStringRef string
CFArrayRef words = fn Words
long length, maxLen = 0
CFMutableStringRef orderedWords = fn MutableStringWithCapacity(0)
for string in words
length = len(string)
if ( length < maxLen ) then continue
if ( fn IsOrderedWord( string ) )
if ( length > maxLen )
MutableStringSetString( orderedWords, @"" )
maxLen = length
end if
MutableStringAppendFormat( orderedWords, @"%@\n", string )
end if
next
print orderedWords
end fn
fn DoIt
HandleEvents
</syntaxhighlight>
=={{header|Gambas}}==
<
Dim sDict As String = File.Load(User.Home &/ "unixdict.txt") 'Store the 'Dictionary'
Dim sOrdered As New String[] 'To store ordered words
Line 2,158 ⟶ 2,386:
Print sHold.Join(gb.NewLine) 'Display the result
End </
Output:
<pre>
Line 2,182 ⟶ 2,410:
Go has strings and Unicode and stuff, but with the dictionary all ASCII
and lower case, strings and Unicode seem overkill. I just worked with byte slices here, only converting the final result to strings for easy output.
<
import (
Line 2,238 ⟶ 2,466:
fmt.Println(string(bs))
}
}</
Output:
<pre>
Line 2,261 ⟶ 2,489:
=={{header|Groovy}}==
Solution:
<
assert isOrdered('abbey')
assert !isOrdered('cat')
Line 2,269 ⟶ 2,497:
def owMax = orderedWords*.size().max()
orderedWords.findAll { it.size() == owMax }.each { println it }</
Output:
Line 2,290 ⟶ 2,518:
=={{header|Haskell}}==
<
-- Words are read from the standard input. We keep in memory only the current
-- set of longest, ordered words.
Line 2,310 ⟶ 2,538:
let ws = longestOrderedWords $ words str
mapM_ putStrLn ws
</syntaxhighlight>
Output:
<
abbott
accent
Line 2,330 ⟶ 2,558:
glossy
knotty
</syntaxhighlight>
Alternative version:
<
isSorted wws@(_ : ws) = and $ zipWith (<=) wws ws
Line 2,342 ⟶ 2,570:
let ow = filter isSorted ls
let maxl = foldr max 0 (map length ow)
print $ filter (\w -> (length w) == maxl) ow</
=={{header|Huginn}}==
<
import Mathematics as math;
import Network as net;
Line 2,369 ⟶ 2,597:
print( "{}\n".format( text.join( algo.sorted( maxOrderedWords ), " " ) ) );
return ( 0 );
}</
=={{header|Icon}} and {{header|Unicon}}==
<
procedure main(A)
Line 2,381 ⟶ 2,609:
}
every write(!\maxList)
end</
{{libheader|Icon Programming Library}}
Line 2,407 ⟶ 2,635:
=={{header|Io}}==
<
words := file readLines
file close
Line 2,423 ⟶ 2,651:
)
orderedWords join(" ") println</
{{output}}
<pre>abbott accent accept access accost almost bellow billow biopsy chilly choosy choppy effort floppy glossy knotty
Line 2,429 ⟶ 2,657:
=={{header|J}}==
<
oWords=: (#~ ] = /:~L:0) cutLF fread 'unixdict.txt'
;:inv (#~ (= >./)@:(#@>)) oWords
abbott accent accept access accost almost bellow billow biopsy chilly choosy choppy effort floppy glossy knotty</
Recap:
Line 2,445 ⟶ 2,673:
{{works with|Java|1.5+}}
This example assumes there is a local copy of the dictionary whose path is given as the first argument to the program.
<
import java.io.FileReader;
import java.io.IOException;
Line 2,487 ⟶ 2,715:
}
}
}</
Output:
<pre>abbott
Line 2,505 ⟶ 2,733:
glossy
knotty</pre>
===Using Java 16===
<syntaxhighlight lang="java">
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
public final class OrderedWords {
public static void main(String[] aArgs) throws IOException {
List<String> ordered = Files.lines(Path.of("unixdict.txt"))
.filter( word -> isOrdered(word) ).toList();
final int maxLength = ordered.stream().map( word -> word.length() ).max(Integer::compare).get();
ordered.stream().filter( word -> word.length() == maxLength ).forEach(System.out::println);
}
private static boolean isOrdered(String aWord) {
return aWord.chars()
.mapToObj( i -> (char) i )
.sorted()
.map(String::valueOf)
.reduce("", String::concat)
.equals(aWord);
}
}
</syntaxhighlight>
<pre>
The same as the Java example above.
</pre>
=={{header|JavaScript}}==
Using [http://nodejs.org/ node.js]:
<
fs.readFile('./unixdict.txt', 'ascii', function (err, data) {
var is_ordered = function(word){return word.split('').sort().join('') === word;},
Line 2,519 ⟶ 2,780:
};
print(longest.sort().join(', ') + '\n');
});</
Output:
Line 2,526 ⟶ 2,787:
Alternative version (also using Node.js):
<
http.get({
Line 2,551 ⟶ 2,812:
console.log(ordered.join(', '));
});
});</
=={{header|jq}}==
{{works with|jq|1.4}}
<
if length <= 1 then true
else .[0] <= .[1] and (.[1:] | is_sorted)
Line 2,568 ⟶ 2,829:
split("\n") | longest_ordered_words</
{{out}}
["abbott","accent","accept","access","accost","almost","bellow","billow","biopsy","chilly","choosy","choppy","effort","floppy","glossy","knotty"]
Line 2,576 ⟶ 2,837:
'''Built-in function''':
<
'''Main''':
<
filter!(issorted, lst)
filter!(x -> length(x) == maximum(length, lst), lst)
println.(lst)</
{{out}}
Line 2,603 ⟶ 2,864:
=={{header|K}}==
<
("abbott"
"accent"
Line 2,619 ⟶ 2,880:
"floppy"
"glossy"
"knotty")</
=={{header|Kotlin}}==
<
fun main(
val
"https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt"
).toURL()
val words = url.openStream().bufferedReader().use {
var max = 0
.filter { it.asSequence().windowed(2).all { it[0] <= it[1] } }
.sortedByDescending(String::length)
.takeWhile { word -> word.length >= max.also { max = word.length } }
.toList()
}
words.forEach(::println)
}
</syntaxhighlight>
=={{header|Lambdatalk}}==
<
{def maxOrderedWords
Line 2,691 ⟶ 2,948:
glossy
knotty
</syntaxhighlight>
=={{header|Lang5}}==
<
"" split
"&'0123456789abcdefghijklmnopqrstuvwxyz" "" split
Line 2,730 ⟶ 2,987:
fh fin filtering fh close ;
ordered-words</
{{out}}
<pre>[ abbott accent accept access accost almost bellow billow biopsy chilly choosy choppy effort floppy glossy knotty ]</pre>
=={{header|Lasso}}==
<
#f->dowithclose => {
#f->foreachLine => {
Line 2,752 ⟶ 3,009:
with w in #ordered
where #w->size == #maxleng
do => {^ #w + '\r' ^}</
{{out}}
<pre>abbott accent accept access accost almost bellow billow biopsy chilly choosy choppy effort floppy glossy knotty</pre>
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
'Ordered wordsFrom Rosetta Code
open "unixdict.txt" for input as #1
Line 2,791 ⟶ 3,048:
close #1
print wordList$
</syntaxhighlight>
Output:
Line 2,813 ⟶ 3,070:
=={{header|Lingo}}==
Code ported from Lua solution.
<
on printLongestOrderedWords (words)
res = []
Line 2,839 ⟶ 3,096:
end repeat
put res
end</
{{Out}}
<pre>-- ["abbott", "accent", "accept", "access", "accost", "almost", "bellow", "billow", "biopsy", "chilly", "choosy", "choppy", "effort", "floppy", "glossy", "knotty"]</pre>
=={{header|Lua}}==
<
maxlen = 0
Line 2,872 ⟶ 3,129:
end
fp:close()</
Output:
<pre>abbott
Line 2,892 ⟶ 3,149:
=={{header|Maple}}==
<
longest := 0:
words := Array():
Line 2,910 ⟶ 3,167:
end if;
end do;
for word in words do print(word); end do;</
{{Out|Output}}
<pre>"abbott"
Line 2,930 ⟶ 3,187:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
data = Select[Import["http://www.puzzlers.org/pub/wordlists/unixdict.txt", "List"],
OrderedQ[Characters[#]] &]},
max = Max[StringLength /@ data];
Select[data, StringLength[#] == max &]]
</syntaxhighlight>
However Mathematica has built in dictionaries for many languages, so here is a more general version...
<
max = Max[StringLength /@ data];
Select[data, StringLength[#] == max &]]
</syntaxhighlight>
<pre>
Line 2,957 ⟶ 3,214:
=={{header|MATLAB}} / {{header|Octave}}==
<
listlen= 0;
fid = fopen('unixdict.txt','r');
Line 2,972 ⟶ 3,229:
end
fclose(fid);
printf('%s\n',list{:}); </
Returns:
Line 2,993 ⟶ 3,250:
=={{header|Nanoquery}}==
<
def is_ordered(word)
Line 3,023 ⟶ 3,280:
end
end
println words</
{{out}}
Line 3,029 ⟶ 3,286:
=={{header|NetRexx}}==
<
options replace format comments java crossref savelog symbols binary
Line 3,068 ⟶ 3,325:
Arrays.sort(wchars)
return dword.equalsIgnoreCase(String(wchars))
</syntaxhighlight>
;Output
<pre>
Line 3,075 ⟶ 3,332:
=={{header|Nim}}==
<
const DictFile = "unixdict.txt"
Line 3,096 ⟶ 3,353:
mx = word.len
words.add word
echo words.join(" ")</
{{out}}
<pre>abbott accent accept access accost almost bellow billow biopsy chilly choosy choppy effort floppy glossy knotty</pre>
Line 3,102 ⟶ 3,359:
=={{header|OCaml}}==
<
try Some(input_line ic)
with End_of_file -> None
Line 3,153 ⟶ 3,410:
let ordered_words = List.filter is_ordered lower_words in
let longest_ordered_words = longest_words ordered_words in
List.iter print_endline longest_ordered_words</
Output:
Line 3,177 ⟶ 3,434:
=={{header|Oforth}}==
<
| w longest l s |
0 ->longest
Line 3,185 ⟶ 3,442:
s longest > ifTrue: [ s ->longest ListBuffer new ->l ]
l add(w)
] l ; </
{{out}}
Line 3,196 ⟶ 3,453:
{{trans|REXX}}
Adapted for ooRexx
<
iFID= 'UNIXDICT.TXT'
w.=''
Line 3,222 ⟶ 3,479:
End
Exit
s: Return left('s',arg(1)>1)</
{{out}}
Same as REXX'
=={{header|PARI/GP}}==
<
v=select(ordered,readstr("~/unixdict.txt"));
N=vecmax(apply(length,v));
select(s->#s==N, v)</
{{out}}
<pre>%1 = ["abbott", "accent", "accept", "access", "accost", "almost", "bellow", "billow", "biopsy", "chilly", "choosy", "choppy", "effort", "floppy", "glossy", "knotty"]</pre>
=={{header|Perl}}==
<
use strict;
use warnings;
Line 3,247 ⟶ 3,504:
close FH;
print "@{$words[-1]}\n";
</syntaxhighlight>
Output:
<pre>
Line 3,254 ⟶ 3,511:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">words</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">unix_dict</span><span style="color: #0000FF;">()</span>
Line 3,268 ⟶ 3,525:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The %d longest ordered words:\n %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">found</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">words</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">found</span><span style="color: #0000FF;">],</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n "</span><span style="color: #0000FF;">)})</span>
<!--</
{{out}}
<pre>
Line 3,279 ⟶ 3,536:
=={{header|Phixmonti}}==
<
0 var maxlen
Line 3,305 ⟶ 3,562:
endwhile
f fclose
words print</
Another solution
<
0 var f
Line 3,333 ⟶ 3,590:
endwhile
f fclose
print</
{{out}}
<pre>
Line 3,340 ⟶ 3,597:
=={{header|Picat}}==
<
Dict = "unixdict.txt",
Words = new_map([Word=Word.length : Word in read_file_lines(Dict), Word == Word.sort()]),
MaxLen = max([Len : _Word=Len in Words]),
println([Word : Word=Len in Words, Len=MaxLen].sort).</
{{out}}
Line 3,350 ⟶ 3,607:
=={{header|PicoLisp}}==
<
(mapc prinl
(maxi '((L) (length (car L)))
(by length group
(filter '((S) (apply <= S))
(make (while (line) (link @))) ) ) ) ) )</
Output:
<pre>abbott
Line 3,375 ⟶ 3,632:
=={{header|PL/I}}==
<
order: procedure options (main); /* 24/11/2011 */
declare word character (20) varying;
Line 3,431 ⟶ 3,688:
end in_order;
end order;
</syntaxhighlight>
OUTPUT:
<pre>
Line 3,454 ⟶ 3,711:
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
$url = 'http://www.puzzlers.org/pub/wordlists/unixdict.txt'
Line 3,471 ⟶ 3,728:
($ordered.Words -join ", ")
Remove-Item -Path "$env:TEMP\unixdict.txt" -Force -ErrorAction SilentlyContinue
</syntaxhighlight>
{{Out}}
Line 3,483 ⟶ 3,740:
Works with SWI-Prolog
<
ordered_words :-
Line 3,527 ⟶ 3,784:
my_compare(R, K1-_V1, K2-_V2) :-
( K1 < K2 -> R = >; K1 > K2 -> R = <; =).
</syntaxhighlight>
Output :
<pre> ?- ordered_words.
Line 3,550 ⟶ 3,807:
=={{header|PureBasic}}==
<
Protected Dim letters.c(wordLength)
Protected *letAdr = @letters()
Line 3,595 ⟶ 3,852:
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</
Sample output:
<pre>abbott accent accept access accost almost bellow billow biopsy chilly
Line 3,602 ⟶ 3,859:
=={{header|Python}}==
===Python: First Solution===
<
url = 'http://www.puzzlers.org/pub/wordlists/unixdict.txt'
Line 3,609 ⟶ 3,866:
maxlen = len(max(ordered, key=len))
maxorderedwords = [word for word in ordered if len(word) == maxlen]
print(' '.join(maxorderedwords))</
===Python: Alternate Solution using one explicit loop===
<
mx, url = 0, 'http://www.puzzlers.org/pub/wordlists/unixdict.txt'
Line 3,622 ⟶ 3,879:
words, mx = [], lenword
words.append(word)
print(' '.join(words))</
'''Sample Output'''
Line 3,629 ⟶ 3,886:
===Python: As a fold===
{{Works with|Python|3.7}}
<
from functools import reduce
from operator import le
import urllib.request
Line 3,651 ⟶ 3,909:
return (
(lng, ([w] if n != lng else xs + [w])) if (
) else nxs
) if lng >= n else nxs
#
def
'''True if the word w is ordered.'''
return
# ------------------------- TEST -------------------------
if __name__ == '__main__':
print(
Line 3,681 ⟶ 3,928:
).read().decode("utf-8").split()
))
)</
{{Out}}
<pre>abbott
Line 3,702 ⟶ 3,949:
=={{header|Quackery}}==
<
[ true swap
Line 3,728 ⟶ 3,975:
$ 'unixdict.txt' sharefile drop nest$
task
witheach [ echo$ sp ]</
{{out}}
Line 3,736 ⟶ 3,983:
=={{header|R}}==
<
ordered = logical()
Line 3,745 ⟶ 3,992:
}
cat(words[ordered][which(nchar(words[ordered])==max(nchar(words[ordered])))],sep="\n")</
{{Out}}
<pre>abbott
Line 3,766 ⟶ 4,013:
=={{header|Racket}}==
<syntaxhighlight lang="racket">
#lang racket
(require net/url)
Line 3,787 ⟶ 4,034:
(loop len longs words)
(loop wlen (cons word (if (> wlen len) '() longs)) words)))))
</syntaxhighlight>
Output:
Line 3,815 ⟶ 4,062:
{{works with|Rakudo|2016.07}}
<syntaxhighlight lang="raku"
{{out}}
Line 3,823 ⟶ 4,070:
=={{header|Red}}==
<
;; code to read url and save to local file:
;;data: read/binary http://www.puzzlers.org/pub/wordlists/unixdict.txt
Line 3,837 ⟶ 4,084:
]
]
probe max</
'''Sample Output'''
<pre>["abbott" "accent" "accept" "access" "accost" "almost" "bellow" "billow" "biopsy" "chilly" "choosy" "choppy" "effort" "floppy" "glossy" "knotty"]
Line 3,852 ⟶ 4,099:
<br>but since the word list (in this case) is already in alphabetical order, this would-be improvement is
<br>mostly moot.
<
iFID= 'UNIXDICT.TXT' /*the filename of the word dictionary. */
m= 1 /*maximum length of an ordered word(s).*/
Line 3,874 ⟶ 4,121:
ghijk
/*──────────────────────────────────────────────────────────────────────────────────────*/
s: if arg(1)==1 then return ''; return "s" /*a simple pluralizer (merely adds "S")*/</
{{out|output|text= when using the default supplied word dictionary:}}
<pre>
Line 3,898 ⟶ 4,145:
=={{header|Ring}}==
<
load "stdlib.ring"
Line 3,943 ⟶ 4,190:
see nl + "done..." + nl
</syntaxhighlight>
Output:
<pre>
Line 3,966 ⟶ 4,213:
done...
</pre>
=={{header|RPL}}==
The only way to use <code>unixdict.txt</code> as input is to download it locally and to convert it into a list of 25104 strings. Fortunately, emulators can handle such a big data structure in RAM.
{{works with|Halcyon Calc|4.2.7}}
≪ "a" DUP
1 4 PICK SIZE '''FOR''' j
SWAP DROP
OVER j DUP SUB
'''IF''' DUP2 > '''THEN''' 99 'j' STO '''END'''
'''NEXT'''
≤ SWAP DROP
≫ '<span style="color:blue">ORDWORD?</span>' STO
≪ 0 → words sizemax
≪ { }
1 words EVAL SIZE '''FOR''' j
words j GET DUP SIZE
'''IF''' DUP sizemax ≥ '''THEN'''
'''IF''' OVER <span style="color:blue">ORDWORD?</span> '''THEN''' <span style="color:grey">@ 2-step test, rather than one with an AND, to save execution time </span>
'''IF''' DUP sizemax > '''THEN'''
'sizemax' STO
SWAP DROP { } SWAP
'''ELSE''' DROP '''END'''
+
'''ELSE''' DROP2 '''END'''
'''ELSE''' DROP2 '''END'''
'''NEXT'''
≫ ≫ '<span style="color:blue">ORDWORDS</span>' STO
'Unixdict' <span style="color:blue">ORDWORDS</span>
{{out}}
<pre>
1: { abbott accent accept access accost almost bellow billow biopsy chilly choosy choppy effort floppy glossy knotty }
</pre>
=={{header|Ruby}}==
<
ordered_words = open('http://www.puzzlers.org/pub/wordlists/unixdict.txt', 'r').select do |word|
word.strip!
Line 3,976 ⟶ 4,257:
grouped = ordered_words.group_by &:size
puts grouped[grouped.keys.max]</
'''Sample Output'''
Line 3,997 ⟶ 4,278:
knotty</pre>
Local version:
<
puts words.group_by(&:size).sort_by(&:first).last.last</
=={{header|Run BASIC}}==
<
j = 1
i = instr(a$,chr$(10),j)
Line 4,020 ⟶ 4,301:
if len(a3$) = maxL then print a3$
n = n + 1
wend</
<pre>abbott
accent
Line 4,039 ⟶ 4,320:
=={{header|Rust}}==
<
fn is_ordered(s: &str) -> bool {
Line 4,081 ⟶ 4,362:
println!("{}", s.to_string());
}
}</
=={{header|Scala}}==
<
/**
Line 4,103 ⟶ 4,384:
val ww = orderedWords( wordsAll ).sortBy( -_.length )
println( ww.takeWhile( _.length == ww.head.length ).mkString("\n") )</
{{out}}
<pre>
Line 4,127 ⟶ 4,408:
The following implementation uses a <tt>char>=?</tt> procedure that accepts an arbitrary number of arguments. This is allowed, but not required, by R5RS, and is provided by many Scheme implementations. It has been tested under GNU Guile 1.8.8.
<
(define sorted-words
(let ((port (open-input-file "unixdict.txt")))
Line 4,148 ⟶ 4,429:
(newline)))
sorted-words)
</syntaxhighlight>
Output:
Line 4,170 ⟶ 4,451:
=={{header|Seed7}}==
<
const func boolean: isOrdered (in string: word) is func
Line 4,218 ⟶ 4,499:
end if;
write(wordList);
end func;</
Output:
Line 4,241 ⟶ 4,522:
=={{header|Sidef}}==
<
var file = %f'unixdict.txt'
Line 4,254 ⟶ 4,535:
}
say words[-1].join(' ')</
{{out}}
<pre>abbott accent accept access accost almost bellow billow biopsy chilly choosy choppy effort floppy glossy knotty</pre>
=={{header|Simula}}==
<
BOOLEAN PROCEDURE ISORDERED(W); TEXT W;
Line 4,313 ⟶ 4,594:
END.
</syntaxhighlight>
{{out}}
<pre>
Line 4,339 ⟶ 4,620:
{{works with|GNU Smalltalk}}
<
file := FileStream open: 'unixdict.txt' mode: FileStream read.
dict := Set new.
Line 4,355 ⟶ 4,636:
r := (r select: [:w| (w size) = ((r at: 1) size)]) asSortedCollection.
r do: [:e| e displayNl].</
Output:
Line 4,376 ⟶ 4,657:
=={{header|SPL}}==
<
max = 0
> i, 1..#.size(words,1)
Line 4,390 ⟶ 4,671:
result += word+#.crlf
<
#.output(result)</
{{out}}
<pre>
Line 4,412 ⟶ 4,693:
=={{header|Standard ML}}==
<
let
fun loop (i, c) =
Line 4,439 ⟶ 4,720:
o foldr longestOrdereds (0, [])
o String.tokens Char.isSpace
o TextIO.inputAll) TextIO.stdIn ^ "\n")</
{{out}}
<pre>abbott accent accept access accost almost bellow billow biopsy chilly choosy choppy effort floppy glossy knotty</pre>
Line 4,445 ⟶ 4,726:
=={{header|Swift}}==
<
guard
Line 4,473 ⟶ 4,754:
maxLengthGroup.forEach { print($0) }
</syntaxhighlight>
{{Out}}
Line 4,497 ⟶ 4,778:
=={{header|Tcl}}==
<
# Pick the ordered words (of maximal length) from a list
Line 4,521 ⟶ 4,802:
set t [http::geturl "http://www.puzzlers.org/pub/wordlists/unixdict.txt"]
puts [chooseOrderedWords [http::data $t]]
http::cleanup $t</
Output:
<pre>
abbott accent accept access accost almost bellow billow biopsy chilly choosy choppy effort floppy glossy knotty
</pre>
=={{header|Transd}}==
<syntaxhighlight lang="Scheme">#lang transd
MainModule: {
_start: (lambda
(with fs FileStream() len 0 maxlen 0 words Vector<String>()
(open-r fs "/mnt/vault/tmp/unixdict.txt") )
(for w in (read-lines fs) do
(= len (size w))
(if (< len maxlen) continue)
(if (is-sorted w)
(if (< maxlen len)
(clear words) (= maxlen len))
(append words w)
))
(lout words)
))
}</syntaxhighlight>
{{out}}
<pre>
["abbott", "accent", "accept", "access", "accost", "almost", "bellow", "billow", "biopsy", "chilly", "choosy", "choppy", "effort", "floppy", "glossy", "knotty"]
</pre>
=={{header|TUSCRIPT}}==
<
$$ MODE TUSCRIPT
SET data = REQUEST ("http://www.puzzlers.org/pub/wordlists/unixdict.txt")
Line 4,556 ⟶ 4,862:
ENDLOOP
ENDCOMPILE
</syntaxhighlight>
Output:
<pre>
Line 4,579 ⟶ 4,885:
=={{header|Ursala}}==
<
#show+
main = leql@bh$^ eql|= (ordered lleq)*~ unixdict_dot_txt</
* <code>leql</code> is a binary predicate testing a pair of lists for less or equal length
* <code>eql</code> tests for equal length
Line 4,614 ⟶ 4,920:
=={{header|VBA}}==
<syntaxhighlight lang="vba">
Public Sub orderedwords(fname As String)
' find ordered words in dict file that have the longest word length
Line 4,691 ⟶ 4,997:
End If
End Function
</syntaxhighlight>
Results:
Line 4,717 ⟶ 5,023:
=={{header|VBScript}}==
Note: The input file is in the same folder as the script.
<
Set infile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) & "\" &_
"unixdict.txt",1)
Line 4,750 ⟶ 5,056:
End If
Next
End Function</
{{out}}
Line 4,771 ⟶ 5,077:
=={{header|Vedit macro language}}==
<
#1 = 2 // length of longest word found
Repeat (ALL) {
Line 4,796 ⟶ 5,102:
}
Buf_Quit(OK) // close file
Reg_Type(10) // display results </
<pre>abbott
Line 4,814 ⟶ 5,120:
glossy
knotty </pre>
=={{header|V (Vlang)}}==
{{trans|Wren}}
<syntaxhighlight lang="Zig">
fn main() {
words := os.read_file("./unixdict.txt") or {println(err) exit(-1)}.split_into_lines()
mut longest_len := 0
mut longest := []string{}
mut u_word := []u8{}
for word in words {
for chars in word {u_word << chars}
u_word.sort()
if word.len > longest_len {
if word == u_word.bytestr() {
longest_len = word.len
longest.clear()
longest << word
}
}
else if word.len == longest_len {
if word == u_word.bytestr() {longest << word}
}
u_word.clear()
}
println("The ${longest.len} ordered words with the longest length (${longest_len}) are:")
print(longest.join("\n"))
}
</syntaxhighlight>
{{out}}
<pre>
The 16 ordered words with the longest length (6) are:
abbott
accent
accept
access
accost
almost
bellow
billow
biopsy
chilly
choosy
choppy
effort
floppy
glossy
knott
</pre>
=={{header|Wren}}==
{{libheader|Wren-sort}}
<
import "./sort" for Sort
var words = File.read("unixdict.txt").split("\n")
Line 4,835 ⟶ 5,190:
}
System.print("The %(longest.count) ordered words with the longest length (%(longestLen)) are:")
System.print(longest.join("\n"))</
{{out}}
Line 4,859 ⟶ 5,214:
=={{header|XPL0}}==
<
int MaxLen, Pass, I, Ch, Ch0;
char Word(25);
Line 4,885 ⟶ 5,240:
until Ch = EOF;
];
]</
{{out}}
Line 4,909 ⟶ 5,264:
=={{header|zkl}}==
One pass, dictionary stays on disk:
<
fcn isLex(word){ word.reduce(fcn(p,c){ (p<=c) and c or T(Void.Stop,False) }) }
File("dict.txt").pump(Void,fcn(w){
Line 4,919 ⟶ 5,274:
})
println("Num words: %d, all size %d\n".fmt(words.len(),sz));
words.pump(Console.println);</
Or, reading dictionary into memory:
<
lwords:=File("dict.txt").readln(*).apply("strip").filter(isLex);
max:=lwords.reduce(fcn(n,w){ w.len()>n and w.len() or n },0);
lwords=lwords.filter(fcn(w,n){ w.len()==n },max);
println("Num words: %d, all size %d\n".fmt(lwords.len(),max));
words.pump(Console.println);</
{{out}}
<pre>
|