Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: ASCII Pattern - Golf

by davido (Cardinal)
on Sep 19, 2003 at 01:02 UTC ( [id://292549]=note: print w/replies, xml ) Need Help??


in reply to ASCII Pattern - Golf

How about this (untested):

$!/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
    I just tested that, and it doesn't seem to work. The abs calls wern't really redundant because you needed to test the greater value displaced from 0, so when you have two negative values -5 < -4 but you still want -5 returned. :)

    UPDATE: Well done with the update, it works nicely when i tested it, i liked the use of the sub too, i only wish the game of golf had a longer time limit so i could have played around with some of these ideas for longer,

    Neil Archibald
    - /dev/IT -

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://292549]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-25 07:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found