Repeated numbers in a sequence
the problem is:
I want to know if there is any way to find repeated digits in a number sequence. for example : 12341 there are two "1's" and in 11 we can find two "1's" also. Is there some mathematical reason between them valid for any number sequence?
I cant use array's or vector's of any kind and I also can't use String. I think this is only a maths problem. Can any one help me?!
Re: Repeated numbers in a sequence
If you are allowed to use Excel and if you enter each digit of a number in a single cell, it will be quite easy to calculate the quantity of each figure (from 0 to 9) which exists in that number. I don’t think there is any other possible way…
Re: Repeated numbers in a sequence
Here's an algorithm that may be able to help.
Number: n.
Repeat these steps Int(Log(n)) + 1 times. The current repition you are on is "k," starting from 0.
1. Find out which numeral (from 0-9) is in the kth position (ones, tens, hundreds place, etc.) of the number. In VB, this would be equal to Int(n \ (10k)) Mod 10.
2. The expression in number 1 will give you a number from 0-9. Keep track of how many times you've gotten each digit and you'll get your answer in the end.
Example:
12341
Repeat Int(4.091) + 1 = 5 times.
Int(12341 \ 1) Mod 10 = 1.
Tally:
1 1's, 0 everything else.
Int(12341 \ 10) Mod 10 = 4.
Tally:
1 1's, 1 4's, 0 everything else.
Etc. through
Int(12341 \ 10000) Mod 10 = 1.
Tally:
2 1's, 1 4's, 1 3's, 1 2's, 0 everything else.
Hope this helps some
Re: Repeated numbers in a sequence
Jemidiah,
Great! I had no idea.
I just wonder how to modify the expression: Int(n \ (10k)) Mod 10, in order to be coded in Excel. Do you know how to do it? Much obliged.
Re: Repeated numbers in a sequence
I actually got to thinking about that part, and it's a bit redundant. In VB the \ operator as opposed to the / operator means integer division, or x \ y = Int(x / y), and Int(x \ y) = x \ y = Int(x / y). Sorry for taking so long to reply, didn't check that email account :)
Re: Repeated numbers in a sequence
Quote:
Originally Posted by jemidiah
I actually got to thinking about that part, and it's a bit redundant. In VB the \ operator as opposed to the / operator means integer division, or x \ y = Int(x / y), and Int(x \ y) = x \ y = Int(x / y). Sorry for taking so long to reply, didn't check that email account :)
"Better late than never"! Thank you so much Jemidiah and have a nice time.
Re: Repeated numbers in a sequence
Incidentally, if you don't need to even bother with what the numbers are, then a simple start check would be to see if the number is greater than 9876543210. If so, then you have to have at least one repeat.
zaza
1 Attachment(s)
Re: Repeated numbers in a sequence
I finally managed to code the problem in Excel and I would like to share the solution with whom might be interested. The application returns the answer up to 9 digits. For greater numbers applies what Zaza said in her last post.
Have fun.