in reply to ASCII Pattern - Golf
$!/usr/bin/perl @A=map{abs}@ARGV;for($y=9;$y>0;$y--){print$A[1]-$y>$A[0]-$_?$A[1]-$y:( +$A[0]-$_)for(1..9);print$/}
Basically all I did was eliminate the redundant use of 'abs', and shortened the name of ARGV. Oh, and used $/ instead of "\n" to save two keystrokes. It's about 15 keystrokes shorter, I believe.
UPDATE:
Many apologies for bungling my untested attempt. As you pointed out, the abs wasn't exactly redundant. I just read precidence wrong. Actually, it was redundant, but its parameters weren't. In the spirit of "do it once and once only" I broke the common functionality out into a subroutine. And as before, I used $/ instead of "\n". The following IS tested, works, and saves you ten keystrokes (for 98 total, plus the shebang line).
sub a{abs$ARGV[shift]-pop}for($y=9;$y;$y--){print a(1,$y)>a(0,$_)?a 1, +$y:a(0,$_)for 1..9;print$/}
Dave
"If I had my life to do over again, I'd be a plumber." -- Albert Einstein
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: ASCII Pattern - Golf
by devslashneil (Friar) on Sep 19, 2003 at 01:08 UTC |