Skip to content

Instantly share code, notes, and snippets.

@LuxXx
Created April 21, 2017 23:23
Show Gist options
  • Save LuxXx/5e6185db7bbeb499c2058171f7f8df79 to your computer and use it in GitHub Desktop.
Save LuxXx/5e6185db7bbeb499c2058171f7f8df79 to your computer and use it in GitHub Desktop.
Project Euler - Problem 40
public class Champernowne {
private static String num = null;
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 1_000_000; i++) {
sb.append(String.valueOf(i));
if (i == 0) sb.append('.');
}
num = sb.toString();
int n = d(1);
for (int i = 1; i < 7; i++) {
int pow = (int) Math.pow(10, i);
n *= d(pow);
}
System.out.println(n);
}
public static int d(int n) {
if (num == null) throw new Error("num is null");
return num.charAt(n + 1) - 48;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment