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

Comment on

by gods
on Feb 11, 2000 at 00:06 UTC ( #3333=superdoc: print w/replies, xml ) Need Help??

When chickenlips makes reference to Scrabble, what I assume is meant is that a word formed from the random characters need not use all of the random characters, but must use only those characters. E.g., 'mad' can be formed from 'randam', but 'madam' cannot (two 'm' characters).

use warnings FATAL => 'all' ; use strict; use Data::Dump; use constant DEBUG => 0; use constant { DBPR_DD_1 => 1 && DEBUG, }; my $random = 'randam'; my %r_count; $r_count{$_}++ for split '', $random; dd \%r_count if DBPR_DD_1; for my $word (qw(a mad ran madnar madam ranx xxxxxx x)) { my %u_count = %r_count; my $ok = scrabblicious($word, %u_count); my $len = 2 + length $random; printf qq{%*s %sproperly formed from '$random' \n}, $len, qq{'$word'}, $ok ? ' ' : 'im'; } sub scrabblicious { my ($word, %u_count) = @_; for my $c (split '', $word) { return if --$u_count{$c} < 0; } return 1; }


'a' properly formed from 'randam' 'mad' properly formed from 'randam' 'ran' properly formed from 'randam' 'madnar' properly formed from 'randam' 'madam' improperly formed from 'randam' 'ranx' improperly formed from 'randam' 'xxxxxx' improperly formed from 'randam' 'x' improperly formed from 'randam'

Update: The definition of  scrabblicious() given above will accept an empty string as a match for a 'tray' of characters. So just add
    return if not length $word;
before the for-loop.

In reply to Re: Regex to compare (if) two strings (Uniquely - I will explain inside) by AnomalousMonk
in thread Regex to compare (if) two strings (Uniquely - I will explain inside) by chickenlips

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (7)
    As of 2016-09-28 22:58 GMT
    Find Nodes?
      Voting Booth?
      Extraterrestrials haven't visited the Earth yet because:

      Results (541 votes). Check out past polls.