Words containing "the" substring: Difference between revisions
Thundergnat (talk | contribs) m (→{{header|Raku}}: link directly to example) |
m (→{{header|REXX}}: added the computer programming language REXX.) |
||
Line 160: | Line 160: | ||
northernmost otherworldly parasympathetic physiotherapist physiotherapy psychotherapeutic psychotherapist psychotherapy |
northernmost otherworldly parasympathetic physiotherapist physiotherapy psychotherapeutic psychotherapist psychotherapy |
||
radiotherapy southeastern southernmost theoretician weatherbeaten weatherproof weatherstrip weatherstripping </pre> |
radiotherapy southeastern southernmost theoretician weatherbeaten weatherproof weatherstrip weatherstripping </pre> |
||
=={{header|REXX}}== |
|||
<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.*/ |
|||
if minL=='' | minL=="," then minL= 12 /* " " " " " " */ |
|||
if iFID=='' | iFID=="," then iFID='unixdict.txt' /* " " " " " " */ |
|||
@.= /*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 /*#*/ |
|||
say copies('─', 25) # "words in the dictionary file: " iFID |
|||
$u= $; upper $u /*obtain an uppercase version of chrs.*/ |
|||
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 long enough? No, then skip. */ |
|||
if pos($u, z)==0 then iterate /*Found the substring? No, then skip.*/ |
|||
finds= finds + 1 /*bump count of substring words found. */ |
|||
say right(left(@.j, 20), 25) /*indent original word for readability.*/ |
|||
end /*j*/ |
|||
/*stick a fork in it, we're all done. */ |
|||
say copies('─', 25) finds " words (with a min. length of" , |
|||
minL') that contains the substring: ' $</lang> |
|||
{{out|output|text= when using the default inputs:}} |
|||
<pre> |
|||
───────────────────────── 25105 words in the dictionary file: 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 |
|||
───────────────────────── 32 words (with a min. length of 12) that contains the substring: the |
|||
</pre> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |
Revision as of 16:22, 6 December 2020
- Task
Using the dictionary unixdict.txt, search words containing "the" substring,
then display the found words (on this page).
The length of any word shown should have a length > 11.
ALGOL 68
<lang algol68># find 12 character (or more) words that have "the" in them # IF FILE input file;
STRING file name = "unixdict.txt"; open( input file, file name, stand in channel ) /= 0
THEN
# failed to open the file # print( ( "Unable to open """ + file name + """", newline ) )
ELSE
# file opened OK # BOOL at eof := FALSE; # set the EOF handler for the file # on logical file end( input file, ( REF FILE f )BOOL: BEGIN # note that we reached EOF on the # # latest read # at eof := TRUE; # return TRUE so processing can continue # TRUE END ); INT the count := 0; WHILE STRING word; get( input file, ( word, newline ) ); NOT at eof DO IF INT w len = ( UPB word + 1 ) - LWB word; w len > 11 THEN BOOL found the := FALSE; FOR w pos FROM LWB word TO UPB word - 2 WHILE NOT found the DO IF word[ w pos : w pos + 2 ] = "the" THEN found the := TRUE; the count +:= 1; print( ( word, " " ) ); IF the count MOD 6 = 0 THEN print( ( newline ) ) ELSE FROM w len + 1 TO 18 DO print( ( " " ) ) OD FI FI OD FI OD; print( ( newline, "found ", whole( the count, 0 ), " ""the"" words", newline ) ); close( input file )
FI</lang>
- Output:
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
FreeBASIC
Reuses some code from Odd words#FreeBASIC <lang freebasic>#define NULL 0
type node
word as string*32 'enough space to store any word in the dictionary nxt as node ptr
end type
function addword( tail as node ptr, word as string ) as node ptr
'allocates memory for a new node, links the previous tail to it, 'and returns the address of the new node dim as node ptr newnode = allocate(sizeof(node)) tail->nxt = newnode newnode->nxt = NULL newnode->word = word return newnode
end function
function length( word as string ) as uinteger
'necessary replacement for the built-in len function, which in this 'case would always return 32 for i as uinteger = 1 to 32 if asc(mid(word,i,1)) = 0 then return i-1 next i return 999
end function
dim as string word dim as node ptr tail = allocate( sizeof(node) ) dim as node ptr head = tail, curr = head, currj tail->nxt = NULL tail->word = "XXXXHEADER"
open "unixdict.txt" for input as #1 while true
line input #1, word if word = "" then exit while if length(word)>11 then tail = addword( tail, word )
wend close #1
dim as string tempword
while curr->nxt <> NULL
for i as uinteger = 1 to length(curr->word)-3 if mid(curr->word,i,3) = "the" then print curr->word next i curr = curr->nxt
wend</lang>
- Output:
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
Raku
A trivial modification of the ABC words task.
<lang perl6>put 'unixdict.txt'.IO.words».fc.grep({ (.chars > 11) && (.contains: 'the') })\
.&{"{+$_} words:\n " ~ .batch(8)».fmt('%-17s').join: "\n "};</lang>
- Output:
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
REXX
<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.*/ if minL== | minL=="," then minL= 12 /* " " " " " " */ if iFID== | iFID=="," then iFID='unixdict.txt' /* " " " " " " */ @.= /*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 /*#*/
say copies('─', 25) # "words in the dictionary file: " iFID $u= $; upper $u /*obtain an uppercase version of chrs.*/ 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 long enough? No, then skip. */ if pos($u, z)==0 then iterate /*Found the substring? No, then skip.*/ finds= finds + 1 /*bump count of substring words found. */ say right(left(@.j, 20), 25) /*indent original word for readability.*/ end /*j*/ /*stick a fork in it, we're all done. */
say copies('─', 25) finds " words (with a min. length of" ,
minL') that contains the substring: ' $</lang>
- output when using the default inputs:
───────────────────────── 25105 words in the dictionary file: 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 ───────────────────────── 32 words (with a min. length of 12) that contains the substring: the
Ring
<lang ring> cStr = read("unixdict.txt") wordList = str2list(cStr) num = 0 the = "the"
see "working..." + nl
ln = len(wordList) for n = ln to 1 step -1
if len(wordList[n]) < 12 del(wordList,n) ok
next
see "Words containing "the" substring:" + nl
for n = 1 to len(wordList)
ind = substr(wordList[n],the) if ind > 0 num = num +1 see "" + num + ". " + wordList[n] + nl ok
next
see "done..." + nl </lang> Output:
working... Founded "the" words are: 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 done...