Odd words: Difference between revisions

44,805 bytes added ,  4 months ago
m
m (→‎{{header|Wren}}: Minor tidy)
 
(38 intermediate revisions by 27 users not shown)
Line 1:
{{Draft task}}
Given a list of words  , (usinguse the words from the dictionary:   [https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt unixdict.txt]).
 
Take the letters at odd indices letters from theeach word,.  If andthe ifresult it'sis present in the list,   then display the   ''odd word''   on this pageresult.
The length of the ''odd word'' should be '''<big>&gt;</big> &nbsp; 4'''.
 
The length of the &nbsp; ''odd word'' &nbsp; should be &nbsp; '''<big>&gt;</big> &nbsp; 4'''.
 
 
{{Template:Strings}}
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">V wordSet = Set(File(‘unixdict.txt’).read().split("\n"))
 
Set[String] oddWordSet
 
L(word) wordSet
I word.len >= 9 & word[(0..).step(2)] C wordSet
oddWordSet.add(word[(0..).step(2)])
 
L(i) sorted(Array(oddWordSet))
print(i)</syntaxhighlight>
 
{{out}}
<pre>
brain
cider
cried
grata
hades
plain
point
saute
sight
slain
spree
trial
</pre>
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<syntaxhighlight lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program oddwords64.s */
/************************************/
/* Constantes */
/************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
.equ BUFFERSIZE, 300000
.equ WORDSIZE, 4
 
//.include "../../ficmacros64.inc" // use for developper debugging
/*******************************************/
/* Structures **/
/*******************************************/
/* structure words array */
.struct 0
st_word_adr:
.struct st_word_adr + 8
st_word_size:
.struct st_word_size + 8
st_word_end:
/************************************/
/* Initialized data */
/************************************/
.data
szMessOpen: .asciz "File open error.\n"
szMessRead: .asciz "File read error.\n"
szMessClose: .asciz "File close error.\n"
szFileName: .asciz "unixdict.txt"
szMessResult: .asciz " : "
szCarriageReturn: .asciz "\n"
szMessStart: .asciz "Program 64 bits start.\n"
/************************************/
/* UnInitialized data */
/************************************/
.bss
sZoneConv: .skip 24
sBuffer: .skip BUFFERSIZE // file buffer
.align 4
WordArray: .skip st_word_end * 0x10000
/************************************/
/* code section */
/************************************/
.text
.global main
main: // entry of program
ldr x0,qAdrszMessStart
bl affichageMess
ldr x0,qAdrszFileName // file name
ldr x1,qAdrsBuffer // read buffer address
ldr x2,#iBufferSize // buffer size
ldr x3,qAdrWordArray // word address array
bl readFile
cmp x0,#-1 // file error ?
beq 100f
mov x2,x0 // word counter
ldr x0,qAdrsBuffer
ldr x1,qAdrWordArray // array address
bl traitWord
 
100: // standard end of the program
mov x0, #0 // return code
mov x8, #EXIT // request to exit program
svc 0 // perform the system call
 
qAdrsZoneConv: .quad sZoneConv
qAdrszMessResult: .quad szMessResult
qAdrszCarriageReturn: .quad szCarriageReturn
qAdrszMessStart: .quad szMessStart
qAdrszFileName: .quad szFileName
qAdrszMessOpen: .quad szMessOpen
qAdrszMessRead: .quad szMessRead
qAdrszMessClose: .quad szMessClose
qAdrsBuffer: .quad sBuffer
iBufferSize: .quad BUFFERSIZE
qAdrWordArray: .quad WordArray
/***************************************************/
/* read file and create array words */
/***************************************************/
/* x0 contains file name */
/* x1 contains a file buffer */
/* x2 contains buffer size */
/* x3 contains array word address */
readFile:
stp x1,lr,[sp,-16]!
stp x2,x3,[sp,-16]!
stp x4,x5,[sp,-16]!
stp x6,x7,[sp,-16]!
stp x8,x9,[sp,-16]!
mov x9,x1 // file buffer
mov x6,x2
mov x1,x0
mov x10,x3
mov x0,AT_FDCWD
mov x2,#O_RDWR // flags
mov x3,#0 // mode
mov x8,#OPEN // file open
svc 0
cmp x0,#0 // error ?
ble 99f
mov x7,x0 // FD save
 
