Thursday, July 14, 2016

#codingexercise
Given an array of strings, find if the given strings can be chained to form a circle. A string X can be put before another string Y in circle if the last character of X is same as first character of Y.
We can use a graph based depth first search or we can use try various permutations of the string.
Permutations:
Void Permute (List<String> a, List<string> b, bool[] used) 
{ 
  If ( b.Length == a.Length { if ( isCircle(b)) Console.Write(b.ToString()); return;} 
  For (int I = 0; I < a.Length ; i++) 
  { 
    If (used[i]) continue; 
     used[i] = true; 
     B.Add(A[i]); 
     Permute(a, b, used); 
     B.RemoveLast();
     used[i] = false; 
  } 
} 
bool isCircle(List<string> a)
{
if (a.Count <=1) return false;
for (int i = 1; i < a.Count; i ++)
     if (a[i].first != a[i-1].Last) 
       return false;
return a[a.Count-1].last == a[0].first;
}
Yesterday we were reading a paper titled "Pelican: a  building block for exascale cold data storage". Pelican treats a group of disks as a single schedulable unit. Resource restrictions such as power consumption, vibrations and failure domains are expressed as constraints over these units.
With the help of resource constraints and scheduling units, Pelican aims to be better than its overprovisioned counterpart racks using computations in software stacks
We will continue this shortly
Discussion on a service : https://1drv.ms/w/s!Ashlm-Nw-wnWk2xYkvf4o1W0hEJk

#codingexercise
Get the minimum number of dice throws required to reach the last cell from the first cell in the snake and ladder game.
int getMinMoves(int[] move, int n)
{
var visited = new bool[n];
var q = new Queue<Tuple<int, int>>(); // vertex, distance
var position = new Tuple<int, int>(0,0);
q.enqueue(t);
while (!q.empty())
{
position = q.Peek();
if (position.first == N-1) break;
q.dequeue();
for ( int j = v+1, j <= v+6 && j < N; ++j)
{
   if (!visited[j])
   {
         var n = new Tuple<int, int>(0, pos.second + 1);
         visited[j]  = true;
         if (move[j] != -1)
                n.first = move[j];
         else
                n.first = j;
         q.enqueue(n);
           
   }
}
}
return position.second;

}

No comments:

Post a Comment