in reply to Re: Rosetta PGA-TRAM
in thread Rosetta PGA-TRAM
If you move the uc you can avoid copying the whole string. Not much savings for a small string I suppose, but you break the clean pipeline nature by copying the input first, rather than doing nothing more than passing each character through the pipeline.
Here's a shaken-up version, starting with noticing how the list return of a for loop is similar to the map function:$x.split('').map({ %rtoa{$_.uc} }).reduce: { $^a+$^b-$a%$b*2 }
sub infix:<ↀ> ($a,$b) { $a+$b-$a%$b*2 } [ↀ] do for $x.split('') { %rtoa{$_.uc} }and an excuse to show off the cool form of the reduction metaoperator.
P.S.: used pre instead of code because Perl Monks still doesn't like Unicode. code escapes out the entities, and the form isn't submitted in UTF-8 so various things are automatically encoded. Nasty.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Rosetta PGA-TRAM
by moritz (Cardinal) on Jun 17, 2009 at 22:42 UTC | |
by John M. Dlugosz (Monsignor) on Jun 17, 2009 at 22:56 UTC |