Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: (Golf) Kaprekar's Process

by larryk (Friar)
on Jun 16, 2001 at 22:03 UTC ( #89076=note: print w/ replies, xml ) Need Help??


in reply to (Golf) Kaprekar's Process

I make your original 79 chars.

sub a { return$i if$_[0]==495;$a=join'',sort{$a<=>$b}split//,pop;$i++;a((rever +se$a)-$a) #23456789_123456789_123456789_123456789_123456789_123456789_123456789_ +123456789 }

if you are sorting single digits then perl's default alphanumeric sort will give the same result as explicitly defining a numeric sort. #71

update: just realised you can use $_ instead of $a. #69

"Argument is futile - you will be ignorralated!"


Comment on Re: (Golf) Kaprekar's Process
Select or Download Code
Re: Re: (Golf) Kaprekar's Process
by srawls (Friar) on Jun 16, 2001 at 23:07 UTC
    Humm, I just counted manually and you're right, it is 79. I wonder why this prints 60:
    print length("return$i if$_[0]==495;$a=join'',sort{$a<=>$b}" ."split//,pop;$i++;a((reverse$a)-$a)");
    Anyway, nice improvements, I should've caught that sort one : )

    Update:Ooops, thanks MeowChow.

    The 15 year old, freshman programmer,
    Stephen Rawls

      You're double-quoting the code, which means that the variables are getting interpolated into undef 0-length strings.
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print
      And I can take it down a litter further massaging your code into this:
      sub g{ # 1 2 3 4 5 6 + 7 # 12345678901234567890123456789012345678901234567890123456789012345678 +9012 return$,if($_=pop)==495;$_=join'',sort split//,$_;$,++;g((reverse)-$ +_) }
      But I can't do one on my own... my own solution came in at 83 :(

      mr.nick ...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://89076]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-07-12 14:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (240 votes), past polls