CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: Reducing numbers to one digit (numerology related)

1. Junior Member
Join Date
Nov 2013
Posts
3

## 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!

2. Elite Member Power Poster
Join Date
Jan 2006
Location
Singapore
Posts
6,761

## Re: Reducing numbers to one digit (numerology related)

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?

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.

3. Junior Member
Join Date
Nov 2013
Posts
3

## Re: Reducing numbers to one digit (numerology related)

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.

4. Elite Member Power Poster
Join Date
Jan 2006
Location
Singapore
Posts
6,761

## Re: Reducing numbers to one digit (numerology related)

Originally Posted by nlw92
I get the pattern, can't believe I didn't think of it.
Good to hear that.

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.

5. Junior Member
Join Date
Nov 2013
Posts
3

## Re: Reducing numbers to one digit (numerology related)

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?

6. ## Re: Reducing numbers to one digit (numerology related)

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

7. Elite Member Power Poster
Join Date
Apr 2000
Location
Belgium (Europe)
Posts
4,626

## 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

THe above works for add/subtract and divide also, there's a bit added complexity in division if there's a remainder.
Last edited by OReubens; November 26th, 2013 at 07:57 AM.

8. Junior Member
Join Date
Apr 2019
Posts
1

hello

9. Member
Join Date
Feb 2017
Posts
458

## Re: Reducing numbers to one digit (numerology related)

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
Last edited by wolle; May 7th, 2019 at 02:37 AM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Click Here to Expand Forum to Full Width