This post fits more into "Useless Use of Perl" or "Insane Application of Regex" but there are no such categories. (And I'm sure someone could obfuscate the code. But I'd rather leave it to the experts.)

Scenario:

Say you're a hard-working grad student working late at night in a grocery store. You're drowsy, can't compute in your head.

In the town you work, the dollar bills could be of any arbitrary denomination ($1.3, $423, $94.32, etc.) but the coins are always quarter (25 cents), dime (10 cents), nickel (5 cents) and penny (1 cent).

Nearby your grocery store is a nightclub. The patrons often come ask you for change. They want you to break their dollar bills into as many quarters as possible (for parking meters).

As a tired Perl programmer and grad student writing a thesis on "Regex as Greek Gods of A.I.", you want to automatically figure out the combination of the number of coins you can break a bill into while maximizing the number of quarters.

Solution:
sub small_change { ('m'x(100*$_[0]))=~/^(m*)\1{24}(m*)\2{9}(m*)\3{4}(m*)$/; print "\$$_[0] can be broken into:\n".length($1)." quarters, ".len +gth($2)." dimes, ".length($3)." nickels and ".length($4)." pennies.\n +"; } small_change(3.43); # print: # $3.43 can be broken into: # 13 quarters, 1 dimes, 1 nickels and 3 pennies.

In reply to "Do you have small change?" by chunlou

Title:
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, details, 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, summary, 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.