Find words whose first and last three letters are equal: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 8: Line 8:


=={{header|Julia}}==
=={{header|Julia}}==
#See Alternade_words#Julia for the foreachword function. Yawn.
See Alternade_words#Julia for the foreachword function. Yawn.
<lang julia>matchfirstlast3(word, _) = length(word) > 5 && word[1:3] == word[end-2:end] ? word : ""
<lang julia>matchfirstlast3(word, _) = length(word) > 5 && word[1:3] == word[end-2:end] ? word : ""
foreachword("unixdict.txt", matchfirstlast3, numcols=4)
foreachword("unixdict.txt", matchfirstlast3, numcols=4)

Revision as of 08:40, 10 February 2021

Find words whose first and last three letters are equal is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task

Use the dictionary  unixdict.txt

Find the words which first and last three letters are equals.

The length of any word shown should have a length   >  5.

Julia

See Alternade_words#Julia for the foreachword function. Yawn. <lang julia>matchfirstlast3(word, _) = length(word) > 5 && word[1:3] == word[end-2:end] ? word : "" foreachword("unixdict.txt", matchfirstlast3, numcols=4)

</lang>

Output:
antiperspirant calendrical    einstein       hotshot
murmur         oshkosh        tartar         testes

Ring

<lang ring> load "stdlib.ring"

cStr = read("unixdict.txt") wordList = str2list(cStr) num = 0

see "working..." + nl see "Words are:" + nl

ln = len(wordList) for n = ln to 1 step -1

   if len(wordList[n]) < 6
      del(wordList,n)
   ok

next

for n = 1 to len(wordList)

   if left(wordList[n],3) = right(wordList[n],3) 
      num = num + 1
      see "" + num + ". " + wordList[n] + nl
   ok

next

see "done..." + nl </lang> Output:

working...
Words are:
1. antiperspirant
2. calendrical
3. einstein
4. hotshot
5. murmur
6. oshkosh
7. tartar
8. testes
done...