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

m
(Added solution for Action!)
m (→‎{{header|Wren}}: Minor tidy)
 
(23 intermediate revisions by 19 users not shown)
Line 10:
{{Template:Strings}}
<br><br>
 
=={{header|11l}}==
<syntaxhighlight lang="11l">L(word) File(‘unixdict.txt’).read().split("\n")
I word.len > 5 & word[0.<3] == word[(len)-3..]
print(word)</syntaxhighlight>
 
{{out}}
<pre>
antiperspirant
calendrical
einstein
hotshot
murmur
oshkosh
tartar
testes
</pre>
 
=={{header|Action!}}==
In the following solution the input file [https://gitlab.com/amarok8bit/action-rosetta-code/-/blob/master/source/unixdict.txt unixdict.txt] is loaded from H6 drive. Altirra emulator automatically converts CR/LF character from ASCII into 155 character in ATASCII charset used by Atari 8-bit computer when one from H6-H10 hard drive under DOS 2.5 is used.
<langsyntaxhighlight Actionlang="action!">BYTE FUNC IsValidWord(CHAR ARRAY word)
BYTE len
 
Line 44 ⟶ 61:
 
FindWords(fname)
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Find_words_whose_first_and_last_three_letters_are_equal.png Screenshot from Atari 8-bit computer]
Line 52 ⟶ 69:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_Io;
with Ada.Strings.Fixed;
 
Line 75 ⟶ 92:
end loop;
Close (File);
end Find_Three_Equals;</langsyntaxhighlight>
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68"># find 6 (or more) character words with the same first and last 3 letters #
IF FILE input file;
STRING file name = "unixdict.txt";
Line 119 ⟶ 136:
print( ( newline, "found ", whole( count, 0 ), " words with the same first and last 3 characters", newline ) );
close( input file )
FI</langsyntaxhighlight>
{{out}}
<pre>
Line 126 ⟶ 143:
found 8 words with the same first and last 3 characters
</pre>
 
=={{header|AppleScript}}==
<syntaxhighlight lang="applescript">on task()
script o
property wrds : words of ¬
(read file ((path to desktop as text) & "www.rosettacode.org:unixdict.txt") as «class utf8»)
property output : {}
end script
repeat with thisWord in o's wrds
if ((thisWord's length > 5) and (thisWord ends with thisWord's text 1 thru 3)) then ¬
set end of o's output to thisWord
end repeat
return o's output's contents
end task
 
task()</syntaxhighlight>
 
{{output}}
<syntaxhighlight lang="applescript">{"antiperspirant", "calendrical", "einstein", "hotshot", "murmur", "oshkosh", "tartar", "testes"}</syntaxhighlight>
 
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">words: read.lines relative "unixdict.txt"
equalHeadTail?: function [w][
equal? first.n: 3 w last.n: 3 w
Line 139 ⟶ 177:
print word
]
]</langsyntaxhighlight>
 
{{out}}
Line 153 ⟶ 191:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">FileRead, db, % A_Desktop "\unixdict.txt"
for i, word in StrSplit(db, "`n", "`r")
if StrLen(word) < 6
Line 160 ⟶ 198:
result .= word "`n"
MsgBox, 262144, , % result
return</langsyntaxhighlight>
{{out}}
<pre>antiperspirant
Line 172 ⟶ 210:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f FIND_WORDS_WHICH_FIRST_AND_LAST_THREE_LETTERS_ARE_EQUALS.AWK unixdict.txt
(length($0) >= 6 && substr($0,1,3) == substr($0,length($0)-2,3))
Line 178 ⟶ 216:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 189 ⟶ 227:
tartar
testes
</pre>
 
=={{header|C}}==
<syntaxhighlight lang="c">
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
 
/* "Using the dictionary unixdict.txt" */
#define DICTIONARY_FILE_NAME "unixdict.txt"
 
/* take into account the first and last 3 letters */
#define CHUNK_LENGTH 3
 
/* "The length of any word shown should be >5" */
#define MIN_WORD_LENGTH 6
 
 
char *create_word_buffer( const char *file_name, size_t *buffer_size );
int wait_for_return( void );
 
 
int main() {
size_t buffer_size = 0;
char *buffer = create_word_buffer( DICTIONARY_FILE_NAME, &buffer_size );
 
if( buffer ) {
FILE *f = fopen( DICTIONARY_FILE_NAME, "r" );
 
if( f ) {
while( fgets(buffer,buffer_size,f) ) {
size_t l = strlen( buffer );
if( '\n'==buffer[l-1] ) buffer[--l] = '\0';
 
if( l>=MIN_WORD_LENGTH &&
0==memcmp(buffer,buffer+l-CHUNK_LENGTH,CHUNK_LENGTH) ) {
printf( "%s\n", buffer );
}
}
 
fclose( f ); f = NULL; /* cleanup */
} else puts( "Couldn't open dictionary file." );
 
free( buffer ); buffer = NULL; /* cleanup */
} else puts( "Couldn't create word buffer." );
 
return wait_for_return();
}
 
 
/*==============================================================================
No need to verify any parameters in any of the following function - the caller
did his homeworks.
==============================================================================*/
 
 
size_t get_line_length( FILE *f ) {
size_t line_length = 0;
int c, ok;
 
do {
c = fgetc(f);
ok = '\n'!=c&&EOF!=c;
line_length += ok;
} while( ok );
 
return line_length;
}
 
 
size_t find_longest_line_in_file( const char *file_name ) {
size_t max_line_length = ((size_t)-1);
 
FILE *f = fopen( file_name, "r" );
 
if( f ) {
max_line_length = 0;
 
while( !feof(f) ) {
size_t line_length = get_line_length( f );
 
if( line_length>max_line_length )
max_line_length = line_length;
}
 
fclose( f ); f = NULL;
}
 
return max_line_length;
}
 
 
char *create_word_buffer( const char *file_name, size_t *buffer_size ) {
char *buffer = NULL;
 
size_t max_line_length = find_longest_line_in_file( file_name );
 
if( ((size_t)-1)!=max_line_length ) {
buffer = calloc( max_line_length+2, sizeof(*buffer) );
if( buffer ) *buffer_size = max_line_length+2;
}
 
return buffer;
}
 
 
int wait_for_return( void ) {
puts( "\nPress Return to exit... " );
while( '\n'!=getchar() );
return 0;
}
</syntaxhighlight>
 
{{out}}
<pre>
antiperspirant
calendrical
einstein
hotshot
murmur
oshkosh
tartar
testes
 
Press Return to exit...
</pre>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <cstdlib>
#include <fstream>
#include <iostream>
Line 211 ⟶ 375:
}
return EXIT_SUCCESS;
}</langsyntaxhighlight>
 
{{out}}
Line 223 ⟶ 387:
7. tartar
8. testes
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
Runs in 13 ms.
 
<syntaxhighlight lang="Delphi">
var Dict: TStringList; {List holds dictionary}
 
 
procedure FindFirst3Last3Match(Memo: TMemo);
{Find words where the first and last 3 characters are identical}
var I: integer;
var First3,Last3: string;
begin
for I:=0 to Dict.Count-1 do
if Length(Dict[I])>5 then
begin
First3:=Copy(Dict[I],1,3);
Last3:=Copy(Dict[I],Length(Dict[I])-2,3);
if First3=Last3 then
begin
Memo.Lines.Add(Dict[I]);
end
end;
end;
 
 
initialization
{Create/load dictionary}
Dict:=TStringList.Create;
Dict.LoadFromFile('unixdict.txt');
Dict.Sorted:=True;
finalization
Dict.Free;
end.
 
