Tuesday, April 18, 2017

We were discussing OSX Spotlight Search on Mac for remote folders, those that can grow arbitrarily large and served over different file protocols. In these cases, the usual method is to connect the shares using Finder application, then to do the following:
To enable spotlight indexing on a network drive, we give the following command:
mdutil /Volumes/name -i on
To disable the indexing of a connected network drive, we give the following command:
mdutil /Volumes/name -i off
To check the status of indexing on a connected network drive, we give the following command:
mdutil /Volumes/name –s
To re-index a mounted drive, we goto preferences > spotlight > privacy
drag a folder or drive into the ‘ignore’ list and then remove the item we just added.
#codingexercise
Find the largest sum in a zigzag path from top to bottom of a matrix where zigzag means no two adjacent rows have the same column values selected

This can be done with dynamic programming starting from a cell (i, j) and ending at a cell on the bottom row
int GetZigZagDP(int[,] M int i,
                                int j, int n)
{
   if (i == n-1)
     return M[i,j];
   // We now consider all the candidates in the next row
   int sum = 0;
   for (int k=0; k<n; k++)
     if (k != j)
       sum = max(sum, GetZigZagDP(M, i+1, k, n));

   return sum + M[i, j];
}


This holds true for right triangle matrix  as well starting at position (i,j)
int GetTrianglePathSumDP(int[,] M, int i, int j, int n)
{
if (j >= M[i].columns) return 0;
if ( i == n-1) return M[i,j];
int sum = 0;
for (int k = 0; k <= i + 1; k++)
     if (k == j || k == j+1)
         sum = Math.Max(0, GetTrianglePathSumDP(M, i+1, k, n));
return sum + M[i,j];
}
sums.max();
For example:
2
4 1
1 2 7
Sums:
10
6 8
1 2 7

No comments:

Post a Comment