#codingexercise
Multiply two linked lists representing large numbers without using additional lists.
List <int> multiply (list <int> first, list <int> second)
{
Int len1 = first.count;
Int len2 = second.count;
First.addRange (second);
Second.reset ();
Int start = 0;
For ( int I = len1- 1; I>=0; i--){
For ( int j = len1+len2-1;j>=0; j- -)
Second.cumulate_with_carry_over (first, len1, i,j, start);
Start++;
}
Return second;
]
}
static void cumulate_with_carry_over(this List<int> second, List<int>first, int len1, int i, int j, int start)
{
int product = first[j]*first[i];
// add product to second at start+j
int val = second[start+j] + product
carryover = val/10;
operand = val %10;
Second [start+j] = operand;
Int k = j- 1;
While (carryover != 0){
Val = second[start +k] +carryover ;
if (val/10 > 0){
carryover = val/10;
operand = val %10;
}else{
carryover = 0;
operand = val
}
if start+k<= 0
Second [start+k] = operand;
second.InsertAt(0, carryover);
Carryover = 0
else
second[start+k] = operand;
//second[start+k-1] += carryover'
}
K = k- 1;
}
return;
}
123
*123
----------
369
246x
123xx
----------
14829
We review some more more common tasks with vCenter along the lines of the ones mentioned in the previous post:
To deploy an OVF:
1) first read the ovf file and get the descriptor
2) parse the descriptor to get datacenter, datastore and resource_pool
3) Create an import spec with the above parameters
4) Take an HttpNFCLease and keep it alive while posting the vmdk
To Reboot VM:
print "The current powerState is: {0}".format(VM.runtime.powerState)
TASK = VM.ResetVM_Task()
tasks.wait_for_tasks(SI, [TASK])
To Rename a VM
# rename creates a task...
task = obj.Rename(new_name)
Multiply two linked lists representing large numbers without using additional lists.
List <int> multiply (list <int> first, list <int> second)
{
Int len1 = first.count;
Int len2 = second.count;
First.addRange (second);
Second.reset ();
Int start = 0;
For ( int I = len1- 1; I>=0; i--){
For ( int j = len1+len2-1;j>=0; j- -)
Second.cumulate_with_carry_over (first, len1, i,j, start);
Start++;
}
Return second;
]
}
static void cumulate_with_carry_over(this List<int> second, List<int>first, int len1, int i, int j, int start)
{
int product = first[j]*first[i];
// add product to second at start+j
int val = second[start+j] + product
carryover = val/10;
operand = val %10;
Second [start+j] = operand;
Int k = j- 1;
While (carryover != 0){
Val = second[start +k] +carryover ;
if (val/10 > 0){
carryover = val/10;
operand = val %10;
}else{
carryover = 0;
operand = val
}
if start+k<= 0
Second [start+k] = operand;
second.InsertAt(0, carryover);
Carryover = 0
else
second[start+k] = operand;
//second[start+k-1] += carryover'
}
K = k- 1;
}
return;
}
123
*123
----------
369
246x
123xx
----------
14829
We review some more more common tasks with vCenter along the lines of the ones mentioned in the previous post:
To deploy an OVF:
1) first read the ovf file and get the descriptor
2) parse the descriptor to get datacenter, datastore and resource_pool
3) Create an import spec with the above parameters
4) Take an HttpNFCLease and keep it alive while posting the vmdk
To Reboot VM:
print "The current powerState is: {0}".format(VM.runtime.powerState)
TASK = VM.ResetVM_Task()
tasks.wait_for_tasks(SI, [TASK])
To Rename a VM
# rename creates a task...
task = obj.Rename(new_name)
No comments:
Post a Comment