Re: A list of numbers without "73"
- To: mathgroup at smc.vnet.net
- Subject: [mg63023] Re: [mg63005] A list of numbers without "73"
- From: gardyloo <gardyloo at mail.wsu.edu>
- Date: Sun, 11 Dec 2005 04:56:45 -0500 (EST)
- References: <200512101103.GAA29418@smc.vnet.net> <439B2238.8040208@mail.wsu.edu>
- Sender: owner-wri-mathgroup at wolfram.com
gardyloo wrote:
>Thomas Schmelzer wrote:
>
>
>
>>Experts,
>>
>>S(i) should be a list of positive integers without the substring "73".
>>
>>My code seems to be very inefficient. I multiply all numbers with 0 if they
>>contain "73", sort the new list, make the union (remove double elements) and
>>delete the first element. Therefore it is necessary to use an if statement
>>in order not to delete the first element of the numbers 1-9. Any more
>>sophisticated ideas?
>>
>>L := Table[k, {k, 1, 9}]
>>
>>S[i_] := S[i] =
>>If[i == 1, L,
>>Delete[Union[
>>Table[k*(1 - Boole[StringMatchQ[ToString[k], "*73*"]]), {k,
>>10^(i - 1), 10^i - 1}]], 1]]
>>
>>
>>
>>Best
>>
>>Thomas
>>
>>
>>
>
> Hi, Thomas,
>
> I don't know about the timing issues inherent with using Select
>(does it check _each_ member of its enclosed list; might, perhaps, an if
>statement for the power "i" used in Range be more efficient? I'm too
>lazy to do rigorous checks), but this should work for you:
>
>S[i_] := Select[Range[10^(i - 1), 10^i - 1], #1 != 73 & ]
>
>
>In[32]:=
>$Version
>
>Out[32]=
>5.2 for Linux (June 20, 2005)
>
>
> Best of luck,
> C.O.
>
OK, so I'm not quite that lazy. A quick logarithmic regression on
fresh kernels gives the evaluation time for your function of roughly
time(i) ~ Exp[-11.54+2.273 *i], in seconds.
My (unrefined) function seems to be roughly 10x as fast (for
exponents -- or values of i -- around 2 to 5), to around 7.5x as fast
(for values of i around 8) , probably due to not having to do
string-matching stuff.
Regards,
C.O.
- References:
- A list of numbers without "73"
- From: "Thomas Schmelzer" <thomas.???@balliol.ox.ac.uk>
- A list of numbers without "73"