Reducing numbers to one digit (numerology related)
Can you come up with an algorithm for me?
If you don't know what numerology is, or how it works just forget it and see if you can solve this problem.
I want to reduce a multiple digit number to one digit by adding each digit together, then again, and again etc...until there is only one digit.
Examples of reduction method:
9999 (9+9+9+9=37 then 3+7=10 then 1+0=1)
8765 (8+7+6+5=26 then 2+6=8)
4444 (4+4+4+4=32 then 3+2=5)
3210 (3+2+1+0=6)
Also, I need to convert letters into numbers in a way that the numbers 1-9 correspond with A-I, J-R, and S-Z (z ending on 8 of course). And I'm hoping there's a short way to program in VB other than A=1 B=2 so on....
Any help is appreciated thanks!
Re: Reducing numbers to one digit (numerology related)
Quote:
Originally Posted by nlw92
I want to reduce a multiple digit number to one digit by adding each digit together, then again, and again etc...until there is only one digit.
Observe the pattern:
7 => 7
8 => 8
9 => 9
10 => 1
11 => 2
12 => 3
13 => 4
14 => 5
15 => 6
16 => 7
17 => 8
18 => 9
19 => 1
20 => 2
21 => 3
Does it remind of a modulo operation, with a small catch?
Quote:
Originally Posted by nlw92
Also, I need to convert letters into numbers in a way that the numbers 1-9 correspond with A-I, J-R, and S-Z (z ending on 8 of course). And I'm hoping there's a short way to program in VB other than A=1 B=2 so on....
Let's assume that you're using a character set where the letters of the English alphabet are contiguous in alphabetical order. You can therefore map the alphabet to an integer from 1 to 26. Next, figure out how you can map the numbers from 1 to 26 to the numbers 1 to 9, according to your desired scheme.
Re: Reducing numbers to one digit (numerology related)
Quote:
Originally Posted by
laserlight
Observe the pattern:
7 => 7
8 => 8
9 => 9
10 => 1
11 => 2
12 => 3
13 => 4
14 => 5
15 => 6
16 => 7
17 => 8
18 => 9
19 => 1
20 => 2
21 => 3
Does it remind of a modulo operation, with a small catch?
Let's assume that you're using a character set where the letters of the English alphabet are contiguous in alphabetical order. You can therefore map the alphabet to an integer from 1 to 26. Next, figure out how you can map the numbers from 1 to 26 to the numbers 1 to 9, according to your desired scheme.
I get the pattern, can't believe I didn't think of it. For the English alphabet I don't know what you mean by mapping. I'm just learning and not very advanced in programming yet, but I learn quick if you can explain it a little more in depth.
Re: Reducing numbers to one digit (numerology related)
Quote:
Originally Posted by nlw92
I get the pattern, can't believe I didn't think of it.
Good to hear that.
Quote:
Originally Posted by nlw92
For the English alphabet I don't know what you mean by mapping.
When you say "I'm hoping there's a short way to program in VB other than A=1 B=2 so on", the "A=1 B=2 so on" is a mapping from the letters to the corresponding numbers. In this case you're using what is called a lookup table, but the "short way to program" involves replacing the lookup table with a mathematical formula.
By the way, numerology usually refers to some system of deriving possibly mystical meaning from numbers, whereas you're looking for something more along the lines of number theory.
Re: Reducing numbers to one digit (numerology related)
Quote:
Originally Posted by
laserlight
Good to hear that.
When you say "I'm hoping there's a short way to program in VB other than A=1 B=2 so on", the "A=1 B=2 so on" is a mapping from the letters to the corresponding numbers. In this case you're using what is called a lookup table, but the "short way to program" involves replacing the lookup table with a mathematical formula.
By the way, numerology usually refers to some system of deriving possibly mystical meaning from numbers, whereas you're looking for something more along the lines of number theory.
It's definitely for numerology, I just didn't fully explain the end goal of the program because I figured the mystical meanings of each number would be irrelevant. I was completely lost when it came to calculating the digital root using code. I think I'm going to use the formula Dr(n)=1+((n-1)mod 9). How do you express mod 9 in Visual basic code?
Re: Reducing numbers to one digit (numerology related)
Quote:
How do you express mod 9 in Visual basic code?
By using the mod operator. See
http://msdn.microsoft.com/en-us/libr...=vs.90%29.aspx
Re: Reducing numbers to one digit (numerology related)
the above is even part of an "oldschool" verification method for checking if your results for manually adding/subtracting/multiplying/dividing large numbers is correct.
suppose you have
A * B = C
where A, B and C are large multidigit numbers, and you want to verify your calculated C is correct.
You COULD do the entire calculation again and verify your result, OR
-> reduce A to a single digit by adding digit values
do the same for B and C and do the same for reduced A * reduced B.
The point being: reduce( reduce(A) * reduce(B)) then this result should be equal to reduce(C).
(or performing the same operation on reduced operands, yields the reduced result).
example:
12345 * 6789 = 83810205
reduce 12345 = 6
reduce 6789 = 3
3*6 = 18 -> reduce to 9
reduce 83810205 = 9 which is equal to the above.
So our result is 'probably' correct.
nowadays of course, you have calculators to do calculations like above :p
THe above works for add/subtract and divide also, there's a bit added complexity in division if there's a remainder.
Re: Reducing numbers to one digit (numerology related)
Re: Reducing numbers to one digit (numerology related)
Quote:
Originally Posted by
hgmoos
hello
This problem is called the digital root. It's presented here including the closed formula solution,
https://en.wikipedia.org/wiki/Digital_root