dbTalk Databases Forums  

Adding digits together

comp.databases.filemaker comp.databases.filemaker


Discuss Adding digits together in the comp.databases.filemaker forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Bill Marriott
 
Posts: n/a

Default Re: Adding digits together - 11-04-2005 , 10:32 PM






The sum of digits is used in a variety of mathematical proofs, theorems, and
games. For example, to determine is a number is divisible by 9. When you
have some spare time, do a Google search on "sum of digits" for some
interesting exercises.

The hard part of the problem seems to be the idea that there could be an
arbitrary number of digits in the source number. This leads many to think
that FileMaker Developer, a recursive function or some kind of script is
required. Such is not the case.

Given n, a text field, containing an integer with an arbitrary number of
digits

Evaluate (
Substitute (n;
["0";"0+"];
["1";"1+"];
["2";"2+"];
["3";"3+"];
["4";"4+"];
["5";"5+"];
["6";"6+"];
["7";"7+"];
["8";"8+"];
["9";"9+"]) & "0")

Will return the sum of those digits.

Enjoy,

Bill

"Matt Wills" <I'm (AT) Witz (DOT) end> wrote

Quote:
Thomas Hansen wrote on (11/4/2005):

Is there an easy way to add the digits in a number together in
Filemaker, ie. add the digits of the number 12 and get 3 as a result? Or
do I have to do this manually, using middle(number; 1; 1) +
middle(number; 2; 1)?

I can't speak for FM designers, but I personally can't think of any
mathematical basis for doing that.

Unless someone else has some obscure numerical name for the process, I
would have to say that your text parsing solution is your best bet.

Matt




Reply With Quote
  #12  
Old   
42
 
Posts: n/a

Default Re: Adding digits together - 11-04-2005 , 10:42 PM






In article <LImdnVKtRZ1sqPHenZ2dnUVZ_tKdnZ2d (AT) comcast (DOT) com>, wjm (AT) wjm (DOT) org
says...
Quote:
The sum of digits is used in a variety of mathematical proofs, theorems, and
games. For example, to determine is a number is divisible by 9. When you
have some spare time, do a Google search on "sum of digits" for some
interesting exercises.

The hard part of the problem seems to be the idea that there could be an
arbitrary number of digits in the source number. This leads many to think
that FileMaker Developer, a recursive function or some kind of script is
required. Such is not the case.

Given n, a text field, containing an integer with an arbitrary number of
digits

Evaluate (
Substitute (n;
["0";"0+"];
["1";"1+"];
["2";"2+"];
["3";"3+"];
["4";"4+"];
["5";"5+"];
["6";"6+"];
["7";"7+"];
["8";"8+"];
["9";"9+"]) & "0")

Will return the sum of those digits.

Enjoy,

Bill
Cool solution, Bill.

Although I think the notion of recusion wasn't on an arbitrary number of
digits, it was on the idea that you might have to perform the addition
an arbitrary number of times until you just had one digit. (although the
mod9 solution dodges that)

-regards,
Dave


Reply With Quote
  #13  
Old   
Bill Marriott
 
Posts: n/a

Default Re: Adding digits together - 11-04-2005 , 11:52 PM



The original poster never did mention if he needed to keep going...

....and the mod 9 answer is quite limited in the scope. It will not handle
the case where he does not want to keep going, and it will not reveal the
intermediate values, should those be desired.

I might also mention, the example from Brian Dunning was taking multiple
values and reducing them to one, not taking one value and expanding it to
multiple iterations -- which is a far more difficult problem. For example:

987987987987987987987
168
15
6

Is three iterations. This cannot be produced by the particular method
Dunning used.

However, we're in luck! For there to be more than three iterations, the
source number would have to exceed

999,999,999,999,999,999,999,999,999,999,999,
999,999,999,999,999,999,999,999,999,999,999,
999,999,999,999,999,999,999,999,999,999,999,
999,999,999,999

....In other words, 1e+111 or greater!

If this is really what is desired then simply duplicating the field a couple
times (SumN based on N; SumSumN based on SumN; SumSumSumN based on SumSumN,
and if truly necessary, SumSumSumSumN based on SumSumSumN) should be much
more pleasant an exercise than designing the proper recursion.

Bill

"42" <nospam (AT) nospam (DOT) com> wrote

Quote:
In article <LImdnVKtRZ1sqPHenZ2dnUVZ_tKdnZ2d (AT) comcast (DOT) com>, wjm (AT) wjm (DOT) org
says...
The sum of digits is used in a variety of mathematical proofs, theorems,
and
games. For example, to determine is a number is divisible by 9. When you
have some spare time, do a Google search on "sum of digits" for some
interesting exercises.

The hard part of the problem seems to be the idea that there could be an
arbitrary number of digits in the source number. This leads many to think
that FileMaker Developer, a recursive function or some kind of script is
required. Such is not the case.

Given n, a text field, containing an integer with an arbitrary number of
digits

Evaluate (
Substitute (n;
["0";"0+"];
["1";"1+"];
["2";"2+"];
["3";"3+"];
["4";"4+"];
["5";"5+"];
["6";"6+"];
["7";"7+"];
["8";"8+"];
["9";"9+"]) & "0")

Will return the sum of those digits.

Enjoy,

Bill

Cool solution, Bill.

Although I think the notion of recusion wasn't on an arbitrary number of
digits, it was on the idea that you might have to perform the addition
an arbitrary number of times until you just had one digit. (although the
mod9 solution dodges that)

-regards,
Dave



Reply With Quote
  #14  
Old   
Thomas Hansen
 
Posts: n/a

Default Re: Adding digits together - 11-05-2005 , 02:33 AM



Thanks to all who helped. I ended up doing it manually - the number
itself was a result of a calculation and would end up with one or to
digits, so instead of checking the number of digits and then adding them
together, I was hoping there was a more elegant way in Filemaker. That
doesn't seem to be, though.


In article <GKHaf.3665$y23.2443@trndny08>, "Matt Wills" <I'm (AT) Witz (DOT) end>
wrote:

Quote:
The root "tverr" came back as "crabby, fractious, glum, moody, peevish,
sulky, sullen"
Heh. :-) I guess that would be a correct translation for one meaning of
the word. However, this version of "tverr" comes from the word "tvers",
meaning something like "across". Thus, "tverrsum" would translate into
something like "sum across" (across the number, that is).

Discussion to follow in comp.databases.filemaker.learningnorwegian :-)

--
Thomas Hansen : th(at)ambolt.no : http://www.ambolt.no/


Reply With Quote
  #15  
Old   
Bill Marriott
 
Posts: n/a

Default Re: Adding digits together - 11-05-2005 , 03:44 AM



Elegant (adj.): Of such tasteful beauty as to elicit admiration

How can you say there is no elegant way to do this?

If it is impossible to have more than two digits, then

Evaluate(Left(Replace ( n & "0"; 2; 0; "+");3))

works beautifully. However, I submit that my Evaluate(Substitute(...))
solution is positively sublime. I don't see how it could get much better
unless you expected FileMaker to have an undocumented Tverrsum() function.

[Grrr]
Bill

"Thomas Hansen" <violon (AT) online (DOT) no> wrote

Quote:
Thanks to all who helped. I ended up doing it manually - the number
itself was a result of a calculation and would end up with one or to
digits, so instead of checking the number of digits and then adding them
together, I was hoping there was a more elegant way in Filemaker. That
doesn't seem to be, though.


In article <GKHaf.3665$y23.2443@trndny08>, "Matt Wills" <I'm (AT) Witz (DOT) end
wrote:

The root "tverr" came back as "crabby, fractious, glum, moody, peevish,
sulky, sullen"

Heh. :-) I guess that would be a correct translation for one meaning of
the word. However, this version of "tverr" comes from the word "tvers",
meaning something like "across". Thus, "tverrsum" would translate into
something like "sum across" (across the number, that is).

Discussion to follow in comp.databases.filemaker.learningnorwegian :-)

--
Thomas Hansen : th(at)ambolt.no : http://www.ambolt.no/



Reply With Quote
  #16  
Old   
Bill Marriott
 
Posts: n/a

Default Re: Adding digits together - 11-05-2005 , 04:02 AM



Actually, for 0>=n<100

Int(n/10 )+Mod(n;10)

gets the job done, as well, and doesn't require any fancy pants text
functions.

Bill

"Thomas Hansen" <violon (AT) online (DOT) no> wrote

Quote:
Thanks to all who helped. I ended up doing it manually - the number
itself was a result of a calculation and would end up with one or to
digits, so instead of checking the number of digits and then adding them
together, I was hoping there was a more elegant way in Filemaker. That
doesn't seem to be, though.


In article <GKHaf.3665$y23.2443@trndny08>, "Matt Wills" <I'm (AT) Witz (DOT) end
wrote:

The root "tverr" came back as "crabby, fractious, glum, moody, peevish,
sulky, sullen"

Heh. :-) I guess that would be a correct translation for one meaning of
the word. However, this version of "tverr" comes from the word "tvers",
meaning something like "across". Thus, "tverrsum" would translate into
something like "sum across" (across the number, that is).

Discussion to follow in comp.databases.filemaker.learningnorwegian :-)

--
Thomas Hansen : th(at)ambolt.no : http://www.ambolt.no/



Reply With Quote
  #17  
Old   
Elm Street
 
Posts: n/a

Default Re: Adding digits together - 01-04-2011 , 07:38 PM



THANK YOU X 9!!!!!!!!!

I'm not a math or programming person. Been trying to generate a repeating serial number 1-9. Pasted your solution and it worked a charm.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.