Click to See Complete Forum and Search --> : Repeated numbers in a sequence
pedro_21
Oct 31st, 2005, 06:10 AM
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?!
Rassis
Nov 1st, 2005, 03:24 PM
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…
jemidiah
Nov 1st, 2005, 07:49 PM
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
Rassis
Nov 2nd, 2005, 02:43 AM
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.
jemidiah
Nov 7th, 2005, 04:20 PM
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 :)
Rassis
Nov 8th, 2005, 01:39 AM
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.
zaza
Nov 14th, 2005, 02:13 PM
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
Rassis
Nov 16th, 2005, 09:00 AM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.