Re: Adding digits together
- From: "Bill Marriott" <wjm@xxxxxxx>
- Date: Sat, 5 Nov 2005 00:52:15 -0500
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@xxxxxxxxxx> wrote in message
news:MPG.1dd5d80f300d9e11989da9@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
> In article <LImdnVKtRZ1sqPHenZ2dnUVZ_tKdnZ2d@xxxxxxxxxxx>, wjm@xxxxxxx
> 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
.
- References:
- Adding digits together
- From: Thomas Hansen
- Re: Adding digits together
- From: Matt Wills
- Re: Adding digits together
- From: Bill Marriott
- Adding digits together
- Prev by Date: Re: Sending pdf
- Next by Date: Re: Sending pdf (Empathy + Workaround)
- Previous by thread: Re: Adding digits together
- Next by thread: Re: Adding digits together
- Index(es):
Relevant Pages
|