Page 1 of 1

Adding Numbers to get a single Number.

Posted: Mon Nov 14, 2011 3:12 am
by amit_singh
Hi , I am new to scripting I am looking for a batch script to take input from a test file(Names.txt) having names & last names and converting each names & last names "alphabets" to its predefined below shown "numeric" value and then adding this numeric value to finally get ONE digit numeric value.
To make it more clear I would like to explain with an example .The Mapping between "Alphabets" & "Number" which I'll be using is as below.
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u","v", "w", "x", "y", "z""1", "2", "3", "4", "5", "8", "3", "5", "1", "1", "2", "3", "4", "5", "7", "8", "1", "2", "3", "4", "6", "6", "6", "5", "1","7"
Rozer Gorth =>Equivalent Numeric value: 2775237245 ==>Individually adding each number(2+7+7+5+2+3+7+2+4+5): 44 ==> Final ONE numeric digit(4+4): 8 Jimy Dacy =>Equivalent Numeric value: 11414131 ==>Individually adding each number(1+1+4+1+4+1+3+1): 16 ==>Final ONE numeric digit(1+6): 7Peter Pace =>Equivalent Numeric value: 854522135 ==>Individually adding each number(8+5+4+5+2+2+1+3+5): 35 ==>Final ONE numeric digit(3+5): 8
So result will be dumped into another file(Result.txt) as
Rozer Gorth : 8Jimy Dacy : 7Peter Pace : 8
I shall be very thankful for any suggestion and help.

Adding Numbers to get a single Number.

Posted: Mon Nov 14, 2011 3:12 am
by amit_singh
Hi , I am new to scripting I am looking for a batch script to take input from a test file(Names.txt) having names & last names and converting each names & last names "alphabets" to its predefined below shown "numeric" value and then adding this numeric value to finally get ONE digit numeric value.
To make it more clear I would like to explain with an example .The Mapping between "Alphabets" & "Number" which I'll be using is as below.
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u","v", "w", "x", "y", "z""1", "2", "3", "4", "5", "8", "3", "5", "1", "1", "2", "3", "4", "5", "7", "8", "1", "2", "3", "4", "6", "6", "6", "5", "1","7"
Rozer Gorth =>Equivalent Numeric value: 2775237245 ==>Individually adding each number(2+7+7+5+2+3+7+2+4+5): 44 ==> Final ONE numeric digit(4+4): 8 Jimy Dacy =>Equivalent Numeric value: 11414131 ==>Individually adding each number(1+1+4+1+4+1+3+1): 16 ==>Final ONE numeric digit(1+6): 7Peter Pace =>Equivalent Numeric value: 854522135 ==>Individually adding each number(8+5+4+5+2+2+1+3+5): 35 ==>Final ONE numeric digit(3+5): 8
So result will be dumped into another file(Result.txt) as
Rozer Gorth : 8Jimy Dacy : 7Peter Pace : 8
I shall be very thankful for any suggestion and help.

Adding Numbers to get a single Number.

Posted: Mon Nov 14, 2011 3:39 pm
by amit_singh
HI Jvierra,

This below script was helped and provided by one fellow person which is adding all Number individually to get ONE final digit....If you can modify the below script to additionally do a lookup for each "Alphabet" for its corresponding "Number" and then Run the below code to get ONE final digit.


@echo offFor /f "usebackq tokens=*" %%* in ( "figures.txt") do Call :MyBatch %%~*pausegoto :EOF----------------------------------------------------------------:numsIf "%No$:~0,1%" GEQ "0" ( set /a cnt=%cnt% + %No$:~0,1% Set "No$=%No$:~1%" goto:nums )Set /a No$=%cnt%Set "Cnt="exit /b 0----------------------------------------------------------------:MyBatch * * * * * * * *Set /a figure = %~1Set /a Cnt = 0Set /a No$ = %figure%:loopCall:numsIf "%No$:~1%" GEQ "0" goto:loopecho The result of %figure% is: %No$%rem pause