Words from neighbour ones: Difference between revisions

Added Algol 68
(Initial FutureBasic task solution added)
(Added Algol 68)
 
(3 intermediate revisions by 3 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 744 ⟶ 869:
MutableStringSetString( mutStr, @"" )
for i = 0 to len(noDuplicates) - 1
MutableStringAppendString( mutStr, fn StringWithFormat( @"%2ld. %@\n", i+1, noDuplicates[i] ) )
next
printf @"%@", mutStr
Line 755 ⟶ 880:
{{output}}
<pre style="height:20ex;">
01. applicate
12. architect
23. astronomy
34. christine
45. christoph
56. committee
67. composite
78. constrict
89. construct
910. different
1011. extensive
1112. greenwood
1213. implement
1314. improvise
1415. intercept
1516. interpret
1617. interrupt
1718. philosoph
1819. prescript
1920. receptive
2021. telephone
2122. transcend
2223. transport
2324. transpose
</pre>
 
 
=={{header|Go}}==
Line 1,393 ⟶ 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,719 ⟶ 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,038

edits