Reducing numbers to one digit (numerology related)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Reducing numbers to one digit (numerology related)

  1. #1
    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. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,194

    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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Nov 2013
    Posts
    3

    Re: Reducing numbers to one digit (numerology related)

    Quote Originally Posted by laserlight View Post
    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. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,194

    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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #5
    Join Date
    Nov 2013
    Posts
    3

    Re: Reducing numbers to one digit (numerology related)

    Quote Originally Posted by laserlight View Post
    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. #6
    Join Date
    Dec 2012
    Location
    England
    Posts
    1,990

    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
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  7. #7
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,638

    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 06:57 AM.

  8. #8
    Join Date
    Jul 2013
    Posts
    168

    Re: Reducing numbers to one digit (numerology related)

    ---
    Last edited by razzle; November 28th, 2013 at 01:08 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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center