in reply to Shuffling cards
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):Ok, I finally checked the full explanation. Here's my sample code to solve the assignment:BIO Past Papers
Please note that:#!/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__
HTH.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Shuffling cards
by Anonymous Monk on Feb 23, 2005 at 14:11 UTC | |
by blazar (Canon) on Feb 23, 2005 at 14:36 UTC | |
by Anonymous Monk on Feb 23, 2005 at 15:46 UTC | |
by blazar (Canon) on Feb 24, 2005 at 09:16 UTC | |
by Anonymous Monk on Feb 24, 2005 at 11:07 UTC |