Words from neighbour ones: Difference between revisions
No edit summary |
(→{{header|Raku}}: Added Raku solution) |
||
Line 14: | Line 14: | ||
<br>If ''newword'' in dictionary then show on this page. |
<br>If ''newword'' in dictionary then show on this page. |
||
<br> lenght of ''newword'' = 9 |
<br> lenght of ''newword'' = 9 |
||
=={{header|Raku}}== |
|||
<lang perl6>my @words_ge_9 = 'unixdict.txt'.IO.lines.grep( *.chars >= 9 ); |
|||
my %words_eq_9 = @words_ge_9 .grep( *.chars == 9 ).Set; |
|||
my @new_words = gather for @words_ge_9.rotor( 9 => -8 ) -> @nine_words { |
|||
my $new_word = [~] map { @nine_words[$_].substr($_, 1) }, ^9; |
|||
take $new_word if %words_eq_9{$new_word}; |
|||
} |
|||
.say for unique @new_words;</lang> |
|||
{{out}} |
|||
<pre> |
|||
applicate |
|||
architect |
|||
astronomy |
|||
christine |
|||
christoph |
|||
committee |
|||
composite |
|||
constrict |
|||
construct |
|||
different |
|||
extensive |
|||
greenwood |
|||
implement |
|||
improvise |
|||
intercept |
|||
interpret |
|||
interrupt |
|||
philosoph |
|||
prescript |
|||
receptive |
|||
telephone |
|||
transcend |
|||
transport |
|||
transpose |
|||
</pre> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |
Revision as of 16:03, 6 February 2021
- 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
Raku
<lang perl6>my @words_ge_9 = 'unixdict.txt'.IO.lines.grep( *.chars >= 9 ); my %words_eq_9 = @words_ge_9 .grep( *.chars == 9 ).Set;
my @new_words = gather for @words_ge_9.rotor( 9 => -8 ) -> @nine_words {
my $new_word = [~] map { @nine_words[$_].substr($_, 1) }, ^9;
take $new_word if %words_eq_9{$new_word};
}
.say for unique @new_words;</lang>
- Output:
applicate architect astronomy christine christoph committee composite constrict construct different extensive greenwood implement improvise intercept interpret interrupt philosoph prescript receptive telephone transcend transport transpose
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...