Words from neighbour ones: Difference between revisions

Added Algol 68
(Added Algol 68)
 
(5 intermediate revisions by 4 users not shown)
Line 39:
print(newWord)</syntaxhighlight>
 
{{out}}
<pre>
applicate
architect
astronomy
christine
christoph
committee
committee
committee
committee
committee
composite
constrict
constrict
construct
different
extensive
greenwood
implement
improvise
intercept
interpret
interrupt
interrupt
philosoph
prescript
receptive
telephone
transcend
transcend
transport
transpose
</pre>
 
=={{header|ALGOL 68}}==
<syntaxhighlight lang="algol68">
# find words where concatenating the nth character from this and the next 8 #
# words results in another word - only words of 9 or more characters are to #
# be considered #
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 - notes eof has been reached and #
# returns TRUE so processing can continue #
on logical file end( input file, ( REF FILE f )BOOL: at eof := TRUE );
 
# table of possible words - there are around 8 000 9+ character words #
[ 1 : 10 000 ]STRING words; # in unixdict.txt #
 
# in-place quick sort an array of strings #
PROC s quicksort = ( REF[]STRING a, INT lb, ub )VOID:
IF ub > lb
THEN
# more than one element, so must sort #
INT left := lb;
INT right := ub;
# choosing the middle element of the array as the pivot #
STRING pivot := a[ left + ( ( right + 1 ) - left ) OVER 2 ];
WHILE
WHILE IF left <= ub THEN a[ left ] < pivot ELSE FALSE FI
DO
left +:= 1
OD;
WHILE IF right >= lb THEN a[ right ] > pivot ELSE FALSE FI
DO
right -:= 1
OD;
left <= right
DO
STRING t := a[ left ];
a[ left ] := a[ right ];
a[ right ] := t;
left +:= 1;
right -:= 1
OD;
s quicksort( a, lb, right );
s quicksort( a, left, ub )
FI # s quicksort # ;
 
# returns the length of s #
OP LENGTH = ( STRING s )INT: 1 + ( UPB s - LWB s );
 
# returns TRUE if words[ low : high ] comntains s, FALSE otherwise #
PROC is word = ( STRING s, INT low, high )BOOL:
IF high < low THEN FALSE
ELSE INT mid = ( low + high ) OVER 2;
IF words[ mid ] > s THEN is word( s, low, mid - 1 )
ELIF words[ mid ] = s THEN TRUE
ELSE is word( s, mid + 1, high )
FI
FI # is word # ;
 
INT min length = 9; # minimum length of word to consider #
INT w count := 0; # store the 9 character words #
WHILE
STRING word;
get( input file, ( word, newline ) );
NOT at eof
DO
IF LENGTH word >= min length THEN
words[ w count +:= 1 ] := word
FI
OD;
close( input file );
s quicksort( words, 1, w count ); # sort the words #
FOR i TO ( w count + 1 ) - min length DO # find the required words #
STRING c word := words[ i ][ LWB words[ i ] ];
INT w pos := i;
FOR c pos TO 8 DO
STRING w = words[ w pos +:= 1 ];
c word +:= w[ c pos + LWB words[ i ] ]
OD;
IF is word( c word, 1, w count ) THEN
print( ( c word, newline ) )
FI
OD
FI
</syntaxhighlight>
{{out}}
<pre>
Line 712 ⟶ 837:
</pre>
 
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
#plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES}
 
local fn WordList as CFArrayRef
CFURLRef url = fn URLWithString( @"http://wiki.puzzlers.org/pub/wordlists/unixdict.txt" )
CFStringRef string = lcase(fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )), testStr
CFArrayRef wordArr = fn StringComponentsSeparatedByString( string, @"\n" )
CFMutableArrayRef wordsToKeep = fn MutableArrayNew
for testStr in wordArr
if len(testStr) > 8 then MutableArrayAddObject( wordsToKeep, testStr )
next
end fn = fn ArrayWithArray( wordsToKeep )
 
local fn TestWords
CFArrayRef wordArr = fn WordList
NSInteger i = 0, j = 0, count = len( wordArr )
CFMutableStringRef mutStr = fn MutableStringNew
CFMutableArrayRef mutArr = fn MutableArrayNew
for i = 0 to count - 9
CFMutableStringRef tempMutStr = fn MutableStringNew
for j = 0 to 8
MutableStringAppendString( tempMutStr, mid( wordArr[i + j], j, 1 ) )
next
if fn ArrayContainsObject( wordArr, tempMutStr ) then MutableArrayAddObject( mutArr, fn StringWithFormat( @"%@", tempMutStr ) )
next
CFArrayRef noDuplicates = fn OrderedSetArray( fn OrderedSetWithArray( mutArr ) )
MutableStringSetString( mutStr, @"" )
for i = 0 to len(noDuplicates) - 1
MutableStringAppendString( mutStr, fn StringWithFormat( @"%2ld. %@\n", i+1, noDuplicates[i] ) )
next
printf @"%@", mutStr
end fn
 
fn TestWords
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre style="height:20ex;">
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
</pre>
 
=={{header|Go}}==
Line 1,324 ⟶ 1,517:
transpose
</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ [] swap
behead nested swap
witheach
[ over 0 peek
over = iff
drop done
nested
dip join ]
join ] is unique ( [ --> [ )
 
 
[ over find swap found ] is has ( [ x --> b )
 
[ [] swap 9 split drop
witheach
[ i^ peek join ] ] is diagonal ( [ --> [ )
 
$ "rosetta/unixdict.txt" sharefile
drop nest$
[] [] rot witheach
[ dup size 9 < iff
drop
else
[ nested join ] ]
dup temp put
dup size 8 - times
[ dup diagonal
temp share
over has iff
[ nested
swap dip join ]
else drop
behead drop ]
temp release
drop
unique
witheach
[ echo$
i^ 4 mod 3 = iff
cr else sp ]</syntaxhighlight>
 
{{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|Raku}}==
Line 1,509 ⟶ 1,754:
<syntaxhighlight lang="ruby">new_word_size = 9
well_sized = File.readlines("unixdict.txt", chomp: true).reject{|word| word.size < new_word_size}
list = well_sized.each_cons(new_word_size).filter_map do |slice|
candidate = (0...new_word_size).inject(""){|res, idx| res << slice[idx][idx] }
puts candidate if well_sized.include?(candidate)
end
puts list.uniq
</syntaxhighlight>
{{out}}
Line 1,520 ⟶ 1,766:
christine
christoph
committee
committee
committee
committee
committee
composite
constrict
constrict
construct
Line 1,536 ⟶ 1,777:
intercept
interpret
interrupt
interrupt
philosoph
Line 1,542 ⟶ 1,782:
receptive
telephone
transcend
transcend
transport
transpose
</pre>
 
=={{header|VBScript}}==
Run it in CScript.
Line 1,655 ⟶ 1,895:
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "io" for File
import "./sort" for Find
import "./fmt" for Fmt
 
var wordList = "unixdict.txt" // local copy
3,044

edits