Created
August 29, 2018 08:54
-
-
Save joriki/e350cd7bf87a144626a167b572a4058d to your computer and use it in GitHub Desktop.
Estimate the probability for a number with independently uniformly randomly chosen decimal digits to appear periodic at some point; see https://math.stackexchange.com/questions/2898079.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Question2898079 { | |
public static void main (String [] args) { | |
long count = 0; | |
long power = 1; | |
for (int n = 1;;n++) { | |
power *= 10; | |
outer: | |
for (long k = 0;k < power;k++) { | |
String s = String.valueOf (k); | |
while (s.length () < n) | |
s = '0' + s; | |
s += s; | |
for (int i = 1;i < n;i++) | |
if (s.substring (0,i).equals (s.substring (i,2 * i))) | |
continue outer; | |
count++; | |
} | |
System.out.println (n + " : " + count + " : " + count / (double) (power * power)); | |
count *= 100; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment