Group Abstract Group Abstract

Message Boards Message Boards

Have the number of double digits, triples ... of any real number

POSTED BY: Claudio Chaib
3 Replies
POSTED BY: Claudio Chaib

Use of simple loops e.g. with Table would make this code more or less comprehensible. Something along the lines below. It counts repeats for each length requested, 2 through n, and also totals the count for each such length.

repeatCounts[val_, len_, n_] := Module[
  {digits, splits},
  digits = RealDigits[N[val, len]][[1]];
  Table[
   splits = Partition[digits, j, 1];
   repeats = Table[Count[splits, {k ..}], {k, 0, 9}];
   {Total[repeats], repeats}
   , {j, 2, n}]
  ]

Example:

Timing[repeatCounts[Pi, 10000000, 11]]

(* Out[468]= {266.4, {{1000191, {99662, 99675, 99931, 100555, 99915, 100490, 99905, 100208, 99781, 100069}}, {99489, {9877, 9828, 9983, 10035, 9781, 10163, 9831, 9978, 9848, 10165}}, {9799, {902, 1005, 980, 964, 923, 1031, 978, 1036, 946, 1034}}, {994, {89, 103, 89, 93, 92, 105, 103, 115, 100, 105}}, {117, {6, 10, 9, 9, 9, 12, 11, 15, 19, 17}}, {15, {1, 1, 0, 2, 0, 2, 1, 2, 2, 4}}, {0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, {0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, {0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, {0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}}} *)

I'm sure the above could be made more memory efficient though possibly at the expense of speed.

POSTED BY: Daniel Lichtblau

At the end of the code where you have y you can place digits to have the ratio of the absolute value when you do the evaluation.

POSTED BY: Claudio Chaib
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard