Words containing "the" substring
- 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.
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
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...