Comment Comment by morazow How would you rate this solution? Assuming we have static keypad grid. long moves(int start = 1, int len) { assert(len > 0); long[] cur = new long[10]; for (int i = 0; i < 10; i++) { cur[i] = 1; } long[] nxt = new long[10]; while (len-- > 0) { nxt[0] = cur[4] + cur[6]; nxt[1] = cur[8] + cur[6]; nxt[2] = cur[7] + cur[9]; nxt[3] = cur[4] + cur[8]; nxt[4] = cur[3] + cur[9] + cur[0]; nxt[5] = 0; nxt[6] = cur[1] + cur[7] + cur[0]; nxt[7] = cur[2] + cur[6]; nxt[8] = cur[1] + cur[3]; nxt[9] = cur[4] + cur[2]; for (int i = 0; i < 10; i++) { cur[i] = nxt[i]; } } return cur[start]; } parent morazow 8 years ago