in reply to Luhn Number Golf
Update: Here is another non-reverse variation at 72 chars. Still a mile behind chipmunk however.sub luhn { $r=$t=0; split//,pop; $r.=$_[$_]*(1+($_+$#_)%2)for+0..@_; $r=~s/(.)/$t+=$1/eg; !chop$t }
sub luhn2 { $_=$i=0; split//,pop; $_.=(1+$i++%2)*pop while@_; s/(.)/+$1/g; $_=eval; !chop }
--
John.
|
|---|