Created
December 26, 2013 00:36
-
-
Save unixpickle/8128312 to your computer and use it in GitHub Desktop.
500th Video Contest Solution
This file contains hidden or 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
| class Solve { | |
| public static int parseInt(char a) { | |
| int num = (int)a; | |
| if (num < (int)'0' || num > (int)'9') { | |
| throw new RuntimeException("Parse error"); | |
| } | |
| return num - (int)'0'; | |
| } | |
| public static boolean is_solution(String key) { | |
| if (key.length() != 11) return false; | |
| int a = parseInt(key.charAt(0)); | |
| int b = parseInt(key.charAt(1)); | |
| int c = parseInt(key.charAt(2)); | |
| int d = parseInt(key.charAt(3)); | |
| int e = parseInt(key.charAt(4)); | |
| int f = parseInt(key.charAt(5)); | |
| int g = parseInt(key.charAt(6)); | |
| int h = parseInt(key.charAt(7)); | |
| int i = parseInt(key.charAt(8)); | |
| int j = parseInt(key.charAt(9)); | |
| int k = parseInt(key.charAt(10)); | |
| try { | |
| if (j / b != f) return false; | |
| if (c / i != b) return false; | |
| if (d / e != a) return false; | |
| if (h / e != b) return false; | |
| if (b % c != e) return false; | |
| if (f % d != j / d) return false; | |
| if (k % i != j) return false; | |
| if (k % d != a * b) return false; | |
| if (e - g != i) return false; | |
| if (d - g != c) return false; | |
| if (k + a != d) return false; | |
| if (a * b != e * i) return false; | |
| } catch (ArithmeticException ex) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| public static void main(String[] args) { | |
| // this would greatly benefit from recursion or more mathematical reasoning | |
| for (int a = 0; a < 10; a++) { | |
| for (int b = 0; b < 10; b++) { | |
| for (int c = 1; c < 10; c++) { | |
| for (int d = 0; d < 10; d++) { | |
| for (int e = 1; e < 10; e++) { | |
| if (d / e != a) continue; | |
| if (b % c != e) continue; | |
| for (int f = 0; f < 10; f++) { | |
| for (int g = 0; g < 10; g++) { | |
| if (d - g != c) continue; | |
| for (int h = 0; h < 10; h++) { | |
| for (int i = 0; i < 10; i++) { | |
| for (int j = 0; j < 10; j++) { | |
| for (int k = 0; k < 10; k++) { | |
| String s = "" + a + b + c + d + e + f + g + h + i + j + k; | |
| if (is_solution(s)) { | |
| System.out.println(s); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment