Guest User

Untitled

a guest
Jun 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. public static void createArray(int rowsCount, int columnsCount) {
  2. int rowStep = 0;
  3. for (int rowIndex = 0; rowIndex < rowsCount; rowIndex++) {
  4. if (Math.pow(2, rowStep + 1) <= rowIndex) {
  5. rowStep++;
  6. }
  7. int columnStep = 0;
  8. for (int columnIndex = 0; columnIndex < columnsCount; columnIndex++) {
  9. if (Math.pow(2, columnStep + 1) <= columnIndex) {
  10. columnStep++;
  11. }
  12. int value = 0;
  13. int maxStep = Math.max(rowStep, columnStep);
  14. for (int stepIndex = 0; stepIndex <= maxStep; stepIndex++) {
  15. int stepPow = (int) Math.pow(2, stepIndex);
  16. int checkRow = (rowIndex / stepPow) % 2;
  17. int checkColumn = (columnIndex / stepPow) % 2;
  18. if (checkRow != checkColumn) {
  19. value += stepPow;
  20. }
  21. }
  22. System.out.print(value + "\t");
  23. }
  24. System.out.println();
  25. }
  26. }
Add Comment
Please, Sign In to add comment