Autogram checker: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|Perl}}: various simplifications)
m (syntax highlighting fixup automation)
Line 66:
In other words, we explicitly ignore details which were not specified in the task description as requirements of all autograms.
 
Implementation: <langsyntaxhighlight lang=J>NB. requires uk and us from rosettacode Number_names#J
normalize=: {{ tolower ' '(I.(tolower=toupper)y)}y }}
normalize=: tolower@#~ tolower~:toupper
Line 92:
grams=: (, }.@rplc&('Zone';'Zsingle')@('Z'&,)L:0) grams
*/+./+./@E.&(normalizep2 Y) every grams
}}</langsyntaxhighlight>
 
Task examples:<langsyntaxhighlight lang=j> autogram {{)n This sentence employs two a's, two c's, two d's, twenty-eight e's, five f's, three g's, eight h's, eleven i's, three l's, two m's, thirteen n's, nine o's, two p's, five r's, twenty-five s's, twenty-three t's, six v's, ten w's, two x's, five y's, and one z.}}
1
autogram {{)n This sentence employs two a's, two c's, two d's, twenty eight e's, five f's, three g's, eight h's, eleven i's, three l's, two m's, thirteen n's, nine o's, two p's, five r's, twenty five s's, twenty three t's, six v's, ten w's, two x's, five y's, and one z.}}
Line 109:
0
autogram {{)n Sixteen e's, five f's, three g's, six h's, nine i's, five n's, four o's, six r's, eighteen s's, eight t's, three u's, three v's, two w's, four z's.}}
0</langsyntaxhighlight>
 
As an aside, this illustrates that rosettacode's J syntax highlighter does not properly handle J's {{)n delimited character literals (a recent language feature, introduced in J903).
Line 115:
=={{header|Julia}}==
Validating the total letter count when used.
<langsyntaxhighlight lang=ruby>""" Rosetta Code task rosettacode.org/mw/index.php?title=Autogram_checker """
 
using DataStructures
Line 192:
println("Test phrase $i is", isautogram(t[1], t[2]) ? " " : " not ", "a valid autogram.\n")
end
</langsyntaxhighlight>{{out}}
<pre>
Test phrase 1 is a valid autogram.
Line 214:
 
=={{header|Perl}}==
<langsyntaxhighlight lang=perl>use v5.36;
use experimental <builtin for_list>;
use Sub::Util 'subname';
Line 278:
if $str =~ /(\d+) letters/;
say "\n" . '=' x 101;
}</langsyntaxhighlight>
{{out}}
<pre style="height:60ex">This sentence employs two a's, two c's, two d's, twenty-eight e's, five f's, three g's, eight h's,
Line 415:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">tests</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"""
Line 522:
<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;">"Autogram? %t%s\n\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">autogram</span><span style="color: #0000FF;">,</span><span style="color: #000000;">diff</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 560:
Using [https://raku.land/github:jkramer/Text::Wrap Text::Wrap] from the ecosystem. Install command: <code>zef install -v git://github.com/jkramer/p6-Text-Wrap.git</code>.
 
<langsyntaxhighlight lang=perl6>my %nums = :0zero, :1one, :2two, :3three, :4four, :5five, :6six, :7seven, :8eight, :9nine, :10ten, :11eleven,
:12twelve, :13thirteen, :14fourteen, :15fifteen, :16sixteen, :17seventeen, :18eighteen, :19nineteen,
:20twenty, :30thirty, :40forty, :50fifty, :60sixty, :70seventy, :80eighty, :90ninety, :100hundred, :1single;
Line 610:
 
say '=' x 100;
}</langsyntaxhighlight>
{{out}}
<pre style="height:50ex;overflow:scroll;">====================================================================================================
Line 738:
{{libheader|Wren-str}}
Frankly, not a bullet-proof solution but good enough to check the required sentences.
<langsyntaxhighlight lang=ecmascript>import "./str" for Str
 
var numbers = [
Line 854:
autogram.call(t[0], t[1])
System.print("=" * 80)
}</langsyntaxhighlight>
 
{{out}}
10,333

edits