New golf was Re: New Perl magazine

Liyang Hu liyang at nerv.cx
Sat Feb 2 15:10:25 CST 2002


On Sat, Feb 02, 2002 at 05:13:59PM +0000, Tony Bowden wrote:
> I took a similar approach at first... (although mine deals with many
> rather than one)
> -F// -pale '$_=0;$n=36**@F;for$d(@F){$d=$o-55if($o=ord$d)>64;$_+=($n/=36)*$d}'

Hmm ... I never knew about -F ...

  1234567890123456789012345678901234567890123456789012345
  -F// -pae'map{$i=$i*36+("A"le$_?-55+ord$_:$_)}@F;$_=$i'
  -F// -pae'map{$i*=36;$i+="A"le$_?-55+ord$_:$_}@F;$_=$i'

55 characters[0]. Can't think of any other way to shorten that, I'm
afraid. Note you do have to invoke it as follows:

  $ echo -n 12AB | perl -F// -pae'map{$i*=36;$i+="A"le$_?-55+ord$_:$_}@F;$_=$i'

(Hey, the rules said ``convert a number'', not ``convert a number
and a newline''.)

I've been doing too much Python^WHaskell ...

/Liyang
[0] How does golf work again? Do I include the switches in the
character count? And the quotes?
-- 
.--| Liyang HU |--| http://nerv.cx/ |--| Caius at Cam |--| ICQ: 39391385 |--.
|  A [programming] language that doesn't affect the way you think        |
|  about programming is not worth knowing.                               |



More information about the Belfast-pm mailing list