[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Fun With Golf - digital roots



On Wed, Oct 18, 2000 at 11:55:22PM +0100, Ian Phillipps wrote:
> On Wed, 18 Oct 2000 at 12:48:21 -0400, Ronald J Kimball wrote:
> > On Wed, Oct 18, 2000 at 12:37:45PM -0400, yanick1@sympatico.ca wrote:
> > > perlgolf hole - Digital Root
> 
> > > Write a subroutine to compute the digital root of any whole number argument.
> > > Winner: sub hole {$_=pop;1while s/(\d)(\d)/$1+$2/ge;$_}
> 
> I didn't know what a digital root was until Google pointed me to
> http://mathworld.wolfram.com/DigitRoot.html, but using the info on that
> page, I submit:
> 
>             sub hole {$_[0]&&($_[0]-1)%9+1}
> 
> or this if you allow it to modify its parameter:
> 
>             sub hole {$_[0]&&$_[0]--%9+1}

Wow, nice work!  (Although you wouldn't have been able to look up that info
during the tournament.  :)  We never looked into finding a pattern in the
results.


> Neither this nor yanick1's submission behave correctly for negative
> numbers, whatever "correctly" means here.

Oops, the description of the hole should have specified positive integers.  :/

Ronald

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe