[algogeeks] Re: Question on algo

2015-10-10 Thread Dave
Very simple. If MAXOR of the entire input set is not equal to zero, there 
are no subsets with equal MAXORs. If MAXOR of the entire set is zero, then 
any two complementary subsets have equal MAXORs. Since there are 2^N (^ is 
the exponential operator) subsets of a set of N elements, Little Panda 
needs to calculate mod((2^N)!,17) (! is the factorial symbol). 

Dave

On Monday, October 5, 2015 at 10:48:11 PM UTC-5, gopi wrote:

> Little Black Panda is mad about XOR operation. Presently he has gone mad 
> and he won't stop performing XOR operation on various numbers.
> Given an array of N numbers, for each subset of the array Little Panda 
> performs MAXOR operation for the subset. MAXOR operation means that he 
> finds XOR of all elements in that subset (if the subset is [1,2,3] then 
> MAXOR is 1^2^3=0) . Little Panda is now exhausted and wants to do something 
> else. Little Panda wants to pick any two subsets the MAXOR of whose are 
> same. Little Panda needs to find the number of selections that he can make. 
> He is very very weak in programming so he wants the answer from you. Please 
> help little panda in finding out his query.
> Since the output can be very large output it modulo 17.
>
> Input Format
> The first line contains N i.e. the length of the array.
> N lines follow, each containing a non-negative integer.
>
> Output Format
> Output Little Panda's Query in a single line.
>
> Constraints
> 1 <= N <= 10
> 0 <= A[i] <= 100
> (where A[i] denotes the value of array element)
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] Re: Question on checking divisibility of binomial coefficients of a number by a prime number

2012-08-27 Thread Dave
@Ankit: I haven't written code for this problem, but here is how I would do 
it. You are given values of n and P, with n being up to a 500-digit number 
(e.g., stored in an array, with say 9 digits of the number stored in each 
of up to 112 (500/9 rounded up) integers and P fitting in one integer. 
 
Write n in base P. You do this using long division to divide n by P. Just 
simulate what you do when you use long division by hand. The remainder is 
the low-order base-P digit of n. Repeat the process on the quotient to get 
successive base-P digits of n, until the quotient is zero. What you now 
have computed is the m_i of the Wikipedia article. 
 
Note the "Consequence" in the article, that the binomial coefficient is 
divisible by the prime if any n_i is greater than the corresponding m_i. 
Note that the binomial coefficient is divisible by the prime if and only if 
the binomial coefficient is zero modulo the prime. So how many possible k 
<= n are there for which any of the n_i (the base-P digits of k) exceed the 
corresponding m_i? It is easier to calculate the number of k with all n_i 
<= m_i: this is just one less than the product all of the (m_i + 1). So 
calculate this number in base-P arithmetic. Then subtract it from the 
base-P representation of n to get the base-P representation of the answer. 
 
Note that we never calculated any binomial coefficients to determine the 
answer!
 
Now convert the base-P representation of the answer back to base 10 to the 
9th power and print it out. You will have to use long long int (64 bits) 
for some of the calculations, although the base-P digits of n and P will 
fit in ordinary 32-bit ints.
 
Dave
 
On Sunday, August 26, 2012 6:56:19 PM UTC-5, Ankit Singh wrote:

> @dave: 
> Can u Please elaborate your idea??
> I didn't understand lucas theorem and in that theorem, i see too much 
> calculation and here we have to deal with testcases upto 100 and each 
> testcase containing n in range of 10500. 
>
>
>  
> On Mon, Aug 27, 2012 at 4:02 AM, Dave  >wrote:
>
>> @Ankit: Apply Lucas' Theorem, which you can find written up in Wikipedia.
>>  
>> Dave
>>
>> On Sunday, August 26, 2012 3:57:18 PM UTC-5, Ankit Singh wrote:
>>
>>> In mathematics, *binomial coefficients* are a family of positive 
>>> integers that occur as coefficients in the binomial theorem. [image: 
>>> \tbinom nk] denotes the number of ways of choosing k objects from n 
>>> different objects.
>>>
>>> However when n and k are too large, we often save them after modulo 
>>> operation by a prime number P. Please calculate how many binomial 
>>> coefficients of n become to 0 after modulo by P.
>>>
>>> *Input*
>>>
>>> The first of input is an integer T , the number of test cases.
>>>
>>> Each of the following T lines contains 2 integers, n and prime P.
>>>
>>> *Output*
>>>
>>> For each test case, output a line contains the number of [image: 
>>> \tbinom nk]s (0<=k<=n) each of which after modulo operation by P is 0.
>>>
>>> *Sample Input*
>>>
>>> 3
>>>
>>> 2 2
>>>
>>> 3 2
>>>
>>> 4 3
>>>
>>> *Sample Output*
>>>
>>> 1
>>>
>>> 0
>>>
>>> 1
>>>
>>> *Constraints:*
>>>
>>> T is less than 100
>>>
>>> n is less than 10500.
>>>  P is less than 109.
>>>  
>>>  
>>>  
>>>  
>>> I Have applied a logic that if any binomial coefficient can be written 
>>> as n!/(n-k)!k!  so if (n/p)>((n-k)/p+k/p) so that coefficient will be 
>>> divisiblr by prime number p. but the problem is range of is so large so if 
>>> i give an input of that much range it will take more then 15 min . although 
>>> complexity of my code is O(n/2) but my program keep on running because of 
>>> very high range of input. Can anyone help me in this please??
>>>  
>>> Thank you
>>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Algorithm Geeks" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/algogeeks/-/aLFSGCkdtmsJ.
>>
>> To post to this group, send email to algo...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> algogeeks+...@googlegroups.com .
>> For more options, visit this group at 
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/1fxRn6HSPaMJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Question on checking divisibility of binomial coefficients of a number by a prime number

2012-08-27 Thread Ankit Singh
@dave:
Can u Please elaborate your idea??
I didn't understand lucas theorem and in that theorem, i see too much
calculation and here we have to deal with testcases upto 100 and each
testcase containing n in range of 10500.



On Mon, Aug 27, 2012 at 4:02 AM, Dave  wrote:

> @Ankit: Apply Lucas' Theorem, which you can find written up in Wikipedia.
>
> Dave
>
> On Sunday, August 26, 2012 3:57:18 PM UTC-5, Ankit Singh wrote:
>
>> In mathematics, *binomial coefficients* are a family of positive
>> integers that occur as coefficients in the binomial theorem. [image:
>> \tbinom nk] denotes the number of ways of choosing k objects from n
>> different objects.
>>
>> However when n and k are too large, we often save them after modulo
>> operation by a prime number P. Please calculate how many binomial
>> coefficients of n become to 0 after modulo by P.
>>
>> *Input*
>>
>> The first of input is an integer T , the number of test cases.
>>
>> Each of the following T lines contains 2 integers, n and prime P.
>>
>> *Output*
>>
>> For each test case, output a line contains the number of [image: \tbinom
>> nk]s (0<=k<=n) each of which after modulo operation by P is 0.
>>
>> *Sample Input*
>>
>> 3
>>
>> 2 2
>>
>> 3 2
>>
>> 4 3
>>
>> *Sample Output*
>>
>> 1
>>
>> 0
>>
>> 1
>>
>> *Constraints:*
>>
>> T is less than 100
>>
>> n is less than 10500.
>> P is less than 109.
>>
>>
>>
>>
>> I Have applied a logic that if any binomial coefficient can be written as
>> n!/(n-k)!k!  so if (n/p)>((n-k)/p+k/p) so that coefficient will be
>> divisiblr by prime number p. but the problem is range of is so large so if
>> i give an input of that much range it will take more then 15 min . although
>> complexity of my code is O(n/2) but my program keep on running because of
>> very high range of input. Can anyone help me in this please??
>>
>> Thank you
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/aLFSGCkdtmsJ.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question on checking divisibility of binomial coefficients of a number by a prime number

2012-08-26 Thread Dave
@Ankit: Apply Lucas' Theorem, which you can find written up in Wikipedia.
 
Dave

On Sunday, August 26, 2012 3:57:18 PM UTC-5, Ankit Singh wrote:

> In mathematics, *binomial coefficients* are a family of positive integers 
> that occur as coefficients in the binomial theorem. [image: \tbinom 
> nk]denotes the number of ways of choosing k objects from n different objects.
>
> However when n and k are too large, we often save them after modulo 
> operation by a prime number P. Please calculate how many binomial 
> coefficients of n become to 0 after modulo by P.
>
> *Input*
>
> The first of input is an integer T , the number of test cases.
>
> Each of the following T lines contains 2 integers, n and prime P.
>
> *Output*
>
> For each test case, output a line contains the number of [image: \tbinom 
> nk]s (0<=k<=n) each of which after modulo operation by P is 0.
>
> *Sample Input*
>
> 3
>
> 2 2
>
> 3 2
>
> 4 3
>
> *Sample Output*
>
> 1
>
> 0
>
> 1
>
> *Constraints:*
>
> T is less than 100
>
> n is less than 10500.
> P is less than 109.
>  
>  
>  
>  
> I Have applied a logic that if any binomial coefficient can be written as 
> n!/(n-k)!k!  so if (n/p)>((n-k)/p+k/p) so that coefficient will be 
> divisiblr by prime number p. but the problem is range of is so large so if 
> i give an input of that much range it will take more then 15 min . although 
> complexity of my code is O(n/2) but my program keep on running because of 
> very high range of input. Can anyone help me in this please??
>  
> Thank you
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/aLFSGCkdtmsJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question

2012-08-22 Thread megha agrawal
Thanks Dave sir !

On Wed, Aug 22, 2012 at 3:47 AM, Dave  wrote:

> @Megha: Answered in one line of code in the post
> https://groups.google.com/d/msg/algogeeks/Fa-5AQR3ACU/jlmjb_nEZCsJ, which
> also contains a link to an explanation of how the algorithm works.
>
> Dave
>
> On Tuesday, August 21, 2012 8:23:21 AM UTC-5, megha agrawal wrote:
>
>>
>>Can anyone suggest solution for this problem?
>>
>>
>>You are given an unsigned integer.Write a function to print the next
>>number which will be having same number of 1 bits present in given
>>num.
>>eg) 6(110) to 9(1001)
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/F8_qYQin6_MJ.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question

2012-08-21 Thread Dave
@Megha: Answered in one line of code in the post 
https://groups.google.com/d/msg/algogeeks/Fa-5AQR3ACU/jlmjb_nEZCsJ, which 
also contains a link to an explanation of how the algorithm works.
 
Dave

On Tuesday, August 21, 2012 8:23:21 AM UTC-5, megha agrawal wrote:

>
>Can anyone suggest solution for this problem?
>
>
>You are given an unsigned integer.Write a function to print the next
>number which will be having same number of 1 bits present in given num.
>eg) 6(110) to 9(1001)
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/F8_qYQin6_MJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question asked in Amazon online test

2012-07-24 Thread Amit
Let's define a term "RANDOMNESS" of array as...
summation of position of each 1's
for eg
RANDOMNESS for 
(0,0,1,0,1,0,1,1)
will be
23
now calculate max possible RANDOMNESS for the given array (each 1 on max 
possible right position)
here it will be 26

so ans will be-->
MAX RANDOMNESS of given array - RANDOMNESS of given array

On Saturday, June 23, 2012 11:34:55 AM UTC+5:30, zerocool142 wrote:
>
> Given an array containing sequence of bits (0 or 1), you have to sort 
> this array in the ascending order i.e. all 0' in first part of array 
> followed by all 1's.   The constraints is that you can swap only the 
> adjacent elements in the array. Find the minimum number of swaps 
> required to sort the given input array. 
>
> Example:   Given the array (0,0,1,0,1,0,1,1) the minimum number of swaps 
> is 3. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/rugRBg0Q0-kJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Question asked in Amazon Online Test

2012-07-01 Thread Akshat Sapra
*Using Stack : *

j = 0;

for ( int i = 0; i < prefix.len(); i++ ) {
if ( isOperator(prefix[i]) ) stk.push(prefix[i]);
else {
   postfix[j] = prefix[i];
   j++;

   while ( !stk.empty() && stk.top == '#' ) {
   stk.pop();
   postfix[j] = stk.top();
   j++;
   stk.pop();
   }

   stk.push('#');
}
}

-- 


Akshat Sapra
Under Graduation(B.Tech)
IIIT-Allahabad(Amethi Campus)
*--*
sapraaks...@gmail.com
akshatsapr...@gmail.com
rit20009008@ iiita.ac.in

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question asked in Amazon Online Test

2012-07-01 Thread neelpulse
I think this algo is correct. 

On Sunday, 1 July 2012 13:06:17 UTC+5:30, Ashu wrote:
>
> count=0;
> Start parsing from left to right
> If operator push in stack.
> In number add in queue and increment count by one,
> if count == 2 then 
> pop from stack add in queue, decrements the count by one.
>
>
> On Friday, 29 June 2012 19:46:43 UTC+5:30, zerocool142 wrote:
>>
>> Given an integer expression in a prefix format (i.e. the operator 
>> precedes the number it is operating on) ,  print the expression in the 
>> post fix format . 
>>
>> Example: If the integer expression is in the prefix format is *+56-78, 
>> the postfix format expression is 56+78-*. Both of these 
>> correspond to the expression (5+6)*(7-8). 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/rDtvZKTNNQcJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question asked in Amazon Online Test

2012-07-01 Thread Ashu
count=0;
Start parsing from left to right
If operator push in stack.
In number add in queue and increment count by one,
if count == 2 then 
pop from stack add in queue, decrements the count by one.


On Friday, 29 June 2012 19:46:43 UTC+5:30, zerocool142 wrote:
>
> Given an integer expression in a prefix format (i.e. the operator 
> precedes the number it is operating on) ,  print the expression in the 
> post fix format . 
>
> Example: If the integer expression is in the prefix format is *+56-78, 
> the postfix format expression is 56+78-*. Both of these 
> correspond to the expression (5+6)*(7-8). 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/N4YE_XpyWjAJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question asked in Amazon online test

2012-06-30 Thread Navin Gupta
 minimum number of swaps required to sort the given input array = no. of 
inveresions in the array 
No. of inversions in the array is defined as no. of pairs (i,j)   such that 
a[i] > a[j]  && ihttps://groups.google.com/d/msg/algogeeks/-/44gDXly-hq0J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question asked in Amazon online test

2012-06-28 Thread Prateek Khurana
Hi,

This one is quite easy. You have to calculate the number of one's before 
every zero and add them up. That's it.

