 Do you know where your variables are? PerlMonks

### Digit Density

 on Dec 27, 2001 at 19:22 UTC Need Help??
 Category: Miscellaneous Author/Contact Info Termix Description: What happens when you have too much time on your hands and you are getting drunk on vodka with a russian mathematician? Well, you get to proving that trancendental numbers are really digit sequences of uniform distribution over the 0 to 9 range. Now that I am sober, I don't understand much of the reason behind all that, but this is a pretty nifty tool to print the relative density of digits in any numeric sequence. You can even use 'bc' or another arbitrary precision calculator to generate your large numbers. How can we make this obfuscated? Thanks japhy for your help. I've incorporated the smaller reader. Actually looking at your array duplication, I can further take out the inner for loop. ```#!/usr/bin/perl #script.pl #basically read all the input, separate the digits, and #then figure out how many of each are there. #@p=split(//,'0000000000'); #map (\$_ =~ s/\D//g, @x=<>); #map ( {\$p[\$_]++;\$c++} split(//,join('',@x))); #print join("\n", map({ \$l=\$m++.' -->';for (\$k=0;\$k<(\$_/\$c)*100;\$k++) +{ \$l.="*"; }; \$l; } @p))."\n"; @p=(0)x10; \$_=join '', <>; ++\$c&&\$p[\$&]++while/\d/g; print join("\n", map({ \$m++.' -->'.(('*')x((\$_/\$c)*100));} @p))."\n"; # use with bc as # echo "space 20;sqrt(2)" | bc -lq | script.pl ```
Replies are listed 'Best First'.
Re: Digit Density
by japhy (Canon) on Dec 27, 2001 at 20:58 UTC
```\$_=join'',<>;
@p=(0)x10;
\$p[\$&]++for/\d/g;
The rest is up to you. I'm just golfing the actual tallying.

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Shoot. I am missing something here. I tried your code. It loops the right number of times, but it seems to only see the last character (the first match in a greedy match). So an input of '12345' looks like '55555'.

To test I tried

```\$x="12345";
for (\$x=~ /./g) {
print \$&;
}
print "\n";

but this gives me "55555" again. I notice, I should be using a while and I try:

```\$x="12345";
while (\$x=~ /./g) {
print \$&;
}
print "\n";

which works. So I changed your code to use a while loop also and it works.

-- termix

Re: Digit Density
by ariels (Curate) on Dec 28, 2001 at 18:21 UTC
Your assumptions about digit distribution of transcendental numbers are incorrect. There are 2 separate concepts: Transcendental numbers are number like e and π and a=10^-(1!)+10^-(2!)+10^-(3!)+10^-(4!)+... which are not roots of equations with rational coefficients. Normal numbers are numbers (like 0.12345678910111213141516..., although that is hard to prove!) that have every finite sequence of digits (either in their base-10 representation (or some other base) or, if you take the stronger more common definition, in all bases) appearing at the "appropriate" frequency.

It is not known whether π is normal. (See my writeup on Everything2 for details and more links). It is known that many transcendental numbers are not normal. For instance, the number a above cannot be normal, as the only digits appearing in its decimal representation are 0 and 1.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://134608]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2023-01-30 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?