Just another Perl shrine PerlMonks

Re^2: Coming soon: Algorithm::Loops (restrictions)

by tye (Sage)
 on Apr 12, 2003 at 07:27 UTC ( #250035=note: print w/replies, xml ) Need Help??

in reply to Re: Coming soon: Algorithm::Loops

I believe the original question doesn't put any limit on number of digits in the numbers

I mostly didn't assume any restrictions on the number of digits in the numbers being added. I derived the restrictions from my desire to have unique numbers and a non-trivial answer.

If I picked two digits, then I'd only have two numbers to add up (XY and YX) and so I can't get a sum of even 200. If I picked four digits, then the number of combinations to search is quite small and might be a fun challange with paper and pencil but didn't seem interesting from the angle I was tackling things. Since I started out wanting to avoid leading zeros, the space to search would be so small that even with pencil and paper it wouldn't be very interesting. (:

But with a quick change of a couple of characters, I see that adding up two 4-digit numbers (having the same digits in different orders) never gives us 2003. But of course it can't, because all such would be even modulo 9 while 2003 is odd modulo 9.

Thanks for the vote in favor of Algo.::Loops.

BTW, I have a much faster version of my code searching for optimal stamp denominations. Still not nearly as fast as I'd like (with one search still going after 120 hours of CPU). I'll post that code when I get some time.

- tye
• Comment on Re^2: Coming soon: Algorithm::Loops (restrictions)

Replies are listed 'Best First'.
Re: Re^2: Coming soon: Algorithm::Loops (restrictions)
by hv (Parson) on Apr 14, 2003 at 15:31 UTC
But with a quick change of a couple of characters, I see that adding up two 4-digit numbers (having the same digits in different orders) never gives us 2003. But of course it can't, because all such would be even modulo 9 while 2003 is odd modulo 9.

Careful now, 7 * 2 = 14 == 5 (modulo 9).

In general (if I remember correctly), for any modulus q, if a does not share a factor with q there exists a b for every c such that a * b == c (modulo q).

Hugo

Create A New User
Node Status?
node history
Node Type: note [id://250035]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2021-04-13 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?