Autogram checker: Difference between revisions

Content added Content deleted
(Still more of the apparent task requirements given that "incorrect" classification.)
(J: adjust for {{incorrect|J|punctuation count is wrong in 7 (but right for 3)}})
Line 62: Line 62:


=={{header|J}}==
=={{header|J}}==
{{incorrect|J|punctuation count is wrong in 7 (but right for 3)}}
The task asks us for a rough check, so we rely on normalization to implement the stable core of the algorithm. Also, we use <tt>us</tt> and <tt>uk</tt> from [[Number_names#J|the Number names task]] and explicitly support autograms with character counts higher than 99 (though of course none appear in the task examples).
The task asks us for a rough check, so we rely on normalization to implement the stable core of the algorithm. Also, we use <tt>us</tt> and <tt>uk</tt> from [[Number_names#J|the Number names task]] and explicitly support autograms with character counts higher than 99 (though of course none appear in the task examples).


Line 78: Line 77:
ukgrams=: letters (uk@],' ',[)each counts
ukgrams=: letters (uk@],' ',[)each counts
*/(+./@E.&normalize&y every usgrams) +. +./@E.&normalize&y every ukgrams
*/(+./@E.&normalize&y every usgrams) +. +./@E.&normalize&y every ukgrams
}}

normalizep=: tolower@#~ e.&(''',-!') +. tolower~:toupper
normalizep2=: rplc&('apostrophe';'''';'comma';',';'hyphen';'-';'exclamation point';'!')

autogramp=: {{
y=. normalizep y
counts=: #/.~ y
letters=: counts (], '''s'#~1<[)each~.y
usgrams=: letters (us@],' ',[)each counts
ukgrams=: letters (uk@],' ',[)each counts
grams=: (, rplc&('''s';'s')L:0) usgrams,:ukgrams
grams=: (, }.@rplc&('Zone';'Zsingle')@('Z'&,)L:0) grams
*/+./+./@E.&(normalizep2 Y) every grams
}}</lang>
}}</lang>


Line 86: Line 99:
autogram {{)n Only the fool would take trouble to verify that his sentence was composed of ten a's, three b's, four c's, four d's, forty-six e's, sixteen f's, four g's, thirteen h's, fifteen i's, two k's, nine l's, four m's, twenty-five n's, twenty-four o's, five p's, sixteen r's, forty-one s's, thirty-seven t's, ten u's, eight v's, eight w's, four x's, eleven y's, twenty-seven commas, twenty-three apostrophes, seven hyphens and, last but not least, a single !}}
autogram {{)n Only the fool would take trouble to verify that his sentence was composed of ten a's, three b's, four c's, four d's, forty-six e's, sixteen f's, four g's, thirteen h's, fifteen i's, two k's, nine l's, four m's, twenty-five n's, twenty-four o's, five p's, sixteen r's, forty-one s's, thirty-seven t's, ten u's, eight v's, eight w's, four x's, eleven y's, twenty-seven commas, twenty-three apostrophes, seven hyphens and, last but not least, a single !}}
1
1
autogram {{)n This pangram contains four as, one b, two cs, one d, thirty es, six fs, five gs, seven hs, eleven is, one j, one k, two ls, two ms, eighteen ns, fifteen os, two ps, one q, five rs, twenty-seven ss, eighteen ts, two us, seven vs, eight ws, two xs, three ys, & one z.}}
autogramp {{)n This pangram contains four as, one b, two cs, one d, thirty es, six fs, five gs, seven hs, eleven is, one j, one k, two ls, two ms, eighteen ns, fifteen os, two ps, one q, five rs, twenty-seven ss, eighteen ts, two us, seven vs, eight ws, two xs, three ys, & one z.}}
0
1
autogram {{)n This sentence contains one hundred and ninety-seven letters: four a's, one b, three c's, five d's, thirty-four e's, seven f's, one g, six h's, twelve i's, three l's, twenty-six n's, ten o's, ten r's, twenty-nine s's, nineteen t's, six u's, seven v's, four w's, four x's, five y's, and one z.}}
autogram {{)n This sentence contains one hundred and ninety-seven letters: four a's, one b, three c's, five d's, thirty-four e's, seven f's, one g, six h's, twelve i's, three l's, twenty-six n's, ten o's, ten r's, twenty-nine s's, nineteen t's, six u's, seven v's, four w's, four x's, five y's, and one z.}}
1
1
autogram {{)n Thirteen e's, five f's, two g's, five h's, eight i's, two l's, three n's, six o's, six r's, twenty s's, twelve t's, three u's, four v's, six w's, four x's, two y's.}}
autogram {{)n Thirteen e's, five f's, two g's, five h's, eight i's, two l's, three n's, six o's, six r's, twenty s's, twelve t's, three u's, four v's, six w's, four x's, two y's.}}
1
1
autogram {{)n Fifteen e's, seven f's, four g's, six h's, eight i's, four n's, five o's, six r's, eighteen s's, eight t's, four u's, three v's, two w's, three x's.}}
autogramp {{)n Fifteen e's, seven f's, four g's, six h's, eight i's, four n's, five o's, six r's, eighteen s's, eight t's, four u's, three v's, two w's, three x's.}}
0
1
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.}}
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</lang>
0</lang>