Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. Good pairs: || Bad pairs:
  2. ________________||________________
  3. 101 | 000 | 012 || 111 | 012 | 002
  4. 212 | 111 | 112 || 122 | 120 | 022
  5. 020 | 222 | 212 || 120 | 202 | 102
  6.  
  7. 00
  8. 10
  9. 11
  10. --
  11. 21 % 3 == 0
  12.  
  13. //The 3 numbers are originally decimal numbers
  14. private static boolean ternary(int a, int b, int c)
  15. {
  16. //Convert each number to a ternary number, add them and assign the result to a string
  17. //This is the best base conversion code I was able to find using native java
  18. String ternary = Integer.toString(Integer.parseInt(Integer.toString(a, 3))
  19. + Integer.parseInt(Integer.toString(b, 3))
  20. + Integer.parseInt(Integer.toString(c, 3)));
  21.  
  22. //For each digit in the number, check if it is divisible by 3. If not, return false
  23. for (int i = 0; i < ternary.length(); i++)
  24. if (Integer.parseInt(ternary.charAt(i) + "") % 3 != 0)
  25. return false;
  26. //If all the numbers passed the test, return true
  27. return true;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement