Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Find count of binary number pattern within concatenated

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91135] Re: [mg91093] Find count of binary number pattern within concatenated
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Thu, 7 Aug 2008 04:39:16 -0400 (EDT)
  • References: <200808060903.FAA22227@smc.vnet.net>

Diana wrote:
> Math folks,
> 
> Can someone tell me how to find the count of the occurrences of "1101"
> within "11011100101110111100010011010101111001101" generated with the
> FromDigits statements below? I will be increasing "n".
> 
> n=13
> 
> FromDigits[Flatten[IntegerDigits[Range[n],2]]]
> 
> 11011100101110111100010011010101111001101.
> 
> FromDigits[IntegerDigits[n, 2]]
> 
> 1101
> 
> Diana

I'd go with not using FromDigits. Instead partition the concatenated 
list of digits, with offset of 1 and length of the number of digits in 
n. Then call on the Count (the Mathematica function, not Dracula).

countValInRangeVal[n_,base_] := Module[
   {digits=IntegerDigits[n,base], alldigits},
   alldigits = Flatten[IntegerDigits[Range[n],base]];
   Count[Partition[alldigits,Length[digits],1], digits]
   ]

If you are fond of long one liners:

countValInRangeVal2[n_,base_] := Count[Partition[Flatten[
   IntegerDigits[Range[n],base]],Length[#],1],#]& [IntegerDigits[n,base]]

Other long one-liners might include

http://en.wikipedia.org/wiki/Long_line_(topology)

or perhaps the final sentence of Joyce's "Ulysses".

Daniel Lichtblau
Wolfram Research


  • Prev by Date: Re: Re: Simplify
  • Next by Date: Mathematica and Mathieu DEQ Results?
  • Previous by thread: Re: Find count of binary number pattern within concatenated number
  • Next by thread: Re: Find count of binary number pattern within concatenated number