mov x0,x7
mov x1,x9 // read buffer address
mov x2,x6
mov x8,#READ // call system read file
svc 0
cmp x0,#0 // error read ?
blt 97f
mov x6,x0 // save file size
mov x0,x7 // FD
mov x8,#CLOSE // call system close file
svc 0
cmp x0,#0 // error close ?
blt 96f
mov x1,#0 // index buffer
mov x2,x9 // file buffer address
mov x3,#0 // word length
mov x5,#0 // word counter
1:
ldrb w4,[x9,x1] // load character file buffer
cmp x4,#0x0D // end word ?
beq 2f // yes
add x1,x1,#1 // increment index and length
add x3,x3,#1
b 1b // and loop
2: //
strb wzr,[x9,x1] // store 0 final in word
cmp x3,#WORDSIZE // word length ?
ble 3f // no ?
mov x0,#st_word_end // structure size
madd x0,x5,x0,x10 // compute word item address
str x2,[x0,#st_word_adr] // store word address in array word
str x3,[x0,#st_word_size] // store word size in array word
add x5,x5,#1 // increment word counter
3:
add x1,x1,#2 // increment index buffer (0D0A)
cmp x1,x6 // end ?
bge 4f
add x2,x9,x1 // new word begin
mov x3,#0 // init word length
b 1b // and loop
4:
mov x0,x5 // return word counter
b 100f
96: // display error messages
ldr x0,qAdrszMessClose
bl affichageMess
mov x0,#-1 // error
b 100f
97:
ldr x0,qAdrszMessRead
bl affichageMess
mov x0,#-1 // error
b 100f
99:
ldr x0,qAdrszMessOpen
bl affichageMess
mov x0,#-1 // error
 
100:
ldp x8,x9,[sp],16
ldp x6,x7,[sp],16
ldp x4,x5,[sp],16
ldp x2,x3,[sp],16
ldp x1,lr,[sp],16
ret
/***************************************************/
/* word analyse */
/***************************************************/
/* x0 contains a file buffer */
/* x1 contains array word address */
/* x2 contains array element */
traitWord:
stp x1,lr,[sp,-16]!
stp x2,x3,[sp,-16]!
stp x4,x5,[sp,-16]!
stp x6,x7,[sp,-16]!
stp x8,x9,[sp,-16]!
stp x10,x12,[sp,-16]!
mov x7,x0 // save buffer address
mov x8,x1 // save array word address
mov x9,x2 // save size
mov x10,#0 // init index word array
sub sp,sp,#80 // reserve 80 byte on stack for work array
mov fp,sp // work array address
1:
mov x0,#st_word_end // structure size
madd x0,x10,x0,x8 // compute word item address
ldr x12,[x0,#st_word_adr] // load one word address
ldr x5,[x0,#st_word_size] // load word size
mov x3,#0 // index word
mov x6,#0 // size new word
2:
ldrb w4,[x12,x3] // load characters on odd index
strb w4,[fp,x6] // store in wprk array on stack
add x6,x6,#1 // increment size new word
add x3,x3,#2 // increment index
cmp x3,x5 // end word ?
ble 2b
cmp x6,#WORDSIZE // length new word ok ?
ble 10f
strb wzr,[fp,x6] // store 0 final new word
// search new word in word array by binary search
// in french recherche dichotomique
mov x3,#0 // low index
sub x4,x9,#1 // high index = number of elements - 1
3: // begin search loop
cmp x3,x4 // low > high
bgt 10f // not found
add x7,x3,x4 // compute (low + high) /2
lsr x7,x7,#1
mov x1,#st_word_end // structure size
madd x2,x7,x1,x8 // compute word item address
ldr x0,[x2,#st_word_adr] // load word array address at new index r7
mov x1,fp // search word address
bl comparerChaines // alpha comparison
cmp x0,#0
beq 4f // find
add x0,x7,1
csel x3,x0,x3,lt // lower -> index low = index + 1
sub x0,x7,1
csel x4,x0,x4,gt // bigger -> index high = index - 1
b 3b // and loop
4: // ok -> display result
mov x0,x12
bl affichageMess
ldr x0,qAdrszMessResult
bl affichageMess
mov x0,fp
bl affichageMess
ldr x0,qAdrszCarriageReturn
bl affichageMess
10:
mov x6,#0 // init new length new word
add x10,x10,#1 // increment index word array
cmp x10,x9 // end ?
blt 1b // no -> loop
100:
add sp,sp,#80 // stack alignement release work array
ldp x10,x12,[sp],16
ldp x8,x9,[sp],16
ldp x6,x7,[sp],16
ldp x4,x5,[sp],16
ldp x2,x3,[sp],16
ldp x1,lr,[sp],16
ret
 
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeARM64.inc"
 
</syntaxhighlight>
{{Out}}
<pre>
Program 64 bits start.
barbarian : brain
childbear : cider
corrigenda : cried
gargantuan : grata
headdress : hades
palladian : plain
propionate : point
salvation : slain
siltation : slain
slingshot : sight
statuette : saute
supersede : spree
supervene : spree
terminable : trial
</pre>
 
=={{header|Ada}}==
Using instances of generic procedure to filter odd/even words.
<syntaxhighlight lang="ada">with Ada.Text_Io;
with Ada.Containers.Indefinite_Ordered_Maps;
 
procedure Odd_Words is
use Ada.Text_Io;
 
package String_Maps is
new Ada.Containers.Indefinite_Ordered_Maps (Key_Type => String,
Element_Type => String);
 
Filename : constant String := "unixdict.txt";
Words : String_Maps.Map;
 
function Get_Odd (Word : String) return String is
Odd : String (1 .. (Word'Length + 1) / 2);
begin
for Index in Odd'Range loop
Odd (Index) := Word (1 + 2 * (Index - 1));
end loop;
return Odd;
end Get_Odd;
 
function Get_Even (Word : String) return String is
Even : String (1 .. Word'Length / 2);
begin
for Index in Even'Range loop
Even (Index) := Word (1 + 1 + 2 * (Index - 1));
end loop;
return Even;
end Get_Even;
 
generic
with function Filter (Word : String) return String;
procedure Iterate_Map;
 
procedure Iterate_Map is
begin
for Word of Words loop
declare
Half : constant String := Filter (Word);
begin
if Half'Length > 4 and then Words.Contains (Half) then
Put (Word); Set_Col (15); Put_Line (Half);
end if;
end;
end loop;
end Iterate_Map;
 
procedure Put_Odd_Words is new Iterate_Map (Get_Odd);
procedure Put_Even_Words is new Iterate_Map (Get_Even);
 
File : File_Type;
begin
Open (File, In_File, Filename);
while not End_Of_File (File) loop
declare
Word : constant String := Get_Line (File);
begin
Words.Insert (Word, Word);
end;
end loop;
Close (File);
 
Put_Line ("Odd words:");
Put_Odd_Words;
New_Line;
 
Put_Line ("Even words:");
Put_Even_Words;
end Odd_Words;</syntaxhighlight>
{{out}}
<pre>Odd words:
barbarian brain
childbear cider
corrigenda cried
gargantuan grata
headdress hades
palladian plain
propionate point
salvation slain
siltation slain
slingshot sight
statuette saute
supersede spree
supervene spree
terminable trial
 
Even words:
cannonball annal
importation motto
psychopomp scoop
starvation train
upholstery posey</pre>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Based on (and almost identical to) the Alternade Words sample.
<langsyntaxhighlight lang="algol68"># find words where the odd letters also form a word #
# use the associative array in the Associate array/iteration task #
PR read "aArray.a68" PR
Line 77 ⟶ 482:
e := NEXT words
OD
FI</langsyntaxhighlight>
{{out}}
As with the Alternade Words Algol 68 sample, the output is not sorted, it has been sorted here for ease of comparison with the other samples' output.
Line 96 ⟶ 501:
terminable: trial
</pre>
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}}
<syntaxhighlight lang ARM Assembly>
/* ARM assembly Raspberry PI */
/* program oddwords.s */
/************************************/
/* Constantes */
/************************************/
/* for this file see task include a file in language ARM assembly*/
.include "../constantes.inc"
.equ READ, 3
.equ WRITE, 4
.equ OPEN, 5
.equ CLOSE, 6
.equ O_RDWR, 0x0002 @ open for reading and writing
.equ BUFFERSIZE, 300000
.equ WORDSIZE, 4
 
//.include "../../ficmacros32.inc" @ use for developper debugging
/*******************************************/
/* Structures **/
/*******************************************/
/* structure words array */
.struct 0
st_word_adr:
.struct st_word_adr + 4
st_word_size:
.struct st_word_size + 4
st_word_end:
/************************************/
/* Initialized data */
/************************************/
.data
szMessOpen: .asciz "File open error.\n"
szMessRead: .asciz "File read error.\n"
szMessClose: .asciz "File close error.\n"
szFileName: .asciz "unixdict.txt"
szMessResult: .asciz " : "
szCarriageReturn: .asciz "\n"
szMessStart: .asciz "Program 32 bits start.\n"
/************************************/
/* UnInitialized data */
/************************************/
.bss
sZoneConv: .skip 24
sBuffer: .skip BUFFERSIZE @ file buffer
.align 4
WordArray: .skip st_word_end * 0x10000
/************************************/
/* code section */
/************************************/
.text
.global main
main: @ entry of program
ldr r0,iAdrszMessStart
bl affichageMess
ldr r0,iAdrszFileName @ file name
ldr r1,iAdrsBuffer @ read buffer address
ldr r2,#iBufferSize @ buffer size
ldr r3,iAdrWordArray @ word address array
bl readFile
cmp r0,#-1 @ file error ?
beq 100f
mov r2,r0 @ word counter
ldr r0,iAdrsBuffer
ldr r1,iAdrWordArray @ array address
bl traitWord
 
100: @ standard end of the program
mov r0, #0 @ return code
mov r7, #EXIT @ request to exit program
svc 0 @ perform the system call
 
iAdrsZoneConv: .int sZoneConv
iAdrszMessResult: .int szMessResult
iAdrszCarriageReturn: .int szCarriageReturn
iAdrszMessStart: .int szMessStart
iAdrszFileName: .int szFileName
iAdrszMessOpen: .int szMessOpen
iAdrszMessRead: .int szMessRead
iAdrszMessClose: .int szMessClose
iAdrsBuffer: .int sBuffer
iBufferSize: .int BUFFERSIZE
iAdrWordArray: .int WordArray
/***************************************************/
/* read file and create array words */
/***************************************************/
/* r0 contains file name */
/* r1 contains a file buffer */
/* r2 contains buffer size */
/* r3 contains array word address */
readFile:
push {r1-r9,lr} @ save registers
mov r9,r1 @ file buffer
mov r6,r2
mov r10,r3
mov r1,#O_RDWR @ flags
mov r2,#0 @ mode
mov r7,#OPEN @ file open
svc 0
cmp r0,#0 @ error ?
ble 99f
mov r8,r0 @ FD save
 
mov r0,r8
mov r1,r9 @ read buffer address
mov r2,r6
mov r7,#READ @ call system read file
svc 0
cmp r0,#0 @ error read ?
blt 97f
mov r6,r0 @ save file size
mov r0,r8 @ FD
mov r7,#CLOSE @ call system close file
svc 0
cmp r0,#0 @ error close ?
blt 96f
mov r1,#0 @ index buffer
mov r2,r9 @ file buffer address
mov r3,#0 @ word length
mov r5,#0 @ word counter
1:
ldrb r4,[r9,r1] @ load character file buffer
cmp r4,#0x0D @ end word ?
beq 2f @ yes
add r1,r1,#1 @ increment index and length
add r3,r3,#1
b 1b @ and loop
2:
mov r4,#0 @
strb r4,[r9,r1] @ store 0 final in word
cmp r3,#WORDSIZE @ word length ?
ble 3f @ no ?
mov r0,#st_word_end @ structure size
mla r0,r5,r0,r10 @ compute word item address
str r2,[r0,#st_word_adr] @ store word address in array word
str r3,[r0,#st_word_size] @ store word size in array word
add r5,r5,#1 @ increment word counter
3:
add r1,r1,#2 @ increment index buffer (0D0A)
cmp r1,r6 @ end ?
bge 4f
add r2,r9,r1 @ new word begin
mov r3,#0 @ init word length
b 1b @ and loop
4:
mov r0,r5 @ return word counter
b 100f
96: @ display error messages
ldr r0,iAdrszMessClose
bl affichageMess
mov r0,#-1 @ error
b 100f
97:
ldr r0,iAdrszMessRead
bl affichageMess
mov r0,#-1 @ error
b 100f
99:
ldr r0,iAdrszMessOpen
bl affichageMess
mov r0,#-1 @ error
 
100:
pop {r1-r9,pc}
/***************************************************/
/* word analyse */
/***************************************************/
/* r0 contains a file buffer */
/* r1 contains array word address */
/* r2 contains array element */
traitWord:
push {r1-r12,lr} @ save registers
mov r7,r0 @ save buffer address
mov r8,r1 @ save array word address
mov r9,r2 @ save size
mov r10,#0 @ init index word array
sub sp,sp,#80 @ reserve 80 byte on stack for work array
mov fp,sp @ work array address
1:
mov r0,#st_word_end @ structure size
mla r0,r10,r0,r8 @ compute word item address
ldr r12,[r0,#st_word_adr] @ load one word address
ldr r5,[r0,#st_word_size] @ load word size
mov r3,#0 @ index word
mov r6,#0 @ size new word
2:
ldrb r4,[r12,r3] @ load characters on odd index
strb r4,[fp,r6] @ store in wprk array on stack
add r6,r6,#1 @ increment size new word
add r3,r3,#2 @ increment index
cmp r3,r5 @ end word ?
ble 2b
cmp r6,#WORDSIZE @ length new word ok ?
ble 10f
mov r4,#0 @ store 0 final new word
strb r4,[fp,r6]
@ search new word in word array by binary search
@ in french recherche dichotomique
mov r3,#0 @ low index
sub r4,r9,#1 @ high index = number of elements - 1
3: @ begin search loop
cmp r3,r4 @ low > high
bgt 10f @ not found
add r7,r3,r4 @ compute (low + high) /2
lsr r7,#1
mov r1,#st_word_end @ structure size
mla r2,r7,r1,r8 @ compute word item address
ldr r0,[r2,#st_word_adr] @ load word array address at new index r7
mov r1,fp @ search word address
bl comparaison @ alpha comparison
cmp r0,#0
beq 4f @ find
addlt r3,r7,#1 @ lower -> index low = index + 1
subgt r4,r7,#1 @ bigger -> index high = index - 1
b 3b @ and loop
4: @ ok -> display result
mov r0,r12
bl affichageMess
ldr r0,iAdrszMessResult
bl affichageMess
mov r0,fp
bl affichageMess
ldr r0,iAdrszCarriageReturn
bl affichageMess
10:
mov r6,#0 @ init new length new word
add r10,r10,#1 @ increment index word array
cmp r10,r9 @ end ?
blt 1b @ no -> loop
100:
add sp,sp,#80 @ stack alignement release work array
pop {r1-r12,pc}
 
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
/* for this file see task include a file in language ARM assembly*/
.include "../affichage.inc"
 
</syntaxhighlight>
{{Out}}
<pre>
Program 32 bits start.
barbarian : brain
childbear : cider
corrigenda : cried
gargantuan : grata
headdress : hades
palladian : plain
propionate : point
salvation : slain
siltation : slain
slingshot : sight
statuette : saute
supersede : spree
supervene : spree
terminable : trial
</pre>
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">words: read.lines relative "unixdict.txt"
 
getOdd: function [w][
odd: new ""
loop.with:'i w 'ch [
if even? i -> 'odd ++ ch
]
odd
]
 
loop words 'word [
ow: getOdd word
if and? [4 < size ow][contains? words ow] ->
print [word "=>" ow]
]</syntaxhighlight>
 
{{out}}
 
<pre>barbarian => brain
childbear => cider
corrigenda => cried
gargantuan => grata
headdress => hades
palladian => plain
propionate => point
salvation => slain
siltation => slain
slingshot => sight
statuette => saute
supersede => spree
supervene => spree
terminable => trial</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f ODD_WORDS.AWK unixdict.txt
#
Line 126 ⟶ 829:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 154 ⟶ 857:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <cstdlib>
#include <fstream>
#include <iomanip>
Line 216 ⟶ 919:
 
return EXIT_SUCCESS;
}</langsyntaxhighlight>
 
{{out}}
Line 244 ⟶ 947:
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
 
procedure ShowOddWords(Memo: TMemo);
var I,J: integer;
var W,S: string;
begin
{Iterate all entries in dictionary}
for I:=0 to UnixDict.Count-1 do
if Length(UnixDict[I])>8 then {Word must be >4, so every other is >8}
begin
W:=UnixDict[I];
{Take every other letter}
J:=1; S:='';
while J<=Length(W) do
begin
S:=S+W[J];
Inc(J,2);
end;
{Check if it is in Dictionary}
if UnixDict.IndexOf(S)>0 then
begin
Memo.Lines.Add(W+' -> '+S);
end;
end;
end;
 
</syntaxhighlight>
{{out}}
<pre>
barbarian -> brain
childbear -> cider
corrigenda -> cried
gargantuan -> grata
headdress -> hades
palladian -> plain
propionate -> point
salvation -> slain
siltation -> slain
slingshot -> sight
statuette -> saute
supersede -> spree
supervene -> spree
terminable -> trial
Elapsed Time: 44.351 ms.
 
</pre>
 
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// Odd words: Nigel Galloway. June 9th., 2021
let dict=seq{use n=System.IO.File.OpenText("unixdict.txt") in while not n.EndOfStream do yield n.ReadLine()}|>Seq.filter(fun n->n.Length>4)|>List.ofSeq
let fN g=let n=g|>String.mapi(fun n g->if n%2=0 then g else ' ')|>String.filter((<>)' ') in match List.contains n dict with true->Some(n,g) |_->None
dict|>Seq.filter(fun n->n.Length>6)|>Seq.choose fN|>Seq.iter(fun(n,g)->printfn "%s -> %s" g n)
</syntaxhighlight>
{{out}}
<pre>
barbarian -> brain
childbear -> cider
corrigenda -> cried
gargantuan -> grata
headdress -> hades
palladian -> plain
propionate -> point
salvation -> slain
siltation -> slain
slingshot -> sight
statuette -> saute
supersede -> spree
supervene -> spree
terminable -> trial
</pre>
=={{header|Factor}}==
This is basically the same program as https://rosettacode.org/wiki/Alternade_words#Factor. <code><evens></code> is a virtual sequence representing the (zero-based) even indices of the input sequence, which this task calls the odd indices.
{{works with|Factor|0.99 2020-08-14}}
<langsyntaxhighlight lang="factor">USING: formatting hash-sets io io.encodings.ascii io.files
kernel literals math sequences sequences.extras sets strings ;
 
Line 260 ⟶ 1,041:
[ length 8 > ] filter
[ odd wordset in? ] filter
[ dup odd "%-15s %s\n" printf ] each</langsyntaxhighlight>
{{out}}
<pre>
Line 281 ⟶ 1,062:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">#define NULL 0
 
type node
Line 338 ⟶ 1,119:
nextword:
curr = curr->nxt
wend</langsyntaxhighlight>
{{out}}
<pre>barbarian ---> brain
Line 361 ⟶ 1,142:
starvation ---> train
upholstery ---> posey</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
 
#plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES}
 
include "NSLog.incl"
 
local fn WordsPassingTest( array as CFArrayRef, obj as CFTypeRef )
end fn = ( len(obj) > 4 )
 
local fn WordList as CFArrayRef
CFURLRef url = fn URLWithString( @"http://wiki.puzzlers.org/pub/wordlists/unixdict.txt" )
CFStringRef string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
CFArrayRef wordList = fn StringComponentsSeparatedByCharactersInSet( string, fn CharacterSetNewlineSet )
IndexSetRef indexes = fn ArrayIndexesOfObjectsPassingTest( wordList, @fn WordsPassingTest, NULL )
wordList = fn ArrayObjectsAtIndexes( wordList, indexes )
end fn = wordList
 
void local fn OddWords
dispatchglobal
CFArrayRef wordList = fn WordList
CFStringRef string
long i
for string in wordList
CFMutableStringRef wd = fn MutableStringWithCapacity(0)
for i = 0 to len(string) step 2
MutableStringAppendString( wd, mid(string,i,1) )
next
if ( len(wd) > 4 )
if ( fn ArrayContainsObject( wordList, wd ) )
NSLog(@"%@",wd)
end if
end if
next
dispatchend
end fn
 
fn OddWords
 
HandleEvents
</syntaxhighlight>
 
{{out}}
<pre>
brain
cider
cried
grata
hades
plain
point
slain
slain
sight
saute
spree
spree
trial
</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 402 ⟶ 1,243:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 422 ⟶ 1,263:
14: terminable -> trial
</pre>
 
=={{header|J}}==
 
In J, the index of the first character is 0, and the index of the second character is 1, thus:<syntaxhighlight lang="j"> >(([-.-.) (#~ $&0 1@#)&.>) (#~ 4<#@>)cutLF fread'unixdict.txt'
annal
motto
posey
scoop
train</syntaxhighlight>
 
However, some languages have 1 for the index of the first character, which would have given us:<syntaxhighlight lang="j"> >(([-.-.) (#~ $&1 0@#)&.>) (#~ 4<#@>)cutLF fread'unixdict.txt'
brain
cider
cried
grata
hades
plain
point
saute
sight
slain
spree
trial</syntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">import java.io.*;
import java.util.*;
 
Line 477 ⟶ 1,341:
int n = 1;
for (StringPair pair : strings) {
System.out.println(String.formatprintf("%2d: %-14s%s\n", n++,
pair.string1, pair.string2));
}
}
Line 490 ⟶ 1,354:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 517 ⟶ 1,381:
5: upholstery posey
</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq''' if `keys_unsorted` is replaced by `keys`
 
Counting the letters from 1...
<syntaxhighlight lang="jq"> def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
 
INDEX(inputs | select(length>4); .)
| . as $dict
| keys_unsorted[]
| select(length > 8)
| (explode | [.[range(0;length;2)]] | implode) as $odd
| select( ($odd|length > 4) and $dict[$odd])
| "\(lpad(10)) : \($odd)"</syntaxhighlight>
{{out}}
Illustrative invocation: jq -nrR -f program.jq unixdict.txt
<pre>
barbarian : brain
childbear : cider
corrigenda : cried
gargantuan : grata
headdress : hades
palladian : plain
propionate : point
salvation : slain
siltation : slain
slingshot : sight
statuette : saute
supersede : spree
supervene : spree
terminable : trial
</pre>
 
 
=={{header|Julia}}==
See [[Alternade_words#Julia]] for the foreachword function.
<langsyntaxhighlight lang="julia">isoddword(w, d) = (o = mapreduce(i -> w[i], *, 1:2:length(w)); haskey(d, o) ? rpad(w, 16) * ": " * o : "")
foreachword("unixdict.txt", isoddword, minlen=9, numcols=1)
</langsyntaxhighlight>{{out}}
<pre>
Word source: unixdict.txt
Line 541 ⟶ 1,439:
terminable : trial
</pre>
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">minOddWordLength = 5
minWordLength = minOddWordLength*2-1
 
dict = {}
for word in io.lines('unixdict.txt') do
local n = #word
if n >= minOddWordLength then -- skip words that are too short
dict[word] = n
end
end
 
for word, len in pairs(dict) do
if len >= minWordLength then
local odd = ""
for o, _ in word:gmatch("(.)(.?)") do
odd = odd .. o
end
if dict[odd] then
print(string.format("%10s → %s", word, odd))
end
end
end</syntaxhighlight>
 
{{out}}
Note: Output will not be alphabetical.
 
<pre> barbarian → brain
childbear → cider
corrigenda → cried
supervene → spree
siltation → slain
terminable → trial
supersede → spree
slingshot → sight
propionate → point
salvation → slain
palladian → plain
gargantuan → grata
headdress → hades
statuette → saute</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">dict = Import["https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt"];
dict //= StringSplit[#, "\n"] &;
ClearAll[OddLetters, OddWordQ]
OddLetters[s_String] := StringTake[s, {1, -1, 2}]
OddWordQ[s_String] := Module[{},
If[StringLength[s] >= 9,
MemberQ[dict, OddLetters[s]]
,
False
]
]
{#, OddLetters[#]} & /@ Select[dict, OddWordQ] // Grid</syntaxhighlight>
{{out}}
<pre>barbarian brain
childbear cider
corrigenda cried
gargantuan grata
headdress hades
palladian plain
propionate point
salvation slain
siltation slain
slingshot sight
statuette saute
supersede spree
supervene spree
terminable trial</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">import sets, strformat, sugar
 
const DictFile = "unixdict.txt"
 
let words = collect(initHashSet, for word in DictFile.lines: {word})
 
var count = 0
for word in DictFile.lines:
var oddWord: string
for i in countup(0, word.high, 2): oddWord.add word[i] # First odd char is at index 0.
if oddWord.len > 4 and oddWord in words:
inc count
echo &"{count:2}: {word:12} → {oddWord}"</syntaxhighlight>
 
{{out}}
<pre> 1: barbarian → brain
2: childbear → cider
3: corrigenda → cried
4: gargantuan → grata
5: headdress → hades
6: palladian → plain
7: propionate → point
8: salvation → slain
9: siltation → slain
10: slingshot → sight
11: statuette → saute
12: supersede → spree
13: supervene → spree
14: terminable → trial</pre>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
@ARGV = 'unixdict.txt';
Line 553 ⟶ 1,553:
my $oddword = s/(.).?/$1/gr;
exists $dict{$oddword} and print " $_ $oddword\n";
}</langsyntaxhighlight>
{{out}}
<pre>
Line 573 ⟶ 1,573:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>sequence words = get_text("demo/unixdict.txt",GT_LF_STRIPPED)
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
function odd(integer /*ch*/, idx) return remainder(idx,2)=1 end function
<span style="color: #004080;">sequence</span> <span style="color: #000000;">words</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">unix_dict</span><span style="color: #0000FF;">()</span>
function oddch(string word) return filter(word,odd) end function
<span style="color: #008080;">function</span> <span style="color: #000000;">oddc</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000080;font-style:italic;">/*ch*/</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">idx</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">idx</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">1</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
function over4(string word) return length(word)>4 end function
<span style="color: #008080;">function</span> <span style="color: #000000;">oddch</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;">filter</span><span style="color: #0000FF;">(</span><span style="color: #000000;">word</span><span style="color: #0000FF;">,</span><span style="color: #000000;">oddc</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
words = filter(filter(apply(words,oddch),over4),"in",words)
<span style="color: #008080;">function</span> <span style="color: #000000;">over4</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;">4</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
printf(1,"%d odd words found: %s\n",{length(words),join(shorten(words,"",3),", ")})</lang>
<span style="color: #000000;">words</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #000000;">words</span><span style="color: #0000FF;">,</span><span style="color: #000000;">oddch</span><span style="color: #0000FF;">),</span><span style="color: #000000;">over4</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"in"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">words</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 odd words found: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">words</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;">words</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><span style="color: #008000;">", "</span><span style="color: #0000FF;">)})</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 585 ⟶ 1,588:
=== Alternative ===
Slightly more traditional, same output.
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>sequence words = get_text("demo/unixdict.txt",GT_LF_STRIPPED),
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
res = {}
<span style="color: #004080;">sequence</span> <span style="color: #000000;">words</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">unix_dict</span><span style="color: #0000FF;">(),</span>
for i=1 to length(words) do
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
string word = words[i], wodd = ""
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">words</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
for oddchar=1 to length(word) by 2 do
<span style="color: #004080;">string</span> <span style="color: #000000;">word</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">words</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span> <span style="color: #000000;">wodd</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""</span>
wodd &= word[oddchar]
<span style="color: #008080;">for</span> <span style="color: #000000;">oddchar</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</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: #008080;">by</span> <span style="color: #000000;">2</span> <span style="color: #008080;">do</span>
end for
<span style="color: #000000;">wodd</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">word</span><span style="color: #0000FF;">[</span><span style="color: #000000;">oddchar</span><span style="color: #0000FF;">]</span>
if length(wodd)>4
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
and find(wodd,words) then
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">wodd</span><span style="color: #0000FF;">)></span><span style="color: #000000;">4</span>
res = append(res,wodd)
<span style="color: #008080;">and</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">wodd</span><span style="color: #0000FF;">,</span><span style="color: #000000;">words</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
end if
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">wodd</span><span style="color: #0000FF;">)</span>
end for
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
printf(1,"%d odd words found: %s\n",{length(res),join(shorten(res,"",3),", ")})</lang>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</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 odd words found: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</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;">res</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><span style="color: #008000;">", "</span><span style="color: #0000FF;">)})</span>
<!--</syntaxhighlight>-->
 
=={{header|Python}}==
===Procedural===
This implementation prints only the unique odd words which appear in unixdict.txt unlike other implementations on this page which print some words twice. The minimum base word length has to be 9 since the problem statement says that odd word lengths must be greater than 4.
 
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">
#Aamrun, 4th October 2021
 
import urllib.request
urllib.request.urlretrieve("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt", "unixdict.txt")
 
dictionary = open("unixdict.txt","r")
 
wordList = dictionary.read().split('\n')
 
dictionary.close()
 
oddWordSet = set({})
 
for word in wordList:
if len(word)>=9 and word[::2] in wordList:
oddWordSet.add(word[::2])
 
[print(i) for i in sorted(oddWordSet)]
</syntaxhighlight>
{{out}}
<pre>brain
cider
cried
grata
hades
plain
point
saute
sight
slain
spree
trial</pre>
 
===Functional===
Defining a dictionary of oddWords, keyed by their sources:
<syntaxhighlight lang="python">'''Odd words'''
 
from os.path import expanduser
from json import dumps
 
 
# oddPairs :: Int -> [String] -> Dict
def oddPairs(minLength):
'''A dictionary of (word::oddWord) pairs
in which the words are drawn from a given wordList,
and the oddWords have at least a minimum length.
'''
def go(wordList):
lexicon = set(wordList)
return {
k: v for k, v in ((w, w[::2]) for w in wordList)
if minLength <= len(v) and v in lexicon
}
return go
 
 
# ------------------------- TEST -------------------------
# main :: IO ()
def main():
'''Odd words of 5 or more characters, paired with their
sources, which are drawn from a local unixdict.txt
'''
print(dumps(
oddPairs(5)(
readFile('~/unixdict.txt').split('\n')
),
indent=4
))
 
 
# ----------------------- GENERIC ------------------------
 
# readFile :: FilePath -> IO String
def readFile(fp):
'''The contents of any file at the path
derived by expanding any ~ in fp.
'''
with open(expanduser(fp), 'r', encoding='utf-8') as f:
return f.read()
 
 
# MAIN ---
if __name__ == '__main__':
main()</syntaxhighlight>
{{Out}}
<pre>{
"barbarian": "brain",
"childbear": "cider",
"corrigenda": "cried",
"gargantuan": "grata",
"headdress": "hades",
"palladian": "plain",
"propionate": "point",
"salvation": "slain",
"siltation": "slain",
"slingshot": "sight",
"statuette": "saute",
"supersede": "spree",
"supervene": "spree",
"terminable": "trial"
}</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="quackery"> [ stack ] is sift.test ( --> s )
protect sift.test
 
[ ]'[ sift.test put
[] [] rot
witheach
[ sift.test share do iff
[ nested join ]
else
[ swap dip
[ nested join ] ] ]
sift.test release ] is siftwith ( [ --> [ [ )
 
[ 1 & ] is odd ( n --> b )
 
[ stack ] is dict ( --> s )
 
[ dict share
dup dip find found ] is indict ( $ --> b )
 
$ "unixdict.txt" sharefile drop
nest$ siftwith [ dup size 4 > ]
nip dict put
dict share
siftwith [ dup size 8 > ]
nip
 
witheach
[ siftwith [ i^ odd ]
drop
dup indict iff
[ echo$ cr ]
else drop ]
 
dict release</syntaxhighlight>
 
{{out}}
 
<pre>brain
cider
cried
grata
hades
plain
point
slain
slain
sight
saute
spree
spree
trial
</pre>
 
=={{header|Raku}}==
 
<syntaxhighlight lang="raku" perl6line>my %words = 'unixdict.txt'.IO.slurp.words.map: * => 1;
 
my (@odds, @evens);
Line 615 ⟶ 1,787:
.put for flat 'Odd words > 4:', @odds.sort;
 
.put for flat "\nEven words > 4:", @evens.sort;</langsyntaxhighlight>
{{out}}
<pre>Odd words > 4:
Line 641 ⟶ 1,813:
 
=={{header|REXX}}==
Any words longer than ten characters are truncated in the output.
=== version 1 ===
<langsyntaxhighlight rwxxlang="rexx">/* REXX */
fid='d:\unix.txt'
ww.=0 /* ww.* the words to be analyzed */
Line 673 ⟶ 1,846:
wo=wo||substr(w,i,1)
End
Return wo</langsyntaxhighlight>
{{out}}
<pre> 1 barbarian brain
Line 692 ⟶ 1,865:
=== version 2, caseless ===
This REXX version doesn't care what order the words in the dictionary are in, &nbsp; nor does it care what
<br>case &nbsp;(lower/upper/mixed)&nbsp; the words are in, &nbsp; the search for alternadesalternates is &nbsp; ''caseless''.
 
It also allows the minimum length to be specified on the command line (CL) as well as the dictionary file identifier.
<langsyntaxhighlight lang="rexx">/*REXX program finds all the caseless "odd words" (within an identified dictionary). */
parse arg minL iFID . /*obtain optional arguments from the CL*/
if minL=='' | minL=="," then minL= 5 /*Not specified? Then use the default.*/
Line 721 ⟶ 1,894:
end /*j*/
/*stick a fork in it, we're all done. */
say copies('─', 30) finds ' "odd words" found with a minimum length of ' minL</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Line 743 ⟶ 1,916:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
cStr = read("unixdict.txt")
wordList = str2list(cStr)
Line 762 ⟶ 1,935:
ok
next
</syntaxhighlight>
</lang>
Output:
<pre>
Line 780 ⟶ 1,953:
13. supervene >> spree
14. terminable >> trial
</pre>
 
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
≪ { }
1 UnixDict SIZE '''FOR''' w
‘UnixDict’ w GET
'''IF''' DUP SIZE 9 ≥ '''THEN'''
""
1 OVER SIZE '''FOR''' k
OVER k DUP SUB +
2 '''STEP'''
SWAP DROP
'''IF''' UnixDict OVER POS '''THEN'''
'''IF''' DUP2 POS NOT '''THEN''' + '''ELSE''' DROP '''END'''
'''ELSE''' DROP '''END'''
'''ELSE''' DROP '''END'''
'''NEXT'''
≫ ‘<span style="color:blue">ODDW</span>’ STO
{{out}}
<pre>
1: { "brain" "cider" "cried" "grata" "hades" "plain" "point" "slain" "slain" "sight" "saute" "spree" "trial" }
</pre>
 
=={{header|Ruby}}==
Binary search (bsearch) speeds things up.
<syntaxhighlight lang="ruby">dict = File.readlines("unixdict.txt", chomp: true).reject{|w| w.size < 5}
dict.each do |w|
next if w.size < 9
odd = w.chars.each_slice(2).map(&:first).join
puts w.ljust(14) + odd if dict.bsearch{|w| odd <=> w}
end</syntaxhighlight>
{{out}}
<pre>barbarian brain
childbear cider
corrigenda cried
gargantuan grata
headdress hades
palladian plain
propionate point
salvation slain
siltation slain
slingshot sight
statuette saute
supersede spree
supervene spree
terminable trial
</pre>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">use std::collections::BTreeSet;
use std::fs::File;
use std::io::{self, BufRead};
Line 838 ⟶ 2,058:
Err(error) => eprintln!("{}", error),
}
}</langsyntaxhighlight>
 
{{out}}
Line 864 ⟶ 2,084:
4: starvation train
5: upholstery posey
</pre>
 
=={{header|Swift}}==
<syntaxhighlight lang="swift">import Foundation
 
let minLength = 5
 
func loadDictionary(_ path: String) throws -> Set<String> {
let contents = try String(contentsOfFile: path, encoding: String.Encoding.ascii)
return Set<String>(contents.components(separatedBy: "\n").filter{$0.count >= minLength})
}
 
func pad(string: String, width: Int) -> String {
return string.count >= width ? string
: string + String(repeating: " ", count: width - string.count)
}
 
func printWords(words: [(String,String)]) {
for (n, (word1, word2)) in words.enumerated() {
print("\(String(format: "%2d", n + 1)): \(pad(string: word1, width: 14))\(word2)")
}
}
 
do {
let dictionary = try loadDictionary("unixdict.txt")
var oddWords: [(String, String)] = []
var evenWords: [(String, String)] = []
for word in dictionary {
if word.count < minLength + 2*(minLength/2) {
continue
}
var oddWord = ""
var evenWord = ""
for (i, c) in word.enumerated() {
if (i & 1) == 0 {
oddWord.append(c)
} else {
evenWord.append(c)
}
}
if dictionary.contains(oddWord) {
oddWords.append((word, oddWord))
}
if dictionary.contains(evenWord) {
evenWords.append((word, evenWord))
}
}
oddWords.sort(by: {$0.0 < $1.0})
evenWords.sort(by: {$0.0 < $1.0})
print("Odd words:")
printWords(words: oddWords)
print("\nEven words:")
printWords(words: evenWords)
} catch {
print(error.localizedDescription)
}</syntaxhighlight>
 
{{out}}
<pre>
Odd words:
1: barbarian brain
2: childbear cider
3: corrigenda cried
4: gargantuan grata
5: headdress hades
6: palladian plain
7: propionate point
8: salvation slain
9: siltation slain
10: slingshot sight
11: statuette saute
12: supersede spree
13: supervene spree
14: terminable trial
 
Even words:
1: cannonball annal
2: importation motto
3: psychopomp scoop
4: starvation train
5: upholstery posey
</pre>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="Rust">
import os
 
fn main() {
mut num := 0
mut word_arr := []u8{}
mut odd_list :=""
word_list := os.read_file("./unixdict.txt") or {println(err) exit(-1)}.split_into_lines()
for word in word_list {
if word.len > 8 {
for idx, chars in word {if idx % 2 == 0 {word_arr << chars}}
if word_list.contains(word_arr.bytestr()) && !odd_list.contains(word) && word_arr.len > 4 {
num++
odd_list += "${num}. ${word} >> ${word_arr.bytestr()} \n"
}
}
word_arr.clear()
}
println(odd_list)
}
</syntaxhighlight>
 
{{out}}
<pre>
1. barbarian >> brain
2. childbear >> cider
3. corrigenda >> cried
4. gargantuan >> grata
5. headdress >> hades
6. palladian >> plain
7. propionate >> point
8. salvation >> slain
9. siltation >> slain
10. slingshot >> sight
11. statuette >> saute
12. supersede >> spree
13. supervene >> spree
14. terminable >> trial
</pre>
 
Line 869 ⟶ 2,211:
{{libheader|Wren-fmt}}
{{libheader|Wren-sort}}
{{libheader|Wren-traititerate}}
<langsyntaxhighlight ecmascriptlang="wren">import "io" for File
import "./fmt" for Fmt
import "./sort" for Find
import "./traititerate" for Stepped
 
var wordList = "unixdict.txt" // local copy
Line 889 ⟶ 2,231:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 911 ⟶ 2,253:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">string 0; \use zero-terminated strings
int Dict(26000); \pointers to words (enough for unixdict.txt)
int DictSize; \actual number of pointers in Dict
Line 977 ⟶ 2,319:
DI:= DI+1;
until DI >= DictSize;
]</langsyntaxhighlight>
 
{{out}}
9,476

edits