Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: testing number of occurrences in a word

by talexb (Chancellor)
on Sep 19, 2006 at 14:14 UTC ( [id://573732]=note: print w/replies, xml ) Need Help??


in reply to testing number of occurrences in a word

Using the definition of an isogram from wikipedia, let's make it into a golf challenge. Anyone?

(The reasoning being, if it's golfed, it won't be acceptable as a homework solution.)

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

  • Comment on Re: testing number of occurrences in a word

Replies are listed 'Best First'.
Re^2: testing number of occurrences in a word
by grinder (Bishop) on Sep 19, 2006 at 15:05 UTC

    49, but then again I suck at golf.

    sub isogram { #234567890#234567890#234567890#234567890#234567890 my%h=map{($_,1)}split//,$_[0];keys%h==length$_[0] } print "$_ is ", (isogram($_) ? '' : 'not '), "an isogram\n" for @ARGV;

    Duh, johngg had the right idea, except he wasn't greedy enough (nor was I. What's with the $_[0]? Sheesh.):

    sub isogram { #23456789 /(.).*\1/ } print "$_ is ", (isogram() ? '' : 'not '), "an isogram\n" for @ARGV;

    That makes for 9.

    • another intruder with the mooring in the heart of the Perl

      Very nice, but your logic is reversed.  Remember, an isogram does NOT have any letters duplicated.

      To keep it golfed, either change the caller of the subroutine:

      print "$_ is ", (isogram() ? 'not ' : ''), "an isogram\n" for @ARGV;

      or, better yet, the subroutine name:

      sub not_isogram { # ... } print "$_ is ", (not_isogram() ? '': 'not '), "an isogram\n" for @ARGV +;

      s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://573732]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-25 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found