Guest User

Untitled

a guest
Oct 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. entryArray = [[1, 2, 3, 4], [12, 13, 14, 5], [11, 16, 15, 6], [10, 9, 8, 7]]
  2.  
  3. exitArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
  4.  
  5. f=lambda m:m.pop(0)+f([list(x)for x in zip(*m)][::-1])if m else m
  6.  
  7. let f=e=>{let t=[],f=r=0,h=-1,n=l=e[0].length;for(;n;)f?f<2?r++:f<3?h--:r--:h++,t.push(e[r][h]),--l||(f%2||n--,f=++f%4,l=n);return t}
  8.  
  9. def f(a):return list(a[0])+f(zip(*a[1:])[::-1])if a else []
  10.  
  11. def f(a) a.empty? ? [] : a.shift+f(a.transpose.reverse) end
  12.  
  13. int f(int n,int a[][n],int*b){int d=0,j=0,k=0,s=0,m=n-1,f=0;for(int i=0;i<n*n;i++,s++){if(s==m){d++,d%=4,s=0,f++;if(f%3==0)m--,f=1;}b[i]=!d?a[j][k++]:d==1?a[j++][k]:d==2?a[j][k--]:a[j--][k];}}
  14.  
  15. int f(int n,int a[][n],int *b){static int d,j,k,s,f,i;int m=n-1;for(;i<n*n;i++,s++){if(s==m){d++;d%=4;s=0;f++;if(f%3==0){m--;f=1;}}b[i]=!d?a[j][k++]:d==1?a[j++][k]:d==2?a[j][k--]:a[j--][k];}}
  16.  
  17. int f(int n,int a[][n],int*b){static d,j,k,s,f,i;int m=n-1;for(;i<n*n;i++,s++)s==m?d++,d%=4,s=0,f++,f%3==0?m--,f=1:m:m,b[i]=!d?a[j][k++]:d==1?a[j++][k]:d==2?a[j][k--]:a[j--][k];}
  18.  
  19. function f(a){for(var b=[];a.length;)b.push(...a.shift()),a.map(c=>b.push(c.pop())),a.reverse().map(c=>c.reverse());return b}
  20.  
  21. #define c(i,j) )std::cout<<m[i][j]<<" ";
  22. using M=std::vector<std::vector<int>>;void s(M&m,int h){int i,n=m.size(),k=n-h-1;if(n>2*h){for(i=h;i<=k;c(h,i++)for(i=h+1;i<=k;c(i++,k)for(i=k-1;i>=h;c(k,i--)for(i=k-1;i>h;c(i--,h)s(m,h+1);}}
  23.  
  24. using namespace std;
  25.  
  26. #define c(i,j) )v.push_back(m[i][j]);
  27. using V=std::vector<int>;
  28. using M=std::vector<V>;void s(M&m,V&v,int h){int i,n=m.size(),k=n-h-1;if(n>2*h){for(i=h;i<=k;c(h,i++)for(i=h+1;i<=k;c(i++,k)for(i=k-1;i>=h;c(k,i--)for(i=k-1;i>h;c(i--,h)s(m,v,h+1);}}
  29.  
  30. #define c(k,r,c) for(i=0;i<k;++i)v.push_back(m[r][c]);
  31. using V=std::vector<int>;void s(std::vector<V>&m,V&v,int h){int r=h,c=h,i,n=m.size(),k=n-2*h-1;if(!k)c(1,r,c)else if(k>0){c(k,r,c++)c(k,r++,c)c(k,r,c--)c(k,r--,c)s(m,v,h+1);}}
  32.  
  33. function g(n,u){b.push(a[n][u]),a[n][u]=null,!a[n][u+1]||0!=n&&a[n-1][u]||g(n,++u),a[n+1]&&a[n+1][u]&&g(++n,u),a[n][u-1]&&g(n,--u),0<n&&a[n-1][u]&&g(--n,u)}
  34.  
  35. a=[[1, 2, 3, 4], [12, 13, 14, 5], [11, 16, 15, 6], [10, 9, 8, 7]]
  36. b=[]
  37. g(0,0);
  38.  
  39. //Implementation
  40. function Position(x, y) {
  41. this.x = x;
  42. this.y = y;
  43. }
  44.  
  45. function getArray(array) {
  46. var res = [];
  47. var position = getNext(0, -1);
  48. while (position) {
  49. res.push(array[position.x][position.y]);
  50. array[position.x][position.y] = undefined;
  51. position = getNext(position.x, position.y);
  52. }
  53. return res;
  54.  
  55. function getNext(x, y) {
  56. if (array[x][y + 1] && (!array[x - 1] || !array[x - 1][y])) return new Position(x, y + 1);
  57. if (array[x + 1] && array[x + 1][y]) return new Position(x + 1, y);
  58. if (array[x][y - 1]) return new Position(x, y - 1);
  59. if (array[x - 1] && array[x - 1][y]) return new Position(x - 1, y);
  60. return undefined;
  61. }
  62. }
  63.  
  64. //Example
  65. var entryArray = [[1, 2, 3, 4], [12, 13, 14, 5], [11, 16, 15, 6], [10, 9, 8, 7]]
  66. var result = getArray(entryArray);
  67.  
  68. function z(b){var c=b.length;if(0==c)return[];if(1==c)return b[0];var d=b[0].slice(0,-1),e=b.slice(0,-1).map(i=>i[c-1]),f=b[c-1].slice(1).reverse(),g=b.slice(1).map(i=>i[0]).reverse(),h=b.slice(1,-1).map(i=>i.slice(1,-1));return[].concat(d,e,f,g,z(h))}
  69.  
  70. void Spiral(int[,]a){int n=a.GetLength(0);int c=n;int v=-n;int s=-1;do{v=-1*v/n;for(int i=0; i<c;i++){s+=v;Write(a[s/n,s%n]+" ");}v*=n;c--;for(int i=0;i<c;i++){s+=v;Write(a[s/n,s%n]+" ");}}while (c>0);}
  71.  
  72. Int32[] Spiral_Min(Int32[,]arr){List<Int32>list=new List<Int32>();Int32 n=arr.GetLength(0);Int32 count=n;Int32 value=-n;Int32 sum=-1;do{value=-1*value/n;for(Int32 i=0;i<count;i++){sum+=value;list.Add(arr[sum/n,sum%n]);}value*=n;count--;for(Int32 i=0;i<count;i++){sum+=value;list.Add(arr[sum/n,sum%n]);}}while(count>0);return list.ToArray();}
  73.  
  74. function f($a){if(empty($a))return[];else{$m=count($a);$n=count($a[0]);$r=[];$k=0;$l=0;while($k<$m&&$l<$n){for($i=$l;$i<$n;++$i)$r[]=$a[$k][$i];$k++;for($i=$k;$i<$m;++$i)$r[]=$a[$i][$n-1];$n--;if($k<$m)for($i=$n-1;$i>=$l;--$i)$r[]=$a[$m-1][$i];$m--;if($l<$n)for($i=$m-1;$i>=$k;--$i)$r[]=$a[$i][$l];$l++;}return$r;}}
  75.  
  76. static int[] f(int[,] a){var r = new List<int>();var n = a.GetLength(0);int j = -1, i = 0; bool h = true;bool d = false;int c = 0;int p = n;int max = n;for (var cnt = 1; cnt <= a.Length; cnt++){i = h ? i : !d ? ++i : --i;j = !h ? j : !d ? ++j : --j;p--;r.Add(a[i, j]);if (p <= 0){h = !h; if ((c + 1) % 2 == 0){d = !d;}if (cnt == n || c > 1 && (c + 1) % 2 != 0){--max;}p = max;c++;}}return r.ToArray();}
Add Comment
Please, Sign In to add comment