Isograms and heterograms: Difference between revisions

m
syntax highlighting fixup automation
(Added Algol 68)
m (syntax highlighting fixup automation)
Line 41:
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68"># find some isograms ( words where each letter occurs the same number of #
# times as the others ) and heterograms ( words where each letter occurs #
# once ). Note a heterogram is an isogram of order 1 #
Line 183:
OD
FI
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 209:
=={{header|Factor}}==
{{works with|Factor|0.99 2022-04-03}}
<langsyntaxhighlight lang="factor">USING: assocs combinators.short-circuit.smart grouping io
io.encodings.ascii io.files kernel literals math math.order
math.statistics sequences sets sorting ;
Line 231:
 
"List of heterograms of length > 10:" print
[ { [ length 10 > ] [ all-unique? ] } && ] .words-by</langsyntaxhighlight>
{{out}}
<pre>
Line 308:
For this task, we want to know the value of n for n-isograms. This value would be zero for words which are not n-isograms. We can implement this by counting how many times each character occurs and determining whether that value is unique. (If it's the unique value, n is the number of times the first character occurs):
 
<langsyntaxhighlight Jlang="j">isogram=: {{ {. (#~ 1= #@~.) #/.~ y }} S:0</langsyntaxhighlight>
 
Also, it's worth noting that unixdict.txt is already in sorted order, even after coercing its contents to lower case:
 
<langsyntaxhighlight Jlang="j"> (-: /:~) cutLF tolower fread 'unixdict.txt'
1</langsyntaxhighlight>
 
With this tool and this knowledge, we are ready to tackle this task (the /: expression sorts, and the #~ expression selects):
 
<langsyntaxhighlight Jlang="j"> > (/: -@isogram,.-@#@>) (#~ 1<isogram) cutLF tolower fread 'unixdict.txt'
aaa
iii
Line 383:
thunderclap
valedictory
voluntarism </langsyntaxhighlight>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="ruby">function isogram(word)
wchars, uchars = collect(word), unique(collect(word))
ulen, wlen = length(uchars), length(wchars)
Line 406:
println("\nHeterogram Length\n", "-"^20)
foreach(t -> println(rpad(t[3], 12), lpad(t[2], 5)), heterograms)
</langsyntaxhighlight>{{out}}
<pre>
N-Isogram N Length
Line 481:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 503:
}
 
say scalar(@heterogram) . " heterograms with more than 10 characters:\n" . join "\n", sort { length $b <=> length $a } @heterogram;</langsyntaxhighlight>
{{out}}
<pre style="height:40ex">2 3-isograms:
Line 578:
 
=={{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;">isogram</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">word</span><span style="color: #0000FF;">)</span>
Line 597:
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sort_columns</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: #7060A8;">unix_dict</span><span style="color: #0000FF;">(),</span><span style="color: #000000;">isogram</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"!="</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">),{-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</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;">"word n length\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #008000;">'\n'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">:=</span><span style="color: #008000;">"%-14s %d %6d"</span><span style="color: #0000FF;">)})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 669:
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>my $file = 'unixdict.txt';
 
my @words = $file.IO.slurp.words.race.map: { $_ => .comb.Bag };
Line 682:
say "\n({+$_}) heterograms with more than $minchars characters:\n" ~
.sort({[-.chars, ~$_]}).join: "\n" given
@words.race.grep({.key.chars >$minchars && .value.values.max == 1})».key;</langsyntaxhighlight>
{{out}}
<pre>(2) 3-isograms:
Line 757:
=={{header|Wren}}==
{{libheader|Wren-str}}
<langsyntaxhighlight lang="ecmascript">import "io" for File
import "./str" for Str
 
Line 808:
.toList
System.print("\nList of heterograms(%(heterograms.count)) of length > 10:")
System.print(heterograms.join("\n"))</langsyntaxhighlight>
 
{{out}}
10,327

edits