Words containing "the" substring: Difference between revisions

add Refal
(add Refal)
 
(83 intermediate revisions by 46 users not shown)
Line 2:
 
;Task:
Using the dictionary   [https://web.archive.org/web/20180611003215/http://wwwwiki.puzzlers.org/pub/wordlists/unixdict.txt unixdict.txt],   search words containing "the" substring,
<br>then display the found words (on this page).
 
Line 10:
{{Template:Strings}}
<br><br>
 
=={{header|11l}}==
<syntaxhighlight lang="11l">L(word) File(‘unixdict.txt’).read().split("\n")
I ‘the’ C word & word.len > 11
print(word)</syntaxhighlight>
 
{{out}}
<pre>
authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping
</pre>
 
=={{header|Action!}}==
In the following solution the input file [https://gitlab.com/amarok8bit/action-rosetta-code/-/blob/master/source/unixdict.txt unixdict.txt] 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.
<syntaxhighlight lang="action!">BYTE FUNC FindS(CHAR ARRAY text,sub)
BYTE i,j,found
 
i=1
WHILE i<=text(0)-sub(0)+1
DO
found=0
FOR j=1 TO sub(0)
DO
IF text(i+j-1)#sub(j) THEN
found=0 EXIT
ELSE
found=1
FI
OD
IF found THEN
RETURN (i)
FI
i==+1
OD
RETURN (0)
 
BYTE FUNC IsValidWord(CHAR ARRAY word)
IF word(0)<=11 THEN RETURN (0) FI
IF FindS(word,"the")=0 THEN RETURN(0) FI
RETURN (1)
 
PROC FindWords(CHAR ARRAY fname)
CHAR ARRAY line(256)
CHAR ARRAY tmp(256)
BYTE pos,dev=[1]
 
pos=2
Close(dev)
Open(dev,fname,4)
WHILE Eof(dev)=0
DO
InputSD(dev,line)
IF IsValidWord(line) THEN
IF pos+line(0)>=39 THEN
PutE() pos=2
FI
Print(line) Put(32)
pos==+line(0)+1
FI
OD
Close(dev)
RETURN
 
PROC Main()
CHAR ARRAY fname="H6:UNIXDICT.TXT"
 
FindWords(fname)
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Words_containing_the_substring.png Screenshot from Atari 8-bit computer]
<pre>
authenticate chemotherapy chrysanthemum clothesbrush clotheshorse eratosthenes featherbedding featherbrain
featherweight gaithersburg hydrothermal lighthearted mathematician neurasthenic nevertheless northeastern
northernmost otherworldly parasympathetic physiotherapist physiotherapy psychotherapeutic psychotherapist psychotherapy
radiotherapy southeastern southernmost theoretician weatherbeaten weatherproof weatherstrip weatherstripping
</pre>
 
=={{header|Ada}}==
<syntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
 
procedure Main is
type col_count is mod 6;
package AF renames Ada.Strings.Fixed;
 
file_name : String := "unixdict.txt";
The_File : File_Type;
Inpt_Str : String (1 .. 40);
Length : Natural;
pattern : String := "the";
Columns : col_count := 0;
Tally : Natural := 0;
sep : constant Character := HT;
begin
 
Open (File => The_File, Mode => In_File, Name => file_name);
 
while not End_Of_File (The_File) loop
Get_Line (File => The_File, Item => Inpt_Str, Last => Length);
 
if Length > 11
and then
AF.Count (Source => Inpt_Str (1 .. Length), Pattern => pattern) > 0
then
Tally := Tally + 1;
Columns := Columns + 1;
Put (Inpt_Str (1 .. Length) & sep);
if Columns = 0 then
New_Line;
end if;
end if;
end loop;
New_Line;
Put_Line ("Found" & Tally'Image & " ""the"" words");
Close (The_File);
end Main;
</syntaxhighlight>
{{output}}
<pre>
authenticate chemotherapy chrysanthemum clothesbrush clotheshorse eratosthenes
featherbedding featherbrain featherweight gaithersburg hydrothermal lighthearted
mathematician neurasthenic nevertheless northeastern northernmost otherworldly
parasympathetic physiotherapist physiotherapy psychotherapeutic psychotherapist psychotherapy
radiotherapy southeastern southernmost theoretician weatherbeaten weatherproof
weatherstrip weatherstripping
Found 32 "the" words
</pre>
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68"># find 12 character (or more) words that have "the" in them #
IF FILE input file;
STRING file name = "unixdict.txt";
Line 56 ⟶ 214:
print( ( newline, "found ", whole( the count, 0 ), " ""the"" words", newline ) );
close( input file )
FI</langsyntaxhighlight>
{{out}}
<pre>
Line 72 ⟶ 230:
 
Using just the core language — 'words':
<langsyntaxhighlight lang="applescript">on wordsContaining(textfile, searchText, minLength)
script o
property wordList : missing value
Line 87 ⟶ 245:
return o's output
end wordsContaining</langsyntaxhighlight>
 
Using just the core language — 'text items':
<langsyntaxhighlight lang="applescript">on wordsContaining(textFile, searchText, minLength)
script o
property textItems : missing value
Line 124 ⟶ 282:
return o's output
end wordsContaining</langsyntaxhighlight>
 
Using a shell script:
<langsyntaxhighlight lang="applescript">on wordsContaining(textFile, searchText, minLength)
-- Set up and execute a shell script which uses grep to find words containing the search text
-- (matching AppleScript's current case-sensitivity setting) and awk to pass those which
Line 141 ⟶ 299:
return paragraphs of (do shell script shellCode)
end wordsContaining</langsyntaxhighlight>
 
Using Foundation methods (AppleScriptObjC):
<langsyntaxhighlight lang="applescript">use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
use scripting additions
Line 168 ⟶ 326:
return (theWords's filteredArrayUsingPredicate:(filter)) as list
end wordsContaining</langsyntaxhighlight>
 
Test code for the task with any of the above:
<langsyntaxhighlight lang="applescript">local textFile, output
set textFile to ((path to desktop as text) & "unixdict.txt") as «class furl»
-- considering case -- Uncomment this and the corresponding 'end' line for case-sensitive searches.
set output to wordsContaining(textFile, "the", 12)
-- end considering
return {count output, output}</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">{32, {"authenticate", "chemotherapy", "chrysanthemum", "clothesbrush", "clotheshorse", "eratosthenes", "featherbedding", "featherbrain", "featherweight", "gaithersburg", "hydrothermal", "lighthearted", "mathematician", "neurasthenic", "nevertheless", "northeastern", "northernmost", "otherworldly", "parasympathetic", "physiotherapist", "physiotherapy", "psychotherapeutic", "psychotherapist", "psychotherapy", "radiotherapy", "southeastern", "southernmost", "theoretician", "weatherbeaten", "weatherproof", "weatherstrip", "weatherstripping"}}</langsyntaxhighlight>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">print.lines
select read.lines relative "unixdict.txt" 'l ->
and? [11 < size l]
[contains? l "the"]</syntaxhighlight>
 
{{out}}
 
<pre>authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping</pre>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">FileRead, wList, % A_Desktop "\unixdict.txt"
SubString := "the"
list := ContainSubStr(wList, SubString)
for i, v in list
result .= i "- " v "`n"
MsgBox, 262144, , % result
return
ContainSubStr(wList, SubString){
oRes := []
for i, w in StrSplit(wList, "`n", "`r")
{
if (StrLen(w) < 12 || !InStr(w, SubString))
continue
oRes.Push(w)
}
return oRes
}</syntaxhighlight>
{{out}}
<pre>1- authenticate
2- chemotherapy
3- chrysanthemum
4- clothesbrush
5- clotheshorse
6- eratosthenes
7- featherbedding
8- featherbrain
9- featherweight
10- gaithersburg
11- hydrothermal
12- lighthearted
13- mathematician
14- neurasthenic
15- nevertheless
16- northeastern
17- northernmost
18- otherworldly
19- parasympathetic
20- physiotherapist
21- physiotherapy
22- psychotherapeutic
23- psychotherapist
24- psychotherapy
25- radiotherapy
26- southeastern
27- southernmost
28- theoretician
29- weatherbeaten
30- weatherproof
31- weatherstrip
32- weatherstripping</pre>
 
=={{header|AutoIt}}==
<syntaxhighlight lang="autoit">
; Includes not needed if you don't want to use the constants
#include <FileConstants.au3>
#include <StringConstants.au3>
#include <MsgBoxConstants.au3>
 
;Initialise some variables and constants
Local Const $sFileName = "unixdict.txt"
Local Const $sStrToFind = "the"
Local $iFoundResults = 0
 
; Open the file for reading and store the handle to a variable.
Local $hFileOpen = FileOpen($sFileName, $FO_READ)
If $hFileOpen = -1 Then
MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
Return False
EndIf
 
; Read the contents of the file using the handle returned by FileOpen.
Local $sFileRead = FileRead($hFileOpen)
 
; Close the handle returned by FileOpen.
FileClose($hFileOpen)
 
; Get each "word" that's on a new line
Local $aArray = StringSplit($sFileRead, @CRLF)
 
; Loop through the array returned by StringSplit to check the length and if it containes the "the" substring.
For $i = 1 To $aArray[0]
If StringLen($aArray[$i]) > 11 Then
If StringInStr($aArray[$i], $sStrToFind) <> 0 Then
; Increment the found results counter
$iFoundResults += 1
; Log the output
ConsoleWrite($aArray[$i])
ConsoleWrite(@CRLF)
EndIf
EndIf
Next
 
ConsoleWrite("Found " & $iFoundResults & " words containing '" & $sStrToFind & "'")
</syntaxhighlight>
{{out}}
<pre>
authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping
Found 32 words containing 'the'>Exit code: 0 Time: 0.07385</pre>
 
=={{header|AWK}}==
The following is an awk one-liner entered at a Posix shell.
 
<langsyntaxhighlight lang="awk">/Code$ awk '/the/ && length($1) > 11' unixdict.txt
authenticate
chemotherapy
Line 217 ⟶ 549:
weatherstrip
weatherstripping
/Code$ </langsyntaxhighlight>
 
=={{header|BASIC}}==
<syntaxhighlight lang="basic">10 OPEN "I",1,"unixdict.txt"
20 IF EOF(1) THEN CLOSE #1: END
30 LINE INPUT #1,W$
40 IF LEN(W$)>11 AND INSTR(W$,"the") THEN PRINT W$
50 GOTO 20</syntaxhighlight>
{{out}}
<pre>authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping</pre>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="vb">f = freefile
open f, "i:\unixdict.txt"
while not eof(f)
a$ = read (f)
if length(a$) > 11 and instr(a$, "the") then print a$
end while
close f</syntaxhighlight>
{{out}}
<pre>Same as BASIC entry.</pre>
 
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{works with|QBasic}}
<syntaxhighlight lang="qbasic">10 OPEN "unixdict.txt" FOR INPUT AS #1
20 WHILE NOT EOF(1)
30 LINE INPUT #1, A$
40 IF LEN(A$) > 11 AND INSTR(A$,"the") THEN PRINT A$
50 WEND
60 CLOSE #1
70 END</syntaxhighlight>
{{out}}
<pre>Same as BASIC entry.</pre>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
<syntaxhighlight lang="qbasic">OPEN "unixdict.txt" FOR INPUT AS #1
WHILE NOT EOF(1)
LINE INPUT #1, W$
IF LEN(W$) > 11 AND INSTR(W$, "the") THEN PRINT W$
WEND
CLOSE #1
END</syntaxhighlight>
{{out}}
<pre>Same as BASIC entry.</pre>
 
=={{header|BCPL}}==
<syntaxhighlight lang="bcpl">get "libhdr"
 
let read(word) = valof
$( let ch = ?
word%0 := 0
$( ch := rdch()
if ch = endstreamch then resultis false
word%0 := word%0 + 1
word%(word%0) := ch
$) repeatuntil ch = '*N'
resultis true
$)
 
let contains(s1,s2) = valof
$( for i=1 to s1%0-s2%0+1
$( for j=1 to s2%0
unless s1%(i+j-1)=s2%j goto next
resultis true
next: loop
$)
resultis false
$)
 
// We need to test for a length of 12 rather than 11,
// because the newline character is included.
let match(word) = word%0 > 12 & contains(word,"the")
 
let start() be
$( let word = vec 63
let file = findinput("unixdict.txt")
test file=0 do
writes("Cannot open unixdict.txt*N")
or
$( selectinput(file)
while read(word) if match(word) do writes(word)
endread()
$)
$)</syntaxhighlight>
{{out}}
<pre style='height:50ex;'>authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping</pre>
 
=={{header|C}}==
<syntaxhighlight lang="c">#include <stdio.h>
#include <string.h>
 
int main() {
char word[128];
FILE *f = fopen("unixdict.txt","r");
if (!f) {
fprintf(stderr, "Cannot open unixdict.txt\n");
return -1;
}
while (!feof(f)) {
fgets(word, sizeof(word), f);
// fgets() includes the \n character, so we need to test
// for a length of 12 (11 letters plus the newline)
if (strlen(word) > 12 && strstr(word,"the"))
printf("%s",word);
}
fclose(f);
return 0;
}</syntaxhighlight>
{{out}}
<pre style="height:50ex;">authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <iostream>
#include <fstream>
 
int main() {
std::string word;
std::ifstream file("unixdict.txt");
if (!file) {
std::cerr << "Cannot open unixdict.txt" << std::endl;
return -1;
}
while (file >> word) {
if (word.length() > 11 && word.find("the") != std::string::npos)
std::cout << word << std::endl;
}
return 0;
}</syntaxhighlight>
{{out}}
<pre style="height:50ex;">authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping</pre>
 
=={{header|Common Lisp}}==
<syntaxhighlight lang="lisp">
(defun print-words-containing-substring (str len path)
(with-open-file (s path :direction :input)
(do ((line (read-line s nil :eof) (read-line s nil :eof)))
((eql line :eof)) (when (and (> (length line) len)
(search str line))
(format t "~a~%" line)))))
 
(print-words-containing-substring "the" 11 "unixdict.txt")
</syntaxhighlight>
{{out}}
<pre>authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping
NIL</pre>
 
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{libheader| System.IOUtils}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
program Words_containing_the_substring;
 
{$APPTYPE CONSOLE}
 
uses
System.SysUtils,
System.IOUtils;
 
var
Words, WordsFound: TArray<string>;
 
begin
Words := TFile.ReadAllLines('unixdict.txt');
 
for var w in Words do
begin
if (w.Length > 11) and (w.IndexOf('the') > -1) then
begin
SetLength(WordsFound, Length(WordsFound) + 1);
WordsFound[High(WordsFound)] := w;
end;
end;
writeln('Words containing "the" having a length > 11 in unixdict.txt:');
 
for var i := 0 to High(WordsFound) do
writeln(i + 1: 2, ': ', WordsFound[i]);
 
readln;
end.</syntaxhighlight>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">\util.g
 
proc theword(*char line) bool:
CharsLen(line) > 11
and CharsIndex(line, "the") ~= -1
corp
 
proc nonrec main() void:
file(1024) dictfile;
[32] char buf;
*char line;
channel input text dict;
open(dict, dictfile, "unixdict.txt");
line := &buf[0];
while readln(dict; line) do
if theword(line) then writeln(line) fi
od;
close(dict)
corp</syntaxhighlight>
{{out}}
<pre style='height:50ex;'>authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping</pre>
 
=={{header|Factor}}==
{{works with|Factor|0.99 2020-08-14}}
<syntaxhighlight lang="factor">USING: io io.encodings.ascii io.files kernel math sequences ;
 
"unixdict.txt" ascii file-lines
[ length 11 > ] filter
[ "the" swap subseq? ] filter
[ print ] each</syntaxhighlight>
{{out}}
<pre style="height:18em">
authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping
</pre>
 
=={{header|Forth}}==
Developed with Gforth 0.7.9
<syntaxhighlight lang="forth">11 constant WordLen
128 constant max-line
 
create SearchSub 80 allot
Create SrcFile 256 allot
Variable fhin
variable Cnt
 
: SrcOpen Srcfile count r/o open-file throw Fhin ! ;
: SrcClose fhin @ close-file throw ;
: third >r over r> swap ;
: cnt++ cnt 1 swap +! ;
: SubStrFound SearchSub count Search ;
 
: read-lines fhin @
begin pad max-line third read-line throw
while pad swap dup WordLen >
if 2dup SubStrFound -rot 2drop
if cnt++ cr type else 2drop then
else 2DROP
then
repeat 2drop ;
 
: Test 0 cnt !
s" ./unixdict.txt" SrcFile place
s" the" SearchSub place
SrcOpen
read-lines
cr ." =============="
cr ." Found " cnt @ . ." Words" cr
SrcClose ;
 
Test
</syntaxhighlight>
{{out}}
<pre>
authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping
==============
Found 32 Words
</pre>
 
=={{header|Fortran}}==
<syntaxhighlight lang="fortran">
program main
implicit none
integer :: lun
character(len=256) :: line
integer :: ios
open(file='unixdict.txt',newunit=lun)
do
read(lun,'(a)',iostat=ios)line
if(ios /= 0)exit
if( index(line,'the') /= 0 .and. len_trim(line) > 11 ) then
write(*,'(a)')trim(line)
endif
enddo
end program main
</syntaxhighlight>
 
{{out}}
<pre>
authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping
</pre>
 
=={{header|FreeBASIC}}==
Reuses some code from [[Odd words#FreeBASIC]]
<langsyntaxhighlight lang="freebasic">#define NULL 0
 
type node
Line 268 ⟶ 1,166:
next i
curr = curr->nxt
wend</langsyntaxhighlight>
{{out}}
<pre>
Line 303 ⟶ 1,201:
weatherstrip
weatherstripping</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">include "NSLog.incl"
 
#plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES}
 
void local fn DoIt
CFURLRef url
CFStringRef string, wd
ErrorRef err = NULL
CFArrayRef array
CFMutableArrayRef mutArray
url = fn URLWithString( @"https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt" )
string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, @err )
if ( string )
array = fn StringComponentsSeparatedByCharactersInSet( string, fn CharacterSetNewlineSet )
mutArray = fn MutableArrayWithCapacity(0)
for wd in array
if ( len(wd) > 11 and fn StringContainsString( wd, @"the" ) )
MutableArrayAddObject( mutArray, wd )
end if
next
string = fn ArrayComponentsJoinedByString( mutArray, @"\n" )
NSLog(@"%@",string)
else
NSLog(@"%@",err)
end if
end fn
 
fn DoIt
 
HandleEvents</syntaxhighlight>
 
{{out}}
<pre>
authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping
</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 338 ⟶ 1,307:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 377 ⟶ 1,346:
</pre>
 
=={{header|JuliaHaskell}}==
<syntaxhighlight lang="haskell">import System.IO (readFile)
<lang julia>function wordscontaining(needle, overlength, dictfile)
import Data.List (isInfixOf)
for haystack in split(read(dictfile, String))
length(haystack) > overlength && occursin(needle, haystack) && println(haystack)
end
end
 
main = do
wordscontaining("the", 11, "unixdict.txt")
txt <- readFile "unixdict.txt"
</lang>{{out}}
let res = [ w | w <- lines txt, isInfixOf "the" w, length w > 11 ]
putStrLn $ show (length res) ++ " words were found:"
mapM_ putStrLn res</syntaxhighlight>
<pre>λ> main
32 words were found:
authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping</pre>
 
=={{header|J}}==
<syntaxhighlight lang="j"> >(#~ (+./@E.~&'the'*11<#)@>) cutLF fread'unixdict.txt'
authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping</syntaxhighlight>
 
=={{header|JavaScript}}==
<syntaxhighlight lang="javascript">
document.write(`
<p>Select a file: <input type="file" id="file"></p>
<p>Get words containing: <input value="THE" type="text" id="cont"></p>
<p>Min. word length: <input type="number" value="12" id="len"></p>
<div id="info"></div><div id="out"></div>
`);
 
function search(inp) {
let cont = document.getElementById('cont').value.toUpperCase(),
len = parseInt(document.getElementById('len').value),
out = document.getElementById('out'),
info = document.getElementById('info'),
result = [], i;
inp = inp.replace(/\n|\r/g, '_');
inp = inp.replace(/__/g, ' ').split(' ');
for (i = 0; i < inp.length; i++)
if (inp[i].length >= len && inp[i].toUpperCase().indexOf(cont) != -1)
result.push(inp[i]);
info.innerHTML = `<h2>${result.length} matches found for ${cont}, min. length ${len}:</h2>`;
out.innerText = result.join(', ');
}
 
document.getElementById('file').onchange = function() {
let fr = new FileReader(),
f = document.getElementById('file').files[0];
fr.onload = function() { search(fr.result); }
fr.readAsText(f);
}
</syntaxhighlight>
{{out}}
<pre>
32 matches found for THE, min. length 12:
authenticate, chemotherapy, chrysanthemum, clothesbrush, clotheshorse, eratosthenes, featherbedding, featherbrain, featherweight, gaithersburg, hydrothermal, lighthearted, mathematician, neurasthenic, nevertheless, northeastern, northernmost, otherworldly, parasympathetic, physiotherapist, physiotherapy, psychotherapeutic, psychotherapist, psychotherapy, radiotherapy, southeastern, southernmost, theoretician, weatherbeaten, weatherproof, weatherstrip, weatherstripping
</pre>
 
=={{header|jq}}==
<syntaxhighlight lang="sh">jq -nrR 'inputs|select(length>11 and index("the"))' unixdict.txt</syntaxhighlight>
One could also use `test("the")` here instead, the difference being that the argument of `test` is a JSON string interpreted as a regular expression.
{{out}}
As for 11l et al.
=={{header|Julia}}==
See [[Alternade_words]] for the foreachword function.
<syntaxhighlight lang="julia">containsthe(w, d) = occursin("the", w) ? w : ""
foreachword("unixdict.txt", containsthe, minlen = 12)
</syntaxhighlight>{{out}}
<pre>
Word source: unixdict.txt
 
authenticate chemotherapy chrysanthemum clothesbrush clotheshorse eratosthenes
featherbedding featherbrain featherweight gaithersburg hydrothermal lighthearted
mathematician neurasthenic nevertheless northeastern northernmost otherworldly
parasympatheticphysiotherapistphysiotherapy psychotherapeuticpsychotherapistpsychotherapy
radiotherapy southeastern southernmost theoretician weatherbeaten weatherproof
weatherstrip weatherstripping
</pre>
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">for word in io.open("unixdict.txt", "r"):lines() do
if #word > 11 and word:find("the") then
print(word)
end
end</syntaxhighlight>
{{out}}
<pre>authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">dict = Once[Import["https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt"]];
dict //= StringSplit[#, "\n"] &;
dict //= Select[StringLength /* GreaterThan[11]];
Select[dict, StringContainsQ["the"]]</syntaxhighlight>
{{out}}
<pre>{authenticate, chemotherapy, chrysanthemum, clothesbrush, clotheshorse, eratosthenes, featherbedding, featherbrain, featherweight, gaithersburg, hydrothermal, lighthearted, mathematician, neurasthenic, nevertheless, northeastern, northernmost, otherworldly, parasympathetic, physiotherapist, physiotherapy, psychotherapeutic, psychotherapist, psychotherapy, radiotherapy, southeastern, southernmost, theoretician, weatherbeaten, weatherproof, weatherstrip, weatherstripping}</pre>
 
=={{header|min}}==
{{works with|min|0.27.1}}
<syntaxhighlight lang="min">"unixdict.txt" fread "\n" split
(length 11 >) filter
("the" indexof -1 !=) filter
(puts!) foreach</syntaxhighlight>
{{out}}
<pre style="height:18em">
authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
Line 420 ⟶ 1,572:
weatherstripping
</pre>
 
=={{header|Nanoquery}}==
<syntaxhighlight lang="nanoquery">words = split(new(Nanoquery.IO.File).open("unixdict.txt").readAll(),"\n")
for word in words
if (word .contains. "the") and (len(word) > 11)
println word
end if
end for</syntaxhighlight>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">import strutils
 
var count = 0
for word in "unixdict.txt".lines:
if word.len > 11 and word.contains("the"):
inc count
echo ($count).align(2), ' ', word</syntaxhighlight>
 
{{out}}
<pre> 1 authenticate
2 chemotherapy
3 chrysanthemum
4 clothesbrush
5 clotheshorse
6 eratosthenes
7 featherbedding
8 featherbrain
9 featherweight
10 gaithersburg
11 hydrothermal
12 lighthearted
13 mathematician
14 neurasthenic
15 nevertheless
16 northeastern
17 northernmost
18 otherworldly
19 parasympathetic
20 physiotherapist
21 physiotherapy
22 psychotherapeutic
23 psychotherapist
24 psychotherapy
25 radiotherapy
26 southeastern
27 southernmost
28 theoretician
29 weatherbeaten
30 weatherproof
31 weatherstrip
32 weatherstripping</pre>
 
=={{header|Objeck}}==
<syntaxhighlight lang="objeck">
class Thes {
function : Main(args : String[]) ~ Nil {
if(args->Size() = 1) {
reader := System.IO.File.FileReader->New(args[0]);
words := Collection.Generic.Vector->New()<String>;
line := reader->ReadLine();
while(line <> Nil) {
if(line->Size() > 11 & line->Has("the")) {
words->AddBack(line);
};
line := reader->ReadLine();
};
reader->Close();
 
found := words->Size();
"Found {$found} word(s):"->PrintLine();
each(i : words) {
word := words->Get(i);
"{$word} "->Print();
if(i > 0 & i % 5 = 0) {
'\n'->Print();
};
};
};
}
}</syntaxhighlight>
 
{{out}}
<pre>
Found 32 word(s):
authenticate chemotherapy chrysanthemum clothesbrush clotheshorse eratosthenes
featherbedding featherbrain featherweight gaithersburg hydrothermal
lighthearted mathematician neurasthenic nevertheless northeastern
northernmost otherworldly parasympathetic physiotherapist physiotherapy
psychotherapeutic psychotherapist psychotherapy radiotherapy southeastern
southernmost theoretician weatherbeaten weatherproof weatherstrip
weatherstripping</pre>
 
=={{header|Pascal}}==
{{works with|Extended Pascal}}
<syntaxhighlight lang="pascal">
program wordsContainingTheSubstring(input, output);
var
word: string(22);
begin
while not EOF do
begin
readLn(word);
if (length(word) > 11) and_then (index(word, 'the') > 0) then
begin
writeLn(word)
end
end
end.
</syntaxhighlight>
If <tt>unixdict.txt</tt> is fed to <tt>stdin</tt>, the standard input file, you will get the following output:
{{out}}
authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping
 
=={{header|Perl}}==
Perl one-liner entered from a Posix shell:
 
<langsyntaxhighlight lang="perl">/Code$ perl -n -e '/(\w*the\w*)/ && length($1)>11 && print' unixdict.txt
authenticate
chemotherapy
Line 457 ⟶ 1,753:
weatherstrip
weatherstripping
/Code$ </langsyntaxhighlight>
 
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>function the(string word) return length(word)>11 and match("the",word) end function
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
sequence words = filter(get_text("demo/unixdict.txt",GT_LF_STRIPPED),the)
<span style="color: #008080;">function</span> <span style="color: #000000;">the</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">word</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">word</span><span style="color: #0000FF;">)></span><span style="color: #000000;">11</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"the"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">word</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
printf(1,"found %d 'the' words:\n%s\n",{length(words),join(shorten(words,"",3),", ")})</lang>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">words</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">unix_dict</span><span style="color: #0000FF;">(),</span><span style="color: #000000;">the</span><span style="color: #0000FF;">)</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;">"found %d 'the' words:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">words</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">words</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">),</span><span style="color: #008000;">", "</span><span style="color: #0000FF;">)})</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 469 ⟶ 1,767:
authenticate, chemotherapy, chrysanthemum, ..., weatherproof, weatherstrip, weatherstripping
</pre>
=={{header|PHP}}==
<syntaxhighlight lang="php"><?php foreach(file("unixdict.txt") as $w) echo (strstr($w, "the") && strlen(trim($w)) > 11) ? $w : "";</syntaxhighlight>
 
=={{header|Plain English}}==
<syntaxhighlight lang="plainenglish">To run:
Start up.
Put "c:\unixdict.txt" into a path.
Read the path into a buffer.
Slap a rider on the buffer.
Loop.
Move the rider (text file rules).
Subtract 1 from the rider's token's last. \newline
Put the rider's token into a word string.
If the word is blank, break.
If the word's length is less than 12, repeat.
If "the" is in the word, write the word on the console.
Repeat.
Wait for the escape key.
Shut down.</syntaxhighlight>
{{out}}
<pre style="height:18em">
authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping
</pre>
 
=={{header|PL/I}}==
<syntaxhighlight lang="pli">the: procedure options(main);
declare dict file;
open file(dict) title('unixdict.txt');
on endfile(dict) stop;
declare word char(32) varying;
do while('1'b);
get file(dict) list(word);
if length(word) > 11 & index(word,'the') ^= 0 then
put skip list(word);
end;
close file(dict);
end the;</syntaxhighlight>
{{out}}
<pre>authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping</pre>
 
=={{header|Processing}}==
<syntaxhighlight lang="processing">String[] words = loadStrings("unixdict.txt");
for (String word : words) {
if (word.contains("the") && word.length() > 11) {
println(word);
}
}</syntaxhighlight>
{{out}}
<pre style="height:18em">authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping</pre>
 
=={{header|Python}}==
<syntaxhighlight lang="python">import urllib.request as request
Entered from a Posix shell:
 
with request.urlopen("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt") as f:
<lang python>/Code$ python -c 'import sys
a = f.read().decode("ASCII").split()
> for line in sys.stdin:
 
> if "the" in line and len(line.strip()) > 11:
for s in a:
> print(line.rstrip())
if len(s) > 11 and "the" in s:
> ' < unixdict.txt
print(s)</syntaxhighlight>
authenticate
 
<pre>authenticate
chemotherapy
chrysanthemum
Line 509 ⟶ 1,953:
weatherproof
weatherstrip
weatherstripping</pre>
 
=={{header|Quackery}}==
Uses a finite state machine to search efficiently for a substring.
(The fsm to search for "the" is built only once, during compilation.)
Presented as a dialogue in the Quackery shell (REPL).
 
<syntaxhighlight lang="quackery">/O> [ $ 'sundry/fsm.qky' loadfile ] now!
... [ dup
... [ $ 'the' buildfsm ] constant
... usefsm over found ] is contains-"the"
... []
... $ 'unixdict.txt' sharefile drop
... nest$ witheach
... [ dup size 12 < iff drop done
... contains-"the" iff [ nested join ]
... else drop ]
... 60 wrap$ cr
...
 
authenticate chemotherapy chrysanthemum clothesbrush
clotheshorse eratosthenes featherbedding featherbrain
featherweight gaithersburg hydrothermal lighthearted
mathematician neurasthenic nevertheless northeastern
northernmost otherworldly parasympathetic physiotherapist
physiotherapy psychotherapeutic psychotherapist
psychotherapy radiotherapy southeastern southernmost
theoretician weatherbeaten weatherproof weatherstrip
weatherstripping
 
/Code$ </lang>
Stack empty.</syntaxhighlight>
 
 
=={{header|R}}==
 
<syntaxhighlight lang="rsplus">words <- readLines("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt")
grep("the", words[nchar(words) > 11], value = T)</syntaxhighlight>
 
{{out}}
 
<pre> [1] "authenticate" "chemotherapy" "chrysanthemum" "clothesbrush"
[5] "clotheshorse" "eratosthenes" "featherbedding" "featherbrain"
[9] "featherweight" "gaithersburg" "hydrothermal" "lighthearted"
[13] "mathematician" "neurasthenic" "nevertheless" "northeastern"
[17] "northernmost" "otherworldly" "parasympathetic" "physiotherapist"
[21] "physiotherapy" "psychotherapeutic" "psychotherapist" "psychotherapy"
[25] "radiotherapy" "southeastern" "southernmost" "theoretician"
[29] "weatherbeaten" "weatherproof" "weatherstrip" "weatherstripping"</pre>
 
=={{header|Raku}}==
A trivial modification of the [[ABC_words#Raku|ABC words]] task.
 
<syntaxhighlight lang="raku" perl6line>put 'unixdict.txt'.IO.words».fc.grep({ (.chars > 11) && (.contains: 'the') })\
.&{"{+$_} words:\n " ~ .batch(8)».fmt('%-17s').join: "\n "};</langsyntaxhighlight>
{{out}}
<pre>32 words:
Line 523 ⟶ 2,013:
northernmost otherworldly parasympathetic physiotherapist physiotherapy psychotherapeutic psychotherapist psychotherapy
radiotherapy southeastern southernmost theoretician weatherbeaten weatherproof weatherstrip weatherstripping </pre>
 
=={{header|Red}}==
<syntaxhighlight lang="rebol">Red[]
 
foreach word read/lines %unixdict.txt [
if all [11 < length? word find word "the"] [print word]
]</syntaxhighlight>
{{out}}
<pre>
authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping
</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
, <ReadFile 1 'unixdict.txt'>: e.Dict
= <Each Show <Filter TheWord e.Dict>>;
};
 
TheWord {
(e.Word), e.Word: e.X 'the' e.Y,
<Lenw e.Word>: s.Len e.Word,
<Compare s.Len 11>: '+' = T;
(e.Word) = F;
};
 
ReadFile {
s.Chan e.Filename =
<Open 'r' s.Chan e.Filename>
<ReadFile (s.Chan)>;
 
(s.Chan), <Get s.Chan>: {
0 = <Close s.Chan>;
e.Line = (e.Line) <ReadFile (s.Chan)>;
};
};
 
Each {
s.F = ;
s.F t.I e.X = <Mu s.F t.I> <Each s.F e.X>;
};
 
Filter {
s.F = ;
s.F t.I e.X, <Mu s.F t.I>: {
T = t.I <Filter s.F e.X>;
F = <Filter s.F e.X>;
};
};
 
Show {
(e.X) = <Prout e.X>;
};</syntaxhighlight>
{{out}}
<pre>authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping</pre>
 
=={{header|REXX}}==
Line 533 ⟶ 2,139:
Programming note: &nbsp; If the minimum length is negative, &nbsp; it indicates to find the words &nbsp; (but not display them), &nbsp; and
<br>only the display the count of found words.
<langsyntaxhighlight lang="rexx">/*REXX program finds words that contain the substring "the" (within an identified dict.)*/
parse arg $ minL iFID . /*obtain optional arguments from the CL*/
if $=='' | $=="," then $= 'the' /*Not specified? Then use the default.*/
Line 540 ⟶ 2,146:
tell= minL>0; minL= abs(minL) /*use absolute value of minimum length.*/
@.= /*default value of any dictionary word.*/
do #=1 while lines(iFID)\==0 /*read each word in the file (word=X).*/
@.#= strip( linein( iFID) ) /*pick off a word from the input line. */
end /*#*/
#= # - 1 /*adjust word count because of DO loop.*/
$u= $; upper $u /*obtain an uppercase version of $. */
say copies('─', 25) # "words in the dictionary file: " iFID
say
finds= 0 /*count of the substring found in dict.*/
do j=1 for #-1; z= @.j; upper z /*process all the words that were found*/
if length(z)<minL then iterate /*Is word too short? Yes, then skip.*/
if pos($u, z)==0 then iterate /*Found the substring? No, " " */
Line 554 ⟶ 2,162:
/*stick a fork in it, we're all done. */
say copies('─', 25) finds " words (with a min. length of" ,
minL') that contains the substring: ' $</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
───────────────────────── 2510525104 words in the dictionary file: unixdict.txt
authenticate
chemotherapy
Line 600 ⟶ 2,208:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
cStr = read("unixdict.txt")
wordList = str2list(cStr)
Line 626 ⟶ 2,234:
 
see "done..." + nl
</syntaxhighlight>
</lang>
Output:
<pre>
Line 664 ⟶ 2,272:
32. weatherstripping
done...
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">File.foreach("unixdict.txt"){|w| puts w if w.size > 11 && w.match?("the") }
</syntaxhighlight>
{{out}}
<pre>authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping
</pre>
 
=={{header|Smalltalk}}==
mhmm - I interpret the words "in this page" as to read the URL and fetch the page then search those words there...
 
{{works with|Smalltalk/X}}
<syntaxhighlight lang ="smalltalk">d := 'unixdict.txt' asFilename contents asSet.
select:[:word | (word size > 11) and:[word includesString:'the']]
page := 'https://www.rosettacode.org/wiki/Words_containing_%22the%22_substring' asURL retrieveContents.
thenDo:#transcribeCR</syntaxhighlight>
page asCollectionOfWords
select:[:word | (word size > 11) and:[word includesString:'the' caseSensitive:trueOrFalseWhoKnows]]
thenDo:#transcribeCR</lang>
 
if counting per word is required (which is overkill here, as there are no duplicates in the file), keep them in a bag:
if not, then take the following:
<syntaxhighlight lang ="smalltalk">'unixdict.txt'bagOfWords asFilename contents:= Bag new.
'unixdict.txt' asFilename contents
select:[:word | (word size > 11) and:[word includesString:'the']]
thenDo:#[:word | bagOfWords add:word. word transcribeCR</lang>].
 
bagOfWords transcribeCR.
bagOfWords size transcribeCR</syntaxhighlight>
 
Note: #transcribeCR is a method in Object which says: "Transcript showCR:self".
 
{{works with|Smalltalk/X}}
Variant (as script file). Save to file: "filter.st":
<langsyntaxhighlight lang="smalltalk">#! /usr/bin/env stx --script
[Stdin atEnd] whileFalse:[
|word|
Line 691 ⟶ 2,340:
Stdout nextPutLine: word
]
]</langsyntaxhighlight>
Execute with:
<langsyntaxhighlight lang="shell">chmod +x filter.st
./filter.st < unixdict.txt</langsyntaxhighlight>
 
The output from the above counting snippet:
{{out}}
<pre>authenticate
chemotherapy
chrysanthemum
...
weatherproof
weatherstrip
weatherstripping
 
Bag(chrysanthemum(*1) hydrothermal(*1) nevertheless(*1) chemotherapy(*1) eratosthenes(*1)
mathematician(*1) ... theoretician(*1) weatherbeaten(*1) weatherstripping(*1))
 
32</pre>
 
=={{header|sed}}==
<syntaxhighlight lang="sed">#!/bin/sed -f
 
/^.\{12\}/!d
/the/!d</syntaxhighlight>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program the_words;
dict := open("unixdict.txt", "r");
loop doing geta(dict, word); until eof(dict) do
word ?:= "";
if #word > 11 and "the" in word then
print(word);
end if;
end loop;
close(dict);
end program;</syntaxhighlight>
{{out}}
<pre>authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping</pre>
 
=={{header|Standard ML}}==
<syntaxhighlight lang="sml">val hasThe = String.isSubstring "the"
 
fun isThe12 s = size s > 11 andalso hasThe s
 
val () = print
((String.concatWith " "
o List.filter isThe12
o String.tokens Char.isSpace
o TextIO.inputAll) TextIO.stdIn ^ "\n")</syntaxhighlight>
{{out}}
<pre>authenticate chemotherapy chrysanthemum clothesbrush clotheshorse eratosthenes featherbedding featherbrain featherweight gaithersburg hydrothermal lighthearted mathematician neurasthenic nevertheless northeastern northernmost otherworldly parasympathetic physiotherapist physiotherapy psychotherapeutic psychotherapist psychotherapy radiotherapy southeastern southernmost theoretician weatherbeaten weatherproof weatherstrip weatherstripping</pre>
 
=={{header|Swift}}==
<syntaxhighlight lang="swift">import Foundation
 
let minLength = 12
let substring = "the"
 
do {
try String(contentsOfFile: "unixdict.txt", encoding: String.Encoding.ascii)
.components(separatedBy: "\n")
.filter{$0.count >= minLength && $0.contains(substring)}
.enumerated()
.forEach{print(String(format: "%2d. %@", $0.0 + 1, $0.1))}
} catch {
print(error.localizedDescription)
}</syntaxhighlight>
 
{{out}}
<pre>
1. authenticate
2. chemotherapy
3. chrysanthemum
4. clothesbrush
5. clotheshorse
6. eratosthenes
7. featherbedding
8. featherbrain
9. featherweight
10. gaithersburg
11. hydrothermal
12. lighthearted
13. mathematician
14. neurasthenic
15. nevertheless
16. northeastern
17. northernmost
18. otherworldly
19. parasympathetic
20. physiotherapist
21. physiotherapy
22. psychotherapeutic
23. psychotherapist
24. psychotherapy
25. radiotherapy
26. southeastern
27. southernmost
28. theoretician
29. weatherbeaten
30. weatherproof
31. weatherstrip
32. weatherstripping
</pre>
 
=={{header|Tcl}}==
<syntaxhighlight lang="tcl">foreach w [read [open unixdict.txt]] {
if {[string first the $w] != -1 && [string length $w] > 11} {
puts $w
}
}</syntaxhighlight>
{{out}}
<pre>authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping</pre>
 
=={{header|VBA}}==
<syntaxhighlight lang="vb">Sub Main_Contain()
Dim ListeWords() As String, Book As String, i As Long, out() As String, count As Integer
Book = Read_File("C:\Users\" & Environ("Username") & "\Desktop\unixdict.txt")
ListeWords = Split(Book, vbNewLine)
For i = LBound(ListeWords) To UBound(ListeWords)
If Len(ListeWords(i)) > 11 Then
If InStr(ListeWords(i), "the") > 0 Then
ReDim Preserve out(count)
out(count) = ListeWords(i)
count = count + 1
End If
End If
Next
Debug.Print "Found : " & count & " words : " & Join(out, ", ")
End Sub
Private Function Read_File(Fic As String) As String
Dim Nb As Integer
Nb = FreeFile
Open Fic For Input As #Nb
Read_File = Input(LOF(Nb), #Nb)
Close #Nb
End Function</syntaxhighlight>
{{out}}
<pre>Found : 32 words : authenticate, chemotherapy, chrysanthemum, clothesbrush, clotheshorse, eratosthenes, featherbedding, featherbrain,
featherweight, gaithersburg, hydrothermal, lighthearted, mathematician, neurasthenic, nevertheless, northeastern, northernmost,
otherworldly, parasympathetic, physiotherapist, physiotherapy, psychotherapeutic, psychotherapist, psychotherapy, radiotherapy,
southeastern, southernmost, theoretician, weatherbeaten, weatherproof, weatherstrip, weatherstripping
</pre>
 
=={{header|VBScript}}==
Run it with Cscript
<syntaxhighlight lang="vb">
with createobject("ADODB.Stream")
.charset ="UTF-8"
.open
.loadfromfile("unixdict.txt")
s=.readtext
end with
a=split (s,vblf)
with new regexp
.pattern=".*?the.*"
 
for each i in a
if len(trim(i))>=11 then
if .test(i) then wscript.echo i
end if
next
end with
</syntaxhighlight>
{{out}}
<pre>
authenticate
brotherhood
calisthenic
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
clothesline
earthenware
endothelial
endothermic
eratosthenes
featherbedding
featherbrain
featherweight
furtherance
furthermore
furthermost
gaithersburg
grandfather
grandmother
hydrothermal
kinesthesis
leatherback
leatherneck
leatherwork
lighthearted
mathematician
netherlands
netherworld
neurasthenic
nevertheless
nonetheless
northeastern
northernmost
otherworldly
parasympathetic
parentheses
parenthesis
parenthetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
smithereens
southeastern
southernmost
sympathetic
thenceforth
theoretician
therapeutic
thereabouts
theretofore
weatherbeaten
weatherproof
weatherstrip
weatherstripping
</pre>
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">import os
 
fn main() {
mut count := 1
mut text :=''
unixdict := os.read_file('./unixdict.txt') or {panic('file not found')}
for word in unixdict.split_into_lines() {
if word.contains('the') && word.len > 11 {text += count++.str() + ': $word \n'}
}
println(text)
}</syntaxhighlight>
 
{{out}}
<pre>
1: authenticate
2: chemotherapy
3: chrysanthemum
4: clothesbrush
5: clotheshorse
6: eratosthenes
7: featherbedding
8: featherbrain
9: featherweight
10: gaithersburg
11: hydrothermal
12: lighthearted
13: mathematician
14: neurasthenic
15: nevertheless
16: northeastern
17: northernmost
18: otherworldly
19: parasympathetic
20: physiotherapist
21: physiotherapy
22: psychotherapeutic
23: psychotherapist
24: psychotherapy
25: radiotherapy
26: southeastern
27: southernmost
28: theoretician
29: weatherbeaten
30: weatherproof
31: weatherstrip
32: weatherstripping
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "io" for File
import "./fmt" for Fmt
 
var wordList = "unixdict.txt" // local copy
Line 710 ⟶ 2,691:
Fmt.print("$2d: $s", count, word)
}
}</langsyntaxhighlight>
 
{{out}}
Line 748 ⟶ 2,729:
32: weatherstripping
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">string 0; \use zero-terminated strings
int I, Ch, Len;
char Word(100); \(longest word in unixdict.txt is 22 chars)
def LF=$0A, CR=$0D, EOF=$1A;
[FSet(FOpen("unixdict.txt", 0), ^I); \open dictionary and set it to device 3
OpenI(3);
repeat I:= 0;
loop [repeat Ch:= ChIn(3) until Ch # CR; \remove possible CR
if Ch=LF or Ch=EOF then quit;
Word(I):= Ch;
I:= I+1;
];
Word(I):= 0; \terminate string
Len:= I;
if Len >= 12 then
for I:= 0 to Len-3 do \scan for "the" (assume lowercase)
if Word(I)=^t & Word(I+1)=^h & Word(I+2)=^e then
[Text(0, Word); CrLf(0)];
until Ch = EOF;
]</syntaxhighlight>
 
{{out}}
<pre>
authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping
</pre>
 
=={{header|Yabasic}}==
<syntaxhighlight lang="yabasic">// Rosetta Code problem: http://rosettacode.org/wiki/Words_containing_"the"_substring
// by Galileo, 02/2022
 
a = open("unixdict.txt")
while not eof(a)
line input #a a$
if len(a$) > 11 and instr(a$, "the") print a$
wend
close a</syntaxhighlight>
{{out}}
<pre>authenticate
chemotherapy
chrysanthemum
clothesbrush
clotheshorse
eratosthenes
featherbedding
featherbrain
featherweight
gaithersburg
hydrothermal
lighthearted
mathematician
neurasthenic
nevertheless
northeastern
northernmost
otherworldly
parasympathetic
physiotherapist
physiotherapy
psychotherapeutic
psychotherapist
psychotherapy
radiotherapy
southeastern
southernmost
theoretician
weatherbeaten
weatherproof
weatherstrip
weatherstripping
---Program done, press RETURN---</pre>
 
{{omit from|6502 Assembly|unixdict.txt is much larger than the CPU's address space.}}
{{omit from|8080 Assembly|See 6502 Assembly.}}
{{omit from|Computer/zero Assembly|See 6502 Assembly.}}
{{omit from|Z80 Assembly|See 6502 Assembly.}}
2,114

edits