Saturday, December 31, 2016

We continue discussing the paper by Papadimitriou  - Algorithms, Games and Internet. We started with Nash equilibrium and then we discussed Internet Equilibria. Nash equilibrium translates to solving linear programming. Unlike Nash Equilibrium, Internet Equilibria  is not achieved by rational contemplation. This game is inherently coalitional. One of the theories suggests to draw the payoffs in such a way that no coalition has an incentive to secede because it cannot make more by itself than what is allocated in the coalition. This splitting of the total payoff forms a "core" but because it is conservative in definition, a game may have an empty core. The Internet equilibria can be described as a flow network with n nodes and a n x n flow matrix where each cell is the total traffic requirements between customers of i and customers of j. The Internet equilibria then translates to a problem of finding an optimum solution in a multicommodity flow problem for the overall network, achieving a flow matrix F' <= F, such that the corresponding payoffs for the nodes xi in terms of the flow matrix cell values summed over all j, are in the core of the coalition game v.
#codingexercise
Yesterday we were discussing spiral matrix traversal. The same algorithm works for anticlockwise direction as well:
#codingexercise
There is a square matrix of order n which is filled from 1 to n^2 in row major. Find the Kth element in spiral traversal of the matrix in anticlockwise direction
Example: Given n=3 and K=5.
Matrix:
1 2 3
4 5 6
7 8 9
Output: 9
By spiral order traversal  we are covering
k  <= n elements in the first column
k <= n+m-1 elements in the last row
k <= n+m-1+n-1 elements in the last column
k <= n+m-1+n-1+m-2 elements in the first row
else element lies in the inner matrix of dimensions m-2 rows and n-2 columns

int GetKthAntiClockWise(int[,] A, int m, int n, int k)
{
if (n <1 || m < 1) return -1;
if (k <= n)
    return A[k-1, 0]; 
if (k <= n+m-1)
   return A[n-1, k-n]; 
if (k <= n+m-1+n-1)
   return A[(n-1-(k-(n+m-1))), m-1];
if (k <= n+m-1+n-1+m-2)
   return A[0, m-1-(k-(n+m-1+n-1))]; 
return GetKthAntiClockWise(A.SubArray(1,1,m-2,n-2), m-2, n-2, k-(2*n+2*m-4)));
}

Friday, December 30, 2016

We continue discussing the paper by Papadimitriou  - Algorithms, Games and Internet. We started with Nash equilibrium  which essentially says that we cannot predict if we consider the decisions by the participants in isolation and instead that decision making must be studied by taking into account the decision-makings of others.  The decision making is expressed in terms of a probability distribution over possible actions by each player. As long as the set of strategies form a convex set, there is a Nash equilibrium and finding Nash equilibrium translates to solving linear programming.
The next game we are going to look into is the Internet Equilibria.  Internet bandwidth is scarce and its allocation to individual end to end flows is achieved via the TCP/IP congestion control protocol. The congestion is handled this way : If the previous batch of packets got through, then increase the batch size by one. If not, decrease it by half. This has been working very well due to its simplicity but it is not clear of which game the Internet TCP/IP congestion control is a Nash equilibrium. There are a few ways in which this equilibria differs from the previous game. First, the equilibrium is not achieved by rational contemplation. It is achieved by interaction and adaptation in an environment where conditions and player populations change rapidly. Third, changes to strategies incur costs. Fourth, players cannot compensate each other by exclusive negotiations. There have been several theories advanced in this regard. The conditional game theory considers a game of n players as a set of possible 2^n-1 coalitions each of which can achieve a particular value which is the best possible sum of payoffs among players among the coalitions, against worst case behavior of players in the rest. However the game needs to be initialized with a certain value for the total payoff among the n players and this is difficult to do in the Internet Equilibria.  Another technique called the "core" was proposed to study these games. A vector in the real space is considered part of the core if the summation of payoffs over each coalition is greater than a particular value for all such coalitions. It draws the payoffs in such a way that no coalition has an incentive to secede because it cannot make more by itself than what is allocated in the coalition. This splitting of the total payoff is intuitive to the notion of equilibria but also very conservative due to which many games may have empty cores. Although the payoffs may not always be split in such a manner, this game is inherently coalitional is undisputed because the game can be seen as a flow network and flow happens due to coalitions.

#codingexercise
There is a square matrix of order n which is filled from 1 to n^2 in row major. Find the Kth element in spiral traversal of the matrix.
Example: Given n=3 and K=5.
Matrix:
1 2 3
4 5 6
7 8 9
Output: 9
By spiral order traversal  we are covering
k  <= m elements in the first row
k <= m+n-1 elements in the last column
k <= m+n-1+m-1 elements in the last row
k <= m+n-1+m-1+n-2 elements in the first column
else element lies in the inner matrix of dimensions m-2 rows and n-2 columns

int GetKth(int[,] A, int m, int n, int k)
{
if (n <1 || m < 1) return -1;
if (k <= m)
    return A[0, k-1];
if (k <= m+n-1)
   return A[k-m, m-1];
if (k <= m+n-1+m-1)
   return A[n-1, (m-1-(k-(m+n-1)))];
if (k <= m+n-1+m-1+n-2)
   return A[n-1-(k-(m+n-1+m-1)), 0];
return GetKth(A.SubArray(1,1,m-2,n-2), m-2, n-2, k-(2*n+2*m-4)));
}


Thursday, December 29, 2016

Yesterday we were discussing the paper by Papadimitriou  - Algorithms, Games and Internet. and we started with Nash equilibrium  which essentially says that we cannot predict if we consider the decisions by the participants in isolation and instead that decision making must be studied by taking into account the decision-makings of others.  The decision making is expressed in terms of a probability distribution over possible actions by each player. A classic example of a game showing Nash equilibrium is prisoner's dilemma. This game is meant to show that two completely rational individuals might not cooperate, even if it appears that it is in their best interest to do so. The equilibrium is a state from where payoffs could be only worse by changing strategies. In the case of prisoner's dilemma, the mutual defection was a state of equilibrium.
It is said that there exists a Nash equilibrium when the set of strategies form a convex set. A convex set is one where we have a distribution of strategies such that their weights or probabilities are all positive and add up to one. In geometry a convex set is as a linear combination of points in real vector space where all the coefficients are non-negative and sum to 1. As an example, a convex combination of two points lies on the line segments between the points. This is exactly what we solve with linear programming. Consequently finding Nash equilibrium translates to solving linear programming. We have seen earlier how a simplex algorithm can be used to solve linear programming. The complexity of the Nash algorithm can therefore be considered similar to solving the linear equations.

#codingexercise
Yesterday we were discussing comparing top left corners of rectangles
A simple compareTo operation can be as follows:
    public int CompareTo(Object obj) {
        if (obj == null) return 1;
        var other = obj as Tuple<int,int>;
        if (other != null)
        {
             if (other.first < this.first && other.second < this.second) return -1;
             if (other.first == this.first && other.second == this.second) return 0;
             return 1;

        }
        else
           throw new ArgumentException("Object is not a Tuple<int,int>");
    }

Wednesday, December 28, 2016

