|
[Date Index]
[Thread Index]
[Author Index]
Re: challenge problem
- To: mathgroup at smc.vnet.net
- Subject: [mg61259] Re: [mg61219] challenge problem
- From: Sseziwa Mukasa <mukasa at jeol.com>
- Date: Fri, 14 Oct 2005 05:53:50 -0400 (EDT)
- References: <200510130539.BAA04503@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On Oct 13, 2005, at 1:39 AM, Murray Eisenberg wrote:
> At http://www.itasoftware.com/careers/eng/job1.php, there are a number
> of interestng programming problems posed. One, the "Lucky Sevens", is
> to write a program that will find the sum of all those integers
> between
> 1 and 10^11 that are divisible by 7 AND whose reversed-digit forms are
> also divisible by 7.
>
> I should think that an elegant and possibly efficient solution in
> Mathematica would be to use the form func /@ Range[10^11]. But since
> Mathematica 5.2 on my my 32-bit Windows machine won't let me form
> Range[10^11], a 64-bit architecture would seem to be required.
64 bits would help but I don't think func/@Range[10^11] is
efficient. First of all we know that we are only interested in the
values in the list Range[7,10^11,7] but the largest problem is that
we are only interested in the sum of the values that meet the
condition, not the list of values themselves. So creating the list
explicitly, or even worse a larger list that contains the potentially
much smaller list of values we are interested in is not an efficient
use of memory.
As a first pass I'd probably use something like
Sum[With[{t=FromDigits[Reverse[IntegerDigits[i]]]},If[Mod[t,7]==0,i,
0]],{i,7,10^11,7}]
This actually has problems doing the sum for 10^7, as does using NSum
so this may be a case where an explicit For loop is preferred in
Mathematica. I tested this expression for 10^7 and it seems to work:
For[s = 0; i = 7, i < 10^7, i += 7,
s += With[{t = FromDigits[Reverse[IntegerDigits[i]]]},
If[Mod[t, 7] == 0, i, 0]]];s
I am not willing to wait to see if it works to 10^11.
Regards,
Ssezi
Prev by Date:
Re: Shadowing of symbols in a package
Next by Date:
Re: TagSet and the listability of Plus[ ]
Previous by thread:
Re: challenge problem
Next by thread:
Re: challenge problem
|