Now that the contest is over. On Mon, 27 Oct 2003, Riley wrote:
> I'm new to the whole golfing game, and I'm trying to get my swing down... > > Regarding this last puzzle, I've created a solution (albeit extremely long > in comparison to some of those I've seen in older puzzles), and in trying to > get a feel for the shortcuts that all of you use, I'm wondering if perhaps > you can look at what I've done and tell me how to make it shorter. > > I apologize for posting this before the puzzle has been closed; I feel my > solution is so long it won't offend anyone. Here goes: > > map{split/ > / Why do you split according to newline? > ;[EMAIL PROTECTED];[EMAIL PROTECTED]; Instead of mapping over <STDIN> and then splitting explictly it is possible to use the -p and -a flag to iterate over STDIN and to split the fields into the @F array. > my$m; Why do you need to declare $m here? To initialize it? > map$m.="-",1..$l; This and the previous statement can be written as $m="-"x$l; > map{$s[$i]=$e[$_]if($e[$_]>$s[ > $i])[EMAIL PROTECTED]; You don't need the parenthesis after the if (they can be omitted for such statement modifiers). And this statement can be summarized as: $s[$i]=(sort{$b<=>[EMAIL PROTECTED]@_])[0] > my$n;map$n.=" ",1...$s[$i]; Instead write $n=$"x$s[$i]; $" contains whitespace. > $e[$i]=$l+$s[$i]; You use $s[$i] several times. You can easily assign it in one of the statements as the = operator returns the value that was assigned. print"$i $n$m\n"}<STDIN> Instead of \n you can have an actual newline. Like $a=" "; <STDIN> can be abbreviated as <> in this case. Of course, what I used was a storage of whitespace strings instead of a storage of numbers, which can be sorted using regular lexicographic sort. I'll post an explanation of my program once I get home. Hope it helps. Regards, Shlomi Fish > > I've been a fan of perl for several years, but my experience has never led > me to the map and grep functions that I've been seeing all over the place > (these functions seem to be rather nice shortcuts for "for" and "foreach" > loops). Looking at the algorithm I've used above, are there any other > obvious places where I can make this code shorter? > > -o0lit3 > > ---------------------------------------------------------------------- Shlomi Fish [EMAIL PROTECTED] Home Page: http://t2.technion.ac.il/~shlomif/ An apple a day will keep a doctor away. Two apples a day will keep two doctors away. Falk Fish