Today we will start discussing the paper by Papadimitriou  - Algorithms, Games and Internet.
In a game, each of the n players can choose among a set of strategies S, i = 1, .. n and there are functions ui, i = 1 .. n: S1 x S2 ... Sn. These functions result in a payoff for each player for each such combined choice. The fundamental question of Game Theory is what constitutes rational behavior in such a situation ? One such explanation is the Nash equilibrium. A combination of strategies xi belongs to S1, xn belongs to Sn, for which ui (x1, ... xi, ... xn) >= ui (x1, ...xi-dash, ...xn) for all i and xi-dash belong to Si: a behaviour that is from which no player has an incentive to deviate. The Nash equilibrium is attained when each player has chosen a strategy and no player benefits from changing his or her strategy. The set of strategy choices and their corresponding payoffs remain unchanged.
Nash equilibrium has a wide variety of applications because it allows us to formalize what happens if several people or several institutions  are making decisions at the same time, and if the outcome depends on the decisions of the others.  Nash's equilibrium essentially says that we cannot predict if we consider the decisions by the participants in isolation and instead that decision making must be studied by taking into account the decision-makings of others.  The decision making is expressed in terms of a probability distribution over possible actions by each player.  The modern version of Nash equilibrium discussion takes into account this mixed strategy which is shown to exist for any zero sum game involving finite set of actions. Nash's equilibrium is considered to be much more broader than pure strategy method because it makes no judgement about the optimality of the equilibrium being generated. This optimality in terms of payoffs or profit is generally restricting in the definition of the equilibrium.  Furthermore it has applications in non-cooperative games or hostile games. A classic example of such a game is prisoner's dilemma.  This game is meant to show that two completely rational individuals might not cooperate, even if it appears that it is in their best interest to do so.  This example is described so. Two members of a criminal gang are arrested and imprisoned Each prisoner is in a solitary confinement with no means of communicating with one another.  The prosecutors lack sufficient evidence to lock each up so they offer a bargain to each prisoner -betray the other by testifying or cooperate with the other by remaining silent. If A and B both betray each other, each of them serves two years in prison. If A betrays B but B remains silent, A will be set free and B will serve three years in prison and vice versa.  If A and B both remain silent, both of them will serve only one year in prison because there is not enough evidence. If each prisoner pursues the individual reward logically, they will both betray each other with less than optimum outcome. Instead if they show a cooperative behaviour and remain silent, they get a better outcome. Remaining silent is not the only option. The players could also choose to defect. In fact, mutual defection is considered the only strong Nash equilibrium in the game.From this equilibrium, the prisoners could only do worse by unilaterally changing strategy. The dilemma is that mutual cooperation yields a better outcome but it is not the rational outcome because from a self interest perspective, the choice to cooperate at the individual level is irrational.
#codingexercise
Find the maximum number of submatrix contained within a bounding rectangle (represented by a list of tuples where the first item in the list is the top left corner and the last is the bottom right)
int GetCount(List<tuple<int,int>> corners, List<List<Tuple<int,int>>> submatrices)
{
return submatrices.Count( x => corners.first() <= x.first() && corners.last()>= x.last());
}
we can have an extension method on the tuple that compares it to another

Tuesday, December 27, 2016

Today we continue discussing the problem of finding largest sub matrix of 1 in a boolean matrix using graph based method. we were saying that the depth first search  allows us to explore islands of ones one after the other. we used the islands to find the submatrix. We said we could stretch the submatrix rectangle within each island to cover most of the island. We showed a method to push the extremes in terms of minimum row and column and maximum row and column to determine the boundaries of the submatrix. We could find the top left corner for the submatrix but the same method also finds every other corner of the submatrix. Moreover, submatrix thus founds answers the question of finding the largest submatrix in the original matrix.
However, we are not limited to the largest such sub-matrix. The graph based depth first search allows us to explore the islands one after the other. Therefore we can rank the islands based on size. This helps us find the kth largest submatrix as well with the same ease as we did with the largest matrix. The smallest submatrix is usually of size one. where a single cell occurs as an island. This is also listed with the islands encountered and since we can sort them based on the size, we have the smallest submatrix appearing at the tail of the list.
This method finds the number of submatrices, their locations inside the matrix alongwith their sizes. Consequently we can tell which part of the matrix has the highest number of such submatrices included. None of the submatrices overlap otherwise they wouldn't be islands, consequently we can determine a bounding rectangle that contains more than a threshold number of submatrices we are interested in. This bounding rectangle gives the portion of the original matrix that is heavier in 1s and consequently determines how lop sided the matrix is. The fraction of the contained submatrices within a half of the original matrix to the total number of submatrices encountered gives us a quantitative number for how heavy or lop sided the original matrix is. Finding this bounding rectangle is a matter of arranging the submatrices by their top left corners and progressively increasing the bottom right of the bounding rectangle until a threshold number of rectangles are completely included within the bounding rectangle or half the original square is reached depending on the choice of our selection criteria. 

