Approach

Written by Isaiah Iliffe from CSESoc Education

A very short solution involves keeping track of xx, the number Joseph's finger is currently over, initially 1, and treating each character as follows:

  • L: decrement xx by 1.
  • R: increment xx by 1.
  • U: decrement xx by 3.
  • D: increment xx by 3.
  • P: print the digit xx.

Alternatively, a 2D array representing the keypad will do the trick.