ABC words: Difference between revisions

20,121 bytes added ,  1 month ago
(Add COBOL)
 
(34 intermediate revisions by 14 users not shown)
Line 1:
{{draft task}}
 
{{omit from|6502 Assembly|unixdict.txt is much larger than the CPU's address space.}}
{{omit from|8080 Assembly|See 6502 Assembly.}}
{{omit from|Z80 Assembly|See 6502 Assembly.}}
 
;Definition
Line 19 ⟶ 16:
 
=={{header|11l}}==
<langsyntaxhighlight lang="11l">L(ln) File(‘unixdict.txt’).read().split("\n")
V? a = ln.find(‘a’)
I a != N
V b = ln.findi(‘b’)
I a < b & b < ln.findi(‘c’)
print(ln)</langsyntaxhighlight>
 
{{out}}
Line 87 ⟶ 84:
=={{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 FindC(CHAR ARRAY text CHAR c)
BYTE i
 
Line 137 ⟶ 134:
 
FindAbcWords(fname)
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/ABC_words.png Screenshot from Atari 8-bit computer]
Line 160 ⟶ 157:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_Io;
with Ada.Strings.Fixed;
 
Line 194 ⟶ 191:
end loop;
Close (File);
end Abc_Words;</langsyntaxhighlight>
{{out}}
<pre>aback abacus abc abdicate abduct abeyance abject abreact
Line 205 ⟶ 202:
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68"># find words that have "a", "b" and "C" in order in them #
IF FILE input file;
STRING file name = "unixdict.txt";
Line 247 ⟶ 244:
OD;
close( input file )
FI</langsyntaxhighlight>
{{out}}
<pre>
Line 309 ⟶ 306:
=={{header|APL}}==
{{works with|Dyalog APL}}
<langsyntaxhighlight lang="apl">abcwords←{
⍺←'abc'
words←((~∊)∘⎕TC⊆⊢) 80 ¯1⎕MAP ⍵
match←∧/∊,2</⍳⍨
(⍺∘match¨words)/words
}</langsyntaxhighlight>
{{out}}
<pre> 11 5 ⍴ abcwords 'unixdict.txt'
Line 328 ⟶ 325:
prefabricate quarterback razorback roadblock sabbatical
snapback strabismic syllabic tabernacle tablecloth </pre>
 
=={{header|AppleScript}}==
===Core language===
This is a fairly simple solution, hard-coded for "a", "b", and "c". The 'offset' commands are performed by AppleScript's StandardAdditions OSAX, so the time taken by the multiple communications between the script and the OSAX makes the code comparatively slow. Still, the overall running time with the specified file on my current machine is less than 1.5 seconds.
<syntaxhighlight lang="applescript">on abcWords(wordFile)
-- The word file text is assumed to be UTF-8 encoded and to have one word per line.
script o
property wordList : paragraphs of (read wordFile as «class utf8»)
end script
set output to {}
repeat with thisWord in o's wordList
set thisWord to thisWord's contents
if ((thisWord contains "c") and ¬
(text 1 thru (offset of "c" in thisWord) of thisWord contains "b") and ¬
(text 1 thru (offset of "b" in thisWord) of thisWord contains "a")) then ¬
set end of output to thisWord
end repeat
return output
end abcWords
 
return abcWords(((path to desktop as text) & "www.rosettacode.org:unixdict.txt") as alias)</syntaxhighlight>
 
{{output}}
<syntaxhighlight lang="applescript">{"aback", "abacus", "abc", "abdicate", "abduct", "abeyance", "abject", "abreact", "abscess", "abscissa", "abscissae", "absence", "abstract", "abstracter", "abstractor", "adiabatic", "aerobacter", "aerobic", "albacore", "alberich", "albrecht", "algebraic", "alphabetic", "ambiance", "ambuscade", "aminobenzoic", "anaerobic", "arabic", "athabascan", "auerbach", "diabetic", "diabolic", "drawback", "fabric", "fabricate", "flashback", "halfback", "iambic", "lampblack", "leatherback", "metabolic", "nabisco", "paperback", "parabolic", "playback", "prefabricate", "quarterback", "razorback", "roadblock", "sabbatical", "snapback", "strabismic", "syllabic", "tabernacle", "tablecloth"}</syntaxhighlight>
 
The following alternative uses delimiters and text items instead and is considerably faster at around 0.25 seconds. Also, for the hell of it, it takes the characters (or even longer substrings) that the returned words must contain as a parameter. Same output here as above.
 
<syntaxhighlight lang="applescript">on abcWords(wordFile, theLetters)
-- The word file text is assumed to be UTF-8 encoded and to have one word per line.
script o
property wordList : paragraphs of (read wordFile as «class utf8»)
end script
set output to {}
set letterCount to (count theLetters)
set astid to AppleScript's text item delimiters
repeat with thisWord in o's wordList
set thisWord to thisWord's contents
set thisLetter to end of theLetters
if (thisWord contains thisLetter) then
set matched to true
repeat with c from (letterCount - 1) to 1 by -1
set AppleScript's text item delimiters to thisLetter
set thisLetter to item c of theLetters
set matched to (thisWord's first text item contains thisLetter)
if (not matched) then exit repeat
end repeat
if (matched) then set end of output to thisWord
end if
end repeat
set AppleScript's text item delimiters to astid
return output
end abcWords
 
return abcWords(((path to desktop as text) & "www.rosettacode.org:unixdict.txt") as alias, {"a", "b", "c"})</syntaxhighlight>
 
===AppleScriptObjC===
This is faster still at 0.01 seconds and uses AppleScriptObjC to access the regex facilities provided by macOS's Foundation framework. It too takes the characters the returned words must contain as a parameter, but, unlike the script above, doesn't recognise longer substring inputs as units in themselves. Same output as with the two "Core language" scripts above.
<syntaxhighlight lang="applescript">use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
use scripting additions
 
on abcWords(wordFile, theLetters)
-- This NSString method used here guesses the word file's text encoding itself.
set wordText to current application's class "NSString"'s stringWithContentsOfFile:(POSIX path of wordFile) ¬
usedEncoding:(missing value) |error|:(missing value)
-- Assuming one word per line, build a regex pattern to match words containing the specified letters in the given order.
set theLetters to join(theLetters, "")
set pattern to "(?mi)^"
repeat with c from 1 to (count theLetters)
set pattern to pattern & (("[^" & text c thru end of theLetters) & ("\\v]*+" & character c of theLetters))
end repeat
set pattern to pattern & ".*+$"
set regexObj to current application's class "NSRegularExpression"'s ¬
regularExpressionWithPattern:(pattern) options:(0) |error|:(missing value)
set wordMatches to regexObj's matchesInString:(wordText) options:(0) range:({0, wordText's |length|()})
set matchRanges to wordMatches's valueForKey:("range")
set output to {}
repeat with thisRange in matchRanges
set end of output to (wordText's substringWithRange:(thisRange)) as text
end repeat
return output
end abcWords
 
on join(lst, delim)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
set txt to lst as text
set AppleScript's text item delimiters to astid
return txt
end join
 
return abcWords(((path to desktop as text) & "www.rosettacode.org:unixdict.txt") as alias, {"a", "b", "c"})</syntaxhighlight>
 
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">words: read.lines relative "unixdict.txt"
 
isABC?: function [w][
Line 348 ⟶ 446:
if isABC? word ->
print word
]</langsyntaxhighlight>
 
{{out}}
Line 409 ⟶ 507:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight lang="autohotkey">FileRead, unixdict, unixdict.txt
Loop, Parse, unixdict, `n
if ABCWord(A_LoopField)
Line 430 ⟶ 528:
return false
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 494 ⟶ 592:
The following one-liner entered into a Posix shell returns the same 55 words as other entries.
 
<langsyntaxhighlight lang="awk">awk '/^[^bc]*a[^c]*b.*c/' unixdict.txt</langsyntaxhighlight>
 
=={{header|BASIC}}==
<langsyntaxhighlight lang="basic">10 DEFINT A,B,C: DEFSTR W
20 OPEN "I",1,"unixdict.txt"
30 IF EOF(1) THEN END
Line 505 ⟶ 603:
70 C = INSTR(W,"c")
80 IF A>0 AND B>0 AND C>0 AND A<B AND B<C THEN PRINT W,
90 GOTO 30</langsyntaxhighlight>
{{out}}
<pre>aback abacus abc abdicate abduct
Line 520 ⟶ 618:
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
let find(s, c) = valof
Line 556 ⟶ 654:
endread()
$)
$)</langsyntaxhighlight>
{{out}}
<pre style='height:50ex'>aback
Line 615 ⟶ 713:
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <string.h>
 
Line 638 ⟶ 736:
}
return 0;
}</langsyntaxhighlight>
{{out}}
<pre style='height:50ex;'>aback
Line 696 ⟶ 794:
tablecloth</pre>
 
=={{header|C# sharp|CSharpC#}}==
Takes an optional command line for other character combinations. User can specify any reasonable number of unique characters. Caveat: see discussion page for issue about specifying repeated characters.
<langsyntaxhighlight lang="csharp">class Program {
static void Main(string[] args) { int bi, i = 0; string chars = args.Length < 1 ? "abc" : args[0];
foreach (var item in System.IO.File.ReadAllLines("unixdict.txt")) {
Line 706 ⟶ 804:
skip: ; } }
}
</syntaxhighlight>
</lang>
{{out}}
Without command line arguments:
Line 730 ⟶ 828:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <cstdlib>
#include <fstream>
#include <iostream>
Line 773 ⟶ 871:
}
return EXIT_SUCCESS;
}</langsyntaxhighlight>
 
{{out}}
Line 835 ⟶ 933:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">abc_word = proc (s: string) returns (bool)
a: int := string$indexc('a', s)
b: int := string$indexc('b', s)
Line 851 ⟶ 949:
end except when end_of_file: end
stream$close(dict)
end start_up</langsyntaxhighlight>
{{out}}
<pre style='height:50ex;'>aback
Line 910 ⟶ 1,008:
 
=={{header|COBOL}}==
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. ABC-WORDS.
Line 950 ⟶ 1,048:
AND B IS LESS THAN C
AND C IS LESS THAN X,
DISPLAY WORD.</langsyntaxhighlight>
{{out}}
<pre style='height:50ex;'>aback
Line 1,012 ⟶ 1,110:
{{libheader| System.IoUtils}}
{{Trans|C#}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program ABC_words;
 
Line 1,066 ⟶ 1,164:
 
{$IFNDEF UNIX} readln; {$ENDIF}
end.</langsyntaxhighlight>
 
=={{header|Diego}}==
<syntaxhighlight lang="diego">add_ary({str},foundWords);
with_file()
()_read⟦{raw},unixdict.txt⟧_splitto(words,⟦\n⟧)
(words)_if⟦[posA]<[posB]<[posC]⟧)_findto(posA,⟦a⟧)_i⟪0⟫_findto(posB,⟦b⟧)_i⟪0⟫_findto(posC,⟦c⟧)_i⟪0⟫
?_(foundWords)_add⟦words⟪⟫⟧;
;
;
;
log_console()_(foundWords);</syntaxhighlight>
 
Alternatively...
<syntaxhighlight lang="diego">add_ary({str},foundWords);
with_file()
()_read⟦{raw},unixdict.txt⟧_splitto(words,⟦\n⟧)
(words)_foreach(word)
?_(word)_findto(posA,⟦a⟧)_i⟪0⟫;
?_(word)_sliceto(foundA,⟦[posA]⟧)
?_(foundA)_findto(posB,⟦b⟧)_i⟪0⟫;
?_(foundA)_sliceto(foundB,⟦[posB]⟧)
?_(foundB)_find⟦c⟧
?_(foundWords)_add[word];
;
;
;
;
;
;
log_console()_(foundWords);</syntaxhighlight>
 
Output:
<pre>aback,abacus,abc,abdicate,abduct,abeyance,abject,abreact,abscess,abscissa,abscissae,absence,abstract,abstracter,abstractor,adiabatic,aerobacter,aerobic,albacore,alberich,albrecht,algebraic,alphabetic,ambiance,ambuscade,aminobenzoic,anaerobic,arabic,athabascan,auerbach,diabetic,diabolic,drawback,fabric,fabricate,flashback,halfback,iambic,lampblack,leatherback,metabolic,nabisco,paperback,parabolic,playback,prefabricate,quarterback,razorback,roadblock,sabbatical,snapback,strabismic,syllabic,tabernacle,tablecloth</pre>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">\util.g
 
proc nonrec abc_word(*char line) bool:
int a, b, c;
a := CharsIndex(line, "a");
b := CharsIndex(line, "b");
c := CharsIndex(line, "c");
a ~= -1 and a < b and b < c
corp
 
proc nonrec main() void:
file(1024) dictfile;
[32] char buf;
*char line;
channel input text dict;
open(dict, dictfile, "unixdict.txt");
line := &buf[0];
while readln(dict; line) do
if abc_word(line) then writeln(line) fi
od;
close(dict)
corp</syntaxhighlight>
{{out}}
<pre style='height:50ex;'>aback
abacus
abc
abdicate
abduct
abeyance
abject
abreact
abscess
abscissa
abscissae
absence
abstract
abstracter
abstractor
adiabatic
aerobacter
aerobic
albacore
alberich
albrecht
algebraic
alphabetic
ambiance
ambuscade
aminobenzoic
anaerobic
arabic
athabascan
auerbach
diabetic
diabolic
drawback
fabric
fabricate
flashback
halfback
iambic
lampblack
leatherback
metabolic
nabisco
paperback
parabolic
playback
prefabricate
quarterback
razorback
roadblock
sabbatical
snapback
strabismic
syllabic
tabernacle
tablecloth</pre>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: grouping io.encodings.ascii io.files kernel prettyprint
sequences sets ;
 
"unixdict.txt" ascii file-lines
[ "abc" within members "abc" = ] filter
5 group simple-table.</langsyntaxhighlight>
{{out}}
<pre>
Line 1,092 ⟶ 1,306:
=={{header|Forth}}==
{{works with|Gforth}}
<langsyntaxhighlight lang="forth">: abc-word? ( addr u -- ? )
false false { a b }
0 do
Line 1,124 ⟶ 1,338:
 
main
bye</langsyntaxhighlight>
 
{{out}}
Line 1,186 ⟶ 1,400:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">
#define NOTINSTRING 9999
 
Line 1,215 ⟶ 1,429:
end if
wend
close #1</langsyntaxhighlight>
{{out}}
<pre>
Line 1,273 ⟶ 1,487:
54. tabernacle
55. tablecloth</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
local fn WordList as CFArrayRef
CFArrayRef wordList = NULL
CFURLRef url = fn URLWithString( @"http://wiki.puzzlers.org/pub/wordlists/unixdict.txt" )
CFStringRef string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
if ( string ) then wordList = fn StringComponentsSeparatedByCharactersInSet( string, fn CharacterSetNewlineSet )
end fn = wordList
 
void local fn ABCWords
CFArrayRef list = fn WordList
CFStringRef string
long abc
 
if ( list ) == NULL then NSLog(@"Unable to load word list") : exit fn
for string in list
abc = instr( 0, string, @"a")
if ( abc == NSNotFound ) then continue
abc = instr( abc, string, @"b")
if ( abc == NSNotFound ) then continue
abc = instr( abc, string, @"c")
if ( abc != NSNotFound ) then NSLog(@"%@",string)
next
end fn
 
fn ABCWords
 
HandleEvents
</syntaxhighlight>
 
{{out}}
<pre style='height:20ex;'>
aback
abacus
abc
abdicate
abduct
abeyance
abject
abreact
abscess
abscissa
abscissae
absence
abstract
abstracter
abstractor
adiabatic
aerobacter
aerobic
albacore
alberich
albrecht
algebraic
alphabetic
ambiance
ambuscade
aminobenzoic
anaerobic
arabic
athabascan
auerbach
diabetic
diabolic
drawback
fabric
fabricate
flashback
halfback
iambic
lampblack
leatherback
metabolic
nabisco
paperback
parabolic
playback
prefabricate
quarterback
razorback
roadblock
sabbatical
snapback
strabismic
syllabic
tabernacle
tablecloth
</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,302 ⟶ 1,607:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,365 ⟶ 1,670:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.MaybeList (isJustelemIndex)
import Data.Maybe (isJust)
 
------------------------ ABC WORDS -----------------------
Line 1,372 ⟶ 1,678:
isABC s =
isJust $
afterChar 'a'residue "bc" 'a' s
>>= afterCharresidue "c" 'b' "c"
>>= afterCharelemIndex 'c' ""
 
afterCharresidue :: CharString -> StringChar -> String -> Maybe String
afterChar cresidue except c = go
where
go [] = Nothing
Line 1,389 ⟶ 1,695:
main =
readFile "unixdict.txt"
>>= mapM_ print . zip [1 ..] . filter isABC . lines</langsyntaxhighlight>
{{Out}}
<pre>(1,"aback")
Line 1,448 ⟶ 1,754:
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">import java.io.BufferedReader;
import java.io.FileReader;
 
Line 1,511 ⟶ 1,817:
return false;
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,548 ⟶ 1,854:
25: pummel 26: supremum
</pre>
 
=={{header|JavaScript}}==
<syntaxhighlight lang="javascript">(() => {
"use strict";
 
// -------------------- ABC WORDS --------------------
 
// isABC :: String -> Bool
const isABC = s =>
// True if the string contains each of 'a' 'b' 'c',
// and their first occurrences in the string are
// in that alphabetical order.
bind(
bind(
residue("a")("bc")(s)
)(
residue("b")("c")
)
)(
r => r.includes("c") || null
) !== null;
 
 
// residue :: Char -> String -> String -> Maybe String
const residue = c =>
// Any characters remaining in a given string
// after the first occurrence of c, or null
// if c is not found, or is preceded by any
// excluded characters.
excluded => {
const go = t =>
(0 < t.length) ? (() => {
const x = t[0];
 
return excluded.includes(x) ? (
null
) : c === x ? (
t.slice(1)
) : go(t.slice(1));
})() : null;
 
return go;
};
 
 
// ---------------------- TEST -----------------------
const main = () =>
lines(readFile("~/unixdict.txt"))
.filter(isABC)
.map((x, i) => `(${1 + i}, ${x})`)
.join("\n");
 
 
// --------------------- GENERIC ---------------------
 
// bind (>>=) :: Maybe a -> (a -> Maybe b) -> Maybe b
const bind = mb =>
// Null if mb is null, or the application of the
// (a -> Maybe b) function mf to the contents of mb.
mf => null === mb ? (
mb
) : mf(mb);
 
 
// lines :: String -> [String]
const lines = s =>
// A list of strings derived from a single string
// which is delimited by \n or by \r\n or \r.
Boolean(s.length) ? (
s.split(/\r\n|\n|\r/u)
) : [];
 
 
// readFile :: FilePath -> IO String
const readFile = fp => {
// The contents of a text file at the
// given file path.
const
e = $(),
ns = $.NSString
.stringWithContentsOfFileEncodingError(
$(fp).stringByStandardizingPath,
$.NSUTF8StringEncoding,
e
);
 
return ObjC.unwrap(
ns.isNil() ? (
e.localizedDescription
) : ns
);
};
 
 
// MAIN ---
return main();
})();</syntaxhighlight>
{{Out}}
<pre>(1, aback)
(2, abacus)
(3, abc)
(4, abdicate)
(5, abduct)
(6, abeyance)
(7, abject)
(8, abreact)
(9, abscess)
(10, abscissa)
(11, abscissae)
(12, absence)
(13, abstract)
(14, abstracter)
(15, abstractor)
(16, adiabatic)
(17, aerobacter)
(18, aerobic)
(19, albacore)
(20, alberich)
(21, albrecht)
(22, algebraic)
(23, alphabetic)
(24, ambiance)
(25, ambuscade)
(26, aminobenzoic)
(27, anaerobic)
(28, arabic)
(29, athabascan)
(30, auerbach)
(31, diabetic)
(32, diabolic)
(33, drawback)
(34, fabric)
(35, fabricate)
(36, flashback)
(37, halfback)
(38, iambic)
(39, lampblack)
(40, leatherback)
(41, metabolic)
(42, nabisco)
(43, paperback)
(44, parabolic)
(45, playback)
(46, prefabricate)
(47, quarterback)
(48, razorback)
(49, roadblock)
(50, sabbatical)
(51, snapback)
(52, strabismic)
(53, syllabic)
(54, tabernacle)
(55, tablecloth)</pre>
 
=={{header|J}}==
A word is an abc word if the order of the indices of 'a', 'b' and 'c' and the final letter of the word are unchanged by sorting. (The index of 'a' would be the length of the word -- one greater than the last index into the word -- if 'a' was missing from the word. So by including that last index in our list of indices to be sorted, we eliminate all words which are missing an 'a', 'b' or 'c'.)<syntaxhighlight lang="j"> >(#~ (-: /:~)@(<:@#,~i.&'abc')@>) cutLF tolower fread 'unixdict.txt'
aback
abacus
abc
abdicate
abduct
abeyance
abject
abreact
abscess
abscissa
abscissae
absence
abstract
abstracter
abstractor
adiabatic
aerobacter
aerobic
albacore
alberich
albrecht
algebraic
alphabetic
ambiance
ambuscade
aminobenzoic
anaerobic
arabic
athabascan
auerbach
diabetic
diabolic
drawback
fabric
fabricate
flashback
halfback
iambic
lampblack
leatherback
metabolic
nabisco
paperback
parabolic
playback
prefabricate
quarterback
razorback
roadblock
sabbatical
snapback
strabismic
syllabic
tabernacle
tablecloth</syntaxhighlight>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<langsyntaxhighlight lang="jq">def is_abc_word:
[index("a", "b", "c")]
| all(.[]; . != null) and .[0] < .[1] and .[1] < .[2] ;
 
select(is_abc_word)</langsyntaxhighlight>
Invocation: jq -rR -f abc-words.jq unixdict.txt
{{out}} (synopsis)
Line 1,568 ⟶ 2,085:
abc
</pre>
 
 
=={{header|Julia}}==
See [[Alternade_words#Julia]] for the foreachword function.
<langsyntaxhighlight lang="julia">function isabcword(w, _)
positions = [findfirst(c -> c == ch, w) for ch in "abc"]
return all(!isnothing, positions) && issorted(positions) ? w : ""
Line 1,578 ⟶ 2,094:
 
foreachword("unixdict.txt", isabcword)
</langsyntaxhighlight>{{out}}
<pre>
Word source: unixdict.txt
Line 1,595 ⟶ 2,111:
 
=={{header|Lua}}==
<langsyntaxhighlight Lualang="lua">for word in io.lines('unixdict.txt') do
if string.find(word, "^[^bc]*a[^c]*b.*c") then
print(word)
end
end</langsyntaxhighlight>
 
=={{header|Modula-2}}==
<langsyntaxhighlight lang="modula2">MODULE ABCWords;
IMPORT SeqIO;
IMPORT Texts;
Line 1,642 ⟶ 2,158:
ts := Texts.Disconnect(dict);
fs := SeqIO.Close(file);
END ABCWords.</langsyntaxhighlight>
{{out}}
<pre style='height:50ex;'>aback
Line 1,701 ⟶ 2,217:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import strutils
 
func isAbcWord(word: string): bool =
Line 1,716 ⟶ 2,232:
if word.isAbcWord:
inc count
echo ($count).align(2), ' ', word</langsyntaxhighlight>
 
{{out}}
Line 1,774 ⟶ 2,290:
54 tabernacle
55 tablecloth</pre>
 
=={{header|Pascal}}==
==={{header|Free Pascal}}===
<syntaxhighlight lang="pascal">
Program abcwords;
uses Classes;
 
const
FNAME = 'unixdict.txt';
 
var
list: TStringList;
str : string;
a,b,c : integer;
 
 
begin
list := TStringList.Create;
list.LoadFromFile(FNAME);
for str in list do
begin
a := pos('a',str);
b := pos('b',str);
c := pos('c',str);
if (a>0) and (b>a) and (c > b) then writeln(str);
end;
end.
</syntaxhighlight>
{{out}}
<pre>
aback
abacus
abc
abdicate
abduct
abeyance
abject
abreact
abscess
abscissa
abscissae
absence
abstract
abstracter
abstractor
adiabatic
aerobacter
aerobic
albacore
alberich
albrecht
algebraic
alphabetic
ambiance
ambuscade
aminobenzoic
anaerobic
arabic
athabascan
auerbach
diabetic
diabolic
drawback
fabric
fabricate
flashback
halfback
iambic
lampblack
leatherback
metabolic
nabisco
paperback
parabolic
playback
prefabricate
quarterback
razorback
roadblock
sabbatical
snapback
strabismic
syllabic
tabernacle
tablecloth
</pre>
 
=={{header|Perl}}==
Outputs same 55 words everyone else finds.
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
@ARGV = 'unixdict.txt';
print grep /^[^bc]*a[^c]*b.*c/, <>;</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;">abc</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">word</span><span style="color: #0000FF;">)</span>
Line 1,791 ⟶ 2,393:
<span style="color: #004080;">sequence</span> <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;">unix_dict</span><span style="color: #0000FF;">(),</span><span style="color: #000000;">abc</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 abc 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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,798 ⟶ 2,400:
 
=={{header|PL/I}}==
<langsyntaxhighlight lang="pli">abcWords: procedure options(main);
declare dict file;
open file(dict) title('unixdict.txt');
Line 1,822 ⟶ 2,424:
end;
end;
end abcWords;</langsyntaxhighlight>
{{out}}
<pre>aback abacus abc abdicate abduct
Line 1,837 ⟶ 2,439:
 
=={{header|Processing}}==
<langsyntaxhighlight lang="processing">String[] words;
 
void setup() {
Line 1,855 ⟶ 2,457:
}
return false;
}</langsyntaxhighlight>
{{out}}
<pre>1 aback
Line 1,916 ⟶ 2,518:
Outputs the same 55 words as other examples when entered in a Posix terminal shell
 
<langsyntaxhighlight lang="python">python -c '
import sys
for ln in sys.stdin:
Line 1,922 ⟶ 2,524:
print(ln.rstrip())
' < unixdict.txt
</syntaxhighlight>
</lang>
 
Or a functionally composed variant, with a predicate which takes a single recursive pass through the characters of each word:
 
<langsyntaxhighlight lang="python">'''ABC Words'''
 
 
Line 1,934 ⟶ 2,536:
first occurrences of each in that order.
'''
return None != bind(
bind(
residue('abc')(, 'bca')(s)
)(
residue('bc')(, 'cb')
)
)(
residue(lambda r: 'c')('') in r
)
 
 
# residue (String, Char -> String) -> String -> Maybe String
def residue(disallowed, c):
'''Any characters remaining in s after c, unless
c is preceded by excluded characters.
'''
def excludinggo(css):
defif go(s):
ifx = s:[0]
return None if x =in disallowed else s[0](
return Nones[1:] if xc in== csx else go(s[1:])
s[1:] if c == x else go(s[1:])
)else:
else:return None
return Nonego
return go
return excluding
 
 
Line 2,004 ⟶ 2,604:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>(1, 'aback')
Line 2,061 ⟶ 2,661:
(54, 'tabernacle')
(55, 'tablecloth')</pre>
 
Or using a regular expression.
 
<syntaxhighlight lang="python">import re
import textwrap
 
RE = re.compile(r"^([^bc\r\n]*a[^c\r\n]*b.*c.*)$", re.M)
 
with open("unixdict.txt") as fd:
abc_words = RE.findall(fd.read())
 
print(f"found {len(abc_words)} ABC words")
print(textwrap.fill(" ".join(abc_words)))</syntaxhighlight>
 
{{out}}
<pre>
found 55 ABC words
aback abacus abc abdicate abduct abeyance abject abreact abscess
abscissa abscissae absence abstract abstracter abstractor adiabatic
aerobacter aerobic albacore alberich albrecht algebraic alphabetic
ambiance ambuscade aminobenzoic anaerobic arabic athabascan auerbach
diabetic diabolic drawback fabric fabricate flashback halfback iambic
lampblack leatherback metabolic nabisco paperback parabolic playback
prefabricate quarterback razorback roadblock sabbatical snapback
strabismic syllabic tabernacle tablecloth
</pre>
 
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ true swap
behead swap
witheach
Line 2,086 ⟶ 2,712:
else drop ]
dup size echo say " words found." cr
70 wrap$</langsyntaxhighlight>
 
{{out}}
Line 2,100 ⟶ 2,726:
prefabricate quarterback razorback roadblock sabbatical snapback
strabismic syllabic tabernacle tablecloth
</pre>
 
=={{header|R}}==
 
<syntaxhighlight lang="R">
library(stringi)
library(dplyr)
 
check_abc <- function(w) {
char_list <- stri_split_boundaries(w, type='character')[[1]]
fpos <- lapply(c("a","b","c"),\(x) grep(x,char_list)) %>% sapply(\(x) x[1])
if (any(is.na(fpos)==T)) return(F)
ifelse(all(sort(fpos) == fpos),T,F)
}
 
rep <- sapply(readLines("unixdict.txt"), \(x) check_abc(x))
print(names(rep[rep == T]))
</syntaxhighlight>
{{out}}
 
<pre>
[1] "aback" "abacus" "abc" "abdicate" "abduct" "abeyance"
[7] "abject" "abreact" "abscess" "abscissa" "abscissae" "absence"
[13] "abstract" "abstracter" "abstractor" "adiabatic" "aerobacter" "aerobic"
[19] "albacore" "alberich" "albrecht" "algebraic" "alphabetic" "ambiance"
[25] "ambuscade" "aminobenzoic" "anaerobic" "arabic" "athabascan" "auerbach"
[31] "diabetic" "diabolic" "drawback" "fabric" "fabricate" "flashback"
[37] "halfback" "iambic" "lampblack" "leatherback" "metabolic" "nabisco"
[43] "paperback" "parabolic" "playback" "prefabricate" "quarterback" "razorback"
[49] "roadblock" "sabbatical" "snapback" "strabismic" "syllabic" "tabernacle"
[55] "tablecloth"
</pre>
 
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">#lang racket
 
(for ((i (in-naturals 1))
(w (filter (curry regexp-match #rx"^[^bc]*a[^c]*b.*c.*$")
(file->lines "../../data/unixdict.txt"))))
(printf "~a\t~a~%" i w))</langsyntaxhighlight>
 
{{out}}
Line 2,135 ⟶ 2,792:
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>put display 'unixdict.txt'.IO.words».fc.grep({ (.index('a')//next) < (.index('b')//next) < (.index('c')//next) }),
:11cols, :fmt('%-12s');
 
Line 2,141 ⟶ 2,798:
cache $list;
$title ~ $list.batch($cols)».fmt($fmt).join: "\n"
}</langsyntaxhighlight>
{{out}}
<pre>55 matching:
Line 2,155 ⟶ 2,812:
 
It also allows the &nbsp; (ABC) &nbsp; characters to be specified on the command line (CL) as well as the dictionary file identifier.
<langsyntaxhighlight lang="rexx">/*REXX program finds all the caseless alternade words (within an identified dictionary).*/
parse arg minL iFID . /*obtain optional arguments from the CL*/
if minL=='' | minL=="," then minL= 6 /*Not specified? Then use the default.*/
Line 2,181 ⟶ 2,838:
end /*j*/
/*stick a fork in it, we're all done. */
say copies('─',30) finds ' alternade words found with a minimum length of ' minL</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Line 2,252 ⟶ 2,909:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
cStr = read("unixdict.txt")
wordList = str2list(cStr)
Line 2,270 ⟶ 2,927:
ok
next
</syntaxhighlight>
</lang>
Output:
<pre>
Line 2,333 ⟶ 2,990:
=={{header|Ruby}}==
translation from Perl
<langsyntaxhighlight lang="ruby">puts File.open("unixdict.txt").grep(/^[^bc]*a[^c]*b.*c/)
</syntaxhighlight>
</lang>
{{out}}Same 55 words:
<pre>aback
Line 2,358 ⟶ 3,015:
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">import Foundation
 
func loadDictionary(_ path: String) throws -> [String] {
Line 2,401 ⟶ 3,058:
} catch {
print(error)
}</langsyntaxhighlight>
 
{{out}}
Line 2,463 ⟶ 3,120:
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">proc is_abc_word word {
regexp {^[^bc]*a[^c]*b.*c} $word
}
Line 2,472 ⟶ 3,129:
 
puts "Found [llength $res] words:"
puts [join $res \n]</langsyntaxhighlight>
{{out}}
<pre>$ tclsh abc_words.tcl
Line 2,533 ⟶ 3,190:
 
=={{header|Transd}}==
<langsyntaxhighlight lang="scheme">#lang transd
 
MainModule : {
Line 2,542 ⟶ 3,199:
(if (match w "^[^bc]*a[^c]*b.*c.*") (lout w))))
)
}</langsyntaxhighlight>{{out}}
<pre>
aback
Line 2,551 ⟶ 3,208:
tabernacle
tablecloth
</pre>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">
import os
 
fn main() {
mut count := 1
mut text :=''
unixdict := os.read_file('./unixdict.txt') or {println('Error: file not found') exit(1)}
for word in unixdict.split_into_lines() {
if word.contains('a')
&& word.index_any('a') < word.index_any('b')
&& word.index_any('b') < word.index_any('c') {
text += count++.str() + ': $word \n'
}
}
println(text)
}
</syntaxhighlight>
 
{{out}}
<pre>
1: aback
2: abacus
3: abc
4: abdicate
5: abduct
6: abeyance
7: abject
8: abreact
9: abscess
10: abscissa
11: abscissae
12: absence
13: abstract
14: abstracter
15: abstractor
16: adiabatic
17: aerobacter
18: aerobic
19: albacore
20: alberich
21: albrecht
22: algebraic
23: alphabetic
24: ambiance
25: ambuscade
26: aminobenzoic
27: anaerobic
28: arabic
29: athabascan
30: auerbach
31: diabetic
32: diabolic
33: drawback
34: fabric
35: fabricate
36: flashback
37: halfback
38: iambic
39: lampblack
40: leatherback
41: metabolic
42: nabisco
43: paperback
44: parabolic
45: playback
46: prefabricate
47: quarterback
48: razorback
49: roadblock
50: sabbatical
51: snapback
52: strabismic
53: syllabic
54: tabernacle
55: tablecloth
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "io" for File
import "./fmt" for Fmt
 
var wordList = "unixdict.txt" // local copy
Line 2,570 ⟶ 3,305:
Fmt.print("$2d: $s", count, word)
}
}</langsyntaxhighlight>
 
{{out}}
Line 2,633 ⟶ 3,368:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">string 0; \use zero-terminated strings
int I, J, K, Ch, Len;
char Word(100); \(longest word in unixdict.txt is 22 chars)
Line 2,662 ⟶ 3,397:
];
until Ch = EOF;
]</langsyntaxhighlight>
 
{{out}}
Line 2,722 ⟶ 3,457:
tablecloth
</pre>
{{omit from|6502 Assembly|unixdict.txt is much larger than the CPU's address space.}}
{{omit from|8080 Assembly|See 6502 Assembly.}}
{{omit from|Z80 Assembly|See 6502 Assembly.}}
44

edits