Monday, December 26, 2016

Today we continue discussing the problem of finding largest sub matrix of 1 in a boolean matrix using graph based method. we were saying that the depth first search  allows us to explore islands of ones one after the other. This way we could count the number of islands. Furthermore we could find the size of each island. we could now tell the largest island. It was however not clear how to find the submatrix contained within an island given that the island could be of irregular shape. In order to find the contained matrix, we merely have to find the corners. we know when we enter an island so we can initialize the minimum and maximum row and columns encountered. Candidates for corners are initialized by the min and max of row,column encountered in that island as the case maybe for that direction. for example, top left will require both row and column value to be minimum. Then the coordinates at these boundary values or adjacent to it such that the area of the sub matrix contained is maximized are used as corners. Therefore we pick the common values for coordinates as close to the corners as possible. for example the sub matrix will have a top row as the higher row value of top left and top right corners. this gives us the submatrix for each island. This method is equally applicable to the largest island as it is applicable to other islands.
#untested but just for explanation.
Tuple<int, int> GetTopLeft(int[,] A, int ROW  int COL, int sr, int sc)
{
assert(A[sr,  sc] == 1); // arbitrary starting point an island
int minr = sr;
int minc = sc;
int maxr = sr:
int maxc = sc;
bool change = True;
while(change)
{
change = False;
for(int k = minr-1; k >= 0 && A[k, minc] && A[k, maxc] ; k--) {minr--; change = True;}
for(int k = maxr+1; k  < ROW  && A[k, minc] && A[k, maxc] ; k++) {maxr++;change = True;}
for(int k = minc-1; k >= 0 && A[minr, k] && A[maxr,k] ; k--) {minc--;change = True;}
for(int k = maxc+1; k < COL  && A[minr, k]  && A[maxr,k]; k++) {maxc++;change = True;}
}
return new Tuple<int, int> (minr, minc);
}

Sunday, December 25, 2016

we were discussing a problem of finding the largest submatrix of 1 in a boolean matrix.
we presented several techniques to solve this including histogram method, iterative method and depth first approach. The depth first approach can find the number as well as sise of islands of 1s. This method explores all eight neighbors of a point. Therefore it visits all points in an island before going to the next island. This helps in knowing the size of the island before going to the others which also helps us deternine the largest island.

void DFS(int[,] A, int ROW, int COL, int row, int col, ref int[,] visited, ref int  size)
{

var rd = { -1,-1,-1,0,0,1,1, 1};
var cd = { -1,0,1,-1,0,1,-1,0,1 };

visited[row,col] = true;
for (int k = 0; k < 8; k++)
    if (isSafe(A, ROW, COL, row + rd[k], col +cd[k])){
           size++;
           DFS(A, ROW, COL, row+rd[k], col+cd[k], ref visited, ref size);
}
}

bool isSafe( int[,] A, int ROW, int COL, int row, int col, ref int[,] visited)
{
if ( row >= 0 && row < ROW &&
      col >= 0 && col < COL &&
      A[row, col] == 1 && !visited[row,col])
      return true;
return false;
}

int countIslands(int[,] A, int ROW, int COL)
{
var visited = new bool[ROW, COL] { False }
int count = 0;
int maxsize = 0;
for (int i = 0; i < ROW; i++)
   for (int j = 0; j < COL; j++)
      if ( A[i,j] == 1 && !visited[i, j])
   {
        int size = 0;
        count++;
        DFS(A, ROW, COL, i, j, ref visited, ref size);
        if (size > maxSize)
             maxSize = size;
   }

}

Saturday, December 24, 2016

we were discussing a problem of finding the largest submatrix of 1 in a boolean matrix.

Another technique is to not divide the matrix into equal parts over and over again but to use a graph and traversal algorithms to find islands. Then for each of these islands find the largest size.

this is therefore a two step procedure.

first, we do a depth first traversal. here we only recurse if the cordinate is safe. by that we mean the points are within the matrix boundaries, are all ones and they have not been visited. we keep a visited matrix which we fill and we can explore all eight adjacencies of a point one at a time. if a cell with value 1 is not visited then we found a new island and make note of this cordinate.


  • second for each island and a cordinate on this island, we can explore its size and the maximum submatrix rectangle contained by any of the techniques mentioned earlier such as the histogram method. This gives us the cordinates and the size of the final submatrix we are interested in.



Friday, December 23, 2016

today we look at a few more alternatives to the submatrix of 1 problem discussed earlier.
one such method is to facilitate merge along vertical and horizontal axis in a way such that contiguous regions of 1s are identified, sized and top left corner identified. then we split the original matrix into  2 power x sub matrices by repeatedly dividing  both x and y axis. This works well for cohesive matrices where the 1s are all together as islands. Since each point is counted only once during the merge before being assigned to a group and the results aggregated, this is more efficient than the nested evaluation of each point as a candidate for top left corner. Moreover we keep track of the top left and bottom right corners of each candidate submatrix from the adjoining contiguous overlaps during each merge. each overlap along a merge front determines the span of the submatrix


today we review a new topic called social balance theory from the chapter on network measures. this theory is about friends and enemies relationships abd i had never really paid attention to it so far. it states:
The friend of my friend is my friend, The friend of my enemy is my enemy, The enemy of my enemy is my friend, The enemy of my friend is my enemy.
All this theory states is that the friends or enemy relationships are consistent when the above is followed.

we can represent these relationships in a graph. The friendhip is denoted by positive edges, the enemity by negative edges and a triangle between participants denotes imbalance if the weights around the edges of the triangle taken together is less than zero. this kind of metric can also be explored for graphs that are not triangular in general.

Thursday, December 22, 2016

#codingexercise
for the  problem duscussed yesterday, we see a few more alternatives

parallel processing
sum along all columns
sum along all rows
if any row or column is all zero
split the matrix on either side of the zeros
compute the submatrix as usual

another method may be to merge two sub matrices along a front
the histogram on both sides of the front are computed starting from the front and progressing outwards
for contiguous non-zero paired entries on the histograms on both sides, the max area is calculated for each contiguous zone out of which the largest is chosen

another method for a merge like above would be to find contiguous zones of ones along the front
for each of the contiguous zone, and for each of the ones in the zone find the max area on both sides noting the common width.
retirn the max of all such combined max.

Wednesday, December 21, 2016

Linux Containers
Today we discuss the Linux Containers. These form isolated environments within the operating system. As we know Linux itself is a modular design with layered components where every component can be replaced with another and the whole operating system can be rebuilt.
The standard layers including the operating system are:

Users
Utility Programs
System Library
Linux OS
Hardware

The interfaces between users and user programs is User Interface.
The interface between utility programs and system library is library interface
The interface between system library and Linux is system call interface.

The LXC hosts more than one containers by being a layer over the OS.  Since the OS can be over real or virtual hardware, we can have the whole stack nested as we nest containers.

A network bridge is established on the host operating system and the containers are usually NAT'ed. This means the containers are not directly reachable from the outside network. With DHCP, they get assigned an ip address so addressing is not a problem but to facilitate inbound and outbound connections, the gateway must be specified in routing table of the containers.  Outbound connections are facilitated with the gateway. If the bridge was established over the original ethernet interface of the host, the inbound connectivity is also established. This way the containers can be accessed by ssh.

Often containers are required to be cut with some customization scripts. These include provisioning a sudo user or enabling ssh access for public keys. All of these can be run as shell commands targeting the specific container from the host with something like:
lxc exec <container_name> -- command


#codingexercise
Find the largest sub matrix rectangle of 1's in a two dimensional binary matrix.
Here's the alternative version to the solution yesterday.
int GetMax(int[,] A, int R, int C)
{
int max = int_min;
for (int i = 0; i < R; i++)
   for (int j = 0; j < C; j++){
        area = AreaWithTopLeft(A,i,j, R, C);
        if (area > max)
             max = area;
     }
return max;
}
int AreaWithTopLeft(int[,] A, int i, int j, int R, int C)
{
int max = 0;
int prev = int_max;
if (A[i,j] != 1) return 0;
for (int x = i; x < R; x++){
   int count = 0;
   for (int y = j; y < C; y++)
   {
      if (A[i,j]  == 1) count++;
   }
   if (count == 0) return max;
   int newmax = min(prev, count) * (x-i+1))
   if (newmax < max)
       return max;
    max = newmax;
   prev = count;
}
return max;
}
we can also optimize the above bailing early so that we dont have to iterate when there are no ones.

Tuesday, December 20, 2016

Serial console on VMWare
Introduction:  We reviewed the DELL Serial Console Option. This document is about the serial console for VMWare Virtual Machines.
Architecture:
The VMWare community suggests using the virtual serial port concentrator. The concentrator also called the proxy has internal connections to several virtual machines in a datacenter and an external connection to a remote system.

The virtual serial port concentrator can be deployed as a virtual appliance involving a single virtual machine. This appliance uses the virtual machine ip address that persists across vMotion events. The Proxy accepts telnet connections from virtual machine and supports the VMWare telnet extension commands and corresponding notifications in addition to forwarding traffic both ways. The proxy serves as a point of authentication on a remote system. Since the telnet connections are internal, they need not be secured. Even a Moxa device server uses telnet console.
A virtual serial port provides out of band access to the virtual machine so that even if we lose network connectivity, we can use the serial console to interact with the machine. When this serial console is available over IP, you can remotely manage a machine even when there is a fault in the OS or the hardware of a machine.
Steps to take on the Proxy:
1.       Start the vspc.py using  - - server option
2.       Configure the vspc.py to start automatically at boot
3.       Edit the local firewall rules on the virtual serial port concentrator to permit 13370/tcp, 13371/tcp and a range of ports for target virtual machines starting at any high value say 63000
Steps to take on each VM
1.       Power off VM
2.       Add a serial port to the VM with the following settings:
On the Hardware tab, click Add.
In the Add Hardware wizard, select Serial Port.
Select where the virtual serial port sends output. It should be one of the following:
Use a physical parallel port
Use output file
Connect to named pipe
Connect via network
Choose the last option
And specify use virtual serial port concentrator and type the vSPC URI as telnet://vspc.local.lan:13370
If we don’t want to use a vSPC and provide a dedicated serial port, We can also use xcat/socat/netcat etc. Refer VMWare how to for virtual serial port configuration
select this end is the server from the first drop-down menu and select
the other end is an application from the second drop-down menu.
To connect the port to the virtual machine when the virtual machine powers on, select Connect at power on.
Click Finish to add the virtual serial port to the virtual machine.
On the Hardware tab, select the new serial port, select Yield CPU on poll, and click OK.
3.       Start the virtual machine
To query the virtual serial port connections opened on the proxy, run, from any machine including laptop with connectivity to the proxy, the following command:
./vSPC.py vspc. local.lan
machine1:500aedefafeae42434-b534dade2eawa5q3:63002
machine2:90834124ewdafwe-aw243123ewdeawdea:63003
etc.
To connect to the serial console, let’s use the corresponding port
telnet vspc.example.com 63002

Caveat : This information is provided as-is by collection from literature. 
Courtesy : VMWare vsphere web services SDK
To view consoles in public cloud refer http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-console.html
#codingexercise
Tell whether a matrix containing 0s and 1s can be divided into 2 sub matrices containing equal number of 1s.
Matrices can be split into two only by vertical or horizontal partitions. We can enumerate all partitions and check

bool HasEqual1and0(int[,] A, int r0, int rn, int c0, int cn)
{
int count = CountOnes(A, r0, rn, c0,cn);
for (int i = r0+1; i <= rn-1; i++)
{
int count1 =  CountOnes(A, r0, i, c0,cn);
int count2 =  CountOnes(A,i+1, rn, c0, cn);
assert(count1+count2 == count);
if (count1 == count2) return true;
}
for (int j = co+1; j<=cn-1;j++)
{
int count1 =  CountOnes(A, r0, rn, c0, j);
int count2 =  CountOnes(A, r0, rn, j+1, cn-1);
assert(count1 + count2 == count);
if (count1 == count2) return true;
}
return false;
}

int CountOnes(int[,] A, int r0, int rn, int c0, int cn)
{
int count = 0;
for (int i = r0; i <= rn; i++)
for (int j = co; j<=cn;j++)
      if (A[i,j] == 1) count++;
return count;
}

Find the largest sub matrix rectangle of 1's in the above matrix:
we  create a histogram and find the maximum area under the histogram
int maxRectange(int[,] A, int R, int C)
{
int result = GetMaxFromHistogram(A[0]); // this is the area of the first row
for (int i = 1; i < R; i++)
{
   for (int j = 0; j < C; j++)
         if (A[i, j] ) A[i, j] += A[i-1, j]
  result = max(result, GetMaxFromHistogram(A[i]));
}
 return result;
}
MaxAreaOfARectangle implemented GetMaxFromHistogram earlier

alternatively the max area of submatrix of 1s can also be found by treating each cell as the top left corner of the rectangle.

Monday, December 19, 2016


Serial Console Access over SSH
iDrac already provides console access via SSH as per the diagram below for certain DELL servers. An API service facilitating console access needs to only secure it by allowing the console access on a customer by customer basis and to only his or her servers: 
Image 
Which specifies console redirection over SSH from iDRAC with the following setting: 
# racadm get iDRAC.SSH.Enable 
[Key=iDRAC.Embedded.1#SSH.1] 
Enable=Enabled 
  1. For each console session initiation and termination, we start the console redirection with the following serial console commands: (All serial console commands are identical and at the same level as RACADM CLI subcommands. This means you can specify serial commands as well as racadm commands from the serial/telnet console. 
  1. racadm racreset – this releases the serial port used previously 
  1. connect <servername> -F 
  1. (Instead of <servername> we can specify switch-x where x represents a module slot number on the chassis). When the system BIOS console redirection setting is set to BMC, the –F option forces the serial console redirection session to switch from BMC to DRAC/MgmtConsole. When the system is rebooted, the BIOS console redirection setting returns to the default setting.  
  1. Reboot the target 
  1. <Enter><~><.>  or ^\ to exit out of the session 
  1. getpbinfo (for power status and power information) 
  1. serveraction ( for executing a server reset/powerdown/graceful powerdown/powerdown/powerup/powercycle)
#codingexercise
Cars 1 to 9 are parked randomly in the slots marked 1 to 9. Using the tenth slot, arrange the cars.

void arrange(ref List<int>cars)
{
for (int i = 0; i <cars.count; i ++)
{
if (cars[i] == i) continue;
for (int j =i+1; j < cars.count; j++){
   if (cars[j] == i){
          Swap(cars,i,j);
   }
}
}
}
the above method can be made linear if we maintain a lookup of where the cars can be found.