Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Good pairs: || Bad pairs:
- ________________||________________
- 101 | 000 | 012 || 111 | 012 | 002
- 212 | 111 | 112 || 122 | 120 | 022
- 020 | 222 | 212 || 120 | 202 | 102
- 00
- 10
- 11
- --
- 21 % 3 == 0
- //The 3 numbers are originally decimal numbers
- private static boolean ternary(int a, int b, int c)
- {
- //Convert each number to a ternary number, add them and assign the result to a string
- //This is the best base conversion code I was able to find using native java
- String ternary = Integer.toString(Integer.parseInt(Integer.toString(a, 3))
- + Integer.parseInt(Integer.toString(b, 3))
- + Integer.parseInt(Integer.toString(c, 3)));
- //For each digit in the number, check if it is divisible by 3. If not, return false
- for (int i = 0; i < ternary.length(); i++)
- if (Integer.parseInt(ternary.charAt(i) + "") % 3 != 0)
- return false;
- //If all the numbers passed the test, return true
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement