Alternade words: Difference between revisions
m
syntax highlighting fixup automation
(Initial Haskell version.) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 25:
{{trans|Nim}}
<
V r = [‘’, ‘’]
L(c) word
Line 42:
L(line) result
V i = L.index
print((‘#2:’.format(i + 1))‘ ’line)</
{{out}}
Line 107:
=={{header|Ada}}==
<
with Ada.Containers.Indefinite_Ordered_Maps;
Line 166:
end;
end loop;
end Alternade_Words;</
{{out}}
<pre style="height: 45ex">accost acs cot
Line 229:
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
<
# use the associative array in the Associate array/iteration task #
PR read "aArray.a68" PR
Line 298:
OD
FI
</syntaxhighlight>
{{out}}
Note - the alternade words as output by this program are not sorted, the output shown here has been sorted for ease of comparison with the output of the other samples.
Line 365:
{{works with|Dyalog APL}}
<
⍺←6
parts←{(⊂k/⍵),⊂(~k←2|⍳≢⍵)/⍵}
Line 371:
long←(⍺≤≢¨words)/words
↑(⊂,parts)¨(∧/∘check∘parts¨long)/long
}</
{{out}}
Line 437:
=={{header|AppleScript}}==
<
Now takes the number of subwords per alternade as a parameter.
Extracted texts are validated against the words in the input list.
Line 539:
set wordList to words of (read wordFile as «class utf8»)
-- Return two-word alternades of 6 or more characters. Result in text form.
return alternades(wordList, 2, 6, text)</
{{output}}
Line 603:
Another example call:
<
return alternades(wordList, 3, 10, list)</
{{output}}
<
=={{header|Arturo}}==
<
loop words 'word [
Line 624:
if and? [contains? words alt1][contains? words alt2] ->
print [word "=>" alt1 alt2]
]</
{{out}}
Line 688:
=={{header|AutoHotkey}}==
<
words := [], sixWords := []
Line 709:
result .= w "`t-> " w1 " " w2 "`n"
}
MsgBox % result</
{{out}}
<pre style="height: 45ex">accost -> acs cot
Line 771:
=={{header|AWK}}==
<
# syntax: GAWK -f ALTERNADE_WORDS.AWK unixdict.txt
#
Line 801:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 866:
=={{header|C}}==
<
#include <string.h>
#include <stdlib.h>
Line 999:
scan_trie(root, check_alternade);
return 0;
}</
{{out}}
Line 1,064:
=={{header|C++}}==
<
#include <fstream>
#include <iomanip>
Line 1,100:
}
return EXIT_SUCCESS;
}</
{{out}}
Line 1,165:
=={{header|F_Sharp|F#}}==
<
// Alternade words: Nigel Galloway. June 10th., 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>2)|>List.ofSeq
Line 1,171:
let fG(n,g)=let fN g=(Array.ofList>>System.String) g in let n,g=fN n,fN g in if List.contains n dict && List.contains g dict then Some(n,g) else None
dict|>Seq.filter(fun n->n.Length>5)|>Seq.iter(fun n->match (fN>>fG) n with Some(g,l)->printfn "%s -> %s * %s" n g l |_->())
</syntaxhighlight>
{{out}}
<pre>
Line 1,234:
</pre>
=={{header|Factor}}==
<
math sequences sequences.extras sets strings ;
Line 1,251:
[ alternade? ] filter
[ length 5 > ] filter
[ dup subwords "%-8s %-4s %-4s\n" printf ] each</
{{out}}
<pre style="height: 45ex">
Line 1,315:
=={{header|FreeBASIC}}==
<
function is_in(word() as string, s as string) as boolean
Line 1,341:
next j
if is_in(word(), alt(0)) and is_in(word(), alt(1)) then print word(i), alt(1), alt(0)
next i</
{{out}}<pre>
accost acs cot
Line 1,404:
=={{header|Go}}==
<
import (
Line 1,449:
}
}
}</
{{out}}
Line 1,516:
=={{header|Haskell}}==
<
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
Line 1,535:
in T.unlines $ map alterShow $ alternades dict $ filter longEnough words'
where longEnough = (>= 6) . T.length
alterShow (w, (x, y)) = T.unwords [w, x, y]</
{{out}}
<pre>
Line 1,601:
=={{header|J}}==
<
alts=: <@deb"1@|:@(_2]\])@> ref=: (#~ 5<#@>) words
;:inv (ref,.alts) #~ alts */@e."1 words
Line 1,661:
troupe top rue
truant tun rat
twirly til wry</
=={{header|Java}}==
<
import java.util.*;
Line 1,698:
}
}
}</
{{out}}
Line 1,767:
Note: For gojq, change `keys_unsorted` to `keys`. The results are unaffected.
<syntaxhighlight lang=jq>
# if the input is an alternade word relative to the keys of $dict,
# then emit [$even, $odd], else false.
Line 1,784:
| (select(.) // empty)
| "\($w) → \(.[0]) \(.[1])"
</syntaxhighlight>
Invocation: jq -n -rR -f alternade-words.jq unixdict.txt
{{out}}
Line 1,849:
=={{header|Julia}}==
<
println("Word source: $wordfile\n")
words = split(read(wordfile, String), r"\s+")
Line 1,869:
foreachword("unixdict.txt", isalternade, minlen = 6, numcols=1)
</
<pre>
Word source: unixdict.txt
Line 1,934:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
dic = StringSplit[dic, "\n"];
largerthansix = Select[dic, StringLength /* GreaterEqualThan[6]];
Line 1,946:
]
all = DeleteCases[Table[AlternadeQ[w, smallerthansix], {w, largerthansix}], {}];
all // Column</
{{out}}
<pre>accost->{acs,cot}
Line 2,008:
=={{header|Nim}}==
<
proc alternatingWords(word: string): array[2, string] =
Line 2,024:
result.add word.align(8) & " → $1 $2" % altWords
result.sort()
for i, line in result: echo ($(i+1)).align(2), ": ", line</
{{out}}
Line 2,087:
=={{header|Perl}}==
<
use strict;
Line 2,099:
my $odd = s/.(.?)/$1/gr;
$words{$even} && $words{$odd} and print "$_ => [ $even $odd ]\n";
}</
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<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>
Line 2,128:
<span style="color: #7060A8;">pp</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;">"alternade words found"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">),{</span><span style="color: #004600;">pp_Nest</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
{{out}}
<pre>
Line 2,163:
=={{header|Picat}}==
{{works with|Picat}}
<
split_word(Word) = Words =>
N = len(Word),
Line 2,188:
end,
close(Reader).
</syntaxhighlight>
{{out}}
<pre style="height: 45ex">
Line 2,253:
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<
main:-
Line 2,293:
odd_even_chars([Ch], [Ch], []):-!.
odd_even_chars([Ch1, Ch2|Chars], [Ch1|Chars1], [Ch2|Chars2]):-
odd_even_chars(Chars, Chars1, Chars2).</
{{out}}
Line 2,359:
=={{header|Python}}==
<
MINLEN = 6
Line 2,424:
odd = word[1::2]
if even in words and odd in words:
print(word, even, odd)</
{{out}}
Line 2,489:
=={{header|Quackery}}==
<
protect sift.test
Line 2,524:
else [ drop 2drop ] ]
dict release</
{{out}}
Line 2,590:
A more straightforward approach:
<
[ $ "rosetta/unixdict.txt" sharefile
Line 2,610:
echo$ cr ]
else drop ]
else 2drop ]</
{{out}}
Line 2,675:
=={{header|Raku}}==
<
my %words = $file.IO.slurp.words.map: * => 1;
Line 2,694:
.say for @alternades > 10
?? (flat @alternades.head(5), '...', @alternades.tail(5))
!! @alternades;</
{{out}}
<pre>58 alternades longer than 5 characters found in unixdict.txt:
Line 2,715:
It also allows the minimum length to be specified on the command line (CL) as well as the dictionary file identifier.
<
parse arg minL iFID . /*obtain optional arguments from the CL*/
if minL=='' | minL=="," then minL= 6 /*Not specified? Then use the default.*/
Line 2,741:
end /*j*/
/*stick a fork in it, we're all done. */
say copies('─',30) finds ' alternade words found with a minimum length of ' minL</
{{out|output|text= when using the default inputs:}}
<pre>
Line 2,811:
Independently developed at the same time as version 1 :-)
<
fid='d:\unix.txt'
cnt.=0 /* cnt.n -> words of length n */
Line 2,851:
s.v=s.v||vv
End
Return s.u s.v</
Output:
<pre>D:\>rexx alternade
Line 2,920:
=={{header|Ring}}==
<
load "stdlib.ring"
Line 2,948:
next
see "done..." + nl
</syntaxhighlight>
Output:
<pre>
Line 3,189:
=={{header|Ruby}}==
<
res = words.filter_map do |word|
Line 3,199:
puts res
</syntaxhighlight>
{{out}}
<pre style="height: 30ex">accost: acs, cot
Line 3,262:
=={{header|Rust}}==
<
use std::fs::File;
use std::io::{self, BufRead};
Line 3,298:
Err(error) => eprintln!("{}", error),
}
}</
{{out}}
Line 3,363:
=={{header|Swift}}==
<
func loadDictionary(_ path: String) throws -> Set<String> {
Line 3,401:
} catch {
print(error.localizedDescription)
}</
{{out}}
Line 3,466:
=={{header|Tcl}}==
<
foreach word [read [open unixdict.txt]] {
dict set unixdict $word {}
Line 3,485:
puts "$word $oddeven"
}
}</
{{out}}
<pre>$ tclsh alternate_words.tcl | column -t
Line 3,549:
=={{header|Vlang}}==
{{trans|go}}
<
fn main() {
Line 3,580:
}
}
}</
{{out}}
<pre>Same as Go entry</pre>
Line 3,587:
{{libheader|Wren-set}}
{{libheader|Wren-fmt}}
<
import "/set" for Set
import "/fmt" for Fmt
Line 3,615:
}
}
}</
{{out}}
Line 3,682:
=={{header|XPL0}}==
<
int Dict(26000); \pointers to words (enough for unixdict.txt)
int DictSize; \actual number of pointers in Dict
Line 3,749:
DI:= DI+1;
until DI >= DictSize;
]</
{{out}}
|