По-русски
English
Solutions of YAPC::Russia::Golf 2008
Rules
Solutions
All the solutions are shown in the order they were received.
Task 1
1
#!/usr/bin/perl
$_=$ARGV[0];
s/(.)(.)/$1-$2+/g;
s/\+$//;
s/^(.+)\+?$/$1/ee;
unless ($_) {
print "yes\n"
} else {
s/(.)(.)$/$1-$2/e;
unless ($_) {
print "yes\n"
} else {
print "no\n"
}
}
2
#!/usr/bin/perl -lp
@h{a,0..9}=(0..9,a);
while ( s/(.)(.)/$h{$1}$h{$2}/ ){
s/^0//;
}
s/0/yes/;
s/\d|a/no/
3
#!/usr/bin/perl -lp
@h{a,0..9}=(0..9,a);
while ( s/(.)(.)/$h{$1}$h{$2}/ ){
s/^0//;
}
s/0/yes/;
s/^.$/no/
4
#!/usr/bin/perl -p
for(;;){while(s/(.)(.?)//){push@a,7 for 1..$1;push@b,8 for 1..$2}($#a,$#b)=($#b,$#a)if@b>@a;pop@a for@b;$_=@a;@a=@b=();last if/^.$/}$_=$_?"no\n":"yes\n"
5
#!/usr/bin/perl -p $_=eval"$_\x2511"?"no\n":"yes\n"
6
#!/usr/bin/perl -p
($a=q~
YAPC::Russia::Golf (-:
~)=~tr [ R : A Y P C ]
[ # 1 _ $ \x25 ]
;$_=eval$a?"no\n":"yes\n";
7
#!perl -p s/(\d)(\d?)/'+'.($1-$2||'00')/eg;s/.*/$_/see;$_=$_?"no\n":"yes\n"
8
s/(\d)(\d?)/'+'.($1-$2||'0')/eg;s/.*/$_/see;$_=$_?"no\n":"yes\n"
9
#!/bin/perl
while (<>) {k($_)until($_<11);print $_==0?'yes':'no';}
sub k {$_=shift;$z=0;map{$z+=$_}map{$y<0?do{$y=1;"-$_"}:do{$y=-1;"+$_"};} /./g;$_ = abs $z}
10
#!/bin/perl
while (<>) {k($_)until($_<11);print $_==0?'yes':'no';}
sub k {$_=shift;$z=0;map{$z+=$_}map{$y<0?do{$y=1;"-$_"}:do{$y=-1;"+$_"};} /./g;$_ = abs $z}
11
A:goto A if/\G0/gc;goto B if/\G1/gc;goto C if/\G2/gc;goto D if/\G3/gc;goto E if/\G4/gc;goto F if/\G5/gc;goto G if/\G6/gc;goto H if/\G7/gc;goto I if/\G8/gc;goto J if/\G9/gc;say"yes";next; B:goto K if/\G0/gc;goto A if/\G1/gc;goto B if/\G2/gc;goto C if/\G3/gc;goto D if/\G4/gc;goto E if/\G5/gc;goto F if/\G6/gc;goto G if/\G7/gc;goto H if/\G8/gc;goto I if/\G9/gc;goto Q; C:goto J if/\G0/gc;goto K if/\G1/gc;goto A if/\G2/gc;goto B if/\G3/gc;goto C if/\G4/gc;goto D if/\G5/gc;goto E if/\G6/gc;goto F if/\G7/gc;goto G if/\G8/gc;goto H if/\G9/gc;goto Q; D:goto I if/\G0/gc;goto J if/\G1/gc;goto K if/\G2/gc;goto A if/\G3/gc;goto B if/\G4/gc;goto C if/\G5/gc;goto D if/\G6/gc;goto E if/\G7/gc;goto F if/\G8/gc;goto G if/\G9/gc;goto Q; E:goto H if/\G0/gc;goto I if/\G1/gc;goto J if/\G2/gc;goto K if/\G3/gc;goto A if/\G4/gc;goto B if/\G5/gc;goto C if/\G6/gc;goto D if/\G7/gc;goto E if/\G8/gc;goto F if/\G9/gc;goto Q; F:goto G if/\G0/gc;goto H if/\G1/gc;goto I if/\G2/gc;goto J if/\G3/gc;goto K if/\G4/gc;goto A if/\G5/gc;goto B if/\G6/gc;goto C if/\G7/gc;goto D if/\G8/gc;goto E if/\G9/gc;goto Q; G:goto F if/\G0/gc;goto G if/\G1/gc;goto H if/\G2/gc;goto I if/\G3/gc;goto J if/\G4/gc;goto K if/\G5/gc;goto A if/\G6/gc;goto B if/\G7/gc;goto C if/\G8/gc;goto D if/\G9/gc;goto Q; H:goto E if/\G0/gc;goto F if/\G1/gc;goto G if/\G2/gc;goto H if/\G3/gc;goto I if/\G4/gc;goto J if/\G5/gc;goto K if/\G6/gc;goto A if/\G7/gc;goto B if/\G8/gc;goto C if/\G9/gc;goto Q; I:goto D if/\G0/gc;goto E if/\G1/gc;goto F if/\G2/gc;goto G if/\G3/gc;goto H if/\G4/gc;goto I if/\G5/gc;goto J if/\G6/gc;goto K if/\G7/gc;goto A if/\G8/gc;goto B if/\G9/gc;goto Q; J:goto C if/\G0/gc;goto D if/\G1/gc;goto E if/\G2/gc;goto F if/\G3/gc;goto G if/\G4/gc;goto H if/\G5/gc;goto I if/\G6/gc;goto J if/\G7/gc;goto K if/\G8/gc;goto A if/\G9/gc;goto Q; K:goto B if/\G0/gc;goto C if/\G1/gc;goto D if/\G2/gc;goto E if/\G3/gc;goto F if/\G4/gc;goto G if/\G5/gc;goto H if/\G6/gc;goto I if/\G7/gc;goto J if/\G8/gc;goto K if/\G9/gc;goto Q; Q:say"no";
12
A();
sub A{&A if/\G0/gc;&B if/\G1/gc;&C if/\G2/gc;&D if/\G3/gc;&E if/\G4/gc;&F if/\G5/gc;&G if/\G6/gc;&H if/\G7/gc;&I if/\G8/gc;&J if/\G9/gc;say"yes";next}
sub B{&K if/\G0/gc;&A if/\G1/gc;&B if/\G2/gc;&C if/\G3/gc;&D if/\G4/gc;&E if/\G5/gc;&F if/\G6/gc;&G if/\G7/gc;&H if/\G8/gc;&I if/\G9/gc;&Q}
sub C{&J if/\G0/gc;&K if/\G1/gc;&A if/\G2/gc;&B if/\G3/gc;&C if/\G4/gc;&D if/\G5/gc;&E if/\G6/gc;&F if/\G7/gc;&G if/\G8/gc;&H if/\G9/gc;&Q}
sub D{&I if/\G0/gc;&J if/\G1/gc;&K if/\G2/gc;&A if/\G3/gc;&B if/\G4/gc;&C if/\G5/gc;&D if/\G6/gc;&E if/\G7/gc;&F if/\G8/gc;&G if/\G9/gc;&Q}
sub E{&H if/\G0/gc;&I if/\G1/gc;&J if/\G2/gc;&K if/\G3/gc;&A if/\G4/gc;&B if/\G5/gc;&C if/\G6/gc;&D if/\G7/gc;&E if/\G8/gc;&F if/\G9/gc;&Q}
sub F{&G if/\G0/gc;&H if/\G1/gc;&I if/\G2/gc;&J if/\G3/gc;&K if/\G4/gc;&A if/\G5/gc;&B if/\G6/gc;&C if/\G7/gc;&D if/\G8/gc;&E if/\G9/gc;&Q}
sub G{&F if/\G0/gc;&G if/\G1/gc;&H if/\G2/gc;&I if/\G3/gc;&J if/\G4/gc;&K if/\G5/gc;&A if/\G6/gc;&B if/\G7/gc;&C if/\G8/gc;&D if/\G9/gc;&Q}
sub H{&E if/\G0/gc;&F if/\G1/gc;&G if/\G2/gc;&H if/\G3/gc;&I if/\G4/gc;&J if/\G5/gc;&K if/\G6/gc;&A if/\G7/gc;&B if/\G8/gc;&C if/\G9/gc;&Q}
sub I{&D if/\G0/gc;&E if/\G1/gc;&F if/\G2/gc;&G if/\G3/gc;&H if/\G4/gc;&I if/\G5/gc;&J if/\G6/gc;&K if/\G7/gc;&A if/\G8/gc;&B if/\G9/gc;&Q}
sub J{&C if/\G0/gc;&D if/\G1/gc;&E if/\G2/gc;&F if/\G3/gc;&G if/\G4/gc;&H if/\G5/gc;&I if/\G6/gc;&J if/\G7/gc;&K if/\G8/gc;&A if/\G9/gc;&Q}
sub K{&B if/\G0/gc;&C if/\G1/gc;&D if/\G2/gc;&E if/\G3/gc;&F if/\G4/gc;&G if/\G5/gc;&H if/\G6/gc;&I if/\G7/gc;&J if/\G8/gc;&K if/\G9/gc;&Q}
sub Q{say"no";next}
13
#!/bin/perl
while (<>) {do {$z=0;map{$z+=$_}map{$y<0?do{$y=1;"-$_"}:do{$y=-1;"+$_"};} /./g;$_ = abs $z} until($_<11);print $_==0?'yes':'no';}
14
#!/bin/perl
while (<>) {do {$_ = abs eval join("",map{$y<0?do{$y=1;"-$_"}:do{$y=-1;"+$_"};} /./g)} until($_<11);print $_==0?'yes':'no';}
15
#!/usr/bin/perl -n
($v,$_)=($_,'_');
while ($v=~/(\d)(\d?)/g){
($c,$d)=($1,$2);
s/(.*)/$c$1$d/;
s/9/18/g;s/8/17/g;s/7/16/g;s/6/15/g;s/5/14/g;s/4/13/g;s/3/12/g;s/2/11/g;s/0//g;
}
s/1{11}//g;
0 while s/1_1/_/g;
print +(/1/?'no':'yes')."
"
16
#!/usr/bin/perl
sub m
{
$_ = shift;
s/0//g;
s/2/11/g;
s/3/111/g;
s/4/1111/g;
s/5/11111/g;
s/6/111111/g;
s/7/1111111/g;
s/8/11111111/g;
s/9/111111111/g;
$_;
}
sub d
{
$a = $b = shift;
$a =~ s/(.)./$1/g;
$b =~ s/.(.|$)/$1/g;
$a = &m($a);
$b = &m($b);
if ($a) {
if ($b) {
if ($b =~ s/$a//) {
$a = $b;
} else {
$a =~ s/$b//;
}
}
}
$a =~ s/11111111111//g;
!$a;
}
while (<>) {
chomp;
print d($_) ? "yes\n" : "no\n";
}
17
perl -ne
'$i=10;@D=map{[map{$i=(1..10,0)[$i]}0..9]}0..10;$i=0;$i=$D[$i]->[$_]for
split "",$_;printf "%-80d%s\n",$_,$i?"no":"yes"'
Task 2
1
#!perl
$n=<>;
while(<>){
my $i;
for $x (split '',$_){$m[$j][$i++]=$x eq '#'?1:0;}
$j++;
}
for $k (1..$n){
if ($n%$k<1){
for $y (0..$j){
for $x (0..200){
my $s;
for $w ($y..$y+$k-1){
$s+=$m[$w][$_] for $x..$x+$n/$k-1;
}
$r=$s if $r<$s;
}
}
}
}
print $r;
2
$q = <>;
for(<>)
{
chomp;
tr/#/1/;
$z = length $_;
$k++;
$j .= $_
}
for $a (1..$q)
{
if(($b = $q / $a) == int $b && $a <= $z && $b <= $k)
{
for(0..$z)
{
$d = ".{$z}" x $_;
for(0..$z)
{
my $f;
$e = $z - $a - $_;
$c = $d . ".{$_}(.{$a}).{$e}" x $b;
map{$f += $_} map{split''} $j =~ qr($c);
$h = $f > $h ? $f : $h
}
}
}
}
print $h
3
#!perl
$n=<>;
while(<>){
$i=0;
for $x (split '',$_){$m[$j][$i++]=$x eq '#'?1:0}
$j++;
}
for $k (1..$n){
if ($n%$k<1){
for $y (0..$j){
for $x (0..$i){
my $s;
for $w ($y..$y+$k-1){
$s+=$m[$w][$_] for $x..$x+$n/$k-1
}
$r=$s if $r<$s
}
}
}
}
print $r;
4
($n,@s)=<>;for$b(1..$n){$n% $b||do{for$x(0..-$b-1+length$s[0]){for$y(0..@s-$n/$b){$c=0;$c+=@{[substr($s[$y+$_],$x,$b)=~/#/g]}for(0..$n/$b-1);$_=$c if$_<$c}}}}say
5
#!/usr/bin/perl
$n = <>;
while (<>) {
chomp;
$w = length if length > $w;
push @d, $_;
}
for $a (1 .. 200) {
next if $n % $a;
$b = $n / $a;
for $x (0 .. $w - $a) {
for $y (0 .. @d - $b) {
my $o;
for (map { $z = substr $_, $x, $a; $z =~ s/#//g } @d[$y .. $y + $b - 1]) {
$o += $_;
}
$m = $o if $o > $m;
}
}
}
print $m+0;