I'm not sure how I'd count this, as it does the printing, also.
#!/usr/bin/perl -l $_ = shift; print"$_ is",(grep$_>1,map++$c{$_},split//)?"n't":'',' an isogram';
Output:
$ perl isogram.pl greet greet isn't an isogram $ perl isogram.pl isogram isogram is an isogram $ perl isogram.pl discrete discrete isn't an isogram
Update: I wouldn't count it, as /(.).*\1/ is much shorter.
Update 2 I'd still count it as the shortest of the non-regex versions. And here it is as a sub for easier counting:
sub is_iso { (grep$_>1,map++$c{$_},split//,shift)?1:0 } $_ = shift; print "$_ is", ( is_iso($_)? "n't" : '' ), ' an isogram';
s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
In reply to Re: testing number of occurrences in a word
by chargrill
in thread testing number of occurrences in a word
by jsmith
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |