Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Umm... or, I could just rotate a square a quarter-turn by iterating over the square's elements:

for (x = 0; x < N; x ++) { for (y = 0; y < N; y ++) { newSquare[x][y] = oldSquare[y][N-1-x]; } }

Of course, in certain representations of the square (such as using a 1-d array) even simpler algorithms can be used.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: