Hey, I'm trying to Perl some BIO past papers (a British programming contest) but I have some results that I can't explain. The program has to take in a string where b, i and o are functions and have coefficients and groupings such as b3(io) does b then io 3 times. Full explanation is here (question two):

BIO Past Papers

Ok, I finally checked the full explanation. Here's my sample code to solve the assignment:
#!/usr/bin/perl -l use strict; use warnings; my @pack=1..8; my %disp; @disp{qw/b i o/}=map { my $t=$_; sub { @_[@$t] }; } [1..7,0], [4,0,5,1,6,2,7,3], [0,4,1,5,2,6,3,7]; sub parse { for (@_) { my $c; s/[()]/ $& eq '(' ? '(=' . $c++ . '=' : '=' . --$c . '=)' /ge; s/(\d)([bio])/$2 x $1/ge; 1 while s/(\d) \(=(\d+)= (.+?) =\2=\)/$3 x $1/gex; } } while (<>) { parse $_; @pack=$disp{$_}->(@pack) for /./g; print "@pack"; } __END__
Please note that:
  1. I don't do any input validation, for the rules partly explicitly partly implicitly state that I must trust it,
  2. this is certainly not the most efficient way to do this, but it is IMHO adequate to the nature of the problem, as of the description,
  3. Also, the sub parse() is by no means necessary, but I wanted to keep it separate it from the main loop.

      HTH.


      In reply to Re: Shuffling cards by blazar
      in thread Shuffling cards by amnesty_puppy

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



    1. Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
    2. Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
    3. Read Where should I post X? if you're not absolutely sure you're posting in the right place.
    4. Please read these before you post! —
    5. 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
    6. 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;
    7. Link using PerlMonks shortcuts! What shortcuts can I use for linking?
    8. See Writeup Formatting Tips and other pages linked from there for more info.