Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Impl.
- var p=parseInt;
- function m(d, i, l, c) {
- if (c>=l*l) return i;
- var x=[d<5?c%l:l-1-c%l,d<5?l-1-p(c/l):p(c/l),i[p(c/l)][c%l],m(d,i,l,c+1)];
- x[3][x[0]][x[1]]=x[2];
- return x[3];
- }
- // Demo
- print( // Pretty print matrix
- m( // "Move"-function
- 0, // Zero-based day of week (0 = monday ..)
- [ // Input matrix
- [ 1, 2, 3, 4, 5, 6],
- [ 7, 8, 9,10,11,12],
- [13,14,15,16,17,18],
- [19,20,21,22,23,24],
- [25,26,27,28,29,30],
- [31,32,33,34,35,36]
- ],
- 6, // N size of matrix
- 0 // Counter, init at 0
- )
- );
- // Pretty print
- function print(arr) {
- for (var i = 0; i < arr.length; i++) {
- console.log('');
- for (var j = 0; j < arr[i].length; j++)
- process.stdout.write(" "+arr[i][j]);
- }
- console.log('');
- console.log('');
- }
- // Output
- // 31 25 19 13 7 1
- // 32 26 20 14 8 2
- // 33 27 21 15 9 3
- // 34 28 22 16 10 4
- // 35 29 23 17 11 5
- // 36 30 24 18 12 6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement