in reply to testing number of occurrences in a word

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';


--chargrill
s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)

Replies are listed 'Best First'.
Re^2: testing number of occurrences in a word
by Not_a_Number (Prior) on Sep 20, 2006 at 11:54 UTC

    You can shorten that further:

    sub is_iso { grep$_>1,map++$c{$_},split// }
    12 fewer strokes :)