devslashneil has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
Recently to pass some time, my friend and i organized a game of golf.
The problem which we set out to solve, was to write a script which takes two arguments (grid coordinates starting from bottom left) and then creates the following patterns.
Pattern created with the coordinates 5,5:
My solution to this problem was:
Neil Archibald
- /dev/IT -
Recently to pass some time, my friend and i organized a game of golf.
The problem which we set out to solve, was to write a script which takes two arguments (grid coordinates starting from bottom left) and then creates the following patterns.
Pattern created with the coordinates 5,5:
Pattern created with the coordinates 2,3:444444444 433333334 432222234 432111234 432101234 432111234 432222234 433333334 444444444
etc.666666667 555555567 444444567 333334567 222234567 111234567 101234567 111234567 222234567
My solution to this problem was:
However i assume a lot of people could do it in a lot less so if anyone is interested in passing a little bit of time, i would love to see some better solutions :)#!/usr/bin/perl for($y=9;$y>0;$y--){print abs$ARGV[1]-$y>abs$ARGV[0]-$_?abs$ARGV[1]-$y +:abs($ARGV[0]-$_)for(1..9);print"\n"}
Neil Archibald
- /dev/IT -
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: ASCII Pattern - Golf
by JamesDotCom (Initiate) on Sep 19, 2003 at 00:41 UTC | |
Re: ASCII Pattern - Golf
by cLive ;-) (Prior) on Sep 19, 2003 at 02:31 UTC | |
Re: ASCII Pattern - Golf
by kvale (Monsignor) on Sep 19, 2003 at 00:42 UTC | |
by tedrek (Pilgrim) on Sep 19, 2003 at 02:22 UTC | |
by tilly (Archbishop) on Sep 19, 2003 at 02:43 UTC | |
Re: ASCII Pattern - Golf
by glwtta (Hermit) on Sep 19, 2003 at 02:13 UTC | |
by cLive ;-) (Prior) on Sep 19, 2003 at 02:38 UTC | |
by devslashneil (Friar) on Sep 19, 2003 at 02:31 UTC | |
Re: ASCII Pattern - Golf (Russ: 83)
by Russ (Deacon) on Sep 19, 2003 at 02:39 UTC | |
by Russ (Deacon) on Sep 19, 2003 at 02:57 UTC | |
by cLive ;-) (Prior) on Sep 19, 2003 at 03:52 UTC | |
by Sidhekin (Priest) on Sep 19, 2003 at 22:56 UTC | |
Re: ASCII Pattern - Golf
by davido (Cardinal) on Sep 19, 2003 at 01:02 UTC | |
by devslashneil (Friar) on Sep 19, 2003 at 01:08 UTC | |
Re: ASCII Pattern - Golf
by halley (Prior) on Sep 19, 2003 at 19:19 UTC |
Back to
Seekers of Perl Wisdom