Re: A list of numbers without "73"
- To: mathgroup at smc.vnet.net
- Subject: [mg63010] Re: [mg63005] A list of numbers without "73"
- From: "Carl K. Woll" <carlw at wolfram.com>
- Date: Sun, 11 Dec 2005 04:56:32 -0500 (EST)
- References: <200512101103.GAA29418@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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]]
>
A simpler approach is to use Pick:
S[i_] := Module[{rng = Range[10^(i - 1), 10^i - 1]},
Pick[rng, StringMatchQ[ToString /@ rng, "*73*"], False]]
This version seems to be about 2.5 times faster. Most of the time is
taken up in using ToString to convert the numbers into strings.
Carl Woll
Wolfram Research
>
>
> Best
>
> Thomas
>
>
>
- References:
- A list of numbers without "73"
- From: "Thomas Schmelzer" <thomas.???@balliol.ox.ac.uk>
- A list of numbers without "73"