Words from neighbour ones: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
No edit summary
Line 3: Line 3:
;Task:
;Task:
Use the dictionary   [https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt unixdict.txt]
Use the dictionary   [https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt unixdict.txt]
<br> Delete from directory words which lenghts are smaller then 9
<br>Let's take the words from next characters:
<br>Let's take the words from next characters:
<br>1 <= n < (dictionary lenght) - 9
<br>1 <= n < (dictionary lenght) - 9

Revision as of 09:19, 6 February 2021

Words from neighbour ones 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
Delete from directory words which lenghts are smaller then 9
Let's take the words from next characters:
1 <= n < (dictionary lenght) - 9
char1 = 1st character of nth word.
char2 = 2st character of (n+1)th word.
char3 = 3st character of (n+2)th word.
...
char9 = 9st character of (n+8)th word.
newword = char1+char2+char3+...+char9
If newword in dictionary then show on this page.
lenght of newword = 9

Ring

<lang ring> cStr = read("unixdict.txt") wordList = str2list(cStr) nextwords = [] num = 0

see "working..." + nl

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

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

next

see "New words are:" + nl

for n = 1 to len(wordList)-9

   c1 = substr(wordList[n],1,1)
   c2 = substr(wordList[n+1],2,1)
   c3 = substr(wordList[n+2],3,1)
   c4 = substr(wordList[n+3],4,1)
   c5 = substr(wordList[n+4],5,1)
   c6 = substr(wordList[n+5],6,1)
   c7 = substr(wordList[n+6],7,1)
   c8 = substr(wordList[n+7],8,1)
   c9 = substr(wordList[n+8],9,1)
   str = c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9 
   ind = find(wordList,str)
   if ind > 0
      add(nextwords,wordList[ind])
   ok

next

nextwords = sort(nextwords) for n = len(nextwords) to 2 step -1

   if nextwords[n] = nextwords[n-1]
      del(nextwords,n)
   ok

next

for n = 1 to len(nextwords)

   see "" + n + ". " + nextwords[n] + nl

next

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

working...
New words are:
1. applicate
2. architect
3. astronomy
4. christine
5. christoph
6. committee
7. composite
8. constrict
9. construct
10. different
11. extensive
12. greenwood
13. implement
14. improvise
15. intercept
16. interpret
17. interrupt
18. philosoph
19. prescript
20. receptive
21. telephone
22. transcend
23. transport
24. transpose
done...