Find words with alternating vowels and consonants: Difference between revisions
Find words with alternating vowels and consonants (view source)
Revision as of 13:06, 27 August 2022
, 1 year agosyntax highlighting fixup automation
(J) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 14:
{{trans|Nim}}
<
V count = 0
Line 30:
count++
print(word.rjust(14), end' I count % 7 == 0 {"\n"} E ‘ ’)
print()</
{{out}}
Line 48:
=={{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.
<
IF c='a OR c='e OR c='i OR c='o OR c='u THEN
RETURN (1)
Line 97:
FindWords(fname)
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Find_words_with_alternating_vowels_and_consonants.png Screenshot from Atari 8-bit computer]
Line 112:
=={{header|Ada}}==
<
with Ada.Strings.Fixed;
Line 144:
end loop;
Close (File);
end Find_Alternating;</
=={{header|ALGOL 68}}==
<
# consonants #
IF FILE input file;
Line 203:
close( input file );
print( ( newline, whole( alternating count, 0 ), " words of alternating vowels and consonants found", newline ) )
FI</
{{out}}
<pre>
Line 225:
The handler here is case- and diacritical-insensitive and has an option to treat "y" as a vowel. With the text file located on the computer's startup disk, it performs the set task in just under a third of a second on my machine, which is probably good enough for such a silly task.
<
With AppleScript's text item delimiters set to all the vowels, the 'text items' of a word with alternating
vowels and consonants are single-character strings (the consonants), with the possibility of an empty
Line 267:
local theText
set theText to (read file ((path to desktop as text) & "unixdict.txt") as «class utf8»)
findWordsWithAlternatingVowelsAndConsonants from theText without yAsVowel given minLength:10</
{{output}}
<
Or if you want to treat "y" as a vowel:
<
local theText
set theText to (read file ((path to desktop as text) & "unixdict.txt") as «class utf8»)
findWordsWithAlternatingVowelsAndConsonants from theText with yAsVowel given minLength:10</
{{output}}
<
===Functional===
Listing 'alternating' words for both '''{a,e,i,o,u}''' and '''{a,e,i,o,u,y}''' interpretations of 'vowel':
<
use framework "Foundation"
use scripting additions
Line 613:
set my text item delimiters to dlm
return s
end unwords</
{{Out}}
<pre>Assuming aeiou – 67 matches:
Line 666:
=={{header|Arturo}}==
<
vowels: [`a` `e` `i` `o` `u`]
alternatingVC?: function [w][
Line 685:
print word
]
]</
{{out}}
Line 758:
=={{header|AutoHotkey}}==
<
vowels := {"a":1, "e":1, "i":1, "o":1, "u":1}, c := 0
Line 781:
}
MsgBox, 262144, , % result
return</
{{out}}
<pre>aboriginal apologetic bimolecular borosilicate calorimeter capacitate capacitive capitoline capitulate
Line 793:
=={{header|AWK}}==
<
{
# have an appropriate length word
Line 815:
{
printf( "\n%d words with alternating vowels and consonants found\n", alternatingCount );
} # END</
{{out}}
<pre>
Line 834:
=={{header|C}}==
<
#include <stdio.h>
#include <stdlib.h>
Line 877:
fclose(fp);
return EXIT_SUCCESS;
}</
{{out}}
Line 951:
=={{header|C++}}==
<
#include <fstream>
#include <iomanip>
Line 990:
}
return EXIT_SUCCESS;
}</
{{out}}
Line 1,064:
=={{header|F_Sharp|F#}}==
<
// Find words with alternating vowels and consonants. Nigel Galloway: January 20th., 2020
let vowels=set['a';'e';'i';'o';'u']
Line 1,071:
seq{use n=System.IO.File.OpenText("unixdict.txt") in while not n.EndOfStream do yield n.ReadLine()}
|>Seq.filter(fun g->g.Length>9 && fN g)|>Seq.iter(printfn "%s")
</syntaxhighlight>
{{out}}
<pre>
Line 1,145:
<code>group-by</code> is used to group words by vowels and consonants. For example, <code>"hello" [ "aeiou" member? ] group-by</code> produces a sequence like <code>{ 'h' 'e' 'll' 'o' }</code>. The number of elements in this grouping is the same as the length of the original word if and only if it has alternating vowels and consonants.
{{works with|Factor|0.99 2020-08-14}}
<
prettyprint sequences ;
"unixdict.txt" ascii file-lines
[ length 9 > ] filter
[ dup [ "aeiou" member? ] group-by [ length ] same? ] filter .</
{{out}}
<pre style="height:20em">
Line 1,226:
=={{header|Forth}}==
{{works with|Gforth}}
<
case
'a' of true endof
Line 1,263:
main
bye</
{{out}}
Line 1,337:
=={{header|FreeBASIC}}==
<
dim as boolean v = false, lv = false
dim as integer i, n, a=0
Line 1,362:
if a mod 10 = 0 then print
wend
close #1</
{{out}}<pre>
aboriginal apologetic bimolecular borosilicate calorimeter capacitate capacitive capitoline capitulate caricature
Line 1,373:
</pre>
=={{header|Go}}==
<
import (
Line 1,424:
}
}
}</
{{out}}
Line 1,500:
=={{header|Haskell}}==
<
import Data.Bifunctor (bimap)
import Data.List.Split (chunksOf)
Line 1,536:
justifyLeft :: Int -> Char -> String -> String
justifyLeft n c s = take n (s <> replicate n c)</
{{Out}}
<pre>67 matching words:
Line 1,560:
=={{header|J}}==
We're looking for words which have more than 9 letters and where any adjacent pair of letters has both a vowel and a consonant.
<
aboriginal
apologetic
Line 1,627:
unimodular
uninominal
verisimilitude</
=={{header|JavaScript}}==
As a standard for an embedded language which may have no access to a file-system,
Line 1,635:
macOS osascript instance of a JSContext.
<
'use strict';
Line 1,813:
// MAIN ---
return main();
})();</
{{Out}}
<pre>67 matches:
Line 1,838:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<
# output: if the $parity elements are all in $array then true, else false
def check($parity; $array):
Line 1,858:
| $word ;
alternating</
{{out}}
Invocation example: jq -nrR -f program.jq unixdict.txt
Line 1,933:
=={{header|Julia}}==
See [[Alternade_words#Julia]] for the foreachword function.
<
onlyodds(f, s) = all(c -> f(c), s[1:2:length(s)]) && !any(c -> f(c), s[2:2:length(s)])
onlyevens(f, s) = !any(c -> f(c), s[1:2:length(s)]) && all(c -> f(c), s[2:2:length(s)])
Line 1,939:
foreachword("unixdict.txt", eitheronlyvowels, minlen = 10)
</
<pre>
Word source: unixdict.txt
Line 1,958:
=={{header|Ksh}}==
<
#!/bin/ksh
Line 2,002:
(( $? )) && print "$REPLY"
done < ${dict}
</syntaxhighlight>
{{out}}<pre>
aboriginal
Line 2,073:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
consonants = DeleteCases[Alphabet[], Alternatives @@ vowels];
dict = Once[Import["https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt"]];
Line 2,083:
Characters[StringTake[#, {2, -1, 2}]]]) || (ContainsAll[
consonants, Characters[StringTake[#, {1, -1, 2}]]] &&
ContainsAll[vowels, Characters[StringTake[#, {2, -1, 2}]]]) &]</
{{out}}
<pre>{aboriginal, apologetic, bimolecular, borosilicate, calorimeter, capacitate, capacitive, capitoline, capitulate, caricature, colatitude, coloratura, colorimeter, debilitate, decelerate, decolonize, definitive, degenerate, deliberate, demodulate, denominate, denotative, deregulate, desiderata, desideratum, dilapidate, diminutive, epigenetic, facilitate, hemosiderin, heretofore, hexadecimal, homogenate, inoperative, judicature, latitudinal, legitimate, lepidolite, literature, locomotive, manipulate, metabolite, nicotinamide, oratorical, paragonite, pejorative, peridotite, peripatetic, polarimeter, recitative, recuperate, rehabilitate, rejuvenate, remunerate, repetitive, reticulate, savonarola, similitude, solicitude, tananarive, telekinesis, teratogenic, topologize, unilateral, unimodular, uninominal, verisimilitude}</pre>
=={{header|Nim}}==
<
const Vowels = {'a', 'e', 'i', 'o', 'u'}
Line 2,103:
inc count
stdout.write word.align(14), if count mod 7 == 0: '\n' else: ' '
echo()</
{{out}}
Line 2,121:
Used [https://metacpan.org/pod/App::a2p a2p].
{{trans|AWK}}
<
use strict;
Line 2,146:
}
printf "\n%d words with alternating vowels and consonants found\n", $alternatingCount;</
{{out}}
<pre>
Line 2,165:
=== Regex solution ===
I've heard rumors that there are more than 5 vowels...
<
$v = qr/[$vowels]/;
$c = qr/[^$vowels]/;
/^ ( ($c$v)+ $c? | ($v$c)+ $v? ) $/ix and say for grep { /.{10}/ } split "\n", do { (@ARGV, $/) = 'unixdict.txt'; <> };</
{{out}}
<pre>aboriginal
Line 2,178:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">vowel</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ch</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"aeiou"</span><span style="color: #0000FF;">)!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
Line 2,189:
<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;">oddeven</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 avac 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>
<!--</
{{out}}
<pre>
Line 2,196:
=={{header|Plain English}}==
<
Start up.
Put "c:\unixdict.txt" into a path.
Line 2,226:
If the string's last's target is any consonant, set another flag.
If the flag is the other flag, say yes.
Say no.</
{{out}}
<pre style="height:20em">
Line 2,300:
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<
open("unixdict.txt", read, Stream),
main(Stream, 0),
Line 2,332:
alternating_vowels_and_consonants([Ch1, Ch2|Chars]):-
(vowel(Ch1) -> \+vowel(Ch2) ; vowel(Ch2)),
alternating_vowels_and_consonants([Ch2|Chars]).</
{{out}}
Line 2,406:
=={{header|Python}}==
<
Line 2,472:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre>67 matching words:
Line 2,496:
=={{header|Quackery}}==
<syntaxhighlight lang="quackery">
[ [] swap ]'[ swap
witheach
Line 2,560:
drop nest$
filter allcriteria
80 wrap$</
{{out}}
Line 2,583:
Here's a bit of variety; the match-lambda for the regex version could also be simplified to regexp-match.
<
(define alternating?/re
Line 2,644:
(check-equal? words/re words/fold)
(check-equal? words/re words/loop)
(check-equal? words/re words/letrec))</
{{out}}
Line 2,653:
Sigh. Yet another "Filter a word list" task. In a effort to make it a ''little'' more interesting, rather than just doing a one-liner, build a grammar and use that to filter.
<syntaxhighlight lang="raku"
token TOP { <|w> <vowel>? ( <consonant> <vowel> )* <consonant>? <|w> }
token vowel { <[aeiou]> }
Line 2,659:
}
say ( grep { VOWCON.parse: .lc }, grep { .chars > 9 }, 'unixdict.txt'.IO.words ).batch(6)».fmt('%-15s').join: "\n";</
{{out}}
<pre>aboriginal apologetic bimolecular borosilicate calorimeter capacitate
Line 2,675:
=={{header|REXX}}==
<
/*──────────────────────────────────────── either have odd letters that are vowels, and */
/*──────────────────────────────────────── even letters that consonants, or vice versa.*/
Line 2,726:
end /*out*/
/*stick a fork in it, we're all done. */
if _\=='' then say substr(_, 2) /*Any residual words? Then show a line*/</
{{out|output|text= when using the default inputs:}}
<pre>
Line 2,744:
=={{header|Ring}}==
<
cStr = read("unixdict.txt")
wordList = str2list(cStr)
Line 2,828:
see "done..." + nl
</syntaxhighlight>
Output:
<pre>
Line 2,907:
=={{header|Ruby}}==
<
res = File.open("unixdict.txt").each_line.select do |line|
Line 2,913:
word.size > 9 && word.chars.each_cons(2).all?{|c1, c2| VOWELS.include?(c1) != VOWELS.include?(c2) }
end
puts res</
{{out}}
<pre style="height:30em">
Line 2,986:
=={{header|Seed7}}==
<
const func boolean: vowel (in char: letter) is
Line 3,031:
close(dictionary);
end if;
end func;</
{{out}}
<pre style="height:36em">
Line 3,104:
=={{header|Swift}}==
<
func isVowel(_ char: Character) -> Bool {
Line 3,127:
} catch {
print(error.localizedDescription)
}</
{{out}}
Line 3,202:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<
import "/fmt" for Fmt
Line 3,234:
Fmt.print("$2d: $s", count, word)
}
}</
{{out}}
Line 3,310:
=={{header|XPL0}}==
<
int Cnt, I, Ch, Len;
char Word(100); \(longest word in unixdict.txt is 22 chars)
Line 3,349:
];
until Ch = EOF;
]</
{{out}}
|