public class Test1 {

public void printArray(int[] tmpArr) {
for (int i : tmpArr) {
System.out.println(i);
}
}
 public int calculateMinSwaps(int[] tmpArr) {
int minSwaps = 0;
int numberOfOne = 0;
for (int i : tmpArr) {
if (i == 1) {
numberOfOne++;
} else {
minSwaps += numberOfOne;
}
}
return minSwaps;
}
 /**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
Test1 test1 = new Test1();
int[] minSwaps = {
1,1,1,0,0,0,1,0
};

// test1.printArray(minSwaps);
int minswap = test1.calculateMinSwaps(minSwaps);
System.out.println(minswap);
}

}


On Saturday, June 23, 2012 11:34:55 AM UTC+5:30, zerocool142 wrote:
>
> Given an array containing sequence of bits (0 or 1), you have to sort 
> this array in the ascending order i.e. all 0' in first part of array 
> followed by all 1's.   The constraints is that you can swap only the 
> adjacent elements in the array. Find the minimum number of swaps 
> required to sort the given input array. 
>
> Example:   Given the array (0,0,1,0,1,0,1,1) the minimum number of swaps 
> is 3. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/XDJ5a5YfykEJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question asked in Amazon online test

2012-06-28 Thread ANKIT BHARDWAJ

get the right most zero and left most one if index of right most zero is 
less than the index of left most one ,the problem is solved other wise swap 
0 and 1 and so on...
i argue this will give minimum swaps...

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/ELCan59xll4J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question asked in Tachyon interview

2012-06-27 Thread Dave
@Zerocool142: See 
https://groups.google.com/d/msg/algogeeks/483lcb0FTY0/YoQTNbOQ3aIJ. It 
implements addition using bitwise operators, and then uses that addition 
function and more bit operations to do multiplication, handling both 
positive and negative (2's complement) numbers.
 
Dave

On Tuesday, June 26, 2012 11:15:36 PM UTC-5, zerocool142 wrote:

> How to multiply two numbers without using * operator? 
> Hint:Use bit operators 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/lPeJnr89TNsJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread Sourabh Singh
@deepika anand

solution given by me is  for getting number of swap's in O(n)

as far as sorting goes any O(n lgn) algo can be used .
if count sort is allowed then O(n) for sorting also.[constant extra space.. ]


On Sat, Jun 23, 2012 at 12:49 AM, ashish jain  wrote:
> @all
>
> yaa.. For getting number of swaps..  we have to calculate total number of
> zeroes on the right for each '1' and on adding them
> we will get the number of swaps. and in O(n) time.
>
>
> On Sat, Jun 23, 2012 at 1:16 PM, Guruprasad Sridharan
>  wrote:
>>
>> It will work because we need to swap only adjacent elements. So we do a
>> sweep from left to right finding the number of ones encountered to the left
>> of a zero when we find a zero. We keep adding the number as we sweep the
>> entire length.
>>
>>
>> On Sat, Jun 23, 2012 at 1:14 PM, deepikaanand 
>> wrote:
>>>
>>> @saurabh..wat array r u getting finallyis it all 1's or in sorted
>>> order for the input
>>>  int a[8]={1,1,1,0,1,0,1,1};
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread ashish jain
@all

yaa.. For getting number of swaps..  we have to calculate total number of
zeroes on the right for each '1' and on adding them
we will get the number of swaps. and in O(n) time.


On Sat, Jun 23, 2012 at 1:16 PM, Guruprasad Sridharan <
sridharan.mi...@gmail.com> wrote:

> It will work because we need to swap only adjacent elements. So we do a
> sweep from left to right finding the number of ones encountered to the left
> of a zero when we find a zero. We keep adding the number as we sweep the
> entire length.
>
>
> On Sat, Jun 23, 2012 at 1:14 PM, deepikaanand wrote:
>
>> @saurabh..wat array r u getting finallyis it all 1's or in sorted
>> order for the input
>>  int a[8]={1,1,1,0,1,0,1,1};
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread Guruprasad Sridharan
It will work because we need to swap only adjacent elements. So we do a
sweep from left to right finding the number of ones encountered to the left
of a zero when we find a zero. We keep adding the number as we sweep the
entire length.

On Sat, Jun 23, 2012 at 1:14 PM, deepikaanand wrote:

> @saurabh..wat array r u getting finallyis it all 1's or in sorted
> order for the input
>  int a[8]={1,1,1,0,1,0,1,1};
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread rajesh pandey
start scanning the array from last .. maintain two pointers. one for last
encountered zero. second for moving backward. whenever you encounter the
one just swap it with the last zero. enhance the pointer till next zero
encounters.  at last you will have the number of swaps.
I think my solution works if i hv not misunderstood the problem..

Correct me if I am wrong.

Regards
Rajesh Pandey


On Sat, Jun 23, 2012 at 12:51 PM, Sourabh Singh wrote:

> @ALL
>
> see if this work's :
>
> #include
> using namespace std;
>
> int a[8]={0,0,1,0,1,0,1,1};
>
> int count_zero(int size)
> {   int i,count =0;
>for(i=0;ireturn count;
> }
> int solve(int size)
> {   int num_zero=count_zero(size);
>int p_zero,p_one,i;
>int count=0;
>p_zero=0;
>for(p_one=0;p_one{
>   if(!a[p_one])
>   {   count+=(p_one-p_zero);
>   p_zero++;
>   a[p_one]=1;
>   }
>}
>return count;
> }
> main()
> { printf("%d\n",solve(8));
>  system("pause");
>  return 0;
> }
>
>
> On Sat, Jun 23, 2012 at 12:09 AM, Darpan Baweja 
> wrote:
> > i think it can be done in O(n)
> > for each 1, calculate no. of zeros in right
> > and adding all no. of zeros in right of all 1's will give no. of swaps.
> >
> > correct me if i am wrong
> >
> >
> > On Sat, Jun 23, 2012 at 12:19 PM, Sourabh Singh <
> singhsourab...@gmail.com>
> > wrote:
> >>
> >> @deepika
> >>
> >> yes, it's giving number of swaps.
> >> still Linear time solution would be better :-)
> >>
> >> On Fri, Jun 22, 2012 at 11:38 PM, deepikaanand  >
> >> wrote:
> >> >
> >> > will bubble sort give number of swaps??
> >> >
> >> > I tried the (bubble sort) code of 1,0,0,1,1,0,1 >swapcount = 5
> >> > and for the array  (0,0,1,0,1,0,1,1)>swapcount = 3
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups "Algorithm Geeks" group.
> >> > To post to this group, send email to algogeeks@googlegroups.com.
> >> > To unsubscribe from this group, send email to
> >> > algogeeks+unsubscr...@googlegroups.com.
> >> > For more options, visit this group at
> >> > http://groups.google.com/group/algogeeks?hl=en.
> >> >
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/algogeeks?hl=en.
> >>
> >
> >
> >
> > --
> > DARPAN BAWEJA
> > 3rd year, I.T
> > MNNIT Allahabad
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread Anurag Gupta
if we just need to determine number of swaps, it can be Done in O(n)

Ex : 11100010

start counting number of zeros from the end
so we have zeroCount = 1

whenever we encounter a 1 we add current zeroCount to numberOfSwaps
so numberOfSwaps = 1
and so on the final value of numberOsSwaps is the answer

correct me if i am wrong

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread deepikaanand
@saurabh..wat array r u getting finallyis it all 1's or in sorted
order for the input
 int a[8]={1,1,1,0,1,0,1,1};

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread Sourabh Singh
@ALL

see if this work's :

#include
using namespace std;

int a[8]={0,0,1,0,1,0,1,1};

int count_zero(int size)
{   int i,count =0;
for(i=0;i wrote:
> i think it can be done in O(n)
> for each 1, calculate no. of zeros in right
> and adding all no. of zeros in right of all 1's will give no. of swaps.
>
> correct me if i am wrong
>
>
> On Sat, Jun 23, 2012 at 12:19 PM, Sourabh Singh 
> wrote:
>>
>> @deepika
>>
>> yes, it's giving number of swaps.
>> still Linear time solution would be better :-)
>>
>> On Fri, Jun 22, 2012 at 11:38 PM, deepikaanand 
>> wrote:
>> >
>> > will bubble sort give number of swaps??
>> >
>> > I tried the (bubble sort) code of 1,0,0,1,1,0,1 >swapcount = 5
>> > and for the array  (0,0,1,0,1,0,1,1)>swapcount = 3
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Algorithm Geeks" group.
>> > To post to this group, send email to algogeeks@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > algogeeks+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/algogeeks?hl=en.
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> DARPAN BAWEJA
> 3rd year, I.T
> MNNIT Allahabad
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread Darpan Baweja
i think it can be done in O(n)
for each 1, calculate no. of zeros in right
and adding all no. of zeros in right of all 1's will give no. of swaps.

correct me if i am wrong

On Sat, Jun 23, 2012 at 12:19 PM, Sourabh Singh wrote:

> @deepika
>
> yes, it's giving number of swaps.
> still Linear time solution would be better :-)
>
> On Fri, Jun 22, 2012 at 11:38 PM, deepikaanand 
> wrote:
> >
> > will bubble sort give number of swaps??
> >
> > I tried the (bubble sort) code of 1,0,0,1,1,0,1 >swapcount = 5
> > and for the array  (0,0,1,0,1,0,1,1)>swapcount = 3
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
*DARPAN BAWEJA*
*3rd year, I.T*
*MNNIT Allahabad*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-22 Thread Sourabh Singh
@deepika

yes, it's giving number of swaps.
still Linear time solution would be better :-)

On Fri, Jun 22, 2012 at 11:38 PM, deepikaanand  wrote:
>
> will bubble sort give number of swaps??
>
> I tried the (bubble sort) code of 1,0,0,1,1,0,1 >swapcount = 5
> and for the array  (0,0,1,0,1,0,1,1)>swapcount = 3
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to 
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question asked in Amazon online test

2012-06-22 Thread deepikaanand

will bubble sort give number of swaps??

I tried the (bubble sort) code of 1,0,0,1,1,0,1 >swapcount = 5
and for the array  (0,0,1,0,1,0,1,1)>swapcount = 3

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question

2011-09-22 Thread Shravan Kumar
@Yogesh Yadav

algo geek's approach is correct. With your number 759845. When you start
moving left from right most integer, you stop when the numbers are no longer
in increasing order, in this case you stop at first integer i.e, at 5 and
swap with 4. Which gives exactly same correct answer as you have mentioned.

On Fri, Sep 23, 2011 at 8:36 AM, Abhishek Goswami wrote:

> I have seen code and output but I think it should be 7965 am i right? if
> you are looking for first largest
>
>
> On Thu, Sep 22, 2011 at 12:46 AM, Anil Arya  wrote:
>
>> http://ideone.com/pmil8
>>
>>
>> On Thu, Sep 22, 2011 at 12:46 AM, Anil Arya wrote:
>>
>>> @kartik
>>> Is it right
>>>
>>>
>>> On Wed, Sep 21, 2011 at 10:24 PM, kartik sachan >> > wrote:
>>>
 obivously it will be first largest 

  --
 You received this message because you are subscribed to the Google
 Groups "Algorithm Geeks" group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>
>>>
>>> --
>>> *Anil  Arya,
>>> Computer Science *
>>> *Motilal Nehru National Institute of Technology,Allahabad .
>>> *
>>>
>>>
>>>
>>
>>
>> --
>> *Anil  Arya,
>> Computer Science *
>> *Motilal Nehru National Institute of Technology,Allahabad .
>> *
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question

2011-09-22 Thread Abhishek Goswami
I have seen code and output but I think it should be 7965 am i right? if you
are looking for first largest

On Thu, Sep 22, 2011 at 12:46 AM, Anil Arya  wrote:

> http://ideone.com/pmil8
>
>
> On Thu, Sep 22, 2011 at 12:46 AM, Anil Arya  wrote:
>
>> @kartik
>> Is it right
>>
>>
>> On Wed, Sep 21, 2011 at 10:24 PM, kartik sachan 
>> wrote:
>>
>>> obivously it will be first largest 
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> *Anil  Arya,
>> Computer Science *
>> *Motilal Nehru National Institute of Technology,Allahabad .
>> *
>>
>>
>>
>
>
> --
> *Anil  Arya,
> Computer Science *
> *Motilal Nehru National Institute of Technology,Allahabad .
> *
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question

2011-09-22 Thread Piyush Kapoor
Isn't it simply finding the next permutation of a number???

On Thu, Sep 22, 2011 at 7:01 PM, Dheeraj Sharma  wrote:

> @bharat...so i thnk 7585 shud hav 7855 as ans..!!
>
>
> On Thu, Sep 22, 2011 at 5:42 PM, Arpit Sood  wrote:
>
>> @yogesh nice algo...
>>
>> it is not even required to sort the left out array, just reverse it :)
>>
>> On Thu, Sep 22, 2011 at 5:05 PM, Yogesh Yadav  wrote:
>>
>>> @ratan: thanks for correction  little correction in my logic...
>>>
>>> start from rightmost digit and search towards left a digit less than
>>> this... if found ... just swap...now after swapping save the index with
>>> which you are swapping ...and after that sort the array in ascending
>>> order...u got the answer... if no small digit found then select second
>>> rightmost digit and follow the same process...and so on...
>>>
>>>
>>> 
>>>
>>> for ex: 759354
>>>
>>> rightmost digit =4
>>>
>>> search for smaller digit than 4 towards left... it will be 3...
>>>
>>> then  7594(53) now make the array in brackets in ascending order...
>>>
>>> answer 759435
>>>
>>> now am i right??
>>>
>>>
>>>
>>> On Thu, Sep 22, 2011 at 4:55 PM, Ratan wrote:
>>>
 the answer should be 759435...

 On Thu, Sep 22, 2011 at 4:45 PM, Yogesh Yadav 
 wrote:
 > my logic: if wrong then plz tell...
 >
 > start from rightmost digit and search towards left a digit less than
 this...
 > if found ... just swap...u got the answer... if no small digit found
 then
 > select second rightmost digit and follow the same process...and so
 on...
 >
 > 
 >
 > for ex: 759354
 >
 > rightmost digit =4
 >
 > search for smaller digit than 4 towards left... it will be 3...
 >
 > then answer 759453
 >
 >
 > 
 >
 > On Thu, Sep 22, 2011 at 4:40 PM, Yogesh Yadav 
 wrote:
 >>
 >> @algo geek:
 >>
 >> there is some error in your logic...
 >>
 >> consider a number 759845
 >>
 >> according to ur logic the number greater than this will be 784559
 >>
 >> but it should be 759854
 >>
 >> .
 >>
 >> On Thu, Sep 22, 2011 at 4:24 PM, algo geek 
 wrote:
 >>>
 >>> Keep a pointer ont the rightmost digit. Keep moving right until you
 find
 >>> the number in increasing number. As soon as this breaks. stop. Swap
 the
 >>> digit at the current position with the smallest digit, but larger
 than the
 >>> current position digit, sort the array to the right of the current
 position
 >>> in descending order.
 >>>
 >>> explanation:
 >>> NUMBER:759854
 >>> INDEX: 012356
 >>>
 >>> Keep the pointer at index 6. Keep moving right as long as numbers
 are in
 >>> increasing fashion. Stop at index 1.
 >>> swap this digit with the smallest digit larger than 5 i.e. 8
 >>> 78(9554)
 >>> now sort the array in parenthesis in descending order
 >>> ans : 784559
 >>>
 >>> For the implementation you can actually create an array of length
 10, to
 >>> keep track of all the digits encounters while moving left. This will
 help in
 >>> sorting as well (similar to counting sort).
 >>> One pass will do the work. You can print the answer directly
 afterwards.
 >>>
 >>> With Regards
 >>> Unknown
 >>>
 >>> On Thu, Sep 22, 2011 at 4:13 PM, Dheeraj Sharma
 >>>  wrote:
 
  in nlog(n)
  #include
  #include
  #include
  #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
  using namespace std;
  int t;
  void quicksort(char arr[],int left,int right)
  {
   if(left>>>   {
 int piv=right;
 int i=left,j=left;
 while((i>>> {
  if(arr[j]>>>  {
  swap(arr[i],arr[j],t);
  i++;
  }
  j++;
 }
 swap(arr[i],arr[piv],t);
 quicksort(arr,left,i-1);
 quicksort(arr,i+1,right);
 }
   }
  int main()
  {
  char str[100],t;
  int arr[100],i=0;
  cin>>str;
  int min=0;
  int len=strlen(str);
  while(str[i])
  {
   if(str[i]<=str[min])
   min=i;
   arr[i]=min;
   i++;
   }
   i=len-1;
   while((arr[i]==i)&&(i>0))
   i--;
   swap(str[i],str[arr[i]],t);
 
  if(i>0)
  quicksort(str,arr[i]+1,len-1);
   

Re: [algogeeks] Re: question

2011-09-22 Thread Dheeraj Sharma
@bharat...so i thnk 7585 shud hav 7855 as ans..!!

On Thu, Sep 22, 2011 at 5:42 PM, Arpit Sood  wrote:

> @yogesh nice algo...
>
> it is not even required to sort the left out array, just reverse it :)
>
> On Thu, Sep 22, 2011 at 5:05 PM, Yogesh Yadav  wrote:
>
>> @ratan: thanks for correction  little correction in my logic...
>>
>> start from rightmost digit and search towards left a digit less than
>> this... if found ... just swap...now after swapping save the index with
>> which you are swapping ...and after that sort the array in ascending
>> order...u got the answer... if no small digit found then select second
>> rightmost digit and follow the same process...and so on...
>>
>>
>> 
>>
>> for ex: 759354
>>
>> rightmost digit =4
>>
>> search for smaller digit than 4 towards left... it will be 3...
>>
>> then  7594(53) now make the array in brackets in ascending order...
>>
>> answer 759435
>>
>> now am i right??
>>
>>
>>
>> On Thu, Sep 22, 2011 at 4:55 PM, Ratan  wrote:
>>
>>> the answer should be 759435...
>>>
>>> On Thu, Sep 22, 2011 at 4:45 PM, Yogesh Yadav  wrote:
>>> > my logic: if wrong then plz tell...
>>> >
>>> > start from rightmost digit and search towards left a digit less than
>>> this...
>>> > if found ... just swap...u got the answer... if no small digit found
>>> then
>>> > select second rightmost digit and follow the same process...and so
>>> on...
>>> >
>>> > 
>>> >
>>> > for ex: 759354
>>> >
>>> > rightmost digit =4
>>> >
>>> > search for smaller digit than 4 towards left... it will be 3...
>>> >
>>> > then answer 759453
>>> >
>>> >
>>> > 
>>> >
>>> > On Thu, Sep 22, 2011 at 4:40 PM, Yogesh Yadav 
>>> wrote:
>>> >>
>>> >> @algo geek:
>>> >>
>>> >> there is some error in your logic...
>>> >>
>>> >> consider a number 759845
>>> >>
>>> >> according to ur logic the number greater than this will be 784559
>>> >>
>>> >> but it should be 759854
>>> >>
>>> >> .
>>> >>
>>> >> On Thu, Sep 22, 2011 at 4:24 PM, algo geek 
>>> wrote:
>>> >>>
>>> >>> Keep a pointer ont the rightmost digit. Keep moving right until you
>>> find
>>> >>> the number in increasing number. As soon as this breaks. stop. Swap
>>> the
>>> >>> digit at the current position with the smallest digit, but larger
>>> than the
>>> >>> current position digit, sort the array to the right of the current
>>> position
>>> >>> in descending order.
>>> >>>
>>> >>> explanation:
>>> >>> NUMBER:759854
>>> >>> INDEX: 012356
>>> >>>
>>> >>> Keep the pointer at index 6. Keep moving right as long as numbers are
>>> in
>>> >>> increasing fashion. Stop at index 1.
>>> >>> swap this digit with the smallest digit larger than 5 i.e. 8
>>> >>> 78(9554)
>>> >>> now sort the array in parenthesis in descending order
>>> >>> ans : 784559
>>> >>>
>>> >>> For the implementation you can actually create an array of length 10,
>>> to
>>> >>> keep track of all the digits encounters while moving left. This will
>>> help in
>>> >>> sorting as well (similar to counting sort).
>>> >>> One pass will do the work. You can print the answer directly
>>> afterwards.
>>> >>>
>>> >>> With Regards
>>> >>> Unknown
>>> >>>
>>> >>> On Thu, Sep 22, 2011 at 4:13 PM, Dheeraj Sharma
>>> >>>  wrote:
>>> 
>>>  in nlog(n)
>>>  #include
>>>  #include
>>>  #include
>>>  #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
>>>  using namespace std;
>>>  int t;
>>>  void quicksort(char arr[],int left,int right)
>>>  {
>>>   if(left>>   {
>>> int piv=right;
>>> int i=left,j=left;
>>> while((i>> {
>>>  if(arr[j]>>  {
>>>  swap(arr[i],arr[j],t);
>>>  i++;
>>>  }
>>>  j++;
>>> }
>>> swap(arr[i],arr[piv],t);
>>> quicksort(arr,left,i-1);
>>> quicksort(arr,i+1,right);
>>> }
>>>   }
>>>  int main()
>>>  {
>>>  char str[100],t;
>>>  int arr[100],i=0;
>>>  cin>>str;
>>>  int min=0;
>>>  int len=strlen(str);
>>>  while(str[i])
>>>  {
>>>   if(str[i]<=str[min])
>>>   min=i;
>>>   arr[i]=min;
>>>   i++;
>>>   }
>>>   i=len-1;
>>>   while((arr[i]==i)&&(i>0))
>>>   i--;
>>>   swap(str[i],str[arr[i]],t);
>>> 
>>>  if(i>0)
>>>  quicksort(str,arr[i]+1,len-1);
>>>  cout<>>   getch();
>>>  }
>>> 
>>> 
>>>  On Thu, Sep 22, 2011 at 3:33 PM, Dheeraj Sharma
>>>   wrote:
>>> >
>>> > #include
>>> > #include
>>> > #include
>>> > #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
>>> > using namespace std;
>>> > 

Re: [algogeeks] Re: question

2011-09-22 Thread Arpit Sood
@yogesh nice algo...

it is not even required to sort the left out array, just reverse it :)

On Thu, Sep 22, 2011 at 5:05 PM, Yogesh Yadav  wrote:

> @ratan: thanks for correction  little correction in my logic...
>
> start from rightmost digit and search towards left a digit less than
> this... if found ... just swap...now after swapping save the index with
> which you are swapping ...and after that sort the array in ascending
> order...u got the answer... if no small digit found then select second
> rightmost digit and follow the same process...and so on...
>
>
> 
>
> for ex: 759354
>
> rightmost digit =4
>
> search for smaller digit than 4 towards left... it will be 3...
>
> then  7594(53) now make the array in brackets in ascending order...
>
> answer 759435
>
> now am i right??
>
>
>
> On Thu, Sep 22, 2011 at 4:55 PM, Ratan  wrote:
>
>> the answer should be 759435...
>>
>> On Thu, Sep 22, 2011 at 4:45 PM, Yogesh Yadav  wrote:
>> > my logic: if wrong then plz tell...
>> >
>> > start from rightmost digit and search towards left a digit less than
>> this...
>> > if found ... just swap...u got the answer... if no small digit found
>> then
>> > select second rightmost digit and follow the same process...and so on...
>> >
>> > 
>> >
>> > for ex: 759354
>> >
>> > rightmost digit =4
>> >
>> > search for smaller digit than 4 towards left... it will be 3...
>> >
>> > then answer 759453
>> >
>> >
>> > 
>> >
>> > On Thu, Sep 22, 2011 at 4:40 PM, Yogesh Yadav 
>> wrote:
>> >>
>> >> @algo geek:
>> >>
>> >> there is some error in your logic...
>> >>
>> >> consider a number 759845
>> >>
>> >> according to ur logic the number greater than this will be 784559
>> >>
>> >> but it should be 759854
>> >>
>> >> .
>> >>
>> >> On Thu, Sep 22, 2011 at 4:24 PM, algo geek  wrote:
>> >>>
>> >>> Keep a pointer ont the rightmost digit. Keep moving right until you
>> find
>> >>> the number in increasing number. As soon as this breaks. stop. Swap
>> the
>> >>> digit at the current position with the smallest digit, but larger than
>> the
>> >>> current position digit, sort the array to the right of the current
>> position
>> >>> in descending order.
>> >>>
>> >>> explanation:
>> >>> NUMBER:759854
>> >>> INDEX: 012356
>> >>>
>> >>> Keep the pointer at index 6. Keep moving right as long as numbers are
>> in
>> >>> increasing fashion. Stop at index 1.
>> >>> swap this digit with the smallest digit larger than 5 i.e. 8
>> >>> 78(9554)
>> >>> now sort the array in parenthesis in descending order
>> >>> ans : 784559
>> >>>
>> >>> For the implementation you can actually create an array of length 10,
>> to
>> >>> keep track of all the digits encounters while moving left. This will
>> help in
>> >>> sorting as well (similar to counting sort).
>> >>> One pass will do the work. You can print the answer directly
>> afterwards.
>> >>>
>> >>> With Regards
>> >>> Unknown
>> >>>
>> >>> On Thu, Sep 22, 2011 at 4:13 PM, Dheeraj Sharma
>> >>>  wrote:
>> 
>>  in nlog(n)
>>  #include
>>  #include
>>  #include
>>  #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
>>  using namespace std;
>>  int t;
>>  void quicksort(char arr[],int left,int right)
>>  {
>>   if(left>   {
>> int piv=right;
>> int i=left,j=left;
>> while((i> {
>>  if(arr[j]>  {
>>  swap(arr[i],arr[j],t);
>>  i++;
>>  }
>>  j++;
>> }
>> swap(arr[i],arr[piv],t);
>> quicksort(arr,left,i-1);
>> quicksort(arr,i+1,right);
>> }
>>   }
>>  int main()
>>  {
>>  char str[100],t;
>>  int arr[100],i=0;
>>  cin>>str;
>>  int min=0;
>>  int len=strlen(str);
>>  while(str[i])
>>  {
>>   if(str[i]<=str[min])
>>   min=i;
>>   arr[i]=min;
>>   i++;
>>   }
>>   i=len-1;
>>   while((arr[i]==i)&&(i>0))
>>   i--;
>>   swap(str[i],str[arr[i]],t);
>> 
>>  if(i>0)
>>  quicksort(str,arr[i]+1,len-1);
>>  cout<>   getch();
>>  }
>> 
>> 
>>  On Thu, Sep 22, 2011 at 3:33 PM, Dheeraj Sharma
>>   wrote:
>> >
>> > #include
>> > #include
>> > #include
>> > #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
>> > using namespace std;
>> > int main()
>> > {
>> > char str[100],t;
>> > cin>>str;
>> >
>> > int len=strlen(str);
>> >  int i,x,boo=1;
>> > for(i=len-1;i>0&&boo;i--)
>> > {
>> > for(x=i-1;x>=0&&boo;x--)
>> > {
>> > if(str[x

Re: [algogeeks] Re: question

2011-09-22 Thread Yogesh Yadav
@ratan: thanks for correction  little correction in my logic...

start from rightmost digit and search towards left a digit less than this...
if found ... just swap...now after swapping save the index with which you
are swapping ...and after that sort the array in ascending order...u got the
answer... if no small digit found then select second rightmost digit and
follow the same process...and so on...



for ex: 759354

rightmost digit =4

search for smaller digit than 4 towards left... it will be 3...

then  7594(53) now make the array in brackets in ascending order...

answer 759435

now am i right??


On Thu, Sep 22, 2011 at 4:55 PM, Ratan  wrote:

> the answer should be 759435...
>
> On Thu, Sep 22, 2011 at 4:45 PM, Yogesh Yadav  wrote:
> > my logic: if wrong then plz tell...
> >
> > start from rightmost digit and search towards left a digit less than
> this...
> > if found ... just swap...u got the answer... if no small digit found then
> > select second rightmost digit and follow the same process...and so on...
> >
> > 
> >
> > for ex: 759354
> >
> > rightmost digit =4
> >
> > search for smaller digit than 4 towards left... it will be 3...
> >
> > then answer 759453
> >
> >
> > 
> >
> > On Thu, Sep 22, 2011 at 4:40 PM, Yogesh Yadav  wrote:
> >>
> >> @algo geek:
> >>
> >> there is some error in your logic...
> >>
> >> consider a number 759845
> >>
> >> according to ur logic the number greater than this will be 784559
> >>
> >> but it should be 759854
> >>
> >> .
> >>
> >> On Thu, Sep 22, 2011 at 4:24 PM, algo geek  wrote:
> >>>
> >>> Keep a pointer ont the rightmost digit. Keep moving right until you
> find
> >>> the number in increasing number. As soon as this breaks. stop. Swap the
> >>> digit at the current position with the smallest digit, but larger than
> the
> >>> current position digit, sort the array to the right of the current
> position
> >>> in descending order.
> >>>
> >>> explanation:
> >>> NUMBER:759854
> >>> INDEX: 012356
> >>>
> >>> Keep the pointer at index 6. Keep moving right as long as numbers are
> in
> >>> increasing fashion. Stop at index 1.
> >>> swap this digit with the smallest digit larger than 5 i.e. 8
> >>> 78(9554)
> >>> now sort the array in parenthesis in descending order
> >>> ans : 784559
> >>>
> >>> For the implementation you can actually create an array of length 10,
> to
> >>> keep track of all the digits encounters while moving left. This will
> help in
> >>> sorting as well (similar to counting sort).
> >>> One pass will do the work. You can print the answer directly
> afterwards.
> >>>
> >>> With Regards
> >>> Unknown
> >>>
> >>> On Thu, Sep 22, 2011 at 4:13 PM, Dheeraj Sharma
> >>>  wrote:
> 
>  in nlog(n)
>  #include
>  #include
>  #include
>  #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
>  using namespace std;
>  int t;
>  void quicksort(char arr[],int left,int right)
>  {
>   if(left   {
> int piv=right;
> int i=left,j=left;
> while((i {
>  if(arr[j]  {
>  swap(arr[i],arr[j],t);
>  i++;
>  }
>  j++;
> }
> swap(arr[i],arr[piv],t);
> quicksort(arr,left,i-1);
> quicksort(arr,i+1,right);
> }
>   }
>  int main()
>  {
>  char str[100],t;
>  int arr[100],i=0;
>  cin>>str;
>  int min=0;
>  int len=strlen(str);
>  while(str[i])
>  {
>   if(str[i]<=str[min])
>   min=i;
>   arr[i]=min;
>   i++;
>   }
>   i=len-1;
>   while((arr[i]==i)&&(i>0))
>   i--;
>   swap(str[i],str[arr[i]],t);
> 
>  if(i>0)
>  quicksort(str,arr[i]+1,len-1);
>  cout<   getch();
>  }
> 
> 
>  On Thu, Sep 22, 2011 at 3:33 PM, Dheeraj Sharma
>   wrote:
> >
> > #include
> > #include
> > #include
> > #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
> > using namespace std;
> > int main()
> > {
> > char str[100],t;
> > cin>>str;
> >
> > int len=strlen(str);
> >  int i,x,boo=1;
> > for(i=len-1;i>0&&boo;i--)
> > {
> > for(x=i-1;x>=0&&boo;x--)
> > {
> > if(str[x] > {
> > swap(str[x],str[i],t);
> > boo=0;
> > }
> > }
> > }
> > if(i>0)
> > {
> >
> > //Sorting...
> >for(int l=x+2;l >{
> >int min=l;
> >for(int k=l+1;k 

Re: [algogeeks] Re: question

2011-09-22 Thread Ratan
the answer should be 759435...

On Thu, Sep 22, 2011 at 4:45 PM, Yogesh Yadav  wrote:
> my logic: if wrong then plz tell...
>
> start from rightmost digit and search towards left a digit less than this...
> if found ... just swap...u got the answer... if no small digit found then
> select second rightmost digit and follow the same process...and so on...
>
> 
>
> for ex: 759354
>
> rightmost digit =4
>
> search for smaller digit than 4 towards left... it will be 3...
>
> then answer 759453
>
>
> 
>
> On Thu, Sep 22, 2011 at 4:40 PM, Yogesh Yadav  wrote:
>>
>> @algo geek:
>>
>> there is some error in your logic...
>>
>> consider a number 759845
>>
>> according to ur logic the number greater than this will be 784559
>>
>> but it should be 759854
>>
>> .
>>
>> On Thu, Sep 22, 2011 at 4:24 PM, algo geek  wrote:
>>>
>>> Keep a pointer ont the rightmost digit. Keep moving right until you find
>>> the number in increasing number. As soon as this breaks. stop. Swap the
>>> digit at the current position with the smallest digit, but larger than the
>>> current position digit, sort the array to the right of the current position
>>> in descending order.
>>>
>>> explanation:
>>> NUMBER:759854
>>> INDEX: 012356
>>>
>>> Keep the pointer at index 6. Keep moving right as long as numbers are in
>>> increasing fashion. Stop at index 1.
>>> swap this digit with the smallest digit larger than 5 i.e. 8
>>> 78(9554)
>>> now sort the array in parenthesis in descending order
>>> ans : 784559
>>>
>>> For the implementation you can actually create an array of length 10, to
>>> keep track of all the digits encounters while moving left. This will help in
>>> sorting as well (similar to counting sort).
>>> One pass will do the work. You can print the answer directly afterwards.
>>>
>>> With Regards
>>> Unknown
>>>
>>> On Thu, Sep 22, 2011 at 4:13 PM, Dheeraj Sharma
>>>  wrote:

 in nlog(n)
 #include
 #include
 #include
 #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
 using namespace std;
 int t;
 void quicksort(char arr[],int left,int right)
 {
  if(left>>>  {
    int piv=right;
    int i=left,j=left;
    while((i>>>    {
     if(arr[j]>>>     {
     swap(arr[i],arr[j],t);
     i++;
     }
     j++;
    }
    swap(arr[i],arr[piv],t);
    quicksort(arr,left,i-1);
    quicksort(arr,i+1,right);
    }
  }
 int main()
 {
     char str[100],t;
     int arr[100],i=0;
     cin>>str;
     int min=0;
     int len=strlen(str);
     while(str[i])
     {
  if(str[i]<=str[min])
  min=i;
  arr[i]=min;
  i++;
  }
  i=len-1;
  while((arr[i]==i)&&(i>0))
  i--;
  swap(str[i],str[arr[i]],t);

 if(i>0)
 quicksort(str,arr[i]+1,len-1);
     cout<>>>  getch();
 }


 On Thu, Sep 22, 2011 at 3:33 PM, Dheeraj Sharma
  wrote:
>
> #include
> #include
> #include
> #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
> using namespace std;
> int main()
> {
>     char str[100],t;
>     cin>>str;
>
>     int len=strlen(str);
>  int i,x,boo=1;
>     for(i=len-1;i>0&&boo;i--)
>     {
>     for(x=i-1;x>=0&&boo;x--)
>     {
>     if(str[x]     {
>     swap(str[x],str[i],t);
>     boo=0;
>     }
>     }
>     }
> if(i>0)
> {
>
> //Sorting...
>    for(int l=x+2;l    {
>    int min=l;
>    for(int k=l+1;k    {
>    if(str[k]    min=k;
>    }
>    swap(str[min],str[l],t);
>    }
> }
>     cout<
>
>  getch();
> }
>
>
> correct me..if m wrong..
>
> On Thu, Sep 22, 2011 at 2:01 PM, Ratan 
> wrote:
>>
>> @dheeraj ... ya u r ryt thnxs for the correction
>>
>> On Thu, Sep 22, 2011 at 1:30 PM, Dheeraj Sharma
>>  wrote:
>> > @Ratan:
>> > i think the next largest here would be 784559
>> >
>> > On Thu, Sep 22, 2011 at 12:39 PM, Ratan 
>> > wrote:
>> >>
>> >> @kartik : to some extent ur code is giving the right answer... btw
>> >> somehow check tis
>> >> let for example the no be 759854
>> >> then the next biggest no is 794558
>> >> btw ur program is giving 795854 which is undoubtedly
>> >> wrong
>> >> the code would giv

Re: [algogeeks] Re: question

2011-09-22 Thread Yogesh Yadav
my logic: if wrong then plz tell...

start from rightmost digit and search towards left a digit less than this...
if found ... just swap...u got the answer... if no small digit found then
select second rightmost digit and follow the same process...and so on...



for ex: 759354

rightmost digit =4

search for smaller digit than 4 towards left... it will be 3...

then answer 759453




On Thu, Sep 22, 2011 at 4:40 PM, Yogesh Yadav  wrote:

> @algo geek:
>
> there is some error in your logic...
>
> consider a number 759845
>
> according to ur logic the number greater than this will be 784559
>
> but it should be 759854
>
> .
>
>
> On Thu, Sep 22, 2011 at 4:24 PM, algo geek  wrote:
>
>> Keep a pointer ont the rightmost digit. Keep moving right until you find
>> the number in increasing number. As soon as this breaks. stop. Swap the
>> digit at the current position with the smallest digit, but larger than the
>> current position digit, sort the array to the right of the current position
>> in descending order.
>>
>> explanation:
>> NUMBER:759854
>> INDEX: 012356
>>
>> Keep the pointer at index 6. Keep moving right as long as numbers are in
>> increasing fashion. Stop at index 1.
>> swap this digit with the smallest digit larger than 5 i.e. 8
>> 78(9554)
>> now sort the array in parenthesis in descending order
>> ans : 784559
>>
>> For the implementation you can actually create an array of length 10, to
>> keep track of all the digits encounters while moving left. This will help in
>> sorting as well (similar to counting sort).
>> One pass will do the work. You can print the answer directly afterwards.
>>
>> With Regards
>> Unknown
>>
>>
>> On Thu, Sep 22, 2011 at 4:13 PM, Dheeraj Sharma <
>> dheerajsharma1...@gmail.com> wrote:
>>
>>> in nlog(n)
>>>
>>> #include
>>> #include
>>> #include
>>> #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
>>> using namespace std;
>>> int t;
>>> void quicksort(char arr[],int left,int right)
>>> {
>>>  if(left>>  {
>>>int piv=right;
>>>int i=left,j=left;
>>>while((i>>{
>>> if(arr[j]>> {
>>> swap(arr[i],arr[j],t);
>>> i++;
>>> }
>>> j++;
>>>}
>>>swap(arr[i],arr[piv],t);
>>>quicksort(arr,left,i-1);
>>>quicksort(arr,i+1,right);
>>>
>>>}
>>>  }
>>> int main()
>>> {
>>> char str[100],t;
>>> int arr[100],i=0;
>>> cin>>str;
>>> int min=0;
>>> int len=strlen(str);
>>> while(str[i])
>>> {
>>>  if(str[i]<=str[min])
>>>  min=i;
>>>  arr[i]=min;
>>>  i++;
>>>  }
>>>  i=len-1;
>>>  while((arr[i]==i)&&(i>0))
>>>  i--;
>>>  swap(str[i],str[arr[i]],t);
>>>
>>> if(i>0)
>>> quicksort(str,arr[i]+1,len-1);
>>> cout<>>  getch();
>>> }
>>>
>>>
>>> On Thu, Sep 22, 2011 at 3:33 PM, Dheeraj Sharma <
>>> dheerajsharma1...@gmail.com> wrote:
>>>
 #include
 #include
 #include
 #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
 using namespace std;
 int main()
 {
 char str[100],t;
 cin>>str;

 int len=strlen(str);
  int i,x,boo=1;
 for(i=len-1;i>0&&boo;i--)
 {
 for(x=i-1;x>=0&&boo;x--)
 {
 if(str[x]>>> {
 swap(str[x],str[i],t);
 boo=0;
 }
 }
 }
 if(i>0)
 {

 //Sorting...
for(int l=x+2;l>>>{
int min=l;
for(int k=l+1;k>>>{
if(str[k]>>>min=k;
}
swap(str[min],str[l],t);
}
 }
 cout<>>>

  getch();
 }


 correct me..if m wrong..


 On Thu, Sep 22, 2011 at 2:01 PM, Ratan wrote:

> @dheeraj ... ya u r ryt thnxs for the correction
>
> On Thu, Sep 22, 2011 at 1:30 PM, Dheeraj Sharma
>  wrote:
> > @Ratan:
> > i think the next largest here would be 784559
> >
> > On Thu, Sep 22, 2011 at 12:39 PM, Ratan 
> wrote:
> >>
> >> @kartik : to some extent ur code is giving the right answer... btw
> >> somehow check tis
> >> let for example the no be 759854
> >> then the next biggest no is 794558
> >> btw ur program is giving 795854 which is undoubtedly
> wrong
> >> the code would give more appropriate result if u sort the numbers
> from
> >> from i to n on meeting the condition of (a[i-1] >>
> >> On Thu, Sep 22, 2011 at 11:53 AM, Ramakant Sharma <
> ramakant...@gmail.com>
> >> wro

Re: [algogeeks] Re: question

2011-09-22 Thread Ratan
the following pseudocode may work:
for(i=l;i>=0;i--)
{
  if(a[i-1] wrote:
> @deeraj : for i/p 7585 u'r code is giving 7855 ..
>
> On Thu, Sep 22, 2011 at 6:54 AM, algo geek  wrote:
>>
>> Keep a pointer ont the rightmost digit. Keep moving right until you find
>> the number in increasing number. As soon as this breaks. stop. Swap the
>> digit at the current position with the smallest digit, but larger than the
>> current position digit, sort the array to the right of the current position
>> in descending order.
>>
>> explanation:
>> NUMBER:759854
>> INDEX: 012356
>>
>> Keep the pointer at index 6. Keep moving right as long as numbers are in
>> increasing fashion. Stop at index 1.
>> swap this digit with the smallest digit larger than 5 i.e. 8
>> 78(9554)
>> now sort the array in parenthesis in descending order
>> ans : 784559
>>
>> For the implementation you can actually create an array of length 10, to
>> keep track of all the digits encounters while moving left. This will help in
>> sorting as well (similar to counting sort).
>> One pass will do the work. You can print the answer directly afterwards.
>>
>> With Regards
>> Unknown
>>
>> On Thu, Sep 22, 2011 at 4:13 PM, Dheeraj Sharma
>>  wrote:
>>>
>>> in nlog(n)
>>> #include
>>> #include
>>> #include
>>> #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
>>> using namespace std;
>>> int t;
>>> void quicksort(char arr[],int left,int right)
>>> {
>>>  if(left>>  {
>>>    int piv=right;
>>>    int i=left,j=left;
>>>    while((i>>    {
>>>     if(arr[j]>>     {
>>>     swap(arr[i],arr[j],t);
>>>     i++;
>>>     }
>>>     j++;
>>>    }
>>>    swap(arr[i],arr[piv],t);
>>>    quicksort(arr,left,i-1);
>>>    quicksort(arr,i+1,right);
>>>    }
>>>  }
>>> int main()
>>> {
>>>     char str[100],t;
>>>     int arr[100],i=0;
>>>     cin>>str;
>>>     int min=0;
>>>     int len=strlen(str);
>>>     while(str[i])
>>>     {
>>>  if(str[i]<=str[min])
>>>  min=i;
>>>  arr[i]=min;
>>>  i++;
>>>  }
>>>  i=len-1;
>>>  while((arr[i]==i)&&(i>0))
>>>  i--;
>>>  swap(str[i],str[arr[i]],t);
>>>
>>> if(i>0)
>>> quicksort(str,arr[i]+1,len-1);
>>>     cout<>>  getch();
>>> }
>>>
>>>
>>> On Thu, Sep 22, 2011 at 3:33 PM, Dheeraj Sharma
>>>  wrote:

 #include
 #include
 #include
 #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
 using namespace std;
 int main()
 {
     char str[100],t;
     cin>>str;

     int len=strlen(str);
  int i,x,boo=1;
     for(i=len-1;i>0&&boo;i--)
     {
     for(x=i-1;x>=0&&boo;x--)
     {
     if(str[x]>>>     {
     swap(str[x],str[i],t);
     boo=0;
     }
     }
     }
 if(i>0)
 {

 //Sorting...
    for(int l=x+2;l>>>    {
    int min=l;
    for(int k=l+1;k>>>    {
    if(str[k]>>>    min=k;
    }
    swap(str[min],str[l],t);
    }
 }
     cout<>>>

  getch();
 }


 correct me..if m wrong..

 On Thu, Sep 22, 2011 at 2:01 PM, Ratan 
 wrote:
>
> @dheeraj ... ya u r ryt thnxs for the correction
>
> On Thu, Sep 22, 2011 at 1:30 PM, Dheeraj Sharma
>  wrote:
> > @Ratan:
> > i think the next largest here would be 784559
> >
> > On Thu, Sep 22, 2011 at 12:39 PM, Ratan 
> > wrote:
> >>
> >> @kartik : to some extent ur code is giving the right answer... btw
> >> somehow check tis
> >> let for example the no be 759854
> >> then the next biggest no is 794558
> >> btw ur program is giving 795854 which is undoubtedly
> >> wrong
> >> the code would give more appropriate result if u sort the numbers
> >> from
> >> from i to n on meeting the condition of (a[i-1] >>
> >> On Thu, Sep 22, 2011 at 11:53 AM, Ramakant Sharma
> >> 
> >> wrote:
> >> > starting from right find first digit less then right most digit,if
> >> > no
> >> > any
> >> > digit is less,then move to next right most and compair when
> >> > found
> >> > exchange those no,
> >> > now sort the no.s up to that index of the given no which is
> >> > exchanged:
> >> > Ex:
> >> > 43987723893239876
> >> > first required sequence: 439877238932[3]987[6] swap these no
> >> > 439877238932[6]{987[3]}
> >> > now sort in decreasing order  439877238932[6]{3789} this is the
> >> > required
> >> > no
> >> > c

Re: [algogeeks] Re: question

2011-09-22 Thread Yogesh Yadav
@algo geek:

there is some error in your logic...

consider a number 759845

according to ur logic the number greater than this will be 784559

but it should be 759854

.

On Thu, Sep 22, 2011 at 4:24 PM, algo geek  wrote:

> Keep a pointer ont the rightmost digit. Keep moving right until you find
> the number in increasing number. As soon as this breaks. stop. Swap the
> digit at the current position with the smallest digit, but larger than the
> current position digit, sort the array to the right of the current position
> in descending order.
>
> explanation:
> NUMBER:759854
> INDEX: 012356
>
> Keep the pointer at index 6. Keep moving right as long as numbers are in
> increasing fashion. Stop at index 1.
> swap this digit with the smallest digit larger than 5 i.e. 8
> 78(9554)
> now sort the array in parenthesis in descending order
> ans : 784559
>
> For the implementation you can actually create an array of length 10, to
> keep track of all the digits encounters while moving left. This will help in
> sorting as well (similar to counting sort).
> One pass will do the work. You can print the answer directly afterwards.
>
> With Regards
> Unknown
>
>
> On Thu, Sep 22, 2011 at 4:13 PM, Dheeraj Sharma <
> dheerajsharma1...@gmail.com> wrote:
>
>> in nlog(n)
>>
>> #include
>> #include
>> #include
>> #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
>> using namespace std;
>> int t;
>> void quicksort(char arr[],int left,int right)
>> {
>>  if(left>  {
>>int piv=right;
>>int i=left,j=left;
>>while((i>{
>> if(arr[j]> {
>> swap(arr[i],arr[j],t);
>> i++;
>> }
>> j++;
>>}
>>swap(arr[i],arr[piv],t);
>>quicksort(arr,left,i-1);
>>quicksort(arr,i+1,right);
>>
>>}
>>  }
>> int main()
>> {
>> char str[100],t;
>> int arr[100],i=0;
>> cin>>str;
>> int min=0;
>> int len=strlen(str);
>> while(str[i])
>> {
>>  if(str[i]<=str[min])
>>  min=i;
>>  arr[i]=min;
>>  i++;
>>  }
>>  i=len-1;
>>  while((arr[i]==i)&&(i>0))
>>  i--;
>>  swap(str[i],str[arr[i]],t);
>>
>> if(i>0)
>> quicksort(str,arr[i]+1,len-1);
>> cout<>  getch();
>> }
>>
>>
>> On Thu, Sep 22, 2011 at 3:33 PM, Dheeraj Sharma <
>> dheerajsharma1...@gmail.com> wrote:
>>
>>> #include
>>> #include
>>> #include
>>> #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
>>> using namespace std;
>>> int main()
>>> {
>>> char str[100],t;
>>> cin>>str;
>>>
>>> int len=strlen(str);
>>>  int i,x,boo=1;
>>> for(i=len-1;i>0&&boo;i--)
>>> {
>>> for(x=i-1;x>=0&&boo;x--)
>>> {
>>> if(str[x]>> {
>>> swap(str[x],str[i],t);
>>> boo=0;
>>> }
>>> }
>>> }
>>> if(i>0)
>>> {
>>>
>>> //Sorting...
>>>for(int l=x+2;l>>{
>>>int min=l;
>>>for(int k=l+1;k>>{
>>>if(str[k]>>min=k;
>>>}
>>>swap(str[min],str[l],t);
>>>}
>>> }
>>> cout<>>
>>>
>>>  getch();
>>> }
>>>
>>>
>>> correct me..if m wrong..
>>>
>>>
>>> On Thu, Sep 22, 2011 at 2:01 PM, Ratan wrote:
>>>
 @dheeraj ... ya u r ryt thnxs for the correction

 On Thu, Sep 22, 2011 at 1:30 PM, Dheeraj Sharma
  wrote:
 > @Ratan:
 > i think the next largest here would be 784559
 >
 > On Thu, Sep 22, 2011 at 12:39 PM, Ratan 
 wrote:
 >>
 >> @kartik : to some extent ur code is giving the right answer... btw
 >> somehow check tis
 >> let for example the no be 759854
 >> then the next biggest no is 794558
 >> btw ur program is giving 795854 which is undoubtedly
 wrong
 >> the code would give more appropriate result if u sort the numbers
 from
 >> from i to n on meeting the condition of (a[i-1]>>> >>
 >> On Thu, Sep 22, 2011 at 11:53 AM, Ramakant Sharma <
 ramakant...@gmail.com>
 >> wrote:
 >> > starting from right find first digit less then right most digit,if
 no
 >> > any
 >> > digit is less,then move to next right most and compair when
 found
 >> > exchange those no,
 >> > now sort the no.s up to that index of the given no which is
 exchanged:
 >> > Ex:
 >> > 43987723893239876
 >> > first required sequence: 439877238932[3]987[6] swap these no
 >> > 439877238932[6]{987[3]}
 >> > now sort in decreasing order  439877238932[6]{3789} this is the
 required
 >> > no
 >> > correct me if any thing wrong
 >> >
 >> >
 >> >
 >> >

Re: [algogeeks] Re: question

2011-09-22 Thread bharatkumar bagana
@deeraj : for i/p 7585 u'r code is giving 7855 ..

On Thu, Sep 22, 2011 at 6:54 AM, algo geek  wrote:

> Keep a pointer ont the rightmost digit. Keep moving right until you find
> the number in increasing number. As soon as this breaks. stop. Swap the
> digit at the current position with the smallest digit, but larger than the
> current position digit, sort the array to the right of the current position
> in descending order.
>
> explanation:
> NUMBER:759854
> INDEX: 012356
>
> Keep the pointer at index 6. Keep moving right as long as numbers are in
> increasing fashion. Stop at index 1.
> swap this digit with the smallest digit larger than 5 i.e. 8
> 78(9554)
> now sort the array in parenthesis in descending order
> ans : 784559
>
> For the implementation you can actually create an array of length 10, to
> keep track of all the digits encounters while moving left. This will help in
> sorting as well (similar to counting sort).
> One pass will do the work. You can print the answer directly afterwards.
>
> With Regards
> Unknown
>
>
> On Thu, Sep 22, 2011 at 4:13 PM, Dheeraj Sharma <
> dheerajsharma1...@gmail.com> wrote:
>
>> in nlog(n)
>>
>> #include
>> #include
>> #include
>> #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
>> using namespace std;
>> int t;
>> void quicksort(char arr[],int left,int right)
>> {
>>  if(left>  {
>>int piv=right;
>>int i=left,j=left;
>>while((i>{
>> if(arr[j]> {
>> swap(arr[i],arr[j],t);
>> i++;
>> }
>> j++;
>>}
>>swap(arr[i],arr[piv],t);
>>quicksort(arr,left,i-1);
>>quicksort(arr,i+1,right);
>>
>>}
>>  }
>> int main()
>> {
>> char str[100],t;
>> int arr[100],i=0;
>> cin>>str;
>> int min=0;
>> int len=strlen(str);
>> while(str[i])
>> {
>>  if(str[i]<=str[min])
>>  min=i;
>>  arr[i]=min;
>>  i++;
>>  }
>>  i=len-1;
>>  while((arr[i]==i)&&(i>0))
>>  i--;
>>  swap(str[i],str[arr[i]],t);
>>
>> if(i>0)
>> quicksort(str,arr[i]+1,len-1);
>> cout<>  getch();
>> }
>>
>>
>> On Thu, Sep 22, 2011 at 3:33 PM, Dheeraj Sharma <
>> dheerajsharma1...@gmail.com> wrote:
>>
>>> #include
>>> #include
>>> #include
>>> #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
>>> using namespace std;
>>> int main()
>>> {
>>> char str[100],t;
>>> cin>>str;
>>>
>>> int len=strlen(str);
>>>  int i,x,boo=1;
>>> for(i=len-1;i>0&&boo;i--)
>>> {
>>> for(x=i-1;x>=0&&boo;x--)
>>> {
>>> if(str[x]>> {
>>> swap(str[x],str[i],t);
>>> boo=0;
>>> }
>>> }
>>> }
>>> if(i>0)
>>> {
>>>
>>> //Sorting...
>>>for(int l=x+2;l>>{
>>>int min=l;
>>>for(int k=l+1;k>>{
>>>if(str[k]>>min=k;
>>>}
>>>swap(str[min],str[l],t);
>>>}
>>> }
>>> cout<>>
>>>
>>>  getch();
>>> }
>>>
>>>
>>> correct me..if m wrong..
>>>
>>>
>>> On Thu, Sep 22, 2011 at 2:01 PM, Ratan wrote:
>>>
 @dheeraj ... ya u r ryt thnxs for the correction

 On Thu, Sep 22, 2011 at 1:30 PM, Dheeraj Sharma
  wrote:
 > @Ratan:
 > i think the next largest here would be 784559
 >
 > On Thu, Sep 22, 2011 at 12:39 PM, Ratan 
 wrote:
 >>
 >> @kartik : to some extent ur code is giving the right answer... btw
 >> somehow check tis
 >> let for example the no be 759854
 >> then the next biggest no is 794558
 >> btw ur program is giving 795854 which is undoubtedly
 wrong
 >> the code would give more appropriate result if u sort the numbers
 from
 >> from i to n on meeting the condition of (a[i-1]>>> >>
 >> On Thu, Sep 22, 2011 at 11:53 AM, Ramakant Sharma <
 ramakant...@gmail.com>
 >> wrote:
 >> > starting from right find first digit less then right most digit,if
 no
 >> > any
 >> > digit is less,then move to next right most and compair when
 found
 >> > exchange those no,
 >> > now sort the no.s up to that index of the given no which is
 exchanged:
 >> > Ex:
 >> > 43987723893239876
 >> > first required sequence: 439877238932[3]987[6] swap these no
 >> > 439877238932[6]{987[3]}
 >> > now sort in decreasing order  439877238932[6]{3789} this is the
 required
 >> > no
 >> > correct me if any thing wrong
 >> >
 >> >
 >> >
 >> >
 >> >
 >> > --
 >> > You received this message because you are subscribed to the Google
 >> > Groups
 >> > "

Re: [algogeeks] Re: question

2011-09-22 Thread algo geek
Keep a pointer ont the rightmost digit. Keep moving right until you find the
number in increasing number. As soon as this breaks. stop. Swap the digit at
the current position with the smallest digit, but larger than the current
position digit, sort the array to the right of the current position in
descending order.

explanation:
NUMBER:759854
INDEX: 012356

Keep the pointer at index 6. Keep moving right as long as numbers are in
increasing fashion. Stop at index 1.
swap this digit with the smallest digit larger than 5 i.e. 8
78(9554)
now sort the array in parenthesis in descending order
ans : 784559

For the implementation you can actually create an array of length 10, to
keep track of all the digits encounters while moving left. This will help in
sorting as well (similar to counting sort).
One pass will do the work. You can print the answer directly afterwards.

With Regards
Unknown

On Thu, Sep 22, 2011 at 4:13 PM, Dheeraj Sharma  wrote:

> in nlog(n)
>
> #include
> #include
> #include
> #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
> using namespace std;
> int t;
> void quicksort(char arr[],int left,int right)
> {
>  if(left  {
>int piv=right;
>int i=left,j=left;
>while((i{
> if(arr[j] {
> swap(arr[i],arr[j],t);
> i++;
> }
> j++;
>}
>swap(arr[i],arr[piv],t);
>quicksort(arr,left,i-1);
>quicksort(arr,i+1,right);
>
>}
>  }
> int main()
> {
> char str[100],t;
> int arr[100],i=0;
> cin>>str;
> int min=0;
> int len=strlen(str);
> while(str[i])
> {
>  if(str[i]<=str[min])
>  min=i;
>  arr[i]=min;
>  i++;
>  }
>  i=len-1;
>  while((arr[i]==i)&&(i>0))
>  i--;
>  swap(str[i],str[arr[i]],t);
>
> if(i>0)
> quicksort(str,arr[i]+1,len-1);
> cout<  getch();
> }
>
>
> On Thu, Sep 22, 2011 at 3:33 PM, Dheeraj Sharma <
> dheerajsharma1...@gmail.com> wrote:
>
>> #include
>> #include
>> #include
>> #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
>> using namespace std;
>> int main()
>> {
>> char str[100],t;
>> cin>>str;
>>
>> int len=strlen(str);
>>  int i,x,boo=1;
>> for(i=len-1;i>0&&boo;i--)
>> {
>> for(x=i-1;x>=0&&boo;x--)
>> {
>> if(str[x]> {
>> swap(str[x],str[i],t);
>> boo=0;
>> }
>> }
>> }
>> if(i>0)
>> {
>>
>> //Sorting...
>>for(int l=x+2;l>{
>>int min=l;
>>for(int k=l+1;k>{
>>if(str[k]>min=k;
>>}
>>swap(str[min],str[l],t);
>>}
>> }
>> cout<>
>>
>>  getch();
>> }
>>
>>
>> correct me..if m wrong..
>>
>>
>> On Thu, Sep 22, 2011 at 2:01 PM, Ratan  wrote:
>>
>>> @dheeraj ... ya u r ryt thnxs for the correction
>>>
>>> On Thu, Sep 22, 2011 at 1:30 PM, Dheeraj Sharma
>>>  wrote:
>>> > @Ratan:
>>> > i think the next largest here would be 784559
>>> >
>>> > On Thu, Sep 22, 2011 at 12:39 PM, Ratan 
>>> wrote:
>>> >>
>>> >> @kartik : to some extent ur code is giving the right answer... btw
>>> >> somehow check tis
>>> >> let for example the no be 759854
>>> >> then the next biggest no is 794558
>>> >> btw ur program is giving 795854 which is undoubtedly wrong
>>> >> the code would give more appropriate result if u sort the numbers from
>>> >> from i to n on meeting the condition of (a[i-1]>> >>
>>> >> On Thu, Sep 22, 2011 at 11:53 AM, Ramakant Sharma <
>>> ramakant...@gmail.com>
>>> >> wrote:
>>> >> > starting from right find first digit less then right most digit,if
>>> no
>>> >> > any
>>> >> > digit is less,then move to next right most and compair when
>>> found
>>> >> > exchange those no,
>>> >> > now sort the no.s up to that index of the given no which is
>>> exchanged:
>>> >> > Ex:
>>> >> > 43987723893239876
>>> >> > first required sequence: 439877238932[3]987[6] swap these no
>>> >> > 439877238932[6]{987[3]}
>>> >> > now sort in decreasing order  439877238932[6]{3789} this is the
>>> required
>>> >> > no
>>> >> > correct me if any thing wrong
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> > --
>>> >> > You received this message because you are subscribed to the Google
>>> >> > Groups
>>> >> > "Algorithm Geeks" group.
>>> >> > To post to this group, send email to algogeeks@googlegroups.com.
>>> >> > To unsubscribe from this group, send email to
>>> >> > algogeeks+unsubscr...@googlegroups.com.
>>> >> > For more options, visit this group at
>>> >> > http://groups.google.com/group/algogeeks?hl=en.
>>> >> >
>>> >>
>>> >>
>>> >>
>>> >> --
>>

Re: [algogeeks] Re: question

2011-09-22 Thread Dheeraj Sharma
in nlog(n)
#include
#include
#include
#define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
using namespace std;
int t;
void quicksort(char arr[],int left,int right)
{
 if(left>str;
int min=0;
int len=strlen(str);
while(str[i])
{
 if(str[i]<=str[min])
 min=i;
 arr[i]=min;
 i++;
 }
 i=len-1;
 while((arr[i]==i)&&(i>0))
 i--;
 swap(str[i],str[arr[i]],t);

if(i>0)
quicksort(str,arr[i]+1,len-1);
cout< wrote:

> #include
> #include
> #include
> #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
> using namespace std;
> int main()
> {
> char str[100],t;
> cin>>str;
>
> int len=strlen(str);
>  int i,x,boo=1;
> for(i=len-1;i>0&&boo;i--)
> {
> for(x=i-1;x>=0&&boo;x--)
> {
> if(str[x] {
> swap(str[x],str[i],t);
> boo=0;
> }
> }
> }
> if(i>0)
> {
>
> //Sorting...
>for(int l=x+2;l{
>int min=l;
>for(int k=l+1;k{
>if(str[k]min=k;
>}
>swap(str[min],str[l],t);
>}
> }
> cout<
>
>  getch();
> }
>
>
> correct me..if m wrong..
>
>
> On Thu, Sep 22, 2011 at 2:01 PM, Ratan  wrote:
>
>> @dheeraj ... ya u r ryt thnxs for the correction
>>
>> On Thu, Sep 22, 2011 at 1:30 PM, Dheeraj Sharma
>>  wrote:
>> > @Ratan:
>> > i think the next largest here would be 784559
>> >
>> > On Thu, Sep 22, 2011 at 12:39 PM, Ratan 
>> wrote:
>> >>
>> >> @kartik : to some extent ur code is giving the right answer... btw
>> >> somehow check tis
>> >> let for example the no be 759854
>> >> then the next biggest no is 794558
>> >> btw ur program is giving 795854 which is undoubtedly wrong
>> >> the code would give more appropriate result if u sort the numbers from
>> >> from i to n on meeting the condition of (a[i-1]> >>
>> >> On Thu, Sep 22, 2011 at 11:53 AM, Ramakant Sharma <
>> ramakant...@gmail.com>
>> >> wrote:
>> >> > starting from right find first digit less then right most digit,if no
>> >> > any
>> >> > digit is less,then move to next right most and compair when found
>> >> > exchange those no,
>> >> > now sort the no.s up to that index of the given no which is
>> exchanged:
>> >> > Ex:
>> >> > 43987723893239876
>> >> > first required sequence: 439877238932[3]987[6] swap these no
>> >> > 439877238932[6]{987[3]}
>> >> > now sort in decreasing order  439877238932[6]{3789} this is the
>> required
>> >> > no
>> >> > correct me if any thing wrong
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "Algorithm Geeks" group.
>> >> > To post to this group, send email to algogeeks@googlegroups.com.
>> >> > To unsubscribe from this group, send email to
>> >> > algogeeks+unsubscr...@googlegroups.com.
>> >> > For more options, visit this group at
>> >> > http://groups.google.com/group/algogeeks?hl=en.
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Ratan Kumar
>> >> B. Tech
>> >> MNNIT,
>> >> Allahabad
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> Groups
>> >> "Algorithm Geeks" group.
>> >> To post to this group, send email to algogeeks@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> algogeeks+unsubscr...@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/algogeeks?hl=en.
>> >>
>> >
>> >
>> >
>> > --
>> > Dheeraj Sharma
>> > Comp Engg.
>> > NIT Kurukshetra
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Algorithm Geeks" group.
>> > To post to this group, send email to algogeeks@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > algogeeks+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/algogeeks?hl=en.
>> >
>>
>>
>>
>> --
>> Ratan Kumar
>> B. Tech
>> MNNIT,
>> Allahabad
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> *Dheeraj Sharma*
> Comp Engg.
> NIT Kurukshetra
>
>
>


-- 
*Dheeraj Sharma*
Comp Engg.
NIT Kurukshetra

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/

Re: [algogeeks] Re: question

2011-09-22 Thread kartik sachan
@ratan suggest some efficient algo...

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question

2011-09-22 Thread Dheeraj Sharma
#include
#include
#include
#define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
using namespace std;
int main()
{
char str[100],t;
cin>>str;

int len=strlen(str);
 int i,x,boo=1;
for(i=len-1;i>0&&boo;i--)
{
for(x=i-1;x>=0&&boo;x--)
{
if(str[x]0)
{

//Sorting...
   for(int l=x+2;l wrote:

> @dheeraj ... ya u r ryt thnxs for the correction
>
> On Thu, Sep 22, 2011 at 1:30 PM, Dheeraj Sharma
>  wrote:
> > @Ratan:
> > i think the next largest here would be 784559
> >
> > On Thu, Sep 22, 2011 at 12:39 PM, Ratan 
> wrote:
> >>
> >> @kartik : to some extent ur code is giving the right answer... btw
> >> somehow check tis
> >> let for example the no be 759854
> >> then the next biggest no is 794558
> >> btw ur program is giving 795854 which is undoubtedly wrong
> >> the code would give more appropriate result if u sort the numbers from
> >> from i to n on meeting the condition of (a[i-1] >>
> >> On Thu, Sep 22, 2011 at 11:53 AM, Ramakant Sharma <
> ramakant...@gmail.com>
> >> wrote:
> >> > starting from right find first digit less then right most digit,if no
> >> > any
> >> > digit is less,then move to next right most and compair when found
> >> > exchange those no,
> >> > now sort the no.s up to that index of the given no which is exchanged:
> >> > Ex:
> >> > 43987723893239876
> >> > first required sequence: 439877238932[3]987[6] swap these no
> >> > 439877238932[6]{987[3]}
> >> > now sort in decreasing order  439877238932[6]{3789} this is the
> required
> >> > no
> >> > correct me if any thing wrong
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups
> >> > "Algorithm Geeks" group.
> >> > To post to this group, send email to algogeeks@googlegroups.com.
> >> > To unsubscribe from this group, send email to
> >> > algogeeks+unsubscr...@googlegroups.com.
> >> > For more options, visit this group at
> >> > http://groups.google.com/group/algogeeks?hl=en.
> >> >
> >>
> >>
> >>
> >> --
> >> Ratan Kumar
> >> B. Tech
> >> MNNIT,
> >> Allahabad
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/algogeeks?hl=en.
> >>
> >
> >
> >
> > --
> > Dheeraj Sharma
> > Comp Engg.
> > NIT Kurukshetra
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
>
>
>
> --
> Ratan Kumar
> B. Tech
> MNNIT,
> Allahabad
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
*Dheeraj Sharma*
Comp Engg.
NIT Kurukshetra

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question

2011-09-22 Thread Ratan
@dheeraj ... ya u r ryt thnxs for the correction

On Thu, Sep 22, 2011 at 1:30 PM, Dheeraj Sharma
 wrote:
> @Ratan:
> i think the next largest here would be 784559
>
> On Thu, Sep 22, 2011 at 12:39 PM, Ratan  wrote:
>>
>> @kartik : to some extent ur code is giving the right answer... btw
>> somehow check tis
>> let for example the no be 759854
>> then the next biggest no is 794558
>> btw ur program is giving 795854 which is undoubtedly wrong
>> the code would give more appropriate result if u sort the numbers from
>> from i to n on meeting the condition of (a[i-1]>
>> On Thu, Sep 22, 2011 at 11:53 AM, Ramakant Sharma 
>> wrote:
>> > starting from right find first digit less then right most digit,if no
>> > any
>> > digit is less,then move to next right most and compair when found
>> > exchange those no,
>> > now sort the no.s up to that index of the given no which is exchanged:
>> > Ex:
>> > 43987723893239876
>> > first required sequence: 439877238932[3]987[6] swap these no
>> > 439877238932[6]{987[3]}
>> > now sort in decreasing order  439877238932[6]{3789} this is the required
>> > no
>> > correct me if any thing wrong
>> >
>> >
>> >
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Algorithm Geeks" group.
>> > To post to this group, send email to algogeeks@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > algogeeks+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/algogeeks?hl=en.
>> >
>>
>>
>>
>> --
>> Ratan Kumar
>> B. Tech
>> MNNIT,
>> Allahabad
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Dheeraj Sharma
> Comp Engg.
> NIT Kurukshetra
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Ratan Kumar
B. Tech
MNNIT,
Allahabad

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question

2011-09-22 Thread Dheeraj Sharma
@Ratan:
i think the next largest here would be 784559

On Thu, Sep 22, 2011 at 12:39 PM, Ratan  wrote:

> @kartik : to some extent ur code is giving the right answer... btw
> somehow check tis
> let for example the no be 759854
> then the next biggest no is 794558
> btw ur program is giving 795854 which is undoubtedly wrong
> the code would give more appropriate result if u sort the numbers from
> from i to n on meeting the condition of (a[i-1]
> On Thu, Sep 22, 2011 at 11:53 AM, Ramakant Sharma 
> wrote:
> > starting from right find first digit less then right most digit,if no any
> > digit is less,then move to next right most and compair when found
> > exchange those no,
> > now sort the no.s up to that index of the given no which is exchanged:
> > Ex:
> > 43987723893239876
> > first required sequence: 439877238932[3]987[6] swap these no
> > 439877238932[6]{987[3]}
> > now sort in decreasing order  439877238932[6]{3789} this is the required
> no
> > correct me if any thing wrong
> >
> >
> >
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
>
>
>
> --
> Ratan Kumar
> B. Tech
> MNNIT,
> Allahabad
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
*Dheeraj Sharma*
Comp Engg.
NIT Kurukshetra

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question

2011-09-22 Thread Ratan
@kartik : to some extent ur code is giving the right answer... btw
somehow check tis
let for example the no be 759854
then the next biggest no is 794558
btw ur program is giving 795854 which is undoubtedly wrong
the code would give more appropriate result if u sort the numbers from
from i to n on meeting the condition of (a[i-1] wrote:
> starting from right find first digit less then right most digit,if no any
> digit is less,then move to next right most and compair when found
> exchange those no,
> now sort the no.s up to that index of the given no which is exchanged:
> Ex:
> 43987723893239876
> first required sequence: 439877238932[3]987[6] swap these no
> 439877238932[6]{987[3]}
> now sort in decreasing order  439877238932[6]{3789} this is the required no
> correct me if any thing wrong
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Ratan Kumar
B. Tech
MNNIT,
Allahabad

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question

2011-09-21 Thread Ramakant Sharma
starting from right find first digit less then right most digit,if no any
digit is less,then move to next right most and compair when found
exchange those no,
now sort the no.s up to that index of the given no which is exchanged:
Ex:
43987723893239876
first required sequence: 439877238932[3]987[6] swap these no
439877238932[6]{987[3]}
now sort in decreasing order  439877238932[6]{3789} this is the required no
correct me if any thing wrong

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question

2011-09-21 Thread kartik sachan
@arya ur code for 7695...giving ans 9765
but ans should be 7965

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question

2011-09-21 Thread Anil Arya
http://ideone.com/pmil8

On Thu, Sep 22, 2011 at 12:46 AM, Anil Arya  wrote:

> @kartik
> Is it right
>
>
> On Wed, Sep 21, 2011 at 10:24 PM, kartik sachan 
> wrote:
>
>> obivously it will be first largest 
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> *Anil  Arya,
> Computer Science *
> *Motilal Nehru National Institute of Technology,Allahabad .
> *
>
>
>


-- 
*Anil  Arya,
Computer Science *
*Motilal Nehru National Institute of Technology,Allahabad .
*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question

2011-09-21 Thread Anil Arya
@kartik
Is it right

On Wed, Sep 21, 2011 at 10:24 PM, kartik sachan wrote:

> obivously it will be first largest 
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*Anil  Arya,
Computer Science *
*Motilal Nehru National Institute of Technology,Allahabad .
*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question

2011-09-21 Thread kartik sachan
obivously it will be first largest 

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question

2011-09-21 Thread Ankuj Gupta
If it is the first largest ?

On Sep 21, 8:02 pm, Dave  wrote:
> @Prasanth: Since there is no requirement to find the next larger
> number, you can go for the largest. Extract the digits into an array
> using modulus and division by 10. Then sort the digits into descending
> order. Finally, construct the answer by repeated multiplication by 10
> and addition.
>
> If you want, you can check to see if the resulting number is greater
> than the original and return an error code if it is just equal to it.
> E.g., 8755 already has its digits in decreasing order, so the above
> algorithm will reproduce 8755.
>
> Dave
>
> On Sep 21, 8:53 am, prasanth n  wrote:
>
>
>
>
>
>
>
> > You have given a positive number you have to find a number which is bigger
> > than that by using same digits available in the number .
> > Example :-
> > You have given a number 7585 , your output should be 7855 .
>
> > --
> > *prasanth*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question

2011-09-21 Thread Dave
@Prasanth: Since there is no requirement to find the next larger
number, you can go for the largest. Extract the digits into an array
using modulus and division by 10. Then sort the digits into descending
order. Finally, construct the answer by repeated multiplication by 10
and addition.

If you want, you can check to see if the resulting number is greater
than the original and return an error code if it is just equal to it.
E.g., 8755 already has its digits in decreasing order, so the above
algorithm will reproduce 8755.

Dave

On Sep 21, 8:53 am, prasanth n  wrote:
> You have given a positive number you have to find a number which is bigger
> than that by using same digits available in the number .
> Example :-
> You have given a number 7585 , your output should be 7855 .
>
> --
> *prasanth*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question -->

2011-09-20 Thread veeru

before, i wrote small mistake
 N=(N&(~0<<(j+1))|(~(~0

[algogeeks] Re: Question -->

2011-09-20 Thread veeru
N=(N&(~0<<(j+1))|(~(~0

[algogeeks] Re: Question -->

2011-09-20 Thread Don
@Dave: Beautiful.
Don

On Sep 20, 11:53 am, Dave  wrote:
> I am missing a couple of parentheses. So make that
>
> N = (N & ~((2 << j) - (1 << i))) | (M << i);
>
> And to make up for the extra post to get it right, I'll explain it:
> 2< 1< The difference of the two is a number with one bits from positions i
> to and including j, and 0 bits elsewhere.
> ~that is a number with 0 bits from positions i to and including j and
> 1 bits elsewhere.
> N&that is the number N with the bits from positions i to and including
> j set to zero.
> M< | puts the two pieces together.
>
> In the above, I've assumed that the field consisting of bits i through
> j inclusive are to be modified. If what is intended is that i is the
> first bit modified and j is the first bit not modified (so that j-i
> bits are modified), then change 2<
> Dave
>
> Dave
>
> On Sep 20, 11:41 am, Dave  wrote:
>
> > @Ishan: Using bitwise operations:
>
> > N = (N & ~((2 << j) - (1 << i) | (M << i);
>
> > Dave
>
> > On Sep 20, 2:03 am, Ishan Aggarwal 
> > wrote:
>
> > > You are given two 32-bit numbers, N and M, and two bit positions, i and
> > > j.Write a method to set all bits between i and j in N equal to M (e.g., M
> > > becomes a substring of N located at i and starting at j).
>
> > > EXAMPLE:
>
> > > Input: N = 100, M = 10101, i = 2, j = 6
>
> > > Output: N = 10001010100
>
> > > --
> > > Kind Regards
> > > Ishan Aggarwal
> > > [image: Aricent Group]
> > > Presidency Tower-A, M.G.Road,Sector-14
> > > Gurgaon,Haryana.122015 INDIA
> > > Phone : +91-9654602663
> > > ishan2.aggar...@aricent.com - Hide quoted text -
>
> > - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question -->

2011-09-20 Thread Dave
I am missing a couple of parentheses. So make that

N = (N & ~((2 << j) - (1 << i))) | (M << i);

And to make up for the extra post to get it right, I'll explain it:
2< wrote:
> @Ishan: Using bitwise operations:
>
> N = (N & ~((2 << j) - (1 << i) | (M << i);
>
> Dave
>
> On Sep 20, 2:03 am, Ishan Aggarwal 
> wrote:
>
>
>
> > You are given two 32-bit numbers, N and M, and two bit positions, i and
> > j.Write a method to set all bits between i and j in N equal to M (e.g., M
> > becomes a substring of N located at i and starting at j).
>
> > EXAMPLE:
>
> > Input: N = 100, M = 10101, i = 2, j = 6
>
> > Output: N = 10001010100
>
> > --
> > Kind Regards
> > Ishan Aggarwal
> > [image: Aricent Group]
> > Presidency Tower-A, M.G.Road,Sector-14
> > Gurgaon,Haryana.122015 INDIA
> > Phone : +91-9654602663
> > ishan2.aggar...@aricent.com - Hide quoted text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Question -->

2011-09-20 Thread Ishan Aggarwal
Can someone explain me what this code is doing??

void main()
{
int n,m i,j;
int max = ~0;
// 1's through position j, then 0's
int left = max  - (( 1 << j) - 1);
//1' after position i
int right = (( 1<< i) -1)
// 1's with 0's betwwen i and j
int mask = left | right ;
// clear i through j , then put m in there
 return ( n & mask ) | ( m << i)
}



On Tue, Sep 20, 2011 at 10:11 PM, Dave  wrote:

> @Ishan: Using bitwise operations:
>
> N = (N & ~((2 << j) - (1 << i) | (M << i);
>
> Dave
>
> On Sep 20, 2:03 am, Ishan Aggarwal 
> wrote:
>  > You are given two 32-bit numbers, N and M, and two bit positions, i and
> > j.Write a method to set all bits between i and j in N equal to M (e.g., M
> > becomes a substring of N located at i and starting at j).
> >
> > EXAMPLE:
> >
> > Input: N = 100, M = 10101, i = 2, j = 6
> >
> > Output: N = 10001010100
> >
> > --
> > Kind Regards
> > Ishan Aggarwal
> > [image: Aricent Group]
> > Presidency Tower-A, M.G.Road,Sector-14
> > Gurgaon,Haryana.122015 INDIA
> > Phone : +91-9654602663
> > ishan2.aggar...@aricent.com 
>
> --
>  You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Kind Regards
Ishan Aggarwal
[image: Aricent Group]
Presidency Tower-A, M.G.Road,Sector-14
Gurgaon,Haryana.122015 INDIA
Phone : +91-9654602663
ishan2.aggar...@aricent.com 

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question -->

2011-09-20 Thread Dave
@Ishan: Using bitwise operations:

N = (N & ~((2 << j) - (1 << i) | (M << i);

Dave

On Sep 20, 2:03 am, Ishan Aggarwal 
wrote:
> You are given two 32-bit numbers, N and M, and two bit positions, i and
> j.Write a method to set all bits between i and j in N equal to M (e.g., M
> becomes a substring of N located at i and starting at j).
>
> EXAMPLE:
>
> Input: N = 100, M = 10101, i = 2, j = 6
>
> Output: N = 10001010100
>
> --
> Kind Regards
> Ishan Aggarwal
> [image: Aricent Group]
> Presidency Tower-A, M.G.Road,Sector-14
> Gurgaon,Haryana.122015 INDIA
> Phone : +91-9654602663
> ishan2.aggar...@aricent.com 

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Question -->

2011-09-20 Thread Yogesh Yadav
@ishan:
there is error in your loop bro...
for(k=31;k>=0;k++)

it should be k--

.
On Tue, Sep 20, 2011 at 3:10 PM, vijay singh wrote:

>
>
> On Tue, Sep 20, 2011 at 2:16 PM, Ishan Aggarwal <
> ishan.aggarwal.1...@gmail.com> wrote:
>
>> Hi,
>>
>> When I am running this program, I am getting segmentation fault. Can u plz
>> confirm where is the error.
>>
>> #include
>> void main()
>> {
>> int Num[31]={0};
>> int Mum[31]={0};
>> int n = 64,m = 7  ,i=0,j=3,k;
>> for(k=31;k>=0;k++)   // k's value should start from 30
>> because Num[31] doesn't exist and hence it is giving
>> {  // segmentation fault.
>> Olny 0...30 indices exist.
>> Num[k]=n & 1;
>> Mum[k]=m & 1;
>> n=n>>1;
>> m=m>>1;
>>  }
>>
>> for(k=i;k<=j;k++)
>> Num[k]=Mum[k];
>>
>> for(k=0;k<=31;k++)
>> printf("%d ", Num[k]);
>> }
>>
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Question -->

2011-09-20 Thread vijay singh
On Tue, Sep 20, 2011 at 2:16 PM, Ishan Aggarwal <
ishan.aggarwal.1...@gmail.com> wrote:

> Hi,
>
> When I am running this program, I am getting segmentation fault. Can u plz
> confirm where is the error.
>
> #include
> void main()
> {
> int Num[31]={0};
> int Mum[31]={0};
> int n = 64,m = 7  ,i=0,j=3,k;
> for(k=31;k>=0;k++)   // k's value should start from 30
> because Num[31] doesn't exist and hence it is giving
> {  // segmentation fault.
> Olny 0...30 indices exist.
> Num[k]=n & 1;
> Mum[k]=m & 1;
> n=n>>1;
> m=m>>1;
> }
>
> for(k=i;k<=j;k++)
> Num[k]=Mum[k];
>
> for(k=0;k<=31;k++)
> printf("%d ", Num[k]);
> }
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Question -->

2011-09-20 Thread Dheeraj Sharma
int num1=0;
int num2=1;
int num3=21;
int j=6;
int i=2;
for(int k=1;k<=(j-i);k++)
{
num2<<=1;
num2+=1;
printf("%d\n",num2);
}
for(int k=1;k<=i;k++)
{
num2<<=1;
num3<<=1;
printf("%d\n",num2);
printf("%d\n",num3);
}
num2=~num2;
num1&=num2;
num1|=num3;
printf("%d",num1);

On Tue, Sep 20, 2011 at 2:27 PM, Ishan Aggarwal <
ishan.aggarwal.1...@gmail.com> wrote:

> Again it is giving the same error. on changing it to 32.
>
>
> On Tue, Sep 20, 2011 at 2:18 PM, abhinav gupta wrote:
>
>> Instead of Num[31] u should tk Num[32]
>>
>> On Tue, Sep 20, 2011 at 2:16 PM, Ishan Aggarwal <
>> ishan.aggarwal.1...@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> When I am running this program, I am getting segmentation fault. Can u
>>> plz confirm where is the error.
>>>
>>> #include
>>> void main()
>>> {
>>> int Num[31]={0};
>>> int Mum[31]={0};
>>> int n = 64,m = 7  ,i=0,j=3,k;
>>> for(k=31;k>=0;k++)
>>> {
>>> Num[k]=n & 1;
>>> Mum[k]=m & 1;
>>> n=n>>1;
>>> m=m>>1;
>>> }
>>>
>>> for(k=i;k<=j;k++)
>>> Num[k]=Mum[k];
>>>
>>> for(k=0;k<=31;k++)
>>> printf("%d ", Num[k]);
>>> }
>>>
>>>
>>> On Tue, Sep 20, 2011 at 1:49 PM, tec  wrote:
>>>
 mask = (1<<(j+1))-(1<>>> n = (n&(~mask)) | m;


 On Sep 20, 3:43 pm, abhinav gupta  wrote:
 > You can also solve the problem by using bit operators. by using >> <<
 & | !
 > .
 > Need sm thinking in dat..No time rite nw!
 >
 > On Tue, Sep 20, 2011 at 1:12 PM, abhinav gupta <
 guptaabhinav...@gmail.com>wrote:
 >
 >
 >
 >
 >
 >
 >
 >
 >
 > > Its because o/p should look like dat.Bt dats simple you can do it
 > > by multiplying bits to power(2, i) and
 > > adding all expressions.Simple!
 > > On Tue, Sep 20, 2011 at 1:09 PM, abhinav gupta <
 guptaabhinav...@gmail.com>wrote
 >
 > >  In the first loop bits are added into the array N and M .I have
 taken two
 > >> integers n and m .
 > >> Caution :
 > >> declare
 >
 > >> int N[31]={0};
 > >> int M[31]={0};
 > >> int n,m,i,j;
 >
 > >>   On Tue, Sep 20, 2011 at 1:02 PM, Ishan Aggarwal <
 > >> ishan.aggarwal.1...@gmail.com> wrote:
 >
 > >>> What are u doing in the first loop running for k=31 to k =0?
 >
 > >>> On Tue, Sep 20, 2011 at 12:50 PM, abhinav gupta <
 > >>> guptaabhinav...@gmail.com> wrote:
 >
 >  U can use single walker (from 0 till 31) to convert integers N
 and M
 >  into array of bits, then
 >  another walker from i to j to replace values.
 >
 >  for(k=31;k>=0;k++)
 >  {
 >  N[k]=n & 01;
 >  M[k]=m &01;
 >  n>>=1;
 >  m>>=1;
 >  }
 >
 >  for(k=i;k<=j;k++)
 >  N[k]=M[k];
 >
 >    On Tue, Sep 20, 2011 at 12:44 PM, abhinav gupta <
 >  guptaabhinav...@gmail.com> wrote:
 >
 > > I can tell you the logic.Take two arrays N and M, put their bits
 in
 > > the array.
 > > Now using i and j index replace the value of N[j] to n[i] by
 M[j] to
 > > M[i].
 > >   On Tue, Sep 20, 2011 at 12:33 PM, Ishan Aggarwal <
 > > ishan.aggarwal.1...@gmail.com> wrote:
 >
 > >> You are given two 32-bit numbers, N and M, and two bit
 positions, i
 > >> and j.Write a method to set all bits between i and j in N equal
 to M (e.g.,
 > >> M becomes a substring of N located at i and starting at j).
 >
 > >> EXAMPLE:
 >
 > >> Input: N = 100, M = 10101, i = 2, j = 6
 >
 > >> Output: N = 10001010100
 >
 > >> --
 > >> Kind Regards
 > >> Ishan Aggarwal
 > >> [image: Aricent Group]
 > >> Presidency Tower-A, M.G.Road,Sector-14
 > >> Gurgaon,Haryana.122015 INDIA
 > >> Phone : +91-9654602663
 > >> ishan2.aggar...@aricent.com 
 >
 > >> --
 > >> You received this message because you are subscribed to the
 Google
 > >> Groups "Algorithm Geeks" group.
 > >> To post to this group, send email to
 algogeeks@googlegroups.com.
 > >> To unsubscribe from this group, send email to
 > >> algogeeks+unsubscr...@googlegroups.com.
 > >> For more options, visit this group at
 > >>http://groups.google.com/group/algogeeks?hl=en.
 >
 > > --
 > > @ |3  # ! /\/ @ \./
 >
 >  --
 >  @ |3  # ! /\/ @ \./
 >
 >  --
 >  You received this message because you are subscribed to the
 Google
 >  Groups "Algorithm Geeks" group.
 >  To post to this group, send email to algogeeks@googlegroups.com.
 >  To unsubscribe from this group, send email to
 >  algogeeks+unsubscr...@googlegroups.com.
 >  For more options, visit this group at
 > http://groups.google.com/group/alg

Re: [algogeeks] Re: Question -->

2011-09-20 Thread Ishan Aggarwal
Again it is giving the same error. on changing it to 32.


On Tue, Sep 20, 2011 at 2:18 PM, abhinav gupta wrote:

> Instead of Num[31] u should tk Num[32]
>
> On Tue, Sep 20, 2011 at 2:16 PM, Ishan Aggarwal <
> ishan.aggarwal.1...@gmail.com> wrote:
>
>> Hi,
>>
>> When I am running this program, I am getting segmentation fault. Can u plz
>> confirm where is the error.
>>
>> #include
>> void main()
>> {
>> int Num[31]={0};
>> int Mum[31]={0};
>> int n = 64,m = 7  ,i=0,j=3,k;
>> for(k=31;k>=0;k++)
>> {
>> Num[k]=n & 1;
>> Mum[k]=m & 1;
>> n=n>>1;
>> m=m>>1;
>> }
>>
>> for(k=i;k<=j;k++)
>> Num[k]=Mum[k];
>>
>> for(k=0;k<=31;k++)
>> printf("%d ", Num[k]);
>> }
>>
>>
>> On Tue, Sep 20, 2011 at 1:49 PM, tec  wrote:
>>
>>> mask = (1<<(j+1))-(1<>> n = (n&(~mask)) | m;
>>>
>>>
>>> On Sep 20, 3:43 pm, abhinav gupta  wrote:
>>> > You can also solve the problem by using bit operators. by using >> << &
>>> | !
>>> > .
>>> > Need sm thinking in dat..No time rite nw!
>>> >
>>> > On Tue, Sep 20, 2011 at 1:12 PM, abhinav gupta <
>>> guptaabhinav...@gmail.com>wrote:
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > > Its because o/p should look like dat.Bt dats simple you can do it
>>> > > by multiplying bits to power(2, i) and
>>> > > adding all expressions.Simple!
>>> > > On Tue, Sep 20, 2011 at 1:09 PM, abhinav gupta <
>>> guptaabhinav...@gmail.com>wrote
>>> >
>>> > >  In the first loop bits are added into the array N and M .I have
>>> taken two
>>> > >> integers n and m .
>>> > >> Caution :
>>> > >> declare
>>> >
>>> > >> int N[31]={0};
>>> > >> int M[31]={0};
>>> > >> int n,m,i,j;
>>> >
>>> > >>   On Tue, Sep 20, 2011 at 1:02 PM, Ishan Aggarwal <
>>> > >> ishan.aggarwal.1...@gmail.com> wrote:
>>> >
>>> > >>> What are u doing in the first loop running for k=31 to k =0?
>>> >
>>> > >>> On Tue, Sep 20, 2011 at 12:50 PM, abhinav gupta <
>>> > >>> guptaabhinav...@gmail.com> wrote:
>>> >
>>> >  U can use single walker (from 0 till 31) to convert integers N and
>>> M
>>> >  into array of bits, then
>>> >  another walker from i to j to replace values.
>>> >
>>> >  for(k=31;k>=0;k++)
>>> >  {
>>> >  N[k]=n & 01;
>>> >  M[k]=m &01;
>>> >  n>>=1;
>>> >  m>>=1;
>>> >  }
>>> >
>>> >  for(k=i;k<=j;k++)
>>> >  N[k]=M[k];
>>> >
>>> >    On Tue, Sep 20, 2011 at 12:44 PM, abhinav gupta <
>>> >  guptaabhinav...@gmail.com> wrote:
>>> >
>>> > > I can tell you the logic.Take two arrays N and M, put their bits
>>> in
>>> > > the array.
>>> > > Now using i and j index replace the value of N[j] to n[i] by M[j]
>>> to
>>> > > M[i].
>>> > >   On Tue, Sep 20, 2011 at 12:33 PM, Ishan Aggarwal <
>>> > > ishan.aggarwal.1...@gmail.com> wrote:
>>> >
>>> > >> You are given two 32-bit numbers, N and M, and two bit
>>> positions, i
>>> > >> and j.Write a method to set all bits between i and j in N equal
>>> to M (e.g.,
>>> > >> M becomes a substring of N located at i and starting at j).
>>> >
>>> > >> EXAMPLE:
>>> >
>>> > >> Input: N = 100, M = 10101, i = 2, j = 6
>>> >
>>> > >> Output: N = 10001010100
>>> >
>>> > >> --
>>> > >> Kind Regards
>>> > >> Ishan Aggarwal
>>> > >> [image: Aricent Group]
>>> > >> Presidency Tower-A, M.G.Road,Sector-14
>>> > >> Gurgaon,Haryana.122015 INDIA
>>> > >> Phone : +91-9654602663
>>> > >> ishan2.aggar...@aricent.com 
>>> >
>>> > >> --
>>> > >> You received this message because you are subscribed to the
>>> Google
>>> > >> Groups "Algorithm Geeks" group.
>>> > >> To post to this group, send email to algogeeks@googlegroups.com
>>> .
>>> > >> To unsubscribe from this group, send email to
>>> > >> algogeeks+unsubscr...@googlegroups.com.
>>> > >> For more options, visit this group at
>>> > >>http://groups.google.com/group/algogeeks?hl=en.
>>> >
>>> > > --
>>> > > @ |3  # ! /\/ @ \./
>>> >
>>> >  --
>>> >  @ |3  # ! /\/ @ \./
>>> >
>>> >  --
>>> >  You received this message because you are subscribed to the Google
>>> >  Groups "Algorithm Geeks" group.
>>> >  To post to this group, send email to algogeeks@googlegroups.com.
>>> >  To unsubscribe from this group, send email to
>>> >  algogeeks+unsubscr...@googlegroups.com.
>>> >  For more options, visit this group at
>>> > http://groups.google.com/group/algogeeks?hl=en.
>>> >
>>> > >>> --
>>> > >>> Kind Regards
>>> > >>> Ishan Aggarwal
>>> > >>> [image: Aricent Group]
>>> > >>> Presidency Tower-A, M.G.Road,Sector-14
>>> > >>> Gurgaon,Haryana.122015 INDIA
>>> > >>> Phone : +91-9654602663
>>> > >>> ishan2.aggar...@aricent.com 
>>> >
>>> > >>> --
>>> > >>> You received this message because you are subscribed to the Google
>>> Groups
>>> > >>> "Algorithm Geeks" group.
>>> > >>> To post to this group, send email to algogeeks@googlegroups.com.
>>> > >>> To unsubscribe from this group, send email to
>>> > >>> algogeeks+unsubscr...@googlegroups.com.
>>> > >>>

Re: [algogeeks] Re: Question -->

2011-09-20 Thread abhinav gupta
Instead of Num[31] u should tk Num[32]

On Tue, Sep 20, 2011 at 2:16 PM, Ishan Aggarwal <
ishan.aggarwal.1...@gmail.com> wrote:

> Hi,
>
> When I am running this program, I am getting segmentation fault. Can u plz
> confirm where is the error.
>
> #include
> void main()
> {
> int Num[31]={0};
> int Mum[31]={0};
> int n = 64,m = 7  ,i=0,j=3,k;
> for(k=31;k>=0;k++)
> {
> Num[k]=n & 1;
> Mum[k]=m & 1;
> n=n>>1;
> m=m>>1;
> }
>
> for(k=i;k<=j;k++)
> Num[k]=Mum[k];
>
> for(k=0;k<=31;k++)
> printf("%d ", Num[k]);
> }
>
>
> On Tue, Sep 20, 2011 at 1:49 PM, tec  wrote:
>
>> mask = (1<<(j+1))-(1<> n = (n&(~mask)) | m;
>>
>>
>> On Sep 20, 3:43 pm, abhinav gupta  wrote:
>> > You can also solve the problem by using bit operators. by using >> << &
>> | !
>> > .
>> > Need sm thinking in dat..No time rite nw!
>> >
>> > On Tue, Sep 20, 2011 at 1:12 PM, abhinav gupta <
>> guptaabhinav...@gmail.com>wrote:
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > > Its because o/p should look like dat.Bt dats simple you can do it
>> > > by multiplying bits to power(2, i) and
>> > > adding all expressions.Simple!
>> > > On Tue, Sep 20, 2011 at 1:09 PM, abhinav gupta <
>> guptaabhinav...@gmail.com>wrote
>> >
>> > >  In the first loop bits are added into the array N and M .I have taken
>> two
>> > >> integers n and m .
>> > >> Caution :
>> > >> declare
>> >
>> > >> int N[31]={0};
>> > >> int M[31]={0};
>> > >> int n,m,i,j;
>> >
>> > >>   On Tue, Sep 20, 2011 at 1:02 PM, Ishan Aggarwal <
>> > >> ishan.aggarwal.1...@gmail.com> wrote:
>> >
>> > >>> What are u doing in the first loop running for k=31 to k =0?
>> >
>> > >>> On Tue, Sep 20, 2011 at 12:50 PM, abhinav gupta <
>> > >>> guptaabhinav...@gmail.com> wrote:
>> >
>> >  U can use single walker (from 0 till 31) to convert integers N and
>> M
>> >  into array of bits, then
>> >  another walker from i to j to replace values.
>> >
>> >  for(k=31;k>=0;k++)
>> >  {
>> >  N[k]=n & 01;
>> >  M[k]=m &01;
>> >  n>>=1;
>> >  m>>=1;
>> >  }
>> >
>> >  for(k=i;k<=j;k++)
>> >  N[k]=M[k];
>> >
>> >    On Tue, Sep 20, 2011 at 12:44 PM, abhinav gupta <
>> >  guptaabhinav...@gmail.com> wrote:
>> >
>> > > I can tell you the logic.Take two arrays N and M, put their bits
>> in
>> > > the array.
>> > > Now using i and j index replace the value of N[j] to n[i] by M[j]
>> to
>> > > M[i].
>> > >   On Tue, Sep 20, 2011 at 12:33 PM, Ishan Aggarwal <
>> > > ishan.aggarwal.1...@gmail.com> wrote:
>> >
>> > >> You are given two 32-bit numbers, N and M, and two bit positions,
>> i
>> > >> and j.Write a method to set all bits between i and j in N equal
>> to M (e.g.,
>> > >> M becomes a substring of N located at i and starting at j).
>> >
>> > >> EXAMPLE:
>> >
>> > >> Input: N = 100, M = 10101, i = 2, j = 6
>> >
>> > >> Output: N = 10001010100
>> >
>> > >> --
>> > >> Kind Regards
>> > >> Ishan Aggarwal
>> > >> [image: Aricent Group]
>> > >> Presidency Tower-A, M.G.Road,Sector-14
>> > >> Gurgaon,Haryana.122015 INDIA
>> > >> Phone : +91-9654602663
>> > >> ishan2.aggar...@aricent.com 
>> >
>> > >> --
>> > >> You received this message because you are subscribed to the
>> Google
>> > >> Groups "Algorithm Geeks" group.
>> > >> To post to this group, send email to algogeeks@googlegroups.com.
>> > >> To unsubscribe from this group, send email to
>> > >> algogeeks+unsubscr...@googlegroups.com.
>> > >> For more options, visit this group at
>> > >>http://groups.google.com/group/algogeeks?hl=en.
>> >
>> > > --
>> > > @ |3  # ! /\/ @ \./
>> >
>> >  --
>> >  @ |3  # ! /\/ @ \./
>> >
>> >  --
>> >  You received this message because you are subscribed to the Google
>> >  Groups "Algorithm Geeks" group.
>> >  To post to this group, send email to algogeeks@googlegroups.com.
>> >  To unsubscribe from this group, send email to
>> >  algogeeks+unsubscr...@googlegroups.com.
>> >  For more options, visit this group at
>> > http://groups.google.com/group/algogeeks?hl=en.
>> >
>> > >>> --
>> > >>> Kind Regards
>> > >>> Ishan Aggarwal
>> > >>> [image: Aricent Group]
>> > >>> Presidency Tower-A, M.G.Road,Sector-14
>> > >>> Gurgaon,Haryana.122015 INDIA
>> > >>> Phone : +91-9654602663
>> > >>> ishan2.aggar...@aricent.com 
>> >
>> > >>> --
>> > >>> You received this message because you are subscribed to the Google
>> Groups
>> > >>> "Algorithm Geeks" group.
>> > >>> To post to this group, send email to algogeeks@googlegroups.com.
>> > >>> To unsubscribe from this group, send email to
>> > >>> algogeeks+unsubscr...@googlegroups.com.
>> > >>> For more options, visit this group at
>> > >>>http://groups.google.com/group/algogeeks?hl=en.
>> >
>> > >> --
>> > >> @ |3  # ! /\/ @ \./
>> >
>> > > --
>> > > @ |3  # ! /\/ @ \./
>> >
>> > --
>> > @ |3  # ! /\/ @ \./
>>
>> --
>> You received this message because you are subscribed to the G

Re: [algogeeks] Re: Question -->

2011-09-20 Thread Ishan Aggarwal
Hi,

When I am running this program, I am getting segmentation fault. Can u plz
confirm where is the error.

#include
void main()
{
int Num[31]={0};
int Mum[31]={0};
int n = 64,m = 7  ,i=0,j=3,k;
for(k=31;k>=0;k++)
{
Num[k]=n & 1;
Mum[k]=m & 1;
n=n>>1;
m=m>>1;
}

for(k=i;k<=j;k++)
Num[k]=Mum[k];

for(k=0;k<=31;k++)
printf("%d ", Num[k]);
}


On Tue, Sep 20, 2011 at 1:49 PM, tec  wrote:

> mask = (1<<(j+1))-(1< n = (n&(~mask)) | m;
>
>
> On Sep 20, 3:43 pm, abhinav gupta  wrote:
> > You can also solve the problem by using bit operators. by using >> << & |
> !
> > .
> > Need sm thinking in dat..No time rite nw!
> >
> > On Tue, Sep 20, 2011 at 1:12 PM, abhinav gupta <
> guptaabhinav...@gmail.com>wrote:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > > Its because o/p should look like dat.Bt dats simple you can do it
> > > by multiplying bits to power(2, i) and
> > > adding all expressions.Simple!
> > > On Tue, Sep 20, 2011 at 1:09 PM, abhinav gupta <
> guptaabhinav...@gmail.com>wrote
> >
> > >  In the first loop bits are added into the array N and M .I have taken
> two
> > >> integers n and m .
> > >> Caution :
> > >> declare
> >
> > >> int N[31]={0};
> > >> int M[31]={0};
> > >> int n,m,i,j;
> >
> > >>   On Tue, Sep 20, 2011 at 1:02 PM, Ishan Aggarwal <
> > >> ishan.aggarwal.1...@gmail.com> wrote:
> >
> > >>> What are u doing in the first loop running for k=31 to k =0?
> >
> > >>> On Tue, Sep 20, 2011 at 12:50 PM, abhinav gupta <
> > >>> guptaabhinav...@gmail.com> wrote:
> >
> >  U can use single walker (from 0 till 31) to convert integers N and M
> >  into array of bits, then
> >  another walker from i to j to replace values.
> >
> >  for(k=31;k>=0;k++)
> >  {
> >  N[k]=n & 01;
> >  M[k]=m &01;
> >  n>>=1;
> >  m>>=1;
> >  }
> >
> >  for(k=i;k<=j;k++)
> >  N[k]=M[k];
> >
> >    On Tue, Sep 20, 2011 at 12:44 PM, abhinav gupta <
> >  guptaabhinav...@gmail.com> wrote:
> >
> > > I can tell you the logic.Take two arrays N and M, put their bits in
> > > the array.
> > > Now using i and j index replace the value of N[j] to n[i] by M[j]
> to
> > > M[i].
> > >   On Tue, Sep 20, 2011 at 12:33 PM, Ishan Aggarwal <
> > > ishan.aggarwal.1...@gmail.com> wrote:
> >
> > >> You are given two 32-bit numbers, N and M, and two bit positions,
> i
> > >> and j.Write a method to set all bits between i and j in N equal to
> M (e.g.,
> > >> M becomes a substring of N located at i and starting at j).
> >
> > >> EXAMPLE:
> >
> > >> Input: N = 100, M = 10101, i = 2, j = 6
> >
> > >> Output: N = 10001010100
> >
> > >> --
> > >> Kind Regards
> > >> Ishan Aggarwal
> > >> [image: Aricent Group]
> > >> Presidency Tower-A, M.G.Road,Sector-14
> > >> Gurgaon,Haryana.122015 INDIA
> > >> Phone : +91-9654602663
> > >> ishan2.aggar...@aricent.com 
> >
> > >> --
> > >> You received this message because you are subscribed to the Google
> > >> Groups "Algorithm Geeks" group.
> > >> To post to this group, send email to algogeeks@googlegroups.com.
> > >> To unsubscribe from this group, send email to
> > >> algogeeks+unsubscr...@googlegroups.com.
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/algogeeks?hl=en.
> >
> > > --
> > > @ |3  # ! /\/ @ \./
> >
> >  --
> >  @ |3  # ! /\/ @ \./
> >
> >  --
> >  You received this message because you are subscribed to the Google
> >  Groups "Algorithm Geeks" group.
> >  To post to this group, send email to algogeeks@googlegroups.com.
> >  To unsubscribe from this group, send email to
> >  algogeeks+unsubscr...@googlegroups.com.
> >  For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
> > >>> --
> > >>> Kind Regards
> > >>> Ishan Aggarwal
> > >>> [image: Aricent Group]
> > >>> Presidency Tower-A, M.G.Road,Sector-14
> > >>> Gurgaon,Haryana.122015 INDIA
> > >>> Phone : +91-9654602663
> > >>> ishan2.aggar...@aricent.com 
> >
> > >>> --
> > >>> You received this message because you are subscribed to the Google
> Groups
> > >>> "Algorithm Geeks" group.
> > >>> To post to this group, send email to algogeeks@googlegroups.com.
> > >>> To unsubscribe from this group, send email to
> > >>> algogeeks+unsubscr...@googlegroups.com.
> > >>> For more options, visit this group at
> > >>>http://groups.google.com/group/algogeeks?hl=en.
> >
> > >> --
> > >> @ |3  # ! /\/ @ \./
> >
> > > --
> > > @ |3  # ! /\/ @ \./
> >
> > --
> > @ |3  # ! /\/ @ \./
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Kind Regards
Ishan Aggarwal
[image: Ar

[algogeeks] Re: Question -->

2011-09-20 Thread tec
mask = (1<<(j+1))-(1< wrote:
> You can also solve the problem by using bit operators. by using >> << & | !
> .
> Need sm thinking in dat..No time rite nw!
>
> On Tue, Sep 20, 2011 at 1:12 PM, abhinav gupta 
> wrote:
>
>
>
>
>
>
>
>
>
> > Its because o/p should look like dat.Bt dats simple you can do it
> > by multiplying bits to power(2, i) and
> > adding all expressions.Simple!
> > On Tue, Sep 20, 2011 at 1:09 PM, abhinav gupta 
> > wrote
>
> >  In the first loop bits are added into the array N and M .I have taken two
> >> integers n and m .
> >> Caution :
> >> declare
>
> >> int N[31]={0};
> >> int M[31]={0};
> >> int n,m,i,j;
>
> >>   On Tue, Sep 20, 2011 at 1:02 PM, Ishan Aggarwal <
> >> ishan.aggarwal.1...@gmail.com> wrote:
>
> >>> What are u doing in the first loop running for k=31 to k =0?
>
> >>> On Tue, Sep 20, 2011 at 12:50 PM, abhinav gupta <
> >>> guptaabhinav...@gmail.com> wrote:
>
>  U can use single walker (from 0 till 31) to convert integers N and M
>  into array of bits, then
>  another walker from i to j to replace values.
>
>  for(k=31;k>=0;k++)
>  {
>  N[k]=n & 01;
>  M[k]=m &01;
>  n>>=1;
>  m>>=1;
>  }
>
>  for(k=i;k<=j;k++)
>  N[k]=M[k];
>
>    On Tue, Sep 20, 2011 at 12:44 PM, abhinav gupta <
>  guptaabhinav...@gmail.com> wrote:
>
> > I can tell you the logic.Take two arrays N and M, put their bits in
> > the array.
> > Now using i and j index replace the value of N[j] to n[i] by M[j] to
> > M[i].
> >   On Tue, Sep 20, 2011 at 12:33 PM, Ishan Aggarwal <
> > ishan.aggarwal.1...@gmail.com> wrote:
>
> >> You are given two 32-bit numbers, N and M, and two bit positions, i
> >> and j.Write a method to set all bits between i and j in N equal to M 
> >> (e.g.,
> >> M becomes a substring of N located at i and starting at j).
>
> >> EXAMPLE:
>
> >> Input: N = 100, M = 10101, i = 2, j = 6
>
> >> Output: N = 10001010100
>
> >> --
> >> Kind Regards
> >> Ishan Aggarwal
> >> [image: Aricent Group]
> >> Presidency Tower-A, M.G.Road,Sector-14
> >> Gurgaon,Haryana.122015 INDIA
> >> Phone : +91-9654602663
> >> ishan2.aggar...@aricent.com 
>
> >> --
> >> You received this message because you are subscribed to the Google
> >> Groups "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/algogeeks?hl=en.
>
> > --
> > @ |3  # ! /\/ @ \./
>
>  --
>  @ |3  # ! /\/ @ \./
>
>  --
>  You received this message because you are subscribed to the Google
>  Groups "Algorithm Geeks" group.
>  To post to this group, send email to algogeeks@googlegroups.com.
>  To unsubscribe from this group, send email to
>  algogeeks+unsubscr...@googlegroups.com.
>  For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
> >>> --
> >>> Kind Regards
> >>> Ishan Aggarwal
> >>> [image: Aricent Group]
> >>> Presidency Tower-A, M.G.Road,Sector-14
> >>> Gurgaon,Haryana.122015 INDIA
> >>> Phone : +91-9654602663
> >>> ishan2.aggar...@aricent.com 
>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups
> >>> "Algorithm Geeks" group.
> >>> To post to this group, send email to algogeeks@googlegroups.com.
> >>> To unsubscribe from this group, send email to
> >>> algogeeks+unsubscr...@googlegroups.com.
> >>> For more options, visit this group at
> >>>http://groups.google.com/group/algogeeks?hl=en.
>
> >> --
> >> @ |3  # ! /\/ @ \./
>
> > --
> > @ |3  # ! /\/ @ \./
>
> --
> @ |3  # ! /\/ @ \./

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question on algorithm

2011-09-19 Thread Don
I divide by 5 to determine how many ways there are to use nickles. I
could have written a for loop:

for(nickles = 0; (quarters+dimes+nickles) <= n; nickles += 5)
  ++result;

But that would have just executed 1+(n-quarters-dimes)/5 times
incrementing result every time. I just computed the result in one step
instead.

Don

On Sep 17, 8:08 am, bharatkumar bagana 
wrote:
> @don:
> will u pls explain why divided by 5 is used 
>
>
>
> On Fri, Sep 16, 2011 at 3:44 PM, prasanth n  wrote:
> > @Don:
> > thanks a lot
>
> > On Sat, Sep 17, 2011 at 12:28 AM, Don  wrote:
>
> >> The algorithm is to count them, looping over the number of quarters
> >> and dimes. Then it is easy to compute the number of nickles which
> >> could be used, and the shortfall is made up with pennies.
> >> It is very common to see a recursive solution, but that is not
> >> necessary or beneficial when the iterative solution is so simple.
> >> Don
>
> >>  int result = 0;
> >>  for(int quarters = 0; quarters <= n; quarters += 25)
> >>      for(int dimes = 0; (quarters+dimes) <= n; dimes += 10)
> >>        result += 1 + (n-quarters-dimes) / 5;
>
> >> On Sep 16, 1:35 pm, prasanth n  wrote:
> >> > Given an infinite number of quarters (25 cents), dimes (10 cents),
> >> nickels
> >> > (5 cents) and pennies (1 cent), write code to calculate the number of
> >> ways
> >> > of representing n cents.
> >> > also do give an algorithm first..
>
> >> > --
> >> > *prasanth*
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/algogeeks?hl=en.
>
> > --
> > *prasanth*
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
>
> **Please do not print this e-mail until urgent requirement. Go Green!!
> Save Papers <=> Save Trees
> *BharatKumar Bagana*
> **http://www.google.com/profiles/bagana.bharatkumar
> *
> Mobile +91 8056127652*
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question on algorithm

2011-09-17 Thread bharatkumar bagana
@don:
will u pls explain why divided by 5 is used 

On Fri, Sep 16, 2011 at 3:44 PM, prasanth n  wrote:

> @Don:
> thanks a lot
>
> On Sat, Sep 17, 2011 at 12:28 AM, Don  wrote:
>
>> The algorithm is to count them, looping over the number of quarters
>> and dimes. Then it is easy to compute the number of nickles which
>> could be used, and the shortfall is made up with pennies.
>> It is very common to see a recursive solution, but that is not
>> necessary or beneficial when the iterative solution is so simple.
>> Don
>>
>>  int result = 0;
>>  for(int quarters = 0; quarters <= n; quarters += 25)
>>  for(int dimes = 0; (quarters+dimes) <= n; dimes += 10)
>>result += 1 + (n-quarters-dimes) / 5;
>>
>> On Sep 16, 1:35 pm, prasanth n  wrote:
>> > Given an infinite number of quarters (25 cents), dimes (10 cents),
>> nickels
>> > (5 cents) and pennies (1 cent), write code to calculate the number of
>> ways
>> > of representing n cents.
>> > also do give an algorithm first..
>> >
>> > --
>> > *prasanth*
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> *prasanth*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 

**Please do not print this e-mail until urgent requirement. Go Green!!
Save Papers <=> Save Trees
*BharatKumar Bagana*
**http://www.google.com/profiles/bagana.bharatkumar
*
Mobile +91 8056127652*


-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question on algorithm

2011-09-16 Thread prasanth n
@Don:
thanks a lot

On Sat, Sep 17, 2011 at 12:28 AM, Don  wrote:

> The algorithm is to count them, looping over the number of quarters
> and dimes. Then it is easy to compute the number of nickles which
> could be used, and the shortfall is made up with pennies.
> It is very common to see a recursive solution, but that is not
> necessary or beneficial when the iterative solution is so simple.
> Don
>
>  int result = 0;
>  for(int quarters = 0; quarters <= n; quarters += 25)
>  for(int dimes = 0; (quarters+dimes) <= n; dimes += 10)
>result += 1 + (n-quarters-dimes) / 5;
>
> On Sep 16, 1:35 pm, prasanth n  wrote:
> > Given an infinite number of quarters (25 cents), dimes (10 cents),
> nickels
> > (5 cents) and pennies (1 cent), write code to calculate the number of
> ways
> > of representing n cents.
> > also do give an algorithm first..
> >
> > --
> > *prasanth*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
*prasanth*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question on algorithm

2011-09-16 Thread Don
The algorithm is to count them, looping over the number of quarters
and dimes. Then it is easy to compute the number of nickles which
could be used, and the shortfall is made up with pennies.
It is very common to see a recursive solution, but that is not
necessary or beneficial when the iterative solution is so simple.
Don

  int result = 0;
  for(int quarters = 0; quarters <= n; quarters += 25)
  for(int dimes = 0; (quarters+dimes) <= n; dimes += 10)
result += 1 + (n-quarters-dimes) / 5;

On Sep 16, 1:35 pm, prasanth n  wrote:
> Given an infinite number of quarters (25 cents), dimes (10 cents), nickels
> (5 cents) and pennies (1 cent), write code to calculate the number of ways
> of representing n cents.
> also do give an algorithm first..
>
> --
> *prasanth*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question --> plz answer

2011-09-16 Thread Gene
Sorry.  Small mistake.  First test should have been

> W(n,k) = (k < 1 || k > n) ? 0 :

This is fixed below.

On Sep 16, 4:48 am, Gene  wrote:
> My guess is that the "and so on..." means we should be able to solve
> this assuming the pyramid is as high as it needs to be in order not
> to
> overflow.
>
> With this the problem gets more interesting.  I worked it out a bit
> farther:
>
> L/C --- Filled cups
> 1 --- 1
> 3 --- 2,3
> 5 --- 5
> 7 --- 4-6
> 8 1/3 --- 8,9
> 11 --- 13
> 13 2/3 --- 12, 14
> 15 --- 7,10
>
> At this point, 17,20 are 1/8 full and 18,19 are 7/8 full.  11,15 are
> empty but beginning to receive water.
>
> After looking at the cockeyed for a while I think it's a simple
> dynamic program:
>
> First let's number the cups differently with pairs (n, k) where n is
> the level number -- top is n=1 -- and k is the ordinal within a level
> -- left is k=1.  So
> at every level n you have (n,1)(n,2) ... (n,n).  Note that n(n-1)/2+k
> gives the numbering in the original problem, so it's easy to convert.
>
> Let W(n,k) be the amount of water that flowed into cup (n,k) after L
> has been poured in at the top.  Then
>
> W(n,k) = (k < 1 || k > n) ? 0 :
>         (n == 1) ? L :
>          max(0, (W(n - 1, k - 1) - C) / 2) + max(0, (W(n - 1, k) -
> C) / 2)
>
> The last line says that the amount that flowed into this cup is equal
> to what's flowed out of the two parents. In turn, what flowed out of a
> parent is half of what flowed in after its capacity C was filled.  Of
> course if that's a negative amount, it's corrected to 0.
>
> The answer to the final question of how much water is in cup (n,k)
> after L has been poured into the top cup is
>
> W(n,k) > C ? C : W(n,k)
>
> On Sep 10, 2:42 pm, Dave  wrote:
>
>
>
> > @Ishan: Here is the algorithm:
>
> > If L <= C, then
> >     cup1 = L
> >     cup2 = cup3 = cup4 = cup5 = cup6 = overflow = 0
> > else if L < 3*C, then
> >     cup1 = C
> >     cup2 = cup3 = (L-C)/2
> >     cup4 = cup5 = cup6 = overflow = 0
> > else if L < 5*C, then
> >     cup1 = cup2 = cup3 = C
> >     cup4 = cup6 = (L-3*C)/4
> >     cup5 = (L-3*C)/2
> >     overflow = 0
> > else if L < 7*C, then
> >     cup1 = cup2 = cup3 = cup5 = C
> >     cup4 = cup6 = (L-3*C)/4
> >     overflow = (L-5*C)/2
> > else if L >= 7*C, then
> >     cup1 = cup2 = cup3 = cup4 = cup5 = cup6 = C
> >     overflow = L-6*C
>
> > And so on.
>
> > Dave
>
> > On Sep 10, 9:40 am, Ishan Aggarwal 
> > wrote:
>
> > > 1.)
>
> > > there is apyramidwith 1 cup at level , 2 at level 2 , 3 at level 3 and so
> > > on..
> > > It looks something like this
> > > 1
> > > 2 3
> > > 4 5 6
> > > every cup has capacity C. you pour L liters of water from top . when cup 1
> > > gets filled , it overflows to cup 2,3 equally, and when they get filled ,
> > > Cup 4 and 6 get water only from 2 and 3 resp but 5 gets water from both 
> > > the
> > > cups and so on.
> > > Now given C and M .Find the amount of water in ith cup.
>
> > > --
> > > Kind Regards
> > > Ishan Aggarwal
> > > [image: Aricent Group]
> > > Presidency Tower-A, M.G.Road,Sector-14
> > > Gurgaon,Haryana.122015 INDIA
> > > Phone : +91-9654602663
> > > ishan2.aggar...@aricent.com 

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question --> plz answer

2011-09-16 Thread Gene
My guess is that the "and so on..." means we should be able to solve
this assuming the pyramid is as high as it needs to be in order not
to
overflow.

With this the problem gets more interesting.  I worked it out a bit
farther:


L/C --- Filled cups
1 --- 1
3 --- 2,3
5 --- 5
7 --- 4-6
8 1/3 --- 8,9
11 --- 13
13 2/3 --- 12, 14
15 --- 7,10

At this point, 17,20 are 1/8 full and 18,19 are 7/8 full.  11,15 are
empty but beginning to receive water.

After looking at the cockeyed for a while I think it's a simple
dynamic program:

First let's number the cups differently with pairs (n, k) where n is
the level number -- top is n=1 -- and k is the ordinal within a level
-- left is k=1.  So
at every level n you have (n,1)(n,2) ... (n,n).  Note that n(n-1)/2+k
gives the numbering in the original problem, so it's easy to convert.

Let W(n,k) be the amount of water that flowed into cup (n,k) after L
has been poured in at the top.  Then

W(n,k) = (k < 1) ? 0 :
(n == 1) ? L :
 max(0, (W(n - 1, k - 1) - C) / 2) + max(0, (W(n - 1, k) -
C) / 2)

The last line says that the amount that flowed into this cup is equal
to what's flowed out of the two parents. In turn, what flowed out of a
parent is half of what flowed in after its capacity C was filled.  Of
course if that's a negative amount, it's corrected to 0.

The answer to the final question of how much water is in cup (n,k)
after L has been poured into the top cup is

W(n,k) > C ? C : W(n,k)

On Sep 10, 2:42 pm, Dave  wrote:
> @Ishan: Here is the algorithm:
>
> If L <= C, then
>     cup1 = L
>     cup2 = cup3 = cup4 = cup5 = cup6 = overflow = 0
> else if L < 3*C, then
>     cup1 = C
>     cup2 = cup3 = (L-C)/2
>     cup4 = cup5 = cup6 = overflow = 0
> else if L < 5*C, then
>     cup1 = cup2 = cup3 = C
>     cup4 = cup6 = (L-3*C)/4
>     cup5 = (L-3*C)/2
>     overflow = 0
> else if L < 7*C, then
>     cup1 = cup2 = cup3 = cup5 = C
>     cup4 = cup6 = (L-3*C)/4
>     overflow = (L-5*C)/2
> else if L >= 7*C, then
>     cup1 = cup2 = cup3 = cup4 = cup5 = cup6 = C
>     overflow = L-6*C
>
> And so on.
>
> Dave
>
> On Sep 10, 9:40 am, Ishan Aggarwal 
> wrote:
>
>
>
> > 1.)
>
> > there is apyramidwith 1 cup at level , 2 at level 2 , 3 at level 3 and so
> > on..
> > It looks something like this
> > 1
> > 2 3
> > 4 5 6
> > every cup has capacity C. you pour L liters of water from top . when cup 1
> > gets filled , it overflows to cup 2,3 equally, and when they get filled ,
> > Cup 4 and 6 get water only from 2 and 3 resp but 5 gets water from both the
> > cups and so on.
> > Now given C and M .Find the amount of water in ith cup.
>
> > --
> > Kind Regards
> > Ishan Aggarwal
> > [image: Aricent Group]
> > Presidency Tower-A, M.G.Road,Sector-14
> > Gurgaon,Haryana.122015 INDIA
> > Phone : +91-9654602663
> > ishan2.aggar...@aricent.com 

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question --> plz answer

2011-09-16 Thread Gene
My guess is that the "and so on..." means we should be able to solve
this assuming the pyramid is as high as it needs to be in order not to
overflow.

With this the problem gets more interesting.  I worked it out a bit
farther:

L/C --- Filled cups
1 --- 1
3 --- 2,3
5 --- 5
7 --- 4-6
8 1/3 --- 8,9
11 --- 13
13 2/3 --- 12, 14
15 --- 7,10

At this point, 17,20 are 1/8 full and 18,19 are 7/8 full.  11,15 are
empty but beginning to receive water.

I know I can build a simulation of what I'm doing by hand to always
get the answer, but I'm thinking there is a simple recurrence or other
algorithm.  Any anybody see it?

Gene

On Sep 10, 2:42 pm, Dave  wrote:
> @Ishan: Here is the algorithm:
>
> If L <= C, then
>     cup1 = L
>     cup2 = cup3 = cup4 = cup5 = cup6 = overflow = 0
> else if L < 3*C, then
>     cup1 = C
>     cup2 = cup3 = (L-C)/2
>     cup4 = cup5 = cup6 = overflow = 0
> else if L < 5*C, then
>     cup1 = cup2 = cup3 = C
>     cup4 = cup6 = (L-3*C)/4
>     cup5 = (L-3*C)/2
>     overflow = 0
> else if L < 7*C, then
>     cup1 = cup2 = cup3 = cup5 = C
>     cup4 = cup6 = (L-3*C)/4
>     overflow = (L-5*C)/2
> else if L >= 7*C, then
>     cup1 = cup2 = cup3 = cup4 = cup5 = cup6 = C
>     overflow = L-6*C
>
> And so on.
>
> Dave
>
> On Sep 10, 9:40 am, Ishan Aggarwal 
> wrote:
>
>
>
> > 1.)
>
> > there is apyramidwith 1 cup at level , 2 at level 2 , 3 at level 3 and so
> > on..
> > It looks something like this
> > 1
> > 2 3
> > 4 5 6
> > every cup has capacity C. you pour L liters of water from top . when cup 1
> > gets filled , it overflows to cup 2,3 equally, and when they get filled ,
> > Cup 4 and 6 get water only from 2 and 3 resp but 5 gets water from both the
> > cups and so on.
> > Now given C and M .Find the amount of water in ith cup.
>
> > --
> > Kind Regards
> > Ishan Aggarwal
> > [image: Aricent Group]
> > Presidency Tower-A, M.G.Road,Sector-14
> > Gurgaon,Haryana.122015 INDIA
> > Phone : +91-9654602663
> > ishan2.aggar...@aricent.com 

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question --> plz answer

2011-09-13 Thread Dave
@Vikas. I tried to understand what you were saying, but couldn't.
Sorry.

Dave.

On Sep 12, 7:33 am, vikas  wrote:
> If L <= C, then
>     cup1 = L
>     cup2 = cup3 = cup4 = cup5 = cup6 = overflow = 0
> else if L < 3*C, then
>     cup1 = C
>     cup2 = cup3 = (L-C)/2
>     cup4 = cup5 = cup6 = overflow = 0
> else if L < 5*C, then
>     cup1 = cup2 = cup3 = C
>     cup4 = cup6 = (L-3*C)/4
>     cup5 = (L-3*C)/2
>     overflow = 0
> else if L < 7*C, then
>     cup1 = cup2 = cup3 = cup5 = C
>     cup4 = cup6 = (L-3*C)/4
>     overflow = (L-5*C)/2
> else if L >= 7*C, then
>     cup1 = cup2 = cup3 = cup4 = cup5 = cup6 = C
>     overflow = L-6*C
>
> take L > 7c
>
> suppose it takes 2t time to fill with rate x
>
> c = x*2t
>
> in first level after time 2t  , water left L - 2xt
>
> in second level , after time 4t   2xt   2xt  L - 6xt
>
> in third level     after time 5t     xt   2xt    xt         /// middle
> will start overflowing by now
>
> after 6t
>                                           3rd level  2xt  2xt   2xt
>                                          4th level   nill xt xt
> nill
> so you see here water used after 6t time is 2xt + 2*2xt +3*2xt + 2xt =
> 14 xt or 7 cups
> here 4th level too have half cups filled , please correct me if
> something is wrong in calculations.
>
> On Sep 12, 3:01 am, Dave  wrote:
>
>
>
> > @Vikas: I think I have it covered. That's what the divisors do. If I'm
> > wrong, give me a value of L where I am wrong.
>
> > Dave
>
> > On Sep 11, 2:17 pm, vikas  wrote:
>
> > > @Dave,
> > >    should not rate of filling be considered here ? if you note , the
> > > side cups are filling in half of rate than to rest of cups in row.
> > > On Sep 11, 10:01 am, bharatkumar bagana 
> > > wrote:
>
> > > > what is M?
>
> > > > On Sat, Sep 10, 2011 at 8:10 PM, Ishan Aggarwal <
>
> > > > ishan.aggarwal.1...@gmail.com> wrote:
> > > > > 1.)
>
> > > > > there is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 
> > > > > and so
> > > > > on..
> > > > > It looks something like this
> > > > > 1
> > > > > 2 3
> > > > > 4 5 6
> > > > > every cup has capacity C. you pour L liters of water from top . when 
> > > > > cup 1
> > > > > gets filled , it overflows to cup 2,3 equally, and when they get 
> > > > > filled ,
> > > > > Cup 4 and 6 get water only from 2 and 3 resp but 5 gets water from 
> > > > > both the
> > > > > cups and so on.
> > > > > Now given C and M .Find the amount of water in ith cup.
>
> > > > > --
> > > > > Kind Regards
> > > > > Ishan Aggarwal
> > > > > [image: Aricent Group]
> > > > > Presidency Tower-A, M.G.Road,Sector-14
> > > > > Gurgaon,Haryana.122015 INDIA
> > > > > Phone : +91-9654602663
> > > > > ishan2.aggar...@aricent.com 
>
> > > > >  --
> > > > > You received this message because you are subscribed to the Google 
> > > > > Groups
> > > > > "Algorithm Geeks" group.
> > > > > To post to this group, send email to algogeeks@googlegroups.com.
> > > > > To unsubscribe from this group, send email to
> > > > > algogeeks+unsubscr...@googlegroups.com.
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/algogeeks?hl=en.
>
> > > > --
>
> > > > **Please do not print this e-mail until urgent requirement. Go Green!!
> > > > Save Papers <=> Save Trees
> > > > *BharatKumar Bagana*
> > > > **http://www.google.com/profiles/bagana.bharatkumar
> > > > *
> > > > Mobile +91 8056127652*
> > > > - Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question --> plz answer

2011-09-12 Thread vikas

If L <= C, then
cup1 = L
cup2 = cup3 = cup4 = cup5 = cup6 = overflow = 0
else if L < 3*C, then
cup1 = C
cup2 = cup3 = (L-C)/2
cup4 = cup5 = cup6 = overflow = 0
else if L < 5*C, then
cup1 = cup2 = cup3 = C
cup4 = cup6 = (L-3*C)/4
cup5 = (L-3*C)/2
overflow = 0
else if L < 7*C, then
cup1 = cup2 = cup3 = cup5 = C
cup4 = cup6 = (L-3*C)/4
overflow = (L-5*C)/2
else if L >= 7*C, then
cup1 = cup2 = cup3 = cup4 = cup5 = cup6 = C
overflow = L-6*C


take L > 7c

suppose it takes 2t time to fill with rate x

c = x*2t

in first level after time 2t  , water left L - 2xt

in second level , after time 4t   2xt   2xt  L - 6xt

in third level after time 5t xt   2xtxt /// middle
will start overflowing by now

after 6t
  3rd level  2xt  2xt   2xt
 4th level   nill xt xt
nill
so you see here water used after 6t time is 2xt + 2*2xt +3*2xt + 2xt =
14 xt or 7 cups
here 4th level too have half cups filled , please correct me if
something is wrong in calculations.


On Sep 12, 3:01 am, Dave  wrote:
> @Vikas: I think I have it covered. That's what the divisors do. If I'm
> wrong, give me a value of L where I am wrong.
>
> Dave
>
> On Sep 11, 2:17 pm, vikas  wrote:
>
>
>
>
>
>
>
> > @Dave,
> >    should not rate of filling be considered here ? if you note , the
> > side cups are filling in half of rate than to rest of cups in row.
> > On Sep 11, 10:01 am, bharatkumar bagana 
> > wrote:
>
> > > what is M?
>
> > > On Sat, Sep 10, 2011 at 8:10 PM, Ishan Aggarwal <
>
> > > ishan.aggarwal.1...@gmail.com> wrote:
> > > > 1.)
>
> > > > there is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 
> > > > and so
> > > > on..
> > > > It looks something like this
> > > > 1
> > > > 2 3
> > > > 4 5 6
> > > > every cup has capacity C. you pour L liters of water from top . when 
> > > > cup 1
> > > > gets filled , it overflows to cup 2,3 equally, and when they get filled 
> > > > ,
> > > > Cup 4 and 6 get water only from 2 and 3 resp but 5 gets water from both 
> > > > the
> > > > cups and so on.
> > > > Now given C and M .Find the amount of water in ith cup.
>
> > > > --
> > > > Kind Regards
> > > > Ishan Aggarwal
> > > > [image: Aricent Group]
> > > > Presidency Tower-A, M.G.Road,Sector-14
> > > > Gurgaon,Haryana.122015 INDIA
> > > > Phone : +91-9654602663
> > > > ishan2.aggar...@aricent.com 
>
> > > >  --
> > > > You received this message because you are subscribed to the Google 
> > > > Groups
> > > > "Algorithm Geeks" group.
> > > > To post to this group, send email to algogeeks@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > algogeeks+unsubscr...@googlegroups.com.
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/algogeeks?hl=en.
>
> > > --
>
> > > **Please do not print this e-mail until urgent requirement. Go Green!!
> > > Save Papers <=> Save Trees
> > > *BharatKumar Bagana*
> > > **http://www.google.com/profiles/bagana.bharatkumar
> > > *
> > > Mobile +91 8056127652*
> > > - Hide quoted text -
>
> > - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question --> plz answer

2011-09-11 Thread Dave
@Vikas: I think I have it covered. That's what the divisors do. If I'm
wrong, give me a value of L where I am wrong.

Dave

On Sep 11, 2:17 pm, vikas  wrote:
> @Dave,
>    should not rate of filling be considered here ? if you note , the
> side cups are filling in half of rate than to rest of cups in row.
> On Sep 11, 10:01 am, bharatkumar bagana 
> wrote:
>
>
>
> > what is M?
>
> > On Sat, Sep 10, 2011 at 8:10 PM, Ishan Aggarwal <
>
> > ishan.aggarwal.1...@gmail.com> wrote:
> > > 1.)
>
> > > there is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 and 
> > > so
> > > on..
> > > It looks something like this
> > > 1
> > > 2 3
> > > 4 5 6
> > > every cup has capacity C. you pour L liters of water from top . when cup 1
> > > gets filled , it overflows to cup 2,3 equally, and when they get filled ,
> > > Cup 4 and 6 get water only from 2 and 3 resp but 5 gets water from both 
> > > the
> > > cups and so on.
> > > Now given C and M .Find the amount of water in ith cup.
>
> > > --
> > > Kind Regards
> > > Ishan Aggarwal
> > > [image: Aricent Group]
> > > Presidency Tower-A, M.G.Road,Sector-14
> > > Gurgaon,Haryana.122015 INDIA
> > > Phone : +91-9654602663
> > > ishan2.aggar...@aricent.com 
>
> > >  --
> > > You received this message because you are subscribed to the Google Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to algogeeks@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > algogeeks+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.
>
> > --
>
> > **Please do not print this e-mail until urgent requirement. Go Green!!
> > Save Papers <=> Save Trees
> > *BharatKumar Bagana*
> > **http://www.google.com/profiles/bagana.bharatkumar
> > *
> > Mobile +91 8056127652*
> > - Hide quoted text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question --> plz answer

2011-09-11 Thread vikas
@Dave,
   should not rate of filling be considered here ? if you note , the
side cups are filling in half of rate than to rest of cups in row.
On Sep 11, 10:01 am, bharatkumar bagana 
wrote:
> what is M?
>
> On Sat, Sep 10, 2011 at 8:10 PM, Ishan Aggarwal <
>
>
>
>
>
>
>
>
>
> ishan.aggarwal.1...@gmail.com> wrote:
> > 1.)
>
> > there is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 and so
> > on..
> > It looks something like this
> > 1
> > 2 3
> > 4 5 6
> > every cup has capacity C. you pour L liters of water from top . when cup 1
> > gets filled , it overflows to cup 2,3 equally, and when they get filled ,
> > Cup 4 and 6 get water only from 2 and 3 resp but 5 gets water from both the
> > cups and so on.
> > Now given C and M .Find the amount of water in ith cup.
>
> > --
> > Kind Regards
> > Ishan Aggarwal
> > [image: Aricent Group]
> > Presidency Tower-A, M.G.Road,Sector-14
> > Gurgaon,Haryana.122015 INDIA
> > Phone : +91-9654602663
> > ishan2.aggar...@aricent.com 
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
>
> **Please do not print this e-mail until urgent requirement. Go Green!!
> Save Papers <=> Save Trees
> *BharatKumar Bagana*
> **http://www.google.com/profiles/bagana.bharatkumar
> *
> Mobile +91 8056127652*
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question --> plz answer

2011-09-10 Thread Dave
@Ishan: Here is the algorithm:

If L <= C, then
cup1 = L
cup2 = cup3 = cup4 = cup5 = cup6 = overflow = 0
else if L < 3*C, then
cup1 = C
cup2 = cup3 = (L-C)/2
cup4 = cup5 = cup6 = overflow = 0
else if L < 5*C, then
cup1 = cup2 = cup3 = C
cup4 = cup6 = (L-3*C)/4
cup5 = (L-3*C)/2
overflow = 0
else if L < 7*C, then
cup1 = cup2 = cup3 = cup5 = C
cup4 = cup6 = (L-3*C)/4
overflow = (L-5*C)/2
else if L >= 7*C, then
cup1 = cup2 = cup3 = cup4 = cup5 = cup6 = C
overflow = L-6*C

And so on.

Dave

On Sep 10, 9:40 am, Ishan Aggarwal 
wrote:
> 1.)
>
> there is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 and so
> on..
> It looks something like this
> 1
> 2 3
> 4 5 6
> every cup has capacity C. you pour L liters of water from top . when cup 1
> gets filled , it overflows to cup 2,3 equally, and when they get filled ,
> Cup 4 and 6 get water only from 2 and 3 resp but 5 gets water from both the
> cups and so on.
> Now given C and M .Find the amount of water in ith cup.
>
> --
> Kind Regards
> Ishan Aggarwal
> [image: Aricent Group]
> Presidency Tower-A, M.G.Road,Sector-14
> Gurgaon,Haryana.122015 INDIA
> Phone : +91-9654602663
> ishan2.aggar...@aricent.com 

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question --> plz answer

2011-09-10 Thread Ankuj Gupta
what is C and M

On Sep 10, 7:40 pm, Ishan Aggarwal 
wrote:
> 1.)
>
> there is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 and so
> on..
> It looks something like this
> 1
> 2 3
> 4 5 6
> every cup has capacity C. you pour L liters of water from top . when cup 1
> gets filled , it overflows to cup 2,3 equally, and when they get filled ,
> Cup 4 and 6 get water only from 2 and 3 resp but 5 gets water from both the
> cups and so on.
> Now given C and M .Find the amount of water in ith cup.
>
> --
> Kind Regards
> Ishan Aggarwal
> [image: Aricent Group]
> Presidency Tower-A, M.G.Road,Sector-14
> Gurgaon,Haryana.122015 INDIA
> Phone : +91-9654602663
> ishan2.aggar...@aricent.com 

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question in C

2011-08-25 Thread Ninad Page


On Aug 24, 6:51 pm, sadhana kumar  wrote:
> Can anyone explain this code pls??
>
> #include 
> #define f(a,b) a##b
> #define g(a) #a
> #define h(a) g(a)
> int main()
> {
> printf("%s\n",h(f(1,2)));
> printf("%s\n",g(f(1,2)));
> return 0;
>
>
>
>
>
>
>
> }

Read about stringizing operator (#) and token pasting operator (##),
if you don't know them already.
Then, please go through the following link to understand the above
code:
http://gcc.gnu.org/onlinedocs/cpp/Argument-Prescan.html#Argument-Prescan

In particular, read the second point: "Macros that call other macros
that stringify or concatenate."

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question on fork()

2011-08-24 Thread DK
@Ankuj: Sorry. I read the getch() as a call to green().
Please ignore the 20 green(). It should be 10 green() instead.

--
DK

http://twitter.com/divyekapoor
http://www.divye.in
http://gplus.to/divyekapoor



-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/hUgNWEGwH5MJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question on fork()

2011-08-24 Thread shashi kant
6 red 10 greens



On Wed, Aug 24, 2011 at 9:25 AM, Ankuj Gupta  wrote:

> how can be there 20 greens ?
>
> On Aug 24, 12:12 am, DK  wrote:
> > The standard library is neither multithread safe nor multiprocess safe.
> > If you want the correct answer, use shared memory and maintain a shared
> > counter. Alternatively, as a quick hack, insert a fflush(stdout) after
> the
> > printf statements.
> >
> > Answer:
> > red() -  6
> > green() - 20
> >
> > --
> > DK
> >
> > http://twitter.com/divyekapoorhttp://gplus.to/divyekapoor
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
*Shashi Kant *
***"Think positive and find fuel in failure"*
*+919002943948
*
*R&D engineer ,
Tejas Networks Ltd Banglore.
*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question on fork()

2011-08-23 Thread Ankuj Gupta
how can be there 20 greens ?

On Aug 24, 12:12 am, DK  wrote:
> The standard library is neither multithread safe nor multiprocess safe.
> If you want the correct answer, use shared memory and maintain a shared
> counter. Alternatively, as a quick hack, insert a fflush(stdout) after the
> printf statements.
>
> Answer:
> red() -  6
> green() - 20
>
> --
> DK
>
> http://twitter.com/divyekapoorhttp://gplus.to/divyekapoor

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question on fork()

2011-08-23 Thread DK
The standard library is neither multithread safe nor multiprocess safe. 
If you want the correct answer, use shared memory and maintain a shared 
counter. Alternatively, as a quick hack, insert a fflush(stdout) after the 
printf statements.

Answer: 
red() -  6
green() - 20


--
DK

http://twitter.com/divyekapoor
http://gplus.to/divyekapoor

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/KlDAxxIM-uoJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question on fork()

2011-08-23 Thread Prem Krishna Chettri
I Can See 10 Green and 10 Red Process.. Can Someone Compile to verify
this...

Prem

On Tue, Aug 23, 2011 at 1:24 AM, gmagog...@gmail.com wrote:

> Infinite times
> Yanan Cao
>
>
>
> On Mon, Aug 22, 2011 at 2:43 PM, Don  wrote:
>
>> // DO NOT RUN THIS! By inspection, how many times will it print "Hello
>> world"?
>> // If you find out by running it, that is cheating. Don't do it!
>> int main()
>> {
>>  int i=0, j=0;
>>  for(i = 0; i*j < 20; ++i)
>>  {
>>if (fork() > 0) ++j;
>>else i = j =  0;
>>printf("Hello world\n");
>>  }
>>  return 0;
>> }
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question on fork()

2011-08-22 Thread gmagog...@gmail.com
Infinite times
Yanan Cao



On Mon, Aug 22, 2011 at 2:43 PM, Don  wrote:

> // DO NOT RUN THIS! By inspection, how many times will it print "Hello
> world"?
> // If you find out by running it, that is cheating. Don't do it!
> int main()
> {
>  int i=0, j=0;
>  for(i = 0; i*j < 20; ++i)
>  {
>if (fork() > 0) ++j;
>else i = j =  0;
>printf("Hello world\n");
>  }
>  return 0;
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question on fork()

2011-08-22 Thread gmagog...@gmail.com
I am getting 6 red and 8 green as expected using the original code
Yanan Cao



On Mon, Aug 22, 2011 at 2:38 PM, Yasir  wrote:

> Surprisingly, if I comment the last if condition ( which is AFTER red()
> call ), it is printing red only 6 times as expected..
> http://ideone.com/XMHzC
>
>  main()
> {
>   fork();
>   int color=fork();
>   if(color==0)
>   fork();
>   red();
> //if(color==0)
> //   fork();
>   green();
>   getch();
>
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/1o7KQKelcswJ.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question on fork()

2011-08-22 Thread Don
// DO NOT RUN THIS! By inspection, how many times will it print "Hello
world"?
// If you find out by running it, that is cheating. Don't do it!
int main()
{
  int i=0, j=0;
  for(i = 0; i*j < 20; ++i)
  {
if (fork() > 0) ++j;
else i = j =  0;
printf("Hello world\n");
  }
  return 0;
}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question on fork()

2011-08-22 Thread Yasir
Surprisingly, if I comment the last if condition ( which is AFTER red() call 
), it is printing red only 6 times as expected..  http://ideone.com/XMHzC

 main()
{
  fork();
  int color=fork();
  if(color==0)
  fork();
  red();
//if(color==0)
//   fork();
  green();
  getch();
  
}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/1o7KQKelcswJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question on fork()

2011-08-22 Thread Ankuj Gupta
I am getting 6 calls to red and 8 calls to green when i built parent
child tree but when i ran this code

http://ideone.com/UBaBB

I got 10 calls to red and 10 calls to green.

Can some explain this ?
On Aug 22, 9:31 pm, ghsjgl k  wrote:
> i saw this question in one of DREAM companies
>
> i dont know the answer
>
>
>
>
>
>
>
> On Mon, Aug 22, 2011 at 11:43 AM, dexter does  wrote:
> > void red()
> > {
>
> > }
> > void green()
> > {
>
> > }
> > main()
> > {
> >       fork();
> >       int color=fork();
> >       if(color==0)
> >                   fork();
> >       red();
> >       if(color==0)
> >                   fork();
> >       green();
> >       getch();
>
> > }
>
> > How many times red and green are called and pls give an explanation for
> > your answer
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question from Google interview

2011-08-19 Thread WgpShashank
I Think Trie is suitable DS for this problem , its similar "Did You Mean" 
Feature of Google 

Paste it in ur address bar
http://www.google.com/#hl=en&source=hp&q=Thatwouldbefantastic&oq=Thatwouldbefantastic&aq=f&aqi=&aql=&gs_sm=e&gs_upl=546l546l0l841l1l1l0l0l0l0l234l234l2-1l1l0&bav=on.2,or.r_gc.r_pw.r_cp.&fp=565b9cf32c7e938&biw=1280&bih=854

we can assume that all valid words are already in Trie(dictionary ) or even 
if they are not we can pre-process them to make a valid dictionary (trie) 
,during this we will mark every valid word we have inserted in trie as valid 
by boolean flag EOW(end of word), after this pre-processing phase, Now we 
will go through given string check for valid word exist or not in Trie if 
found we set space in given string & keep continuing this un till finished 
whole string.
structure of trie

struct node
{
   char  character;   // character of the node
   bool  eow; // indicates a complete word
   int   prefixes;// indicates how many words have the 
prefix
   node* edge[52];// references to all possible sons //only 
alphabates
} *root;// trie root node
 

correct me if any flaw in approach 

*
Thanks
Shashank Mani 
Computer Science
Birla Institute of Technology Mesra*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/Zdhpn8ant7cJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question from Google interview

2011-08-18 Thread Navneet
I have an answer to the problem which requires a single pass of string
to get the output string. (Though debatable if it covers all cases)

Look to make it as time efficient as possible.

On Aug 19, 2:28 am, Dave  wrote:
> @Icy: We agree that you have to look ahead in order to set the spaces
> correctly. The only point of difference is whether you choose to
> become more greedy or less greedy when looking ahead fails.
>
> Dave
>
> On Aug 18, 2:55 pm, "icy`"  wrote:
>
>
>
>
>
>
>
> > Well no, I would think it would match "Balls"  for him, since it is
> > greedy --> it would try to match as much as possible that works/is in
> > dict.  So I have to agree with Aditya here, but I would go from the
> > back/right to the left. So I would first get " round",  then hopefully
> > " are round"  and finally "Balls are round".
>
> > Now it gets tricky if the remaining left section cannot be broken into
> > words.  Then we'd have to backtrack once and take the next less-greedy
> > match, and try again.  If that fails, take even less greedier match ,
> > or backtrack yet again.
>
> > On Aug 18, 1:05 pm, Dave  wrote:
>
> > > @Aditya: You probably have to be a bit more careful than that. You
> > > can't add the space until both the first part is a word in the
> > > dictionary and the rest of the string can also be broken into words in
> > > the dictionary. Consider "Ballsareround." Your algorithm seems to put
> > > a space after the second "l", but then no initial part of "sareround"
> > > may be in your dictionary. In that case, you have to reject that space
> > > and continue until you get to a division point such that both the
> > > first part is in the dictionary and the second part can be broken into
> > > words. Sounds like a good place for recursion.
>
> > > Dave
>
> > > On Aug 18, 10:52 am, aditya kumar 
> > > wrote:
>
> > > > not sure abt the algo but we can think in terms of tokeninzing . ie go 
> > > > for
> > > > greedy method . greedy looks for maximum match . extract the token and 
> > > > match
> > > > with the dictionary word . if match found then add the additional space 
> > > > else
> > > > look for next token .
> > > > On Thu, Aug 18, 2011 at 9:10 PM, Navneet Gupta 
> > > > wrote:
>
> > > > > Given a string containing multiple words such that spaces between 
> > > > > words is
> > > > > missing. Also, you have a dictionary containing valid words.
>
> > > > > Ex. "Thatwouldbefantastic"
>
> > > > > Output a string with proper spaces inserted.
>
> > > > > Output - "That would be fantastic"
>
> > > > > The case of words like bandwidth present can be discounted.
>
> > > > > --
> > > > > Regards,
> > > > > Navneet
>
> > > > > --
> > > > > You received this message because you are subscribed to the Google 
> > > > > Groups
> > > > > "Algorithm Geeks" group.
> > > > > To post to this group, send email to algogeeks@googlegroups.com.
> > > > > To unsubscribe from this group, send email to
> > > > > algogeeks+unsubscr...@googlegroups.com.
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question from Google interview

2011-08-18 Thread Dave
@Icy: We agree that you have to look ahead in order to set the spaces
correctly. The only point of difference is whether you choose to
become more greedy or less greedy when looking ahead fails.

Dave

On Aug 18, 2:55 pm, "icy`"  wrote:
> Well no, I would think it would match "Balls"  for him, since it is
> greedy --> it would try to match as much as possible that works/is in
> dict.  So I have to agree with Aditya here, but I would go from the
> back/right to the left. So I would first get " round",  then hopefully
> " are round"  and finally "Balls are round".
>
> Now it gets tricky if the remaining left section cannot be broken into
> words.  Then we'd have to backtrack once and take the next less-greedy
> match, and try again.  If that fails, take even less greedier match ,
> or backtrack yet again.
>
> On Aug 18, 1:05 pm, Dave  wrote:
>
>
>
> > @Aditya: You probably have to be a bit more careful than that. You
> > can't add the space until both the first part is a word in the
> > dictionary and the rest of the string can also be broken into words in
> > the dictionary. Consider "Ballsareround." Your algorithm seems to put
> > a space after the second "l", but then no initial part of "sareround"
> > may be in your dictionary. In that case, you have to reject that space
> > and continue until you get to a division point such that both the
> > first part is in the dictionary and the second part can be broken into
> > words. Sounds like a good place for recursion.
>
> > Dave
>
> > On Aug 18, 10:52 am, aditya kumar 
> > wrote:
>
> > > not sure abt the algo but we can think in terms of tokeninzing . ie go for
> > > greedy method . greedy looks for maximum match . extract the token and 
> > > match
> > > with the dictionary word . if match found then add the additional space 
> > > else
> > > look for next token .
> > > On Thu, Aug 18, 2011 at 9:10 PM, Navneet Gupta 
> > > wrote:
>
> > > > Given a string containing multiple words such that spaces between words 
> > > > is
> > > > missing. Also, you have a dictionary containing valid words.
>
> > > > Ex. "Thatwouldbefantastic"
>
> > > > Output a string with proper spaces inserted.
>
> > > > Output - "That would be fantastic"
>
> > > > The case of words like bandwidth present can be discounted.
>
> > > > --
> > > > Regards,
> > > > Navneet
>
> > > > --
> > > > You received this message because you are subscribed to the Google 
> > > > Groups
> > > > "Algorithm Geeks" group.
> > > > To post to this group, send email to algogeeks@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > algogeeks+unsubscr...@googlegroups.com.
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question from Google interview

2011-08-18 Thread icy`

Well no, I would think it would match "Balls"  for him, since it is
greedy --> it would try to match as much as possible that works/is in
dict.  So I have to agree with Aditya here, but I would go from the
back/right to the left. So I would first get " round",  then hopefully
" are round"  and finally "Balls are round".

Now it gets tricky if the remaining left section cannot be broken into
words.  Then we'd have to backtrack once and take the next less-greedy
match, and try again.  If that fails, take even less greedier match ,
or backtrack yet again.

On Aug 18, 1:05 pm, Dave  wrote:
> @Aditya: You probably have to be a bit more careful than that. You
> can't add the space until both the first part is a word in the
> dictionary and the rest of the string can also be broken into words in
> the dictionary. Consider "Ballsareround." Your algorithm seems to put
> a space after the second "l", but then no initial part of "sareround"
> may be in your dictionary. In that case, you have to reject that space
> and continue until you get to a division point such that both the
> first part is in the dictionary and the second part can be broken into
> words. Sounds like a good place for recursion.
>
> Dave
>
> On Aug 18, 10:52 am, aditya kumar 
> wrote:
>
>
>
>
>
>
>
> > not sure abt the algo but we can think in terms of tokeninzing . ie go for
> > greedy method . greedy looks for maximum match . extract the token and match
> > with the dictionary word . if match found then add the additional space else
> > look for next token .
> > On Thu, Aug 18, 2011 at 9:10 PM, Navneet Gupta wrote:
>
> > > Given a string containing multiple words such that spaces between words is
> > > missing. Also, you have a dictionary containing valid words.
>
> > > Ex. "Thatwouldbefantastic"
>
> > > Output a string with proper spaces inserted.
>
> > > Output - "That would be fantastic"
>
> > > The case of words like bandwidth present can be discounted.
>
> > > --
> > > Regards,
> > > Navneet
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to algogeeks@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > algogeeks+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question from Google interview

2011-08-18 Thread Dave
@Aditya: You probably have to be a bit more careful than that. You
can't add the space until both the first part is a word in the
dictionary and the rest of the string can also be broken into words in
the dictionary. Consider "Ballsareround." Your algorithm seems to put
a space after the second "l", but then no initial part of "sareround"
may be in your dictionary. In that case, you have to reject that space
and continue until you get to a division point such that both the
first part is in the dictionary and the second part can be broken into
words. Sounds like a good place for recursion.

Dave

On Aug 18, 10:52 am, aditya kumar 
wrote:
> not sure abt the algo but we can think in terms of tokeninzing . ie go for
> greedy method . greedy looks for maximum match . extract the token and match
> with the dictionary word . if match found then add the additional space else
> look for next token .
> On Thu, Aug 18, 2011 at 9:10 PM, Navneet Gupta wrote:
>
>
>
> > Given a string containing multiple words such that spaces between words is
> > missing. Also, you have a dictionary containing valid words.
>
> > Ex. "Thatwouldbefantastic"
>
> > Output a string with proper spaces inserted.
>
> > Output - "That would be fantastic"
>
> > The case of words like bandwidth present can be discounted.
>
> > --
> > Regards,
> > Navneet
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question

2011-08-07 Thread bugaboo
1) Firstly, size of the data type depends on the language. With C/C++,
since they are not platform independent, size of integer varies from
machine to machine.
2) With C/C++, the size depends on the underlying hardware
(architecture).
HardwareOSPossible
   -
 32 32 Yes
 32 64 No
 64 32 Yes
 64 64 Yes

So, basically, size of a data type in C/C++ depends on the
Smallest(Hardware, OS). Put in other words, since OS size has to be <=
hardware, technically, it boils down to the OS size.

If the compiler is 32 bit and OS is 64, then the compiler size takes
preference. Generally most 64 bit OS will emulate 32 bit OS, so old
legacy software can run on it.



On Aug 7, 12:38 am, hary rathor  wrote:
> in a 64 bit computer is that is capable of transfer 64 bit at a time
> 64 bit os means it capable of handle these 64 bit at time .but 32 it os use
> only half of bus
> so "theorytically not practically" 64 bit is 8 time faster than 32 bit os .
> and 64 bit os can address more ram  at time .
> cause of wide 64 bit address bus. this architecture is called x-64 based bit
> and 32 bit os is called x-86 based architecture.
> as we know that when be some compiler  are capable of install on both type
> of os 32 and 64. that compiler will use 32 bit based
> addressing system that result sizeof address 4 byte. if your compiler is
> completely build for 64 bit os that definitely it has to use
> 64 bit address lan that require 8 byte size integer size to hold this wide
> address.
>
> so there for 3 type of os is available in market
>
> x86
> x64
> x86 x64
>
> now Windows 8 will come with 128 bit addressing system
>
> i hope this can make you more clear

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Question

2011-08-06 Thread saurabh singh
Always ready to help mate:)
Party do ab:D

On Sat, Aug 6, 2011 at 4:55 PM, UTKARSH SRIVASTAV
wrote:

> thnx saurabh i got ac
>
>
>
> On Sat, Aug 6, 2011 at 4:22 AM, UTKARSH SRIVASTAV  > wrote:
>
>> MY LOGIC IS .LET AFTER N STEPS RELATION BETWEEN NUMBER OF
>> ONES(1),ZEROONE(01) AND DOUBLEZERO(00) IS
>>
>> INITIALLY
>> ONE=1
>> ZEROONE=0
>> DOUBLEZERO=0
>>
>> FOR N=1
>> K=ONE
>> L=ZEROONE
>> M=DOUBLEZERO
>> ONE=K+L+M
>> ZEROONE=K+M
>> DOUBLEZERO=L
>> i.e. ONE=1  ZERONE=1 DOUBLEZERO=0
>>
>> FOR N=2
>> K=ONE
>> L=ZEROONE
>> M=DOUBLEZERO
>> ONE=K+L+M
>> ZEROONE=K+M
>> DOUBLEZERO=L
>> i.e. ONE=2  ZERONE=1 DOUBLEZERO=1
>>
>>
>> FOR N=3
>> K=ONE
>> L=ZEROONE
>> M=DOUBLEZERO
>> ONE=K+L+M
>> ZEROONE=K+M
>> DOUBLEZERO=L
>> i.e. ONE=3  ZERONE=1 DOUBLEZERO=1
>>
>> FOR N=4
>> K=ONE
>> L=ZEROONE
>> M=DOUBLEZERO
>> ONE=K+L+M
>> ZEROONE=K+M
>> DOUBLEZERO=L
>> i.e. ONE=8  ZERONE=5 DOUBLEZERO=3
>>
>>
>>
>>
>>
>>
>>
>> --
>> *UTKARSH SRIVASTAV
>> CSE-3
>> B-Tech 3rd Year
>> @MNNIT ALLAHABAD*
>>
>>
>
>
> --
> *UTKARSH SRIVASTAV
> CSE-3
> B-Tech 3rd Year
> @MNNIT ALLAHABAD*
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question

2011-08-06 Thread UTKARSH SRIVASTAV
thnx saurabh i got ac


On Sat, Aug 6, 2011 at 4:22 AM, UTKARSH SRIVASTAV
wrote:

> MY LOGIC IS .LET AFTER N STEPS RELATION BETWEEN NUMBER OF
> ONES(1),ZEROONE(01) AND DOUBLEZERO(00) IS
>
> INITIALLY
> ONE=1
> ZEROONE=0
> DOUBLEZERO=0
>
> FOR N=1
> K=ONE
> L=ZEROONE
> M=DOUBLEZERO
> ONE=K+L+M
> ZEROONE=K+M
> DOUBLEZERO=L
> i.e. ONE=1  ZERONE=1 DOUBLEZERO=0
>
> FOR N=2
> K=ONE
> L=ZEROONE
> M=DOUBLEZERO
> ONE=K+L+M
> ZEROONE=K+M
> DOUBLEZERO=L
> i.e. ONE=2  ZERONE=1 DOUBLEZERO=1
>
>
> FOR N=3
> K=ONE
> L=ZEROONE
> M=DOUBLEZERO
> ONE=K+L+M
> ZEROONE=K+M
> DOUBLEZERO=L
> i.e. ONE=3  ZERONE=1 DOUBLEZERO=1
>
> FOR N=4
> K=ONE
> L=ZEROONE
> M=DOUBLEZERO
> ONE=K+L+M
> ZEROONE=K+M
> DOUBLEZERO=L
> i.e. ONE=8  ZERONE=5 DOUBLEZERO=3
>
>
>
>
>
>
>
> --
> *UTKARSH SRIVASTAV
> CSE-3
> B-Tech 3rd Year
> @MNNIT ALLAHABAD*
>
>


-- 
*UTKARSH SRIVASTAV
CSE-3
B-Tech 3rd Year
@MNNIT ALLAHABAD*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question

2011-08-06 Thread UTKARSH SRIVASTAV
MY LOGIC IS .LET AFTER N STEPS RELATION BETWEEN NUMBER OF
ONES(1),ZEROONE(01) AND DOUBLEZERO(00) IS

INITIALLY
ONE=1
ZEROONE=0
DOUBLEZERO=0

FOR N=1
K=ONE
L=ZEROONE
M=DOUBLEZERO
ONE=K+L+M
ZEROONE=K+M
DOUBLEZERO=L
i.e. ONE=1  ZERONE=1 DOUBLEZERO=0

FOR N=2
K=ONE
L=ZEROONE
M=DOUBLEZERO
ONE=K+L+M
ZEROONE=K+M
DOUBLEZERO=L
i.e. ONE=2  ZERONE=1 DOUBLEZERO=1


FOR N=3
K=ONE
L=ZEROONE
M=DOUBLEZERO
ONE=K+L+M
ZEROONE=K+M
DOUBLEZERO=L
i.e. ONE=3  ZERONE=1 DOUBLEZERO=1

FOR N=4
K=ONE
L=ZEROONE
M=DOUBLEZERO
ONE=K+L+M
ZEROONE=K+M
DOUBLEZERO=L
i.e. ONE=8  ZERONE=5 DOUBLEZERO=3







-- 
*UTKARSH SRIVASTAV
CSE-3
B-Tech 3rd Year
@MNNIT ALLAHABAD*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Question

2011-07-29 Thread Anika Jain
i also feel the point of kiddle is ryt.. can anybody plz explain more

On Jul 26, 12:18 am, SkRiPt KiDdIe  wrote:
> How much time does he reach home is a bad question to ask.
>
> Say i walk 90-x minutes before i meet my driver.If i had walked x more
> minutes the driver would have reached my office. I save the driver's  x
> minutes which he takes for onwards journey from the point of meet.Eventually
> i save 20 min (onward+backward) from the trip.
>
> x=20/2 and so i walk for 80 minutes.
>
> Further conclusions can't be made i hope.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: question

2011-07-28 Thread tech rascal
lets say-
if a=1 1 0 0 1 0 1 1
   b=0 1 1 1 0 1 1 1
by finding xor of a & b, u will be able to find how many bits in a are reqd
to be changed to get b
bcoz if bits in a & b are different at any position then only u need to
change( 0->1 or 1->0) else not

code

int bitswapreqd(int a, int b)
{
int c, count;
c=a^b;
//now counting the no. of 1's in c
if(c==0)  //if both no's are same
return 0;
while(c!=0)
{
c=c & (01);
if(c==1)
count++;
c>>1;
}
return count;
}

On Fri, Jul 29, 2011 at 4:03 AM, Tim Zheng  wrote:

> int BitFlipRequired::bitFlipRequired(int A, int B){
>int count(0);
>int bitMask(1);
>
>A ^= B;
>
>for (unsigned int bitPosition = 0; bitPosition < sizeof(int)*8;
> bitPosition++){
>if ((A & bitMask) != 0)
>count++;
>bitMask <<= 1;
>}
>return count;
> }
>
>
> On Jul 28, 2:43 pm, sylvester  wrote:
> > i just read this quetion somewhere...i dont have any idea what exactly
> > they mean by this...so m looking for any soln that can be possible
> >
> > On Jul 29, 2:19 am, Tim Zheng  wrote:
> >
> >
> >
> >
> >
> >
> >
> > > What's the basic operation on A allowed here to convert it to B? Just
> > > to flip individual bit?
> >
> > > On Jul 28, 2:14 pm, sylvester  wrote:
> >
> > > > Given two integers A & B. Determine how many bits required to convert
> > > > A to B. Write a function int BitSwapReqd(int A, int B);
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question

2011-07-28 Thread Tim Zheng
int BitFlipRequired::bitFlipRequired(int A, int B){
int count(0);
int bitMask(1);

A ^= B;

for (unsigned int bitPosition = 0; bitPosition < sizeof(int)*8;
bitPosition++){
if ((A & bitMask) != 0)
count++;
bitMask <<= 1;
}
return count;
}


On Jul 28, 2:43 pm, sylvester  wrote:
> i just read this quetion somewhere...i dont have any idea what exactly
> they mean by this...so m looking for any soln that can be possible
>
> On Jul 29, 2:19 am, Tim Zheng  wrote:
>
>
>
>
>
>
>
> > What's the basic operation on A allowed here to convert it to B? Just
> > to flip individual bit?
>
> > On Jul 28, 2:14 pm, sylvester  wrote:
>
> > > Given two integers A & B. Determine how many bits required to convert
> > > A to B. Write a function int BitSwapReqd(int A, int B);

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question

2011-07-28 Thread sylvester
i just read this quetion somewhere...i dont have any idea what exactly
they mean by this...so m looking for any soln that can be possible

On Jul 29, 2:19 am, Tim Zheng  wrote:
> What's the basic operation on A allowed here to convert it to B? Just
> to flip individual bit?
>
> On Jul 28, 2:14 pm, sylvester  wrote:
>
>
>
>
>
>
>
> > Given two integers A & B. Determine how many bits required to convert
> > A to B. Write a function int BitSwapReqd(int A, int B);

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: question

2011-07-28 Thread Tim Zheng
What's the basic operation on A allowed here to convert it to B? Just
to flip individual bit?

On Jul 28, 2:14 pm, sylvester  wrote:
> Given two integers A & B. Determine how many bits required to convert
> A to B. Write a function int BitSwapReqd(int A, int B);

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



  1   2   >