Re: A list of numbers without "73"

*To*: mathgroup at smc.vnet.net*Subject*: [mg63027] Re: A list of numbers without "73"*From*: Peter Pein <petsie at dordos.net>*Date*: Sun, 11 Dec 2005 04:56:52 -0500 (EST)*References*: <dnee1r$1ep$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Thomas Schmelzer schrieb: > 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, it seems to be more efficient to construct only numbers without the sequence 73 instead of testing already existing ones: s2[1] = Range[1, 9]; s2[i_] := Flatten[(10*#1 + If[Mod[#1, 10] == 7, {0, 1, 2, 4, 5, 6, 7, 8, 9}, Range[0, 9]] & ) /@ s2[i - 1]] Timing[Length[#1[6]]]& /@ {S, s2} --> {{7.765*Second, 854569}, {0.953*Second, 854569}} Ceers, Peter