Skip to content

Instantly share code, notes, and snippets.

@joriki
Created August 29, 2018 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joriki/e350cd7bf87a144626a167b572a4058d to your computer and use it in GitHub Desktop.
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.
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