|
require "cam.pm" ;{ $projects -> CPMBOPPC ; } |
|||||||||||||||||||||||||||
|
In the reformattings that are posted below, the variable and function names have been kept the same, but '"."' has been squashed and the code has been reformatted with spaces to make subroutines more readable. In the order in which the solutions were entered, Matthew Byng-Maddick sent in the draining beer glass as a non-entry (given that he was going to judge the competition): Requirements: ANSI terminal
/Cam.pm_-_Program_with_Beer/;sub
r{$d=~s/^(..)//;return(hex$1)};#
$e ="
02 0A
10 00
02 09
02 0F
03 08
02 10
03 09
02 0F
04 0A
020E040B020D040C020C040D020B020E
020A020E0C00";$e=~s/\s+//g;1;sub
g{$l=shift;$d=$e;while(length(
$d)){($n,$s1,$h,$s2)=(r,r,r,r)
;for(1..$n){$s++;$a=(31-$l)>$s
?chr(32):"@";print(chr(32)x$s1
,"#"x$h,${a}x($s2*2),"#"x$h,
"\n")}}}print"\e[2J";for$t((
reverse(2..28))){$s=0;sleep(
1);print"\e[0;0H";g($t);}$_=
"Qevax*Orre,*Cebtenz*Crey"
.",*Pnz.cz\n";s/\*/chr(32)
/eg;tr/a-zA-Z/n-za-mN-ZA-M
/;print;m{Cam.pm_for_info_
see_our_website_at:.....
.http://www.cam.pm.org/.
Real_Perl_mongers_drink_
Real_Beer._Join_CAMRA!!}
Andy Wardley posted his to london.pm, and not with any seriousness, but it is included here for completeness: Requirements: run from a file
#!/usr/bin/perl
################################
################################
## ##
## ##
## ##
## ##
## ##
## ##
## ##
## ##
## ##
## ##
################################
################################
##############################
##############################
##############################
##############################
############################
open(ALE,$0);<ALE>;$/=undef;
############################
$beer=<ALE>;$beer=~s/\S/#/g;
##########################
print($beer);#############
##########################
##########################
########################
########################
########################
########################
Dave Cantrell submitted this calculator for great circle distances next: Requirements: Two command line arguments
$foo='$spc=chr(32);$pi&=&4*atan2
(1,1);$radius=6367000;sub°2ra
d{ $_
[0 ]*
$p i/
18 0}
su b&
ac os
{a ta
n2 (s
qr t(
1- $_
[0]*$_[0]),$_[0])}($l1,$l3)=&dms
2degs(shift);($l2,$l4)=&dms2degs
(shift);printf("%8d${spc}km\n"
,distance($l1,$l3,$l2,$l4)/100
0);printf("%8d${spc}miles\n",d
istance($l1,$l3,$l2,$l4)/1609.
344);sub&distance{$radius*ac
os(sin($_[0])*sin($_[2])+cos
($_[0])*&cos($_[2])*cos($_[1
]-$_[3]));}sub&dms2degs{$_[0
]=~/(\d?\d\d):(\d\d):(\d\d
)([NS]),(\d?\d\d):(\d\d):(
\d\d)([EW])/i;deg2rad(($1+
$2/60+$3/3600)*(($4eq"N")?
1:-1)),°2rad(($5+$6/6
0+$7/3600)*(($8eq"E")?1:
-1));}';$foo=~s/\s//gi;$
foo=~y/&/\t/;eval($foo);
And then Sebastian Bleasdale submitted a program which fitted the classic PONG game into the pint glass: Requirements: ANSI terminal in cbreak and noecho mode (stty cbreak -echo)
#Please_Turn_Off_Text_Buffering#
print"\e[H\e[J";$a=$b=$n=$m=#sfb
10 ;#
$_ ="
"# #"
." "#
." #"
;# "|
$# =#
$_ x#
24 ,#
$c =#
$d=.03;for(;;++$->5**4?$-=0:do{#
(select$_=chr(1),"","",0)[0]||#$
next;sysread(STDIN,$_,1)}){/k/
?$n-=($n>5):/a/?$m-=($m>5):/s/
?$m+=($m<69):/l/?$n+=($n<69):1
;(($a+=$c)<2and$a=2)|($a>72and
$a=72)and$c=-$c;($b+=$d)<1&#
abs($a-$m)<4and$b=1.1,$d=-$d
,$c+=($a-$m)/50;$b>23&abs($a
-$n)<4and$b=22.9,$d=-$d,$c+=
($a-$n)/50;$c*=0.9while#Pong
abs($c)>.09;$b>=1&$b<23or#
die;substr(($o=$#),1698+$n
,8)="~k~~~~l~";substr($o,#
int($b)*74+$a,2)="()";#$
substr($o,$m-4,8)="_a__"
."__s_";print"\e[;H$o"};
Jonathan Amery then came up with a Mandelbrot set grapher: Requirements: ANSI terminal upon which stty size will work
open(S,"stty\040size\040|");$_=#
<S>;/(\w*)#cam.pmBFOPerlPContest
\W (#
\w *)
/x ;#
$s =#
$1 <(
$2 -1
)/ 2?
$1 *2
:# :)
$2 -1
;$si="\e[0;3";$sij="\e[1;3";@st=
($si."1m",$si."2m",$si."3m",$si.
"4m",$si."5m",$si."6m",$si.###
"7m",$sij."0m",$sij."1m",$sij.
"2m",$sij."3m",$sij."4m",$sij.
"5m",$sij."6m",$sij."7m");for(
;$a<$s/2;$a++){print"\n";for
($b=0;$b<$s;$b++){$r=0;$c=0;
for($d=0;$d<@st;$d++){$nr=$r
*$r-$c*$c;$c=2*$r*$c+$a*(5/#
$s)-1.25;$r=$nr+$b*(2.5/$s
)-2;if($r*$r+$c*$c>4){#JDA
print((@st)[$d]."@");last;
}}if($d==@st){print$si.###
"0m@";}}}$_=<>;#Best.run
#in.an.ANSI.colour.term#
##as.large.as.possible##
#Press<return>to.finish#
And then, just as it was all about to go quiet, Colin Watson came up with his Star Wars style vector graphics. Requirements: ANSI terminal with exported LINES and COLUMNS environment variables
($.,$;)=@ENV{LINES,COLUMNS};$_='
.2:2/5.=:2.69A..6:9D..6>.G;1.29J
.. 6;
.M ;1
.2 9P
.. 6;
.S 6.
.6 9V
.. 0>
.Z :2
.6 9a
.. 6>
.d;1.29g..6;.j;1.29m..6;';for$w(
0..29){$#="\e[H";for($i=$.*2;$i;
--$i){$@=(B^b)x$;if--$|;$h=$.*
2/($.*2-$i+1);s/\s//g;$v=($h-1
)*$./2;while(/(.{6})/g){($t,$x
,$y,$r,$k,$l)=map-46+$_,unpack
c6,$1;$p=$t?+$k:$y;$q=$t?$l:
$y;$z=$r+.8;(next)if$v<$w+$p
-$z||$v>$w+$q+$z;$y+=$w;for(
0..$;*2-1){$u=($h*($_-$;)+$;
)*32/$;;(next)if$u<$x-$z||
$u>$x+$z;if(!$t){$d=sqrt((
$v-$y)**2+($u-$x)**2);next
if$d<$r-.8||$z<$d;$d=atan2
($y-$v,$x-$u)/atan2(0,-1
)*4+4;(next)if$d<$k||$l<
$d}substr$@,$_/2,1,'*'}}
$|||($#.=$@.$/)}print$#}
|