#!/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__