Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Re: (Golf) Kaprekar's Process

by sean (Beadle)
on Jun 17, 2001 at 21:38 UTC ( #89179=note: print w/replies, xml ) Need Help??


in reply to Re: (Golf) Kaprekar's Process
in thread (Golf) Kaprekar's Process

This doesn't work for a lot of numbers, because you're checking AFTER the sort, for 459, which could've been 459,495,954,945,549, or 594 before the sort. your code gets the right answer when it was anything EXCEPT 495 before the sort.
For example, 247:

1: 742-247 = 495
the answer is 1.

your code produces 2.

Replies are listed 'Best First'.
Re: Re: Re: (Golf) Kaprekar's Process
by tachyon (Chancellor) on Jun 18, 2001 at 03:19 UTC

    Good point, what can I say, seemed like a good idea at the time. The thinking was that any combination of 4,5,9 will sort to 954 and reverse to 459 so the timing of the sort was not important. As you note this breaks down in some cases. The QA was a bit suboptimal - I just bunged in the two examples and when they worked...

    Drat! I knew sneaking in a solution shorter than MeowChow was to good to be true :-)

    Cheers

    tachyon

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://89179]
help
Chatterbox?
[marioroy]: might need 2 or 3 backslash for \n. Also \\;
[Lady_Aleena]: shmem, there is MP3::Info/
[Discipulus]: too much complex qx when you know perl are better to avoid
[marioroy]: might need to backslash \'*.mp3\'
[marioroy]: It's a quoting issue inside qx. It's File::Find or qx. LA chooses qx. Almost there.
[marioroy]: Also \"%S\\\n\" oh my, not fun.
[Discipulus]: good night folks
[marioroy]: I will make a mp3info script that takes the -p "%S\n" args and test qx. I'm on the road, so will come back.
[marioroy]: All because File::Find is not fun for LA.
[marioroy]: good night Discipulus.

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2017-04-23 21:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.