ABC words: Difference between revisions
Content added Content deleted
(Python alternative) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 19: | Line 19: | ||
=={{header|11l}}== |
=={{header|11l}}== |
||
< |
<syntaxhighlight lang=11l>L(ln) File(‘unixdict.txt’).read().split("\n") |
||
V? a = ln.find(‘a’) |
V? a = ln.find(‘a’) |
||
I a != N |
I a != N |
||
V b = ln.findi(‘b’) |
V b = ln.findi(‘b’) |
||
I a < b & b < ln.findi(‘c’) |
I a < b & b < ln.findi(‘c’) |
||
print(ln)</ |
print(ln)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 87: | Line 87: | ||
=={{header|Action!}}== |
=={{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. |
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. |
||
< |
<syntaxhighlight lang=Action!>BYTE FUNC FindC(CHAR ARRAY text CHAR c) |
||
BYTE i |
BYTE i |
||
Line 137: | Line 137: | ||
FindAbcWords(fname) |
FindAbcWords(fname) |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/ABC_words.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/ABC_words.png Screenshot from Atari 8-bit computer] |
||
Line 160: | Line 160: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
< |
<syntaxhighlight lang=Ada>with Ada.Text_Io; |
||
with Ada.Strings.Fixed; |
with Ada.Strings.Fixed; |
||
Line 194: | Line 194: | ||
end loop; |
end loop; |
||
Close (File); |
Close (File); |
||
end Abc_Words;</ |
end Abc_Words;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>aback abacus abc abdicate abduct abeyance abject abreact |
<pre>aback abacus abc abdicate abduct abeyance abject abreact |
||
Line 205: | Line 205: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
< |
<syntaxhighlight lang=algol68># find words that have "a", "b" and "C" in order in them # |
||
IF FILE input file; |
IF FILE input file; |
||
STRING file name = "unixdict.txt"; |
STRING file name = "unixdict.txt"; |
||
Line 247: | Line 247: | ||
OD; |
OD; |
||
close( input file ) |
close( input file ) |
||
FI</ |
FI</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 309: | Line 309: | ||
=={{header|APL}}== |
=={{header|APL}}== |
||
{{works with|Dyalog APL}} |
{{works with|Dyalog APL}} |
||
< |
<syntaxhighlight lang=apl>abcwords←{ |
||
⍺←'abc' |
⍺←'abc' |
||
words←((~∊)∘⎕TC⊆⊢) 80 ¯1⎕MAP ⍵ |
words←((~∊)∘⎕TC⊆⊢) 80 ¯1⎕MAP ⍵ |
||
match←∧/∊,2</⍳⍨ |
match←∧/∊,2</⍳⍨ |
||
(⍺∘match¨words)/words |
(⍺∘match¨words)/words |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 11 5 ⍴ abcwords 'unixdict.txt' |
<pre> 11 5 ⍴ abcwords 'unixdict.txt' |
||
Line 332: | Line 332: | ||
===Core language=== |
===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. |
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. |
-- The word file text is assumed to be UTF-8 encoded and to have one word per line. |
||
script o |
script o |
||
Line 350: | Line 350: | ||
end abcWords |
end abcWords |
||
return abcWords(((path to desktop as text) & "www.rosettacode.org:unixdict.txt") as alias)</ |
return abcWords(((path to desktop as text) & "www.rosettacode.org:unixdict.txt") as alias)</syntaxhighlight> |
||
{{output}} |
{{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. |
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. |
-- The word file text is assumed to be UTF-8 encoded and to have one word per line. |
||
script o |
script o |
||
Line 385: | Line 385: | ||
end abcWords |
end abcWords |
||
return abcWords(((path to desktop as text) & "www.rosettacode.org:unixdict.txt") as alias, {"a", "b", "c"})</ |
return abcWords(((path to desktop as text) & "www.rosettacode.org:unixdict.txt") as alias, {"a", "b", "c"})</syntaxhighlight> |
||
===AppleScriptObjC=== |
===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. |
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 framework "Foundation" |
||
use scripting additions |
use scripting additions |
||
Line 428: | Line 428: | ||
end join |
end join |
||
return abcWords(((path to desktop as text) & "www.rosettacode.org:unixdict.txt") as alias, {"a", "b", "c"})</ |
return abcWords(((path to desktop as text) & "www.rosettacode.org:unixdict.txt") as alias, {"a", "b", "c"})</syntaxhighlight> |
||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang=rebol>words: read.lines relative "unixdict.txt" |
||
isABC?: function [w][ |
isABC?: function [w][ |
||
Line 449: | Line 449: | ||
if isABC? word -> |
if isABC? word -> |
||
print word |
print word |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 510: | Line 510: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
< |
<syntaxhighlight lang=autohotkey>FileRead, unixdict, unixdict.txt |
||
Loop, Parse, unixdict, `n |
Loop, Parse, unixdict, `n |
||
if ABCWord(A_LoopField) |
if ABCWord(A_LoopField) |
||
Line 531: | Line 531: | ||
return false |
return false |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 595: | Line 595: | ||
The following one-liner entered into a Posix shell returns the same 55 words as other entries. |
The following one-liner entered into a Posix shell returns the same 55 words as other entries. |
||
< |
<syntaxhighlight lang=awk>awk '/^[^bc]*a[^c]*b.*c/' unixdict.txt</syntaxhighlight> |
||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
< |
<syntaxhighlight lang=basic>10 DEFINT A,B,C: DEFSTR W |
||
20 OPEN "I",1,"unixdict.txt" |
20 OPEN "I",1,"unixdict.txt" |
||
30 IF EOF(1) THEN END |
30 IF EOF(1) THEN END |
||
Line 606: | Line 606: | ||
70 C = INSTR(W,"c") |
70 C = INSTR(W,"c") |
||
80 IF A>0 AND B>0 AND C>0 AND A<B AND B<C THEN PRINT W, |
80 IF A>0 AND B>0 AND C>0 AND A<B AND B<C THEN PRINT W, |
||
90 GOTO 30</ |
90 GOTO 30</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>aback abacus abc abdicate abduct |
<pre>aback abacus abc abdicate abduct |
||
Line 621: | Line 621: | ||
=={{header|BCPL}}== |
=={{header|BCPL}}== |
||
< |
<syntaxhighlight lang=bcpl>get "libhdr" |
||
let find(s, c) = valof |
let find(s, c) = valof |
||
Line 657: | Line 657: | ||
endread() |
endread() |
||
$) |
$) |
||
$)</ |
$)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex'>aback |
<pre style='height:50ex'>aback |
||
Line 716: | Line 716: | ||
=={{header|C}}== |
=={{header|C}}== |
||
< |
<syntaxhighlight lang=c>#include <stdio.h> |
||
#include <string.h> |
#include <string.h> |
||
Line 739: | Line 739: | ||
} |
} |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex;'>aback |
<pre style='height:50ex;'>aback |
||
Line 799: | Line 799: | ||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
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. |
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. |
||
< |
<syntaxhighlight lang=csharp>class Program { |
||
static void Main(string[] args) { int bi, i = 0; string chars = args.Length < 1 ? "abc" : args[0]; |
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")) { |
foreach (var item in System.IO.File.ReadAllLines("unixdict.txt")) { |
||
Line 807: | Line 807: | ||
skip: ; } } |
skip: ; } } |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Without command line arguments: |
Without command line arguments: |
||
Line 831: | Line 831: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang=cpp>#include <cstdlib> |
||
#include <fstream> |
#include <fstream> |
||
#include <iostream> |
#include <iostream> |
||
Line 874: | Line 874: | ||
} |
} |
||
return EXIT_SUCCESS; |
return EXIT_SUCCESS; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 936: | Line 936: | ||
=={{header|CLU}}== |
=={{header|CLU}}== |
||
< |
<syntaxhighlight lang=clu>abc_word = proc (s: string) returns (bool) |
||
a: int := string$indexc('a', s) |
a: int := string$indexc('a', s) |
||
b: int := string$indexc('b', s) |
b: int := string$indexc('b', s) |
||
Line 952: | Line 952: | ||
end except when end_of_file: end |
end except when end_of_file: end |
||
stream$close(dict) |
stream$close(dict) |
||
end start_up</ |
end start_up</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex;'>aback |
<pre style='height:50ex;'>aback |
||
Line 1,011: | Line 1,011: | ||
=={{header|COBOL}}== |
=={{header|COBOL}}== |
||
< |
<syntaxhighlight lang=cobol> IDENTIFICATION DIVISION. |
||
PROGRAM-ID. ABC-WORDS. |
PROGRAM-ID. ABC-WORDS. |
||
Line 1,051: | Line 1,051: | ||
AND B IS LESS THAN C |
AND B IS LESS THAN C |
||
AND C IS LESS THAN X, |
AND C IS LESS THAN X, |
||
DISPLAY WORD.</ |
DISPLAY WORD.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex;'>aback |
<pre style='height:50ex;'>aback |
||
Line 1,113: | Line 1,113: | ||
{{libheader| System.IoUtils}} |
{{libheader| System.IoUtils}} |
||
{{Trans|C#}} |
{{Trans|C#}} |
||
< |
<syntaxhighlight lang=Delphi> |
||
program ABC_words; |
program ABC_words; |
||
Line 1,167: | Line 1,167: | ||
{$IFNDEF UNIX} readln; {$ENDIF} |
{$IFNDEF UNIX} readln; {$ENDIF} |
||
end.</ |
end.</syntaxhighlight> |
||
=={{header|Diego}}== |
=={{header|Diego}}== |
||
< |
<syntaxhighlight lang=diego>add_ary({str},foundWords); |
||
with_file() |
with_file() |
||
()_read⟦{raw},unixdict.txt⟧_splitto(words,⟦\n⟧) |
()_read⟦{raw},unixdict.txt⟧_splitto(words,⟦\n⟧) |
||
Line 1,178: | Line 1,178: | ||
; |
; |
||
; |
; |
||
log_console()_(foundWords);</ |
log_console()_(foundWords);</syntaxhighlight> |
||
Alternatively... |
Alternatively... |
||
< |
<syntaxhighlight lang=diego>add_ary({str},foundWords); |
||
with_file() |
with_file() |
||
()_read⟦{raw},unixdict.txt⟧_splitto(words,⟦\n⟧) |
()_read⟦{raw},unixdict.txt⟧_splitto(words,⟦\n⟧) |
||
Line 1,197: | Line 1,197: | ||
; |
; |
||
; |
; |
||
log_console()_(foundWords);</ |
log_console()_(foundWords);</syntaxhighlight> |
||
Output: |
Output: |
||
Line 1,203: | Line 1,203: | ||
=={{header|Draco}}== |
=={{header|Draco}}== |
||
< |
<syntaxhighlight lang=draco>\util.g |
||
proc nonrec abc_word(*char line) bool: |
proc nonrec abc_word(*char line) bool: |
||
Line 1,227: | Line 1,227: | ||
close(dict) |
close(dict) |
||
corp</ |
corp</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex;'>aback |
<pre style='height:50ex;'>aback |
||
Line 1,286: | Line 1,286: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang=factor>USING: grouping io.encodings.ascii io.files kernel prettyprint |
||
sequences sets ; |
sequences sets ; |
||
"unixdict.txt" ascii file-lines |
"unixdict.txt" ascii file-lines |
||
[ "abc" within members "abc" = ] filter |
[ "abc" within members "abc" = ] filter |
||
5 group simple-table.</ |
5 group simple-table.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,309: | Line 1,309: | ||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
{{works with|Gforth}} |
{{works with|Gforth}} |
||
< |
<syntaxhighlight lang=forth>: abc-word? ( addr u -- ? ) |
||
false false { a b } |
false false { a b } |
||
0 do |
0 do |
||
Line 1,341: | Line 1,341: | ||
main |
main |
||
bye</ |
bye</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,403: | Line 1,403: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang=freebasic> |
||
#define NOTINSTRING 9999 |
#define NOTINSTRING 9999 |
||
Line 1,432: | Line 1,432: | ||
end if |
end if |
||
wend |
wend |
||
close #1</ |
close #1</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,492: | Line 1,492: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang=go>package main |
||
import ( |
import ( |
||
Line 1,519: | Line 1,519: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,582: | Line 1,582: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang=haskell>import Data.List (elemIndex) |
||
import Data.Maybe (isJust) |
import Data.Maybe (isJust) |
||
Line 1,607: | Line 1,607: | ||
main = |
main = |
||
readFile "unixdict.txt" |
readFile "unixdict.txt" |
||
>>= mapM_ print . zip [1 ..] . filter isABC . lines</ |
>>= mapM_ print . zip [1 ..] . filter isABC . lines</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>(1,"aback") |
<pre>(1,"aback") |
||
Line 1,666: | Line 1,666: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang=java>import java.io.BufferedReader; |
||
import java.io.FileReader; |
import java.io.FileReader; |
||
Line 1,729: | Line 1,729: | ||
return false; |
return false; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,768: | Line 1,768: | ||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
< |
<syntaxhighlight lang=javascript>(() => { |
||
"use strict"; |
"use strict"; |
||
Line 1,862: | Line 1,862: | ||
// MAIN --- |
// MAIN --- |
||
return main(); |
return main(); |
||
})();</ |
})();</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>(1, aback) |
<pre>(1, aback) |
||
Line 1,921: | Line 1,921: | ||
=={{header|J}}== |
=={{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'.)< |
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 |
aback |
||
abacus |
abacus |
||
Line 1,976: | Line 1,976: | ||
syllabic |
syllabic |
||
tabernacle |
tabernacle |
||
tablecloth</ |
tablecloth</syntaxhighlight> |
||
=={{header|jq}}== |
=={{header|jq}}== |
||
{{works with|jq}} |
{{works with|jq}} |
||
'''Works with gojq, the Go implementation of jq''' |
'''Works with gojq, the Go implementation of jq''' |
||
< |
<syntaxhighlight lang=jq>def is_abc_word: |
||
[index("a", "b", "c")] |
[index("a", "b", "c")] |
||
| all(.[]; . != null) and .[0] < .[1] and .[1] < .[2] ; |
| all(.[]; . != null) and .[0] < .[1] and .[1] < .[2] ; |
||
select(is_abc_word)</ |
select(is_abc_word)</syntaxhighlight> |
||
Invocation: jq -rR -f abc-words.jq unixdict.txt |
Invocation: jq -rR -f abc-words.jq unixdict.txt |
||
{{out}} (synopsis) |
{{out}} (synopsis) |
||
Line 2,000: | Line 2,000: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
See [[Alternade_words#Julia]] for the foreachword function. |
See [[Alternade_words#Julia]] for the foreachword function. |
||
< |
<syntaxhighlight lang=julia>function isabcword(w, _) |
||
positions = [findfirst(c -> c == ch, w) for ch in "abc"] |
positions = [findfirst(c -> c == ch, w) for ch in "abc"] |
||
return all(!isnothing, positions) && issorted(positions) ? w : "" |
return all(!isnothing, positions) && issorted(positions) ? w : "" |
||
Line 2,006: | Line 2,006: | ||
foreachword("unixdict.txt", isabcword) |
foreachword("unixdict.txt", isabcword) |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
Word source: unixdict.txt |
Word source: unixdict.txt |
||
Line 2,023: | Line 2,023: | ||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
< |
<syntaxhighlight lang=Lua>for word in io.lines('unixdict.txt') do |
||
if string.find(word, "^[^bc]*a[^c]*b.*c") then |
if string.find(word, "^[^bc]*a[^c]*b.*c") then |
||
print(word) |
print(word) |
||
end |
end |
||
end</ |
end</syntaxhighlight> |
||
=={{header|Modula-2}}== |
=={{header|Modula-2}}== |
||
< |
<syntaxhighlight lang=modula2>MODULE ABCWords; |
||
IMPORT SeqIO; |
IMPORT SeqIO; |
||
IMPORT Texts; |
IMPORT Texts; |
||
Line 2,070: | Line 2,070: | ||
ts := Texts.Disconnect(dict); |
ts := Texts.Disconnect(dict); |
||
fs := SeqIO.Close(file); |
fs := SeqIO.Close(file); |
||
END ABCWords.</ |
END ABCWords.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex;'>aback |
<pre style='height:50ex;'>aback |
||
Line 2,129: | Line 2,129: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang=Nim>import strutils |
||
func isAbcWord(word: string): bool = |
func isAbcWord(word: string): bool = |
||
Line 2,144: | Line 2,144: | ||
if word.isAbcWord: |
if word.isAbcWord: |
||
inc count |
inc count |
||
echo ($count).align(2), ' ', word</ |
echo ($count).align(2), ' ', word</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,205: | Line 2,205: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
Outputs same 55 words everyone else finds. |
Outputs same 55 words everyone else finds. |
||
< |
<syntaxhighlight lang=perl>#!/usr/bin/perl |
||
@ARGV = 'unixdict.txt'; |
@ARGV = 'unixdict.txt'; |
||
print grep /^[^bc]*a[^c]*b.*c/, <>;</ |
print grep /^[^bc]*a[^c]*b.*c/, <>;</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang=Phix>(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<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> |
<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 2,219: | Line 2,219: | ||
<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: #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> |
<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> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,226: | Line 2,226: | ||
=={{header|PL/I}}== |
=={{header|PL/I}}== |
||
< |
<syntaxhighlight lang=pli>abcWords: procedure options(main); |
||
declare dict file; |
declare dict file; |
||
open file(dict) title('unixdict.txt'); |
open file(dict) title('unixdict.txt'); |
||
Line 2,250: | Line 2,250: | ||
end; |
end; |
||
end; |
end; |
||
end abcWords;</ |
end abcWords;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>aback abacus abc abdicate abduct |
<pre>aback abacus abc abdicate abduct |
||
Line 2,265: | Line 2,265: | ||
=={{header|Processing}}== |
=={{header|Processing}}== |
||
< |
<syntaxhighlight lang=processing>String[] words; |
||
void setup() { |
void setup() { |
||
Line 2,283: | Line 2,283: | ||
} |
} |
||
return false; |
return false; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>1 aback |
<pre>1 aback |
||
Line 2,344: | Line 2,344: | ||
Outputs the same 55 words as other examples when entered in a Posix terminal shell |
Outputs the same 55 words as other examples when entered in a Posix terminal shell |
||
< |
<syntaxhighlight lang=python>python -c ' |
||
import sys |
import sys |
||
for ln in sys.stdin: |
for ln in sys.stdin: |
||
Line 2,350: | Line 2,350: | ||
print(ln.rstrip()) |
print(ln.rstrip()) |
||
' < unixdict.txt |
' < unixdict.txt |
||
</syntaxhighlight> |
|||
</lang> |
|||
Or a functionally composed variant, with a predicate which takes a single recursive pass through the characters of each word: |
Or a functionally composed variant, with a predicate which takes a single recursive pass through the characters of each word: |
||
< |
<syntaxhighlight lang=python>'''ABC Words''' |
||
Line 2,430: | Line 2,430: | ||
# MAIN --- |
# MAIN --- |
||
if __name__ == '__main__': |
if __name__ == '__main__': |
||
main()</ |
main()</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>(1, 'aback') |
<pre>(1, 'aback') |
||
Line 2,490: | Line 2,490: | ||
Or using a regular expression. |
Or using a regular expression. |
||
< |
<syntaxhighlight lang=python>import re |
||
import textwrap |
import textwrap |
||
Line 2,499: | Line 2,499: | ||
print(f"found {len(abc_words)} ABC words") |
print(f"found {len(abc_words)} ABC words") |
||
print(textwrap.fill(" ".join(abc_words)))</ |
print(textwrap.fill(" ".join(abc_words)))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,516: | Line 2,516: | ||
=={{header|Quackery}}== |
=={{header|Quackery}}== |
||
< |
<syntaxhighlight lang=Quackery> [ true swap |
||
behead swap |
behead swap |
||
witheach |
witheach |
||
Line 2,538: | Line 2,538: | ||
else drop ] |
else drop ] |
||
dup size echo say " words found." cr |
dup size echo say " words found." cr |
||
70 wrap$</ |
70 wrap$</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,556: | Line 2,556: | ||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang=racket>#lang racket |
||
(for ((i (in-naturals 1)) |
(for ((i (in-naturals 1)) |
||
(w (filter (curry regexp-match #rx"^[^bc]*a[^c]*b.*c.*$") |
(w (filter (curry regexp-match #rx"^[^bc]*a[^c]*b.*c.*$") |
||
(file->lines "../../data/unixdict.txt")))) |
(file->lines "../../data/unixdict.txt")))) |
||
(printf "~a\t~a~%" i w))</ |
(printf "~a\t~a~%" i w))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,587: | Line 2,587: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
< |
<syntaxhighlight lang=perl6>put display 'unixdict.txt'.IO.words».fc.grep({ (.index('a')//next) < (.index('b')//next) < (.index('c')//next) }), |
||
:11cols, :fmt('%-12s'); |
:11cols, :fmt('%-12s'); |
||
Line 2,593: | Line 2,593: | ||
cache $list; |
cache $list; |
||
$title ~ $list.batch($cols)».fmt($fmt).join: "\n" |
$title ~ $list.batch($cols)».fmt($fmt).join: "\n" |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>55 matching: |
<pre>55 matching: |
||
Line 2,607: | Line 2,607: | ||
It also allows the (ABC) characters to be specified on the command line (CL) as well as the dictionary file identifier. |
It also allows the (ABC) characters to be specified on the command line (CL) as well as the dictionary file identifier. |
||
< |
<syntaxhighlight lang=rexx>/*REXX program finds all the caseless alternade words (within an identified dictionary).*/ |
||
parse arg minL iFID . /*obtain optional arguments from the CL*/ |
parse arg minL iFID . /*obtain optional arguments from the CL*/ |
||
if minL=='' | minL=="," then minL= 6 /*Not specified? Then use the default.*/ |
if minL=='' | minL=="," then minL= 6 /*Not specified? Then use the default.*/ |
||
Line 2,633: | Line 2,633: | ||
end /*j*/ |
end /*j*/ |
||
/*stick a fork in it, we're all done. */ |
/*stick a fork in it, we're all done. */ |
||
say copies('─',30) finds ' alternade words found with a minimum length of ' minL</ |
say copies('─',30) finds ' alternade words found with a minimum length of ' minL</syntaxhighlight> |
||
{{out|output|text= when using the default input:}} |
{{out|output|text= when using the default input:}} |
||
<pre> |
<pre> |
||
Line 2,704: | Line 2,704: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang=ring> |
||
cStr = read("unixdict.txt") |
cStr = read("unixdict.txt") |
||
wordList = str2list(cStr) |
wordList = str2list(cStr) |
||
Line 2,722: | Line 2,722: | ||
ok |
ok |
||
next |
next |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 2,785: | Line 2,785: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
translation from Perl |
translation from Perl |
||
< |
<syntaxhighlight lang=ruby>puts File.open("unixdict.txt").grep(/^[^bc]*a[^c]*b.*c/) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}}Same 55 words: |
{{out}}Same 55 words: |
||
<pre>aback |
<pre>aback |
||
Line 2,810: | Line 2,810: | ||
=={{header|Swift}}== |
=={{header|Swift}}== |
||
< |
<syntaxhighlight lang=swift>import Foundation |
||
func loadDictionary(_ path: String) throws -> [String] { |
func loadDictionary(_ path: String) throws -> [String] { |
||
Line 2,853: | Line 2,853: | ||
} catch { |
} catch { |
||
print(error) |
print(error) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,915: | Line 2,915: | ||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
< |
<syntaxhighlight lang=tcl>proc is_abc_word word { |
||
regexp {^[^bc]*a[^c]*b.*c} $word |
regexp {^[^bc]*a[^c]*b.*c} $word |
||
} |
} |
||
Line 2,924: | Line 2,924: | ||
puts "Found [llength $res] words:" |
puts "Found [llength $res] words:" |
||
puts [join $res \n]</ |
puts [join $res \n]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>$ tclsh abc_words.tcl |
<pre>$ tclsh abc_words.tcl |
||
Line 2,985: | Line 2,985: | ||
=={{header|Transd}}== |
=={{header|Transd}}== |
||
< |
<syntaxhighlight lang=scheme>#lang transd |
||
MainModule : { |
MainModule : { |
||
Line 2,994: | Line 2,994: | ||
(if (match w "^[^bc]*a[^c]*b.*c.*") (lout w)))) |
(if (match w "^[^bc]*a[^c]*b.*c.*") (lout w)))) |
||
) |
) |
||
}</ |
}</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
aback |
aback |
||
Line 3,006: | Line 3,006: | ||
=={{header|Vlang}}== |
=={{header|Vlang}}== |
||
< |
<syntaxhighlight lang=vlang>import os |
||
fn main() { |
fn main() { |
||
Line 3,019: | Line 3,019: | ||
println(text) |
println(text) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 3,082: | Line 3,082: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
< |
<syntaxhighlight lang=ecmascript>import "io" for File |
||
import "/fmt" for Fmt |
import "/fmt" for Fmt |
||
Line 3,097: | Line 3,097: | ||
Fmt.print("$2d: $s", count, word) |
Fmt.print("$2d: $s", count, word) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,160: | Line 3,160: | ||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang=XPL0>string 0; \use zero-terminated strings |
||
int I, J, K, Ch, Len; |
int I, J, K, Ch, Len; |
||
char Word(100); \(longest word in unixdict.txt is 22 chars) |
char Word(100); \(longest word in unixdict.txt is 22 chars) |
||
Line 3,189: | Line 3,189: | ||
]; |
]; |
||
until Ch = EOF; |
until Ch = EOF; |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |