|
[Date Index]
[Thread Index]
[Author Index]
Re: A list of numbers without "73"
- To: mathgroup at smc.vnet.net
- Subject: [mg63043] Re: A list of numbers without "73"
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Sun, 11 Dec 2005 22:25:17 -0500 (EST)
- Organization: The Open University, Milton Keynes, UK
- References: <dnee1r$1ep$1@smc.vnet.net> <dngtq5$mvu$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Thomas Schmelzer wrote:
> I forgot to say that S(i) is a list of positive integers with i digits.
> Best,
> Thomas
>
> "Thomas Schmelzer" <thomas.??? at balliol.ox.ac.uk> schrieb im Newsbeitrag
> news:dnee1r$1ep$1 at smc.vnet.net...
>
>>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,
You could try a combination of *DeleteCases* and *IntegerDigits* as in
In[1]:=
s[n_]:=FromDigits/@DeleteCases[IntegerDigits/@Range[10^(n-1),
10^n-1], {___,7,3,___}]
In[2]:=
s[6]//Short//Timing
Out[2]=
{19.828 Second,{100000,100001,
100002,100003,100004,100005,100006,100007,100008,\[LeftSkeleton]854551\
\[RightSkeleton],999991,999992,999993,999994,999995,999996,999997,999998,\
999999}}
In[3]:=
Complement[Range[10^5,10^6-1],s[6]]//Short
Out[3]//Short=
{100073,100173,100273,100373,100473,100573,100673,100730,100731,\
\[LeftSkeleton]45413\[RightSkeleton],999734,999735,999736,999737,999738,\
999739,999773,999873,999973}
In[4]:=
$Version
Out[4]=
5.2 for Microsoft Windows (June 20, 2005)
(Tested on a Pentium IV 2.6 GHz, 512 Mo)
Best regards,
/J.M.
Prev by Date:
Re: Simple task with Mathematica
Next by Date:
Re: Simple task with Mathematica
Previous by thread:
Re: A list of numbers without "73"
Next by thread:
A more syntactically compact way?
|