Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Digit Density

by termix (Beadle)
on Dec 27, 2001 at 19:22 UTC ( #134608=sourcecode: print w/replies, xml ) Need Help??
Category: Miscellaneous
Author/Contact Info Termix

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.

#basically read all the input, separate the digits, and
#then figure out how many of each are there.

#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";

$_=join '', <>;
print join("\n", map({ $m++.' -->'.(('*')x(($_/$c)*100));}  @p))."\n";

# use with bc as 
# echo "space 20;sqrt(2)" | bc -lq |
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://134608]
[Corion]: Yeah, I just did su -; perl -wle "print getlogin" and it still printed corion
LanX YT auto-caption: "The Uk sends a breakfast negotiator to brothels"
[tye]: cool. For some reason I couldn't remember it nor come up with a good search strategy (other than crowd sourcing).
[davido]: hm, that seems to also survive $< manipulations @corion so good call.
[Corion]: tye: I also more randomly stumbled over it, as "who am i" unix implementation didn't really provide much help. But Wikipedia linked me to the List of Unix Programs (or something like it), and from there ...
[talexb]: Wasn't Brexit the name of the first Santana album?
[tye]: That's funny, saying getlogin() is less secure. For some uses, it is far superior to getpwuid(), precisely for reasons of security.
[LanX]: search strategy => Perl Functions by Category
[Corion]: ... I found discussion of the who utility and that it uses the POSIX 2008 getlogin function (but that function was available much earlier and thus even exists in Perl, as a search for getlogin on CPAN brought up Perl 5.26 as first hit
[tye]: oh, LanX, but I was thinking that it was not a function that Perl provided.

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2017-06-23 18:49 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (554 votes). Check out past polls.