Skip to content

Instantly share code, notes, and snippets.

@alwarren
Last active May 19, 2019 22:01
Show Gist options
  • Save alwarren/40d928754f09a8e1c9ec38f6a32aa714 to your computer and use it in GitHub Desktop.
Save alwarren/40d928754f09a8e1c9ec38f6a32aa714 to your computer and use it in GitHub Desktop.
A simple Java challenge in Cartesian space.

A simple Java challenge. This really stumped me the first time I ran across it. I made it work but looking at the code made absolutley no sense. Give it a try and let me know how you do.

Consider the following values:

 8  1  3 
 4  0  2 
 7  6  5 
  1. Store the values in a two-dimensional array of int.
  2. Move the 0 up by modifying a single index and swapping two values.
  3. Print the result.
 8  0  3 
 4  1  2 
 7  6  5 

Rules.

  1. You may only use Java.
  2. You may only use a single array of type int[][].
  3. All intermediate variables must be int.
  4. You may only use the operators +, -, =, ++, --, or ==.
  5. You may not use any libraries other that System.out to print a result.

Question. Did you get it the first try?

Hint. There is an important distinction between values of a 2D array and cartesian space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment