#codingexercise
Print all possible words from phone digits. An n digit number is given, and all words that are possible by pressing these numbers must be listed.
var hashTable = new List<int>(){"", "", "abc", "def", "ghi", "jkl",
"mno", "pqrs", "tuv", "wxyz"};
void combineKeypad(List<int> number, int n, int current, int level, ref List<char> candidate)
{
if (current == n) {
Console.Write(candidate);
return;
}
If (number[current] ==0 || number[current] == 1){
combineKeypad(number, n, current+1, level, ref candidate);
Return;}
for (int i =0; i < hashTable(number[current]).Length; i++)
{
candidate[level] = hashTable[number[current]][i];
combineKeypad(number, n, current+1, level +1, ref candidate);
candidate[level] = '/0';
}
}
}
combineKeypad(number, n, 0,0, ref result);
In the previous post, we talked about making docker containers to scale out with the resources of the host.One simple approach to this would be for Docker to treat the host as a cluster and not a single instance. This way the abstraction layer can assume more power than the original host while enabling additional nodes to be brought up or taken down. The most important ability of a cluster in the scale to which it can allow distributed computing. By introducing a layer that redirects to different nodes of the cluster in the native linux calls via agents, docker can continue to roll apps from one host to another and for that matter one cluster to another.
We can also use the concept of a 'lid' in that the applications are not brought down but all the data flows are temporarily cut off. This does not require changes to the network interfaces but just that data flow to a particular docker is rerouted to another. We call this a lid to the container. By not requiring the applications to be powered down, docker can even switch regions without any changes to all that it supports. The mapping information between services and dependencies are now maintained by docker as an extension to the format in which the applications currently declare their dependencies to docker.
The layer of redirection from the application to the host via docker does not necessarily have to be one that supports clusters. Consider rack compute and storage where there is a large number of cores and storage available. On such a fabric, virtual machines of all sizes can be spun up and shut down. If the redirection layer supports targeting the linux host dynamically, the application workloads can benefit from increased hardware resources dynamically as the applications are moved by docker from one host to another.
In a sense, this is similar to vMotion of virtual machines but for hosts. The difference is that the physical resource of cpu and storage can grow and shrink to the workload without having the applications to know about it. This is dynamic scale up and down versus scale out.
#codingexercise
Determine if a particular arrangement of 15 puzzle is solvable.
for a given grid of width N, an N*N-1 puzzle will be solvable as follows:
bool IsSolvable(int[,] board,int N)
{
int count = GetInversions(board);
// if grid is odd, return true if inversions is even
if (N & 1)
return !(count & 1);
else
{
int pos = findXPosition(board);
if (pos & 1)
return !(count & 1);
else
return count & 1;
}
}
Print all possible words from phone digits. An n digit number is given, and all words that are possible by pressing these numbers must be listed.
var hashTable = new List<int>(){"", "", "abc", "def", "ghi", "jkl",
"mno", "pqrs", "tuv", "wxyz"};
void combineKeypad(List<int> number, int n, int current, int level, ref List<char> candidate)
{
if (current == n) {
Console.Write(candidate);
return;
}
If (number[current] ==0 || number[current] == 1){
combineKeypad(number, n, current+1, level, ref candidate);
Return;}
for (int i =0; i < hashTable(number[current]).Length; i++)
{
candidate[level] = hashTable[number[current]][i];
combineKeypad(number, n, current+1, level +1, ref candidate);
candidate[level] = '/0';
}
}
}
combineKeypad(number, n, 0,0, ref result);
In the previous post, we talked about making docker containers to scale out with the resources of the host.One simple approach to this would be for Docker to treat the host as a cluster and not a single instance. This way the abstraction layer can assume more power than the original host while enabling additional nodes to be brought up or taken down. The most important ability of a cluster in the scale to which it can allow distributed computing. By introducing a layer that redirects to different nodes of the cluster in the native linux calls via agents, docker can continue to roll apps from one host to another and for that matter one cluster to another.
We can also use the concept of a 'lid' in that the applications are not brought down but all the data flows are temporarily cut off. This does not require changes to the network interfaces but just that data flow to a particular docker is rerouted to another. We call this a lid to the container. By not requiring the applications to be powered down, docker can even switch regions without any changes to all that it supports. The mapping information between services and dependencies are now maintained by docker as an extension to the format in which the applications currently declare their dependencies to docker.
The layer of redirection from the application to the host via docker does not necessarily have to be one that supports clusters. Consider rack compute and storage where there is a large number of cores and storage available. On such a fabric, virtual machines of all sizes can be spun up and shut down. If the redirection layer supports targeting the linux host dynamically, the application workloads can benefit from increased hardware resources dynamically as the applications are moved by docker from one host to another.
In a sense, this is similar to vMotion of virtual machines but for hosts. The difference is that the physical resource of cpu and storage can grow and shrink to the workload without having the applications to know about it. This is dynamic scale up and down versus scale out.
#codingexercise
Determine if a particular arrangement of 15 puzzle is solvable.
for a given grid of width N, an N*N-1 puzzle will be solvable as follows:
bool IsSolvable(int[,] board,int N)
{
int count = GetInversions(board);
// if grid is odd, return true if inversions is even
if (N & 1)
return !(count & 1);
else
{
int pos = findXPosition(board);
if (pos & 1)
return !(count & 1);
else
return count & 1;
}
}
No comments:
Post a Comment