</syntaxhighlight>
{{out}}
<pre>
antiperspirant
calendrical
einstein
hotshot
murmur
oshkosh
tartar
testes
</pre>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// First and last three letters are equal. Nigel Galloway: February 18th., 2021
let fN g=if String.length g<6 then false else g.[..2]=g.[g.Length-3..]
seq{use n=System.IO.File.OpenText("unixdict.txt") in while not n.EndOfStream do yield n.ReadLine()}|>Seq.filter fN|>Seq.iter(printfn "%s")
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 245 ⟶ 458:
===Read entire file===
This version reads the entire dictionary file into memory and filters it. This is the fastest version by far. Factor is optimized for making multiple passes over data; it actually takes longer if we combine the two filters into one, either with short-circuiting or non-short-circuiting <code>and</code>.
<langsyntaxhighlight lang="factor">USING: io io.encodings.ascii io.files kernel math sequences ;
 
"unixdict.txt" ascii file-lines
[ length 5 > ] filter
[ [ 3 head-slice ] [ 3 tail-slice* ] bi = ] filter
[ print ] each</langsyntaxhighlight>
{{out}}
<pre>
Line 265 ⟶ 478:
===Read file line by line===
This version reads the dictionary file line by line and prints out words that fit the criteria. This ends up being a bit more imperative and deeply nested, but unlike the version above, we only load one word at a time, saving quite a bit of memory.
<langsyntaxhighlight lang="factor">USING: combinators.short-circuit io io.encodings.ascii io.files
kernel math sequences ;
 
Line 280 ⟶ 493:
] when*
] loop
] with-file-reader</langsyntaxhighlight>
{{out}}
As above.
Line 286 ⟶ 499:
===Lazy file I/O===
This version lazily reads the input file by treating a stream like a lazy list with the <code>llines</code> word. This allows us the nice style of the first example with the memory benefits of the second example. Unlike in the first example, combining the filters would buy us some time here, as lazy lists aren't as efficient as sequences.
<langsyntaxhighlight lang="factor">USING: io io.encodings.ascii io.files kernel lists lists.lazy
math sequences ;
 
Line 292 ⟶ 505:
[ length 5 > ] lfilter
[ [ 3 head-slice ] [ 3 tail-slice* ] bi = ] lfilter
[ print ] leach</langsyntaxhighlight>
{{out}}
As above.
Line 298 ⟶ 511:
=={{header|Forth}}==
{{works with|Gforth}}
<langsyntaxhighlight lang="forth">: first-last-three-equal { addr len -- ? }
len 5 <= if false exit then
addr 3 addr len 3 - + 3 compare 0= ;
Line 321 ⟶ 534:
 
main
bye</langsyntaxhighlight>
 
{{out}}
Line 336 ⟶ 549:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">#define NULL 0
 
type node
Line 386 ⟶ 599:
nextword:
curr = curr->nxt
wend</langsyntaxhighlight>
{{out}}
<pre>
Line 397 ⟶ 610:
tartar
testes</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
#plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES}
 
local fn Words as CFArrayRef
CFURLRef url = fn URLWithString( @"http://wiki.puzzlers.org/pub/wordlists/unixdict.txt" )
CFStringRef string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
CFArrayRef array = fn StringComponentsSeparatedByCharactersInSet( string, fn CharacterSetNewlineSet )
PredicateRef predicate = fn PredicateWithFormat( @"self.length > %d", 5 )
end fn = fn ArrayFilteredArrayUsingPredicate( array, predicate )
 
void local fn DoIt
CFArrayRef words = fn Words
CFStringRef wd
for wd in words
if ( fn StringIsEqual( left(wd,3), right(wd,3) ) )
print wd
end if
next
end fn
 
fn DoIt
 
HandleEvents
</syntaxhighlight>
 
{{out}}
<pre>
antiperspirant
calendrical
einstein
hotshot
murmur
oshkosh
tartar
testes
</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 424 ⟶ 675:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 437 ⟶ 688:
8: testes
</pre>
 
=={{header|J}}==
<syntaxhighlight lang="j"> >(#~ ((3&{. -: _3&{.)*5<#)@>) cutLF fread 'unixdict.txt'
antiperspirant
calendrical
einstein
hotshot
murmur
oshkosh
tartar
testes</syntaxhighlight>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<langsyntaxhighlight lang="jq">select(length > 5 and .[:3] == .[-3:])</langsyntaxhighlight>
{{out}}
Invocation example: jq -rRM -f program.jq unixdict.txt
Line 457 ⟶ 719:
=={{header|Julia}}==
See Alternade_words#Julia for the foreachword function.
<langsyntaxhighlight lang="julia">matchfirstlast3(word, _) = length(word) > 5 && word[1:3] == word[end-2:end] ? word : ""
foreachword("unixdict.txt", matchfirstlast3, numcols=4)</langsyntaxhighlight>{{out}}
<pre>
Word source: unixdict.txt
Line 467 ⟶ 729:
 
=={{header|Ksh}}==
<langsyntaxhighlight lang="ksh">#!/bin/ksh
 
# Find list of words (> 5 chars) where 1st 3 and last 3 letters are the same
Line 489 ⟶ 751:
[[ ${first} == ${last} ]] && print ${word}
 
done < ${dict}</langsyntaxhighlight>
 
{{out}}
Line 500 ⟶ 762:
tartar
testes</pre>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
The unixdict.txt has been loaded from https://web.archive.org and stored in a wiki page, lib_UNIXDICT, from which it can be required on demand in any other one.
 
{require lib_UNIXDICT}
 
{def look
{lambda {}
{S.replace \s by {div} in
{S.map {lambda {:w}
{if {and {> {W.length :w} 5}
{W.equal? {W.slice 0 3 :w}
{W.slice -3 {W.length :w} :w} }}
then :w
else}} {S.replace else by el.se in UNIXDICT}} }}}
-> look
{look}
->
antiperspirant
calendrical
einstein
hotshot
murmur
oshkosh
tartar
testes
 
Note: Due to a "weakness" of the {if then else} special form, where the else separator is not protected, every occurences of the string "else" in the input text must be replaced by some "broken word" before the search, for instance "el.se" and restored after if necessary.
</syntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">dict = Once[Import["https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt"]];
dict //= StringSplit[#, "\n"] &;
dict //= Select[StringLength /* GreaterThan[5]];
Select[dict, StringTake[#, 3] === StringTake[#, -3] &]</langsyntaxhighlight>
{{out}}
<pre>{"antiperspirant", "calendrical", "einstein", "hotshot", "murmur", "oshkosh", "tartar", "testes"}</pre>
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">for word in "unixdict.txt".lines:
if word.len > 5:
if word[0..2] == word[^3..^1]:
echo word</langsyntaxhighlight>
 
{{out}}
Line 527 ⟶ 820:
=={{header|Perl}}==
as one-liner ..
<langsyntaxhighlight lang="perl">// 20210212 Perl programming solution
 
perl -ne '/(?=^(.{3}).*\1$)^.{6,}$/&&print' unixdict.txt
Line 533 ⟶ 826:
# minor variation
 
perl -ne 's/(?=^(.{3}).*\1$)^.{6,}$/print/e' unixdict.txt</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">flaste</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">word</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">word</span><span style="color: #0000FF;">)></span><span style="color: #000000;">5</span> <span style="color: #008080;">and</span> <span style="color: #000000;">word</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">3</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">word</span><span style="color: #0000FF;">[-</span><span style="color: #000000;">3</span><span style="color: #0000FF;">..-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">flastes</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">unix_dict</span><span style="color: #0000FF;">(),</span><span style="color: #000000;">flaste</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d words: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">flastes</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">flastes</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">))})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 548 ⟶ 841:
 
=={{header|PL/I}}==
<langsyntaxhighlight lang="pli">firstAndLast3Equal: procedure options(main);
declare dict file;
open file(dict) title('unixdict.txt');
Line 561 ⟶ 854:
put skip list(word);
end;
end firstAndLast3Equal;</langsyntaxhighlight>
{{out}}
<pre>antiperspirant
Line 574 ⟶ 867:
=={{header|Python}}==
Tested on Python 3+, the file download will work only if the link is still active. It is possible that you may be able to fetch the file in your browser but download via code may still fail. Check whether you are connected to a VPN, it works on open networks
<syntaxhighlight lang="python">
<lang Python>
import urllib.request
urllib.request.urlretrieve("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt", "unixdict.txt")
Line 587 ⟶ 880:
if len(word)>5 and word[:3].lower()==word[-3:].lower():
print(word)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 602 ⟶ 895:
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ [] swap ]'[ swap
witheach [
dup nested
Line 613 ⟶ 906:
filter [ size 5 > ]
filter [ 3 split -3 split nip = ]
witheach [ echo$ cr ]</langsyntaxhighlight>
 
{{out}}
Line 628 ⟶ 921:
 
=={{header|R}}==
<langsyntaxhighlight Rlang="rsplus">dict <- scan("https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt", what = character())
dict[nchar(dict) > 5 & substr(dict, 1, 3) == substr(dict, nchar(dict) - 2, nchar(dict))]</langsyntaxhighlight>
 
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">#lang racket
 
(define ((prefix-and-suffix-match? len) str)
Line 642 ⟶ 935:
 
(module+ main
(filter (prefix-and-suffix-match? 3) (file->lines "../../data/unixdict.txt")))</langsyntaxhighlight>
 
{{out}}
Line 649 ⟶ 942:
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line># 20210210 Raku programming solution
 
my ( \L, \N, \IN ) = 5, 3, 'unixdict.txt';
 
for IN.IO.lines { .say if .chars > L and .substr(0,N) eq .substr(*-N,*) }
</syntaxhighlight>
</lang>
{{out}}
<pre>
antiperspirant
calendrical
einstein
hotshot
murmur
oshkosh
tartar
testes
</pre>
 
=={{header|Red}}==
<syntaxhighlight lang="rebol">Red[]
 
foreach word read/lines %unixdict.txt [
if all [
greater? length? word 5
equal? take/part copy word 3 take/part/last copy word 3
][
print word
]
]</syntaxhighlight>
{{out}}
<pre>
Line 675 ⟶ 991:
It also allows the length ('''3''') of the first and last number of letters to be specified, &nbsp; and also the minimum length of the
<br>words to be searched on the command line (CL) as well as specifying the dictionary file identifier.
<langsyntaxhighlight lang="rexx">/*REXX pgm finds words in an specified dict. which have the same 1st and last 3 letters.*/
parse arg minL many iFID . /*obtain optional arguments from the CL*/
if minL=='' | minL=="," then minL= 6 /* " " " " " " */
Line 699 ⟶ 1,015:
/*stick a fork in it, we're all done. */
say copies('─', 30) finds " words found that the left " many ' letters match the' ,
"right letters which a word has a minimal length of " minL</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre style="font-size:89%">
Line 715 ⟶ 1,031:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
 
Line 740 ⟶ 1,056:
 
see "done..." + nl
</syntaxhighlight>
</lang>
Output:
<pre>
Line 754 ⟶ 1,070:
8. testes
done...
</pre>
 
=={{header|RPL}}==
The only way to use unixdict.txt as input is to convert it into a list of 25104 strings. Luckily, emulators can handle such a big data structure in RAM.
{{works with|Halcyon Calc|4.2.7}}
≪ { }
<span style="color:red">1</span> <span style="color:green">UnixDict</span> SIZE '''FOR''' j
‘<span style="color:green">UnixDict</span>’ j GET
'''IF''' DUP SIZE <span style="color:red">5</span> ≤ '''THEN''' DROP '''ELSE'''
DUP <span style="color:red">1 3</span> SUB
OVER DUP SIZE DUP <span style="color:red">2</span> - SWAP SUB
'''IF''' == '''THEN''' + '''ELSE''' DROP '''END'''
'''END'''
'''NEXT'''
≫ ≫ ‘<span style="color:blue">SAME3</span>’ STO
{{out}}
<pre>
1: { "antiperspirant" "calendrical" "einstein" "hotshot" "murmur" "oshkosh" "tartar" "testes" }
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">words =puts File.readlines("unixdict.txt", chomp: true).mapselect{|w| w.end_with?(&:chompw[0,3]) && w.size > 5}
</syntaxhighlight>
puts words.select{|w| w.end_with?(w[0,3]) && w.size > 5}
</lang>
{{out}}
<pre>antiperspirant
Line 770 ⟶ 1,103:
testes
</pre>
 
=={{header|sed}}==
<syntaxhighlight lang="sed">/^\(...\).*\1$/!d</syntaxhighlight>
{{out}}
<pre>
$ sed -f ends3eq.sed unixdict.txt
antiperspirant
calendrical
einstein
hotshot
murmur
oshkosh
tartar
testes
</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">File("unixdict.txt").open_r.each {|word|
word.len > 5 || next
if (word.ends_with(word.first(3))) {
say word
}
}</syntaxhighlight>
{{out}}
<pre>
antiperspirant
calendrical
einstein
hotshot
murmur
oshkosh
tartar
testes
</pre>
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">import Foundation
 
do {
Line 781 ⟶ 1,149:
} catch {
print(error.localizedDescription)
}</langsyntaxhighlight>
 
{{out}}
Line 793 ⟶ 1,161:
7. tartar
8. testes
</pre>
 
=={{header|VBScript}}==
After building a program checking for the 3 letters in any order, I found people just checked the same trigraph at start and end. I modified my program so it puts an asterisk after the words in the "standard" answer. Run the ssript with CScript.
<syntaxhighlight lang="vb">
with createobject("ADODB.Stream")
.charset ="UTF-8"
.open
.loadfromfile("unixdict.txt")
s=.readtext
end with
a=split (s,vblf)
 
set d= createobject("Scripting.Dictionary")
for each aa in a
x=trim(aa)
l=len(x)
if l>5 then
d.removeall
for i=1 to 3
m=mid(x,i,1)
if not d.exists(m) then d.add m,null
next
res=true
for i=l-2 to l
m=mid(x,i,1)
if not d.exists(m) then
res=false:exit for
else
d.remove(m)
end if
next
if res then
wscript.stdout.write left(x & space(15),15)
if left(x,3)=right(x,3) then wscript.stdout.write "*"
wscript.stdout.writeline
end if
end if
next
</syntaxhighlight>
{{out}}
<pre>
alfalfa
antiperspirant *
calendrical *
cataract
deadhead
earthenware
einstein *
encumbrance
greenberg
hannah
hotshot *
marjoram
murmur *
oshkosh *
tartar *
teammate
tenement
testes *
</pre>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">import os
 
fn main() {
mut result :=''
unixdict := os.read_file('./unixdict.txt') or {println('Error: file not found') exit(1)}
for word in unixdict.split_into_lines() {
if word.len > 5 {
if word.substr(0, 3) == word.substr(word.len - 3, word.len) {
result += word + '\n'
}
}
}
println(result)
}
</syntaxhighlight>
 
{{out}}
<pre>
antiperspirant
calendrical
einstein
hotshot
murmur
oshkosh
tartar
testes
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "io" for File
import "./fmt" for Fmt
 
var wordList = "unixdict.txt" // local copy
Line 809 ⟶ 1,266:
count = count + 1
Fmt.print("$d: $s", count, w)
}</langsyntaxhighlight>
 
{{out}}
Line 821 ⟶ 1,278:
7: tartar
8: testes
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">string 0; \Use zero-terminated strings
int I, Ch, Len;
char Word(100); \(longest word in unixdict.txt is 22 chars)
def LF=$0A, CR=$0D, EOF=$1A;
[FSet(FOpen("unixdict.txt", 0), ^I); \open dictionary and set it to device 3
OpenI(3);
repeat I:= 0;
loop [repeat Ch:= ChIn(3) until Ch # CR; \remove possible CR
if Ch=LF or Ch=EOF then quit;
Word(I):= Ch;
I:= I+1;
];
Word(I):= 0; \terminate string
Len:= I;
if Len >= 6 then
if Word(0) = Word(Len-3) &
Word(1) = Word(Len-2) &
Word(2) = Word(Len-1) then
[Text(0, Word); CrLf(0)];
until Ch = EOF;
]</syntaxhighlight>
 
{{out}}
<pre>
antiperspirant
calendrical
einstein
hotshot
murmur
oshkosh
tartar
testes
</pre>
9,482

edits