[algogeeks] Re: Help me find my Recursive algo complexity

2012-10-10 Thread KK
Hi Vicky.. Its O(n^K) as u are iterating over all the elements of array for 
each of the k element subset!!

On Monday, 8 October 2012 23:53:15 UTC+5:30, ((** VICKY **)) wrote:

 Hi, I wrote code for generating all possible sets of length k in a array 
 of length n. I did using recursion, but i'm not able to calc the 
 complexity systematically [image: :-/] Kindly help me.
  11:39 PM

 i.p {1,2,3,4,5} k =2
 o.p
 Vector has : 1 2 3 4 5  
 1 1 2 
 2 1 3 
 3 1 4 
 4 1 5 
 5 2 3 
 6 2 4 
 7 2 5 
 8 3 4 
 9 3 5 
 10 4 5 

 Approach:

 Assume I have a selected and remaining set, now initially all will be 
 remaining set and selected set= {}. 

 In first step pick 1 and grow recursion with it as root and pick 2,3,4,5 
 (n-1) as possible picks. Now print those sets since k=2(base case) is 
 reached. 
 Now grow recursion with 2 as root and 3,4,5 (n-2) as possible 
 picks(childs) print them. Repeat till i reach 5 where i have no children 
 possible as rem set is empty.   

 void print_all(vectorintsel,vectorintrem, int n){
 if(sel.size() == n)
 {
 static int cnt = 1;
 coutcnt++ ;
 for(int i = 0; i  n; i++)
 coutsel[i] ;
 coutendl;
 return;
 sel.erase(sel.begin(),sel.end());
 }
 for(int i = 0; i  rem.size(); i++)
 {
  
 vectorintnow,curr_sel;
 //for(int j = 0; j  i; j++)
   //  now.push_back(rem[j]);
 for(int j = i+1; jrem.size(); j++)
 now.push_back(rem[j]);
// coutnow has : ;
 //for(int i = 0; i  now.size(); i++)
   //  coutnow[i] ;
 //coutendl;
 for(int i = 0; i  sel.size(); i++)
 curr_sel.push_back(sel[i]);
 curr_sel.push_back(rem[i]);
 print_all(curr_sel,now,n);
 }}
  

 -- 
 Cheers,
  
   Vicky

  

-- 
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/-/GTlxcHY8JDYJ.
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: Help woth LISP

2012-07-09 Thread Geoffrey Summerhayes
Looks pretty standard. It starts by placing one queen on each square of the 
bottom row, then working up through the
rows trying to put a queen in each column. If it can place a queen it gets 
added as a possible solution.
The always test in the inner loop checks the 'rook' horizontal and then the 
'bishop' diagonal.
The bishop test is a bit tricky, it looks at (x rows up, y columns across 
from a previously placed queen)
If x and y are equal it's on the diagonal.

--
Geoffrey Summerhayes

On Sunday, July 8, 2012 8:00:54 PM UTC-4, Victor Manuel Grijalva Altamirano 
wrote:


 The next solve the problem of eight Queeen... but i don't undestand 
 it!!! can you explain me?

 (defun n-queens (n m)
   (
 
 if (= n 1)
 (loop for x from 1 to m collect (list x))
 
 
 (loop for sol in (n-queens (1- n) m) nconc
   (loop for col from 1 to m when
 (loop for row from 0 to (length sol) for c in sol
   always (and (/= col c)
   (/= (abs (- c col)) (1+ row)))
   finally (return (cons col sol))
 )
collect it
   )
  )
 )
  )




 -- 
 Victor Manuel Grijalva Altamirano
 Universidad Tecnologica de La Mixteca


-- 
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/-/qv0m-4stZdEJ.
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: Help sourcebit !!!

2011-10-06 Thread aditya kumar
guys its my sincere request to all .. before posting any question plz plz do
search for archives first . if you would had done that you could have got
better knowledge .


On Wed, Oct 5, 2011 at 9:14 PM, raman shukla shukla.rama...@gmail.comwrote:

 Hey mate dont worry there is nothing like pattern, You should be able
 to think little logical and write normal JAVA programs like
 implementation of different sorting algorithm in java and finding
 regular expression in text file. This is only required, no need to
 panic. All the best.

 On Oct 5, 5:31 pm, praveen raj praveen0...@gmail.com wrote:
  Plz put the technical written paper pattern ...of sourcebit... and some
  sample papers...of what type of questions(level) would be asked...

 --
 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: Help sourcebit !!!

2011-10-05 Thread raman shukla
Hey mate dont worry there is nothing like pattern, You should be able
to think little logical and write normal JAVA programs like
implementation of different sorting algorithm in java and finding
regular expression in text file. This is only required, no need to
panic. All the best.

On Oct 5, 5:31 pm, praveen raj praveen0...@gmail.com wrote:
 Plz put the technical written paper pattern ...of sourcebit... and some
 sample papers...of what type of questions(level) would be asked...

-- 
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: help

2011-09-13 Thread DIVIJ WADHAWAN
Try material of MBA coaching institutes wiz Career Launcher,Time
etc

On Sep 12, 6:11 pm, wellwisher p9047551...@gmail.com wrote:
 please suggest me some good aptitude books

-- 
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: help

2011-09-13 Thread mithun bs
Quantitative Aptitude by R.S.Agarwal.

On Tue, Sep 13, 2011 at 2:12 PM, DIVIJ WADHAWAN divij...@gmail.com wrote:

 Try material of MBA coaching institutes wiz Career Launcher,Time
 etc

 On Sep 12, 6:11 pm, wellwisher p9047551...@gmail.com wrote:
  please suggest me some good aptitude books

 --
 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.




-- 
Mithun.B.S
M:9916775380

-- 
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: Help on Recursion Bit Operators related problems

2011-08-04 Thread Navneet
bit twiddling hacks, a stanford resource.

http://graphics.stanford.edu/~seander/bithacks.html

On Aug 4, 10:55 am, Shashank Jain shashan...@gmail.com wrote:
 even this is a gud 
 1.http://www.cprogramming.com/tutorial/bitwise_operators.html

 Shashank Jain
 IIIrd year
 Computer Engineering
 Delhi College of Engineering

 On Thu, Aug 4, 2011 at 1:35 AM, Samba Ganapavarapu 
 sambasiv...@gmail.comwrote:







  thanks raj,
  is this the bitwise operator tutorial that you told about ?

 http://www.topcoder.com/tc?module=Staticd1=tutorialsd2=bitManipulation

  On Wed, Aug 3, 2011 at 3:48 PM, raj kumar megamonste...@gmail.com wrote:

  the best way to identify recursion is   when  finding solution to a
  problem consist of finding solution to a sub problem
  ex-5!=5*(4!)=5*4*(3!).
  for bits see topcoder tutorials on bitwise operators

  --
  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: Help on Recursion Bit Operators related problems

2011-08-04 Thread Samba Ganapavarapu
thank you Shashank  navneet

- Samba

On Thu, Aug 4, 2011 at 3:24 AM, Navneet navneetn...@gmail.com wrote:

 bit twiddling hacks, a stanford resource.

 http://graphics.stanford.edu/~seander/bithacks.html

 On Aug 4, 10:55 am, Shashank Jain shashan...@gmail.com wrote:
  even this is a gud 1.
 http://www.cprogramming.com/tutorial/bitwise_operators.html
 
  Shashank Jain
  IIIrd year
  Computer Engineering
  Delhi College of Engineering
 
  On Thu, Aug 4, 2011 at 1:35 AM, Samba Ganapavarapu 
 sambasiv...@gmail.comwrote:
 
 
 
 
 
 
 
   thanks raj,
   is this the bitwise operator tutorial that you told about ?
 
  
 http://www.topcoder.com/tc?module=Staticd1=tutorialsd2=bitManipulation
 
   On Wed, Aug 3, 2011 at 3:48 PM, raj kumar megamonste...@gmail.com
 wrote:
 
   the best way to identify recursion is   when  finding solution to a
   problem consist of finding solution to a sub problem
   ex-5!=5*(4!)=5*4*(3!).
   for bits see topcoder tutorials on bitwise operators
 
   --
   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.



[algogeeks] Re: help..

2011-07-14 Thread rj7
@sunny how did you arrive at the bit wise operation thing1

-- 
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: help to code

2011-07-06 Thread Tushar Bindal
Evenly divisible simply means that a number should be completely divisible
by the given numbers, i.e., it should give a whole number as an answer when
divided by that particular number. Evenly divisible doesn't mean that
quotient should be an even number. It just needs to be a whole number.
Probably this link can help you understand that
http://en.wiktionary.org/wiki/evenly_divisible

So if you agree with my interpretation that numbers which are not divisible
by all 5 numbers should be taken into account, then my code is correct.
:)

-- 
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: Help!!

2011-07-06 Thread KK
Hey anyone Pl help... its clearly written code and algo u know vry
well so it wont take much time :)

On Jul 5, 8:43 pm, KK kunalkapadi...@gmail.com wrote:
 This is the solution to the MST problem
 m getting WA again n again... cant figure out where's the mistake...
 so plzzz help!!!https://www.spoj.pl/problems/BLINNET/

 #includeiostream
 #includestring
 #includevector
 #includelist
 #includequeue

 #define MAXINT (int)9e9
 #define TR(a,it)        for(typeof((a).begin()) it=(a).begin(); it!
 =(a).end(); ++it)
 using namespace std;

 struct node
 {
        long int data;
        string name;
        long int cost;
        long int distance;
        long int parent;

        friend bool operator(const node a, const node b);

 };

 long int prims(vector listnode  adjlist, int n);

 int main()
 {
      freopen(input.txt, r, stdin);
      freopen(output.txt, w, stdout);

      long int n, t, no_neigh;
      cin  t;
      while(t--)
      {
                vector listnode  adjlist;
                node temp;
                getchar();
                cin  n;
                adjlist.resize(n + 1);
                for(int i=1; i=n; i++)
                {
                         cin  temp.name;
                         //temp.data = i;
                         //adjlist[i].push_back(temp);

                         cin  no_neigh;
                         for(int j=1; j=no_neigh; j++)
                         {
                                  cin  temp.data  temp.cost;
                                  adjlist[i].push_back(temp);
                         }
                }

                /*for(int i=1; i=n; i++)
                {
                    cout  i  :  endl;
                    TR(adjlist[i], it)
                       cout  it-data it-cost  endl;
                }*/

                cout  prims(adjlist, n)  endl;
      }

 }

 bool operator(const node a, const node b)
 {
      return a.distance  b.distance;

 }

 long int prims(vector listnode  adjlist, int n)
 {
       priority_queuenode, vectornode, greaternode  pq;
       node heap[n+1];
       for(long int i=1; i=n; i++)
       {
             heap[i].data = i;
             heap[i].distance = MAXINT;
             heap[i].parent = -1;
       }

       long int start = 1;
       heap[start].distance = 0;
       pq.push(heap[start]);

       while(!pq.empty())
       {
             node top = pq.top();   pq.pop();
             //cout  popped :  top.data endl;
             if(top.distance = heap[top.data].distance)
             {
                   //cout  Traversed   endl;
                   TR(adjlist[top.data], it)
                   {
                        if(heap[it-data].distance  it-cost)
                        {
                             heap[it-data].distance = it-cost;
                             heap[it-data].parent = top.data;
                             //cout  Pushed   it-data  endl;
                             pq.push(heap[it-data]);
                        }
                   }
             }
       }

       long int sum = 0;
       for(int i=1; i=n; i++)
           sum += heap[i].distance;
       return sum;







 }

-- 
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: help to code

2011-07-05 Thread shiv narayan
@ tushar
as per your interpretation this looks coreect...but i am not saying to
exclude all no's which are divisible by first 5 prime no ..question
says to exclude those no which are evenly divisible by first 5 prime
no..

On Jul 5, 10:47 pm, Tushar Bindal tushicom...@gmail.com wrote:
 If my interpretation is right, following should be the code.

 int main()
 {
 int userInteger = 0;
 cout  Enter A Number endl;
 cin  userInteger; // Ask For a number from the user
 if (userInteger  0) // Is the number valid?
 {
 int result = 0;
 int prime[5] = { 2, 3, 5, 7, 11 };
 int a,b, count = 0;
 *for(a=1;a=userInteger;++a) // Looping to user's input
 {
   for(b=0;b  5;++b) // Looping the prime numbers array
    {
    if (a % prime[b] == 0) //if divisible by any number, just end it there
    break;
   }
  //break or end of loop will bring the control here
  if(b==5) //a was not divisible by any of the first 5 prime numbers
  {
  result+=a;
  ++count;
  }}*

 cout  Numbers Not evenly divisible by 5 prime numbers:   count
  endl;
 cout  The Sum of numbers not evenly divisible by 5 prime numbers: 
  result  endl;}

 getch();
 return 0;

 }

 --- 
 -

 As per my solution,
 Test Cases:
 1)
 userInteger = 20
 count = 4
 Numbers will be: 1, 13, 17, 19
 result = 50

 2)
 userInteger = 35
 count = 7
 Numbers will be: 1, 13, 17, 19, 23, 29, 31
 result = 133

 Even numbers can never be there in this list as they are all divisible by 2.
 Bfore 169, only prime numbers can be included.
 Hope my interpretation of your question was correct

-- 
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: help to code

2011-07-05 Thread shiv narayan
@ tushar just one modification to you code would make the things
correct.makin  if (a % 2*prime[b] == 0) inspite of  if (a % prime[b]
== 0)  would take care  of even things
hope i am correct..
thanx! for the reply

On Jul 5, 10:47 pm, Tushar Bindal tushicom...@gmail.com wrote:
 If my interpretation is right, following should be the code.

 int main()
 {
 int userInteger = 0;
 cout  Enter A Number endl;
 cin  userInteger; // Ask For a number from the user
 if (userInteger  0) // Is the number valid?
 {
 int result = 0;
 int prime[5] = { 2, 3, 5, 7, 11 };
 int a,b, count = 0;
 *for(a=1;a=userInteger;++a) // Looping to user's input
 {
   for(b=0;b  5;++b) // Looping the prime numbers array
    {
    if (a % prime[b] == 0) //if divisible by any number, just end it there
    break;
   }
  //break or end of loop will bring the control here
  if(b==5) //a was not divisible by any of the first 5 prime numbers
  {
  result+=a;
  ++count;
  }}*

 cout  Numbers Not evenly divisible by 5 prime numbers:   count
  endl;
 cout  The Sum of numbers not evenly divisible by 5 prime numbers: 
  result  endl;}

 getch();
 return 0;

 }

 --- 
 -

 As per my solution,
 Test Cases:
 1)
 userInteger = 20
 count = 4
 Numbers will be: 1, 13, 17, 19
 result = 50

 2)
 userInteger = 35
 count = 7
 Numbers will be: 1, 13, 17, 19, 23, 29, 31
 result = 133

 Even numbers can never be there in this list as they are all divisible by 2.
 Bfore 169, only prime numbers can be included.
 Hope my interpretation of your question was correct

-- 
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: help..

2011-07-03 Thread cegprakash
@sameer: thank you

On Jul 2, 3:47 pm, sameer.mut...@gmail.com sameer.mut...@gmail.com
wrote:
 nn-1  is the expression to find out if n is a power of 2...If nn-1 returns
 0 its a power of 2 else its not.
 And what sunny said is also ryt

 On Sat, Jul 2, 2011 at 3:47 PM, sunny agrawal sunny816.i...@gmail.comwrote:







  @cegprakash
  Expression resets the least significant set bit

  On Sat, Jul 2, 2011 at 3:20 PM, mohit goel mohitgoel291...@gmail.comwrote:

  May be this can work.give any counter example...
  int count;
  main()
  {
        int l,rope,cuts;
        scanf(%d%d,l,rope);
        count =0;

         find_cuts(l,rope);
         printf(cuts needed is %d,count);
         getch();
         return 0;
         }

   int find_cuts(int l,int rope)

   {

      if(l==rope)
      return count;
       count++;
       printf(%d,count);
       l=l/2;
       if(l==rope)
       return count;
       if(ropel)
       rope =rope-l;

       find_cuts(l,rope);

   }

  --
  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.

  --
  Sunny Aggrawal
  B-Tech IV year,CSI
  Indian Institute Of Technology,Roorkee

   --
  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: help..

2011-07-03 Thread cegprakash
@mohit: nice soln :)

On Jul 2, 2:50 pm, mohit goel mohitgoel291...@gmail.com wrote:
 May be this can work.give any counter example...
 int count;
 main()
 {
       int l,rope,cuts;
       scanf(%d%d,l,rope);
       count =0;

        find_cuts(l,rope);
        printf(cuts needed is %d,count);
        getch();
        return 0;
      }

  int find_cuts(int l,int rope)

  {

     if(l==rope)
     return count;
      count++;
      printf(%d,count);
      l=l/2;
      if(l==rope)
      return count;
      if(ropel)
      rope =rope-l;

      find_cuts(l,rope);

  }

-- 
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: help..

2011-07-03 Thread cegprakash
@mohit: a little change in your function to make it work..
  int find_cuts(int l,int rope)

  int find_cuts(int l,int rope)

 {

if(l==rope)
return count;
 count++;
   // printf(%d,count);
 l=l/2;
 if(l==rope)
 return count;
 if(ropel)
 rope =rope-l;

 return find_cuts(l,rope);

 }

-- 
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: help..

2011-07-03 Thread cegprakash
@avi dullu: explanation of your code plz..

On Jul 3, 3:57 am, Avi Dullu avi.du...@gmail.com wrote:
 Another alternative soln.

 int rec_cut(int l, int k) {
   if (l == k) return 0;
   int tmp = k - (l1);
   return 1 + rec_cut(l1, tmp = 0 ? k : tmp);

 }

 int main() {
   int l, k;
   scanf(%d%d, l, k);
   printf(%d\n, rec_cut(l, k));
   return 0;

 }

 Veni Vedi Slumber !

 On Sat, Jul 2, 2011 at 9:47 PM, varun pahwa varunpahwa2...@gmail.comwrote:





  @sunny thnx for the correction.

  On Sat, Jul 2, 2011 at 9:16 AM, varun pahwa varunpahwa2...@gmail.comwrote:

  @sunny ya  i wanted to write the while(k % m == 0)

  On Sat, Jul 2, 2011 at 3:47 AM, sameer.mut...@gmail.com 
  sameer.mut...@gmail.com wrote:

  nn-1  is the expression to find out if n is a power of 2...If nn-1
  returns 0 its a power of 2 else its not.
  And what sunny said is also ryt

  On Sat, Jul 2, 2011 at 3:47 PM, sunny agrawal 
  sunny816.i...@gmail.comwrote:

  @cegprakash
  Expression resets the least significant set bit

   On Sat, Jul 2, 2011 at 3:20 PM, mohit goel 
  mohitgoel291...@gmail.comwrote:

  May be this can work.give any counter example...
  int count;
  main()
  {
        int l,rope,cuts;
        scanf(%d%d,l,rope);
        count =0;

         find_cuts(l,rope);
         printf(cuts needed is %d,count);
         getch();
         return 0;
         }

   int find_cuts(int l,int rope)

   {

      if(l==rope)
      return count;
       count++;
       printf(%d,count);
       l=l/2;
       if(l==rope)
       return count;
       if(ropel)
       rope =rope-l;

       find_cuts(l,rope);

   }

  --
  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.

  --
  Sunny Aggrawal
  B-Tech IV year,CSI
  Indian Institute Of Technology,Roorkee

   --
  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.

  --
  Varun Pahwa
  B.Tech (IT)
  7th Sem.
  Indian Institute of Information Technology Allahabad.
  Ph : 09793899112 ,08011820777
  Official Email :: rit2008...@iiita.ac.in
  Another Email :: varunpahwa.ii...@gmail.com

  People who fail to plan are those who plan to fail.

  --
  Varun Pahwa
  B.Tech (IT)
  7th Sem.
  Indian Institute of Information Technology Allahabad.
  Ph : 09793899112 ,08011820777
  Official Email :: rit2008...@iiita.ac.in
  Another Email :: varunpahwa.ii...@gmail.com

  People who fail to plan are those who plan to fail.

   --
  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: help..

2011-07-03 Thread cegprakash
i was actually trying this problem..

www.spoj.pl/problems/LQDCANDY

I'm getting WA still..


#includemath.h
#includestdio.h
int cnt;
inline int find_cuts(int l,int rope)
{
if(l==rope)
return cnt;
cnt++;
 l=l/2;
 if(l==rope)
return cnt;
 if(ropel)
rope-=l;

 return find_cuts(l,rope);
}

int main(){
  int t;
  scanf(%d,t);
  while(t--){
 int n,needed;
 scanf(%d,n);
 int x=log2(n);
 int p=(int)pow(2,x);
 if(n!=p)
needed=(int)pow(2,x+1);
 else{
 printf(%d 0\n,n);
 continue;
 }
 if(n%2==1)
printf(%d %d\n,needed,(int)log2(needed));
 else{
   cnt=0;
   printf(%d %d\n,needed,find_cuts(needed,n));

 }
  }
}

-- 
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: help..

2011-07-03 Thread saurabh singh
I think its problem of overflow?
the input data is 10^18.Otherwise the problem is trivial

On Sun, Jul 3, 2011 at 7:02 PM, cegprakash cegprak...@gmail.com wrote:

 i was actually trying this problem..

 www.spoj.pl/problems/LQDCANDY

 I'm getting WA still..


 #includemath.h
 #includestdio.h
 int cnt;
 inline int find_cuts(int l,int rope)
 {
if(l==rope)
return cnt;
cnt++;
  l=l/2;
 if(l==rope)
 return cnt;
 if(ropel)
 rope-=l;

 return find_cuts(l,rope);
 }

 int main(){
  int t;
  scanf(%d,t);
  while(t--){
 int n,needed;
 scanf(%d,n);
 int x=log2(n);
 int p=(int)pow(2,x);
 if(n!=p)
needed=(int)pow(2,x+1);
 else{
 printf(%d 0\n,n);
 continue;
 }
 if(n%2==1)
printf(%d %d\n,needed,(int)log2(needed));
 else{
   cnt=0;
   printf(%d %d\n,needed,find_cuts(needed,n));

 }
  }
 }

 --
 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: help..

2011-07-02 Thread cegprakash
that will not work.

for example we need a rope of length 4 from a rope of length 16

we need 2 cuts

16== 8 + 8 == 8+ 4+ 4

-- 
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: help..

2011-07-02 Thread cegprakash
nope

On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote:
 yup :)

 On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah shalinisah.luv4cod...@gmail.com

  wrote:
  i guess the no. of 1s in the binary representation of the number is the
  answer..for 6 its 2...

  On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com wrote:

  the length of the rope is l units.
  I can only cut any rope into two halves.

  for example if the length of the rope is 8 and we need a length of
  rope 6

  we first cut into two halves and we get 4, 4
  now we cut any of the half again and we get 4,2,2

  now we can merge 4 and 2 and form a rope of length 6.

  in this example we need a minimum of 2 cuts to get the length of rope
  6 from 8

  assume that l is always a power of 2 and we need always a even length
  of rope from it how to find the number of minimum cuts needed to get
  the new rope?.

  --
  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: help..

2011-07-02 Thread varun pahwa
k - rope of desired length.
l - rope of given length
m = 2;
while(k % m)
m *= 2;
ans :: (log2(l) - log2(m) + 1).
ex.
k = 6,l = 8
so initially m = 2;
after 1st iteration m = 4;
then break;
so min = log2(8) - log2(4) + 1  = 3 -2 + 1 = 2.


On Sat, Jul 2, 2011 at 1:16 AM, cegprakash cegprak...@gmail.com wrote:

 nope

 On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote:
  yup :)
 
  On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah 
 shalinisah.luv4cod...@gmail.com
 
   wrote:
   i guess the no. of 1s in the binary representation of the number is the
   answer..for 6 its 2...
 
   On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com
 wrote:
 
   the length of the rope is l units.
   I can only cut any rope into two halves.
 
   for example if the length of the rope is 8 and we need a length of
   rope 6
 
   we first cut into two halves and we get 4, 4
   now we cut any of the half again and we get 4,2,2
 
   now we can merge 4 and 2 and form a rope of length 6.
 
   in this example we need a minimum of 2 cuts to get the length of rope
   6 from 8
 
   assume that l is always a power of 2 and we need always a even length
   of rope from it how to find the number of minimum cuts needed to get
   the new rope?.
 
   --
   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.




-- 
Varun Pahwa
B.Tech (IT)
7th Sem.
Indian Institute of Information Technology Allahabad.
Ph : 09793899112 ,08011820777
Official Email :: rit2008...@iiita.ac.in
Another Email :: varunpahwa.ii...@gmail.com

People who fail to plan are those who plan to fail.

-- 
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: help..

2011-07-02 Thread sunny agrawal
xor the length of the rope with the required length and difference between
the indexes of first set and last set bit *may* be the answer !!

On Sat, Jul 2, 2011 at 1:46 PM, cegprakash cegprak...@gmail.com wrote:

 nope

 On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote:
  yup :)
 
  On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah 
 shalinisah.luv4cod...@gmail.com
 
   wrote:
   i guess the no. of 1s in the binary representation of the number is the
   answer..for 6 its 2...
 
   On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com
 wrote:
 
   the length of the rope is l units.
   I can only cut any rope into two halves.
 
   for example if the length of the rope is 8 and we need a length of
   rope 6
 
   we first cut into two halves and we get 4, 4
   now we cut any of the half again and we get 4,2,2
 
   now we can merge 4 and 2 and form a rope of length 6.
 
   in this example we need a minimum of 2 cuts to get the length of rope
   6 from 8
 
   assume that l is always a power of 2 and we need always a even length
   of rope from it how to find the number of minimum cuts needed to get
   the new rope?.
 
   --
   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.




-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
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: help..

2011-07-02 Thread cegprakash
k is an even number and m=2 in your code. k%2 is always 0. your while
loop does nothing.

On Jul 2, 1:26 pm, varun pahwa varunpahwa2...@gmail.com wrote:
 k - rope of desired length.
 l - rope of given length
 m = 2;
 while(k % m)
 m *= 2;
 ans :: (log2(l) - log2(m) + 1).
 ex.
 k = 6,l = 8
 so initially m = 2;
 after 1st iteration m = 4;
 then break;
 so min = log2(8) - log2(4) + 1  = 3 -2 + 1 = 2.



 On Sat, Jul 2, 2011 at 1:16 AM, cegprakash cegprak...@gmail.com wrote:
  nope

  On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote:
   yup :)

   On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah 
  shalinisah.luv4cod...@gmail.com

wrote:
i guess the no. of 1s in the binary representation of the number is the
answer..for 6 its 2...

On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com
  wrote:

the length of the rope is l units.
I can only cut any rope into two halves.

for example if the length of the rope is 8 and we need a length of
rope 6

we first cut into two halves and we get 4, 4
now we cut any of the half again and we get 4,2,2

now we can merge 4 and 2 and form a rope of length 6.

in this example we need a minimum of 2 cuts to get the length of rope
6 from 8

assume that l is always a power of 2 and we need always a even length
of rope from it how to find the number of minimum cuts needed to get
the new rope?.

--
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.

 --
 Varun Pahwa
 B.Tech (IT)
 7th Sem.
 Indian Institute of Information Technology Allahabad.
 Ph : 09793899112 ,08011820777
 Official Email :: rit2008...@iiita.ac.in
 Another Email :: varunpahwa.ii...@gmail.com

 People who fail to plan are those who plan to fail.

-- 
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: help..

2011-07-02 Thread sunny agrawal
@varun
I think u want to write

while (k % m == 0)

On Sat, Jul 2, 2011 at 1:56 PM, varun pahwa varunpahwa2...@gmail.comwrote:

 k - rope of desired length.
 l - rope of given length
 m = 2;
 while(k % m)
 m *= 2;
 ans :: (log2(l) - log2(m) + 1).
 ex.
 k = 6,l = 8
 so initially m = 2;
 after 1st iteration m = 4;
 then break;
 so min = log2(8) - log2(4) + 1  = 3 -2 + 1 = 2.



 On Sat, Jul 2, 2011 at 1:16 AM, cegprakash cegprak...@gmail.com wrote:

 nope

 On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote:
  yup :)
 
  On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah 
 shalinisah.luv4cod...@gmail.com
 
   wrote:
   i guess the no. of 1s in the binary representation of the number is
 the
   answer..for 6 its 2...
 
   On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com
 wrote:
 
   the length of the rope is l units.
   I can only cut any rope into two halves.
 
   for example if the length of the rope is 8 and we need a length of
   rope 6
 
   we first cut into two halves and we get 4, 4
   now we cut any of the half again and we get 4,2,2
 
   now we can merge 4 and 2 and form a rope of length 6.
 
   in this example we need a minimum of 2 cuts to get the length of rope
   6 from 8
 
   assume that l is always a power of 2 and we need always a even length
   of rope from it how to find the number of minimum cuts needed to get
   the new rope?.
 
   --
   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.




 --
 Varun Pahwa
 B.Tech (IT)
 7th Sem.
 Indian Institute of Information Technology Allahabad.
 Ph : 09793899112 ,08011820777
 Official Email :: rit2008...@iiita.ac.in
 Another Email :: varunpahwa.ii...@gmail.com

 People who fail to plan are those who plan to fail.

  --
 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.




-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
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: help..

2011-07-02 Thread cegprakash
whats mean by first set bit and last set bit? do you simply mean the
index of first and last bit?

On Jul 2, 1:25 pm, sunny agrawal sunny816.i...@gmail.com wrote:
 xor the length of the rope with the required length and difference between
 the indexes of first set and last set bit *may* be the answer !!



 On Sat, Jul 2, 2011 at 1:46 PM, cegprakash cegprak...@gmail.com wrote:
  nope

  On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote:
   yup :)

   On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah 
  shalinisah.luv4cod...@gmail.com

wrote:
i guess the no. of 1s in the binary representation of the number is the
answer..for 6 its 2...

On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com
  wrote:

the length of the rope is l units.
I can only cut any rope into two halves.

for example if the length of the rope is 8 and we need a length of
rope 6

we first cut into two halves and we get 4, 4
now we cut any of the half again and we get 4,2,2

now we can merge 4 and 2 and form a rope of length 6.

in this example we need a minimum of 2 cuts to get the length of rope
6 from 8

assume that l is always a power of 2 and we need always a even length
of rope from it how to find the number of minimum cuts needed to get
the new rope?.

--
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.

 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee

-- 
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: help..

2011-07-02 Thread sunny agrawal
yes i have written that only
difference between indexes of first set bit and last set bit

On Sat, Jul 2, 2011 at 2:08 PM, cegprakash cegprak...@gmail.com wrote:

 whats mean by first set bit and last set bit? do you simply mean the
 index of first and last bit?

 On Jul 2, 1:25 pm, sunny agrawal sunny816.i...@gmail.com wrote:
  xor the length of the rope with the required length and difference
 between
  the indexes of first set and last set bit *may* be the answer !!
 
 
 
  On Sat, Jul 2, 2011 at 1:46 PM, cegprakash cegprak...@gmail.com wrote:
   nope
 
   On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote:
yup :)
 
On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah 
   shalinisah.luv4cod...@gmail.com
 
 wrote:
 i guess the no. of 1s in the binary representation of the number is
 the
 answer..for 6 its 2...
 
 On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com
   wrote:
 
 the length of the rope is l units.
 I can only cut any rope into two halves.
 
 for example if the length of the rope is 8 and we need a length of
 rope 6
 
 we first cut into two halves and we get 4, 4
 now we cut any of the half again and we get 4,2,2
 
 now we can merge 4 and 2 and form a rope of length 6.
 
 in this example we need a minimum of 2 cuts to get the length of
 rope
 6 from 8
 
 assume that l is always a power of 2 and we need always a even
 length
 of rope from it how to find the number of minimum cuts needed to
 get
 the new rope?.
 
 --
 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.
 
  --
  Sunny Aggrawal
  B-Tech IV year,CSI
  Indian Institute Of Technology,Roorkee

 --
 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.




-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
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: help..

2011-07-02 Thread sunny agrawal
l = 81 0 0 0
k = 6   0 1 1 0
xor  1 1 1 0
difference = 2

l = 161 0 0 0 0
k = 4 0 0 1 0 0
xor


On Sat, Jul 2, 2011 at 2:09 PM, sunny agrawal sunny816.i...@gmail.comwrote:

 yes i have written that only
 difference between indexes of first set bit and last set bit

 On Sat, Jul 2, 2011 at 2:08 PM, cegprakash cegprak...@gmail.com wrote:

 whats mean by first set bit and last set bit? do you simply mean the
 index of first and last bit?

 On Jul 2, 1:25 pm, sunny agrawal sunny816.i...@gmail.com wrote:
  xor the length of the rope with the required length and difference
 between
  the indexes of first set and last set bit *may* be the answer !!
 
 
 
  On Sat, Jul 2, 2011 at 1:46 PM, cegprakash cegprak...@gmail.com
 wrote:
   nope
 
   On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote:
yup :)
 
On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah 
   shalinisah.luv4cod...@gmail.com
 
 wrote:
 i guess the no. of 1s in the binary representation of the number
 is the
 answer..for 6 its 2...
 
 On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com
   wrote:
 
 the length of the rope is l units.
 I can only cut any rope into two halves.
 
 for example if the length of the rope is 8 and we need a length
 of
 rope 6
 
 we first cut into two halves and we get 4, 4
 now we cut any of the half again and we get 4,2,2
 
 now we can merge 4 and 2 and form a rope of length 6.
 
 in this example we need a minimum of 2 cuts to get the length of
 rope
 6 from 8
 
 assume that l is always a power of 2 and we need always a even
 length
 of rope from it how to find the number of minimum cuts needed to
 get
 the new rope?.
 
 --
 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.
 
  --
  Sunny Aggrawal
  B-Tech IV year,CSI
  Indian Institute Of Technology,Roorkee

 --
 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.




 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee




-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
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: help..

2011-07-02 Thread cegprakash
even that won't work

for example:
if we need a length of rope 14 from a length of rope 16

according to varun's algo

initially m=2
14%2 is 0.. so m=4
14%4 is not 0.. break..

so log2(16)-log2(14)+ 1 == 4-3+1 = 2 which is wrong

but actually we need atleast 3 cuts.
16== 8 + 8 == 8+ 4+ 4 == 8 + 4+ 2 + 2.. now we can merge 2,4 and 8
to form 14



On Jul 2, 1:35 pm, sunny agrawal sunny816.i...@gmail.com wrote:
 @varun
 I think u want to write

 while (k % m == 0)

 On Sat, Jul 2, 2011 at 1:56 PM, varun pahwa varunpahwa2...@gmail.comwrote:



  k - rope of desired length.
  l - rope of given length
  m = 2;
  while(k % m)
  m *= 2;
  ans :: (log2(l) - log2(m) + 1).
  ex.
  k = 6,l = 8
  so initially m = 2;
  after 1st iteration m = 4;
  then break;
  so min = log2(8) - log2(4) + 1  = 3 -2 + 1 = 2.

  On Sat, Jul 2, 2011 at 1:16 AM, cegprakash cegprak...@gmail.com wrote:

  nope

  On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote:
   yup :)

   On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah 
  shalinisah.luv4cod...@gmail.com

wrote:
i guess the no. of 1s in the binary representation of the number is
  the
answer..for 6 its 2...

On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com
  wrote:

the length of the rope is l units.
I can only cut any rope into two halves.

for example if the length of the rope is 8 and we need a length of
rope 6

we first cut into two halves and we get 4, 4
now we cut any of the half again and we get 4,2,2

now we can merge 4 and 2 and form a rope of length 6.

in this example we need a minimum of 2 cuts to get the length of rope
6 from 8

assume that l is always a power of 2 and we need always a even length
of rope from it how to find the number of minimum cuts needed to get
the new rope?.

--
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.

  --
  Varun Pahwa
  B.Tech (IT)
  7th Sem.
  Indian Institute of Information Technology Allahabad.
  Ph : 09793899112 ,08011820777
  Official Email :: rit2008...@iiita.ac.in
  Another Email :: varunpahwa.ii...@gmail.com

  People who fail to plan are those who plan to fail.

   --
  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.

 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee

-- 
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: help..

2011-07-02 Thread cegprakash
@varun: i think it works.. could u tell me how u found it

-- 
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: help..

2011-07-02 Thread cegprakash
@ sunny: so your's doesn't work right?

-- 
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: help..

2011-07-02 Thread sunny agrawal
why ?

On Sat, Jul 2, 2011 at 2:20 PM, cegprakash cegprak...@gmail.com wrote:

 @ sunny: so your's doesn't work right?

 --
 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.




-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
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: help..

2011-07-02 Thread cegprakash
@varun: explanation or proof for your soln. plz..

-- 
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: help..

2011-07-02 Thread cegprakash
oh fine.. got it now.. set bit is '1' right.. and is there any short
ways to find the difference between first set and short set bit
without dividing by 2 repeatedly?

-- 
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: help..

2011-07-02 Thread sunny agrawal
for a number N
first set bit(From Left) is simply integer value of log(N)
last set bit can be calculated as

N = N-(N(N-1)); and then Log(N)

int i = log(n);
n -= n(n-1);
int j = log(n);

i-j will be the answer.


On Sat, Jul 2, 2011 at 2:34 PM, cegprakash cegprak...@gmail.com wrote:

 oh fine.. got it now.. set bit is '1' right.. and is there any short
 ways to find the difference between first set and short set bit
 without dividing by 2 repeatedly?

 --
 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.




-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
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: help..

2011-07-02 Thread cegprakash
awesome!! thank you so much :)

On Jul 2, 2:11 pm, sunny agrawal sunny816.i...@gmail.com wrote:
 for a number N
 first set bit(From Left) is simply integer value of log(N)
 last set bit can be calculated as

 N = N-(N(N-1)); and then Log(N)

 int i = log(n);
 n -= n(n-1);
 int j = log(n);

 i-j will be the answer.

 On Sat, Jul 2, 2011 at 2:34 PM, cegprakash cegprak...@gmail.com wrote:
  oh fine.. got it now.. set bit is '1' right.. and is there any short
  ways to find the difference between first set and short set bit
  without dividing by 2 repeatedly?

  --
  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.

 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee

-- 
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: help..

2011-07-02 Thread cegprakash
btw what N = N-(N(N-1))  does actually

On Jul 2, 2:11 pm, sunny agrawal sunny816.i...@gmail.com wrote:
 for a number N
 first set bit(From Left) is simply integer value of log(N)
 last set bit can be calculated as

 N = N-(N(N-1)); and then Log(N)

 int i = log(n);
 n -= n(n-1);
 int j = log(n);

 i-j will be the answer.

 On Sat, Jul 2, 2011 at 2:34 PM, cegprakash cegprak...@gmail.com wrote:
  oh fine.. got it now.. set bit is '1' right.. and is there any short
  ways to find the difference between first set and short set bit
  without dividing by 2 repeatedly?

  --
  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.

 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee

-- 
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: help..

2011-07-02 Thread sunny agrawal
try out with examples!!
u will surely get in 2-3 examples

N(N-1) is a very famous expression, used in counting set bits. see what
this expression return

On Sat, Jul 2, 2011 at 2:51 PM, cegprakash cegprak...@gmail.com wrote:

 btw what N = N-(N(N-1))  does actually

 On Jul 2, 2:11 pm, sunny agrawal sunny816.i...@gmail.com wrote:
  for a number N
  first set bit(From Left) is simply integer value of log(N)
  last set bit can be calculated as
 
  N = N-(N(N-1)); and then Log(N)
 
  int i = log(n);
  n -= n(n-1);
  int j = log(n);
 
  i-j will be the answer.
 
  On Sat, Jul 2, 2011 at 2:34 PM, cegprakash cegprak...@gmail.com wrote:
   oh fine.. got it now.. set bit is '1' right.. and is there any short
   ways to find the difference between first set and short set bit
   without dividing by 2 repeatedly?
 
   --
   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.
 
  --
  Sunny Aggrawal
  B-Tech IV year,CSI
  Indian Institute Of Technology,Roorkee

 --
 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.




-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
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: help..

2011-07-02 Thread santosh mahto
@sunny

that will  work fine(xoring).
In place of Xoring u can also do OR of two number and find the distance
between fist set bit from left and first set bit from right,

Since bit operation is really fast operation so best algo this is of
complexity O(1);

Explanation How it works:

In l only one bit will be set. In m  multiple bit  would be set with all bit
before the bit set in l.
NOW suppose u divde l in 2 parts means u have shifted set bit of l to the
right.
dividing again will shift set bit in l to the right.
u have to divide till  set bit in l reached the position where first  bit of
m is set.

how many times u have shifted is count of  dividng the rope

its Simple.

u can check with any example


Thanks
Santosh
On Sat, Jul 2, 2011 at 2:41 PM, sunny agrawal sunny816.i...@gmail.comwrote:

 for a number N
 first set bit(From Left) is simply integer value of log(N)
 last set bit can be calculated as

 N = N-(N(N-1)); and then Log(N)

 int i = log(n);
 n -= n(n-1);
 int j = log(n);

 i-j will be the answer.



 On Sat, Jul 2, 2011 at 2:34 PM, cegprakash cegprak...@gmail.com wrote:

 oh fine.. got it now.. set bit is '1' right.. and is there any short
 ways to find the difference between first set and short set bit
 without dividing by 2 repeatedly?

 --
  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.




 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee

 --
  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: help..

2011-07-02 Thread santosh mahto
@sunny

the no of set bits in m will tell what all length(4,2 in above case)
are need to be merged.
e.g if if  m ==6 then m = 0110
 since bit set position are 2 and 1.
so length of rope  need to combine is 2^2=4 and 2^1 = 2;i.e 4 and 2

Thnaks
Santosh

On Sat, Jul 2, 2011 at 2:58 PM, santosh mahto santoshbit2...@gmail.comwrote:

 @sunny

 that will  work fine(xoring).
 In place of Xoring u can also do OR of two number and find the distance
 between fist set bit from left and first set bit from right,

 Since bit operation is really fast operation so best algo this is of
 complexity O(1);

 Explanation How it works:

 In l only one bit will be set. In m  multiple bit  would be set with all
 bit before the bit set in l.
 NOW suppose u divde l in 2 parts means u have shifted set bit of l to the
 right.
 dividing again will shift set bit in l to the right.
 u have to divide till  set bit in l reached the position where first  bit
 of m is set.

 how many times u have shifted is count of  dividng the rope

 its Simple.

 u can check with any example


 Thanks
 Santosh
   On Sat, Jul 2, 2011 at 2:41 PM, sunny agrawal 
 sunny816.i...@gmail.comwrote:

 for a number N
 first set bit(From Left) is simply integer value of log(N)
 last set bit can be calculated as

 N = N-(N(N-1)); and then Log(N)

 int i = log(n);
 n -= n(n-1);
 int j = log(n);

 i-j will be the answer.



 On Sat, Jul 2, 2011 at 2:34 PM, cegprakash cegprak...@gmail.com wrote:

 oh fine.. got it now.. set bit is '1' right.. and is there any short
 ways to find the difference between first set and short set bit
 without dividing by 2 repeatedly?

 --
  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.




 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee

 --
  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: help..

2011-07-02 Thread cegprakash
@ sunny

21 is 0
32 is 2
43 is 0
5 4 is 4
65 is 4

I don't find anything

-- 
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: help..

2011-07-02 Thread cegprakash
power of 2 less than n right?

On Jul 2, 2:38 pm, cegprakash cegprak...@gmail.com wrote:
 @ sunny

 21 is 0
 32 is 2
 43 is 0
 5 4 is 4
 65 is 4

 I don't find anything

-- 
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: help..

2011-07-02 Thread cegprakash
no no.. it should be multiple of 2 less than n? even that doesn't
satisfies for 43

On Jul 2, 2:41 pm, cegprakash cegprak...@gmail.com wrote:
 power of 2 less than n right?

 On Jul 2, 2:38 pm, cegprakash cegprak...@gmail.com wrote:

  @ sunny

  21 is 0
  32 is 2
  43 is 0
  5 4 is 4
  65 is 4

  I don't find anything

-- 
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: help..

2011-07-02 Thread mohit goel
May be this can work.give any counter example...
int count;
main()
{
  int l,rope,cuts;
  scanf(%d%d,l,rope);
  count =0;

   find_cuts(l,rope);
   printf(cuts needed is %d,count);
   getch();
   return 0;
   }

 int find_cuts(int l,int rope)

 {

if(l==rope)
return count;
 count++;
 printf(%d,count);
 l=l/2;
 if(l==rope)
 return count;
 if(ropel)
 rope =rope-l;

 find_cuts(l,rope);

 }

-- 
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: help..

2011-07-02 Thread sunny agrawal
@cegprakash
Expression resets the least significant set bit

On Sat, Jul 2, 2011 at 3:20 PM, mohit goel mohitgoel291...@gmail.comwrote:

 May be this can work.give any counter example...
 int count;
 main()
 {
   int l,rope,cuts;
   scanf(%d%d,l,rope);
   count =0;

find_cuts(l,rope);
printf(cuts needed is %d,count);
getch();
return 0;
}

  int find_cuts(int l,int rope)

  {

 if(l==rope)
 return count;
  count++;
  printf(%d,count);
  l=l/2;
  if(l==rope)
  return count;
  if(ropel)
  rope =rope-l;

  find_cuts(l,rope);


  }

 --
 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.




-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
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: help..

2011-07-02 Thread sameer.mut...@gmail.com
nn-1  is the expression to find out if n is a power of 2...If nn-1 returns
0 its a power of 2 else its not.
And what sunny said is also ryt

On Sat, Jul 2, 2011 at 3:47 PM, sunny agrawal sunny816.i...@gmail.comwrote:

 @cegprakash
 Expression resets the least significant set bit


 On Sat, Jul 2, 2011 at 3:20 PM, mohit goel mohitgoel291...@gmail.comwrote:

 May be this can work.give any counter example...
 int count;
 main()
 {
   int l,rope,cuts;
   scanf(%d%d,l,rope);
   count =0;

find_cuts(l,rope);
printf(cuts needed is %d,count);
getch();
return 0;
}

  int find_cuts(int l,int rope)

  {

 if(l==rope)
 return count;
  count++;
  printf(%d,count);
  l=l/2;
  if(l==rope)
  return count;
  if(ropel)
  rope =rope-l;

  find_cuts(l,rope);


  }

 --
 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.




 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee

  --
 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: help..

2011-07-02 Thread varun pahwa
@sunny ya  i wanted to write the while(k % m == 0)

On Sat, Jul 2, 2011 at 3:47 AM, sameer.mut...@gmail.com 
sameer.mut...@gmail.com wrote:

 nn-1  is the expression to find out if n is a power of 2...If nn-1
 returns 0 its a power of 2 else its not.
 And what sunny said is also ryt


 On Sat, Jul 2, 2011 at 3:47 PM, sunny agrawal sunny816.i...@gmail.comwrote:

 @cegprakash
 Expression resets the least significant set bit


 On Sat, Jul 2, 2011 at 3:20 PM, mohit goel mohitgoel291...@gmail.comwrote:

 May be this can work.give any counter example...
 int count;
 main()
 {
   int l,rope,cuts;
   scanf(%d%d,l,rope);
   count =0;

find_cuts(l,rope);
printf(cuts needed is %d,count);
getch();
return 0;
}

  int find_cuts(int l,int rope)

  {

 if(l==rope)
 return count;
  count++;
  printf(%d,count);
  l=l/2;
  if(l==rope)
  return count;
  if(ropel)
  rope =rope-l;

  find_cuts(l,rope);


  }

 --
 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.




 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee

  --
 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.




-- 
Varun Pahwa
B.Tech (IT)
7th Sem.
Indian Institute of Information Technology Allahabad.
Ph : 09793899112 ,08011820777
Official Email :: rit2008...@iiita.ac.in
Another Email :: varunpahwa.ii...@gmail.com

People who fail to plan are those who plan to fail.

-- 
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: help..

2011-07-02 Thread varun pahwa
@sunny thnx for the correction.

On Sat, Jul 2, 2011 at 9:16 AM, varun pahwa varunpahwa2...@gmail.comwrote:

 @sunny ya  i wanted to write the while(k % m == 0)


 On Sat, Jul 2, 2011 at 3:47 AM, sameer.mut...@gmail.com 
 sameer.mut...@gmail.com wrote:

 nn-1  is the expression to find out if n is a power of 2...If nn-1
 returns 0 its a power of 2 else its not.
 And what sunny said is also ryt


 On Sat, Jul 2, 2011 at 3:47 PM, sunny agrawal sunny816.i...@gmail.comwrote:

 @cegprakash
 Expression resets the least significant set bit


  On Sat, Jul 2, 2011 at 3:20 PM, mohit goel 
 mohitgoel291...@gmail.comwrote:

 May be this can work.give any counter example...
 int count;
 main()
 {
   int l,rope,cuts;
   scanf(%d%d,l,rope);
   count =0;

find_cuts(l,rope);
printf(cuts needed is %d,count);
getch();
return 0;
}

  int find_cuts(int l,int rope)

  {

 if(l==rope)
 return count;
  count++;
  printf(%d,count);
  l=l/2;
  if(l==rope)
  return count;
  if(ropel)
  rope =rope-l;

  find_cuts(l,rope);


  }

 --
 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.




 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee

  --
 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.




 --
 Varun Pahwa
 B.Tech (IT)
 7th Sem.
 Indian Institute of Information Technology Allahabad.
 Ph : 09793899112 ,08011820777
 Official Email :: rit2008...@iiita.ac.in
 Another Email :: varunpahwa.ii...@gmail.com

 People who fail to plan are those who plan to fail.




-- 
Varun Pahwa
B.Tech (IT)
7th Sem.
Indian Institute of Information Technology Allahabad.
Ph : 09793899112 ,08011820777
Official Email :: rit2008...@iiita.ac.in
Another Email :: varunpahwa.ii...@gmail.com

People who fail to plan are those who plan to fail.

-- 
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: help..

2011-07-02 Thread Avi Dullu
Another alternative soln.

int rec_cut(int l, int k) {
  if (l == k) return 0;
  int tmp = k - (l1);
  return 1 + rec_cut(l1, tmp = 0 ? k : tmp);
}

int main() {
  int l, k;
  scanf(%d%d, l, k);
  printf(%d\n, rec_cut(l, k));
  return 0;
}

Veni Vedi Slumber !


On Sat, Jul 2, 2011 at 9:47 PM, varun pahwa varunpahwa2...@gmail.comwrote:

 @sunny thnx for the correction.


 On Sat, Jul 2, 2011 at 9:16 AM, varun pahwa varunpahwa2...@gmail.comwrote:

 @sunny ya  i wanted to write the while(k % m == 0)


 On Sat, Jul 2, 2011 at 3:47 AM, sameer.mut...@gmail.com 
 sameer.mut...@gmail.com wrote:

 nn-1  is the expression to find out if n is a power of 2...If nn-1
 returns 0 its a power of 2 else its not.
 And what sunny said is also ryt


 On Sat, Jul 2, 2011 at 3:47 PM, sunny agrawal 
 sunny816.i...@gmail.comwrote:

 @cegprakash
 Expression resets the least significant set bit


  On Sat, Jul 2, 2011 at 3:20 PM, mohit goel 
 mohitgoel291...@gmail.comwrote:

 May be this can work.give any counter example...
 int count;
 main()
 {
   int l,rope,cuts;
   scanf(%d%d,l,rope);
   count =0;

find_cuts(l,rope);
printf(cuts needed is %d,count);
getch();
return 0;
}

  int find_cuts(int l,int rope)

  {

 if(l==rope)
 return count;
  count++;
  printf(%d,count);
  l=l/2;
  if(l==rope)
  return count;
  if(ropel)
  rope =rope-l;

  find_cuts(l,rope);


  }

 --
 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.




 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee

  --
 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.




 --
 Varun Pahwa
 B.Tech (IT)
 7th Sem.
 Indian Institute of Information Technology Allahabad.
 Ph : 09793899112 ,08011820777
 Official Email :: rit2008...@iiita.ac.in
 Another Email :: varunpahwa.ii...@gmail.com

 People who fail to plan are those who plan to fail.




 --
 Varun Pahwa
 B.Tech (IT)
 7th Sem.
 Indian Institute of Information Technology Allahabad.
 Ph : 09793899112 ,08011820777
 Official Email :: rit2008...@iiita.ac.in
 Another Email :: varunpahwa.ii...@gmail.com

 People who fail to plan are those who plan to fail.

  --
 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: Help

2011-02-15 Thread Don
Mike Johnson wrote:
 Plesae rite a program for me to find prime nummers. It should be recursive 
 prorgram. What duz that mean?
 If u type a nummer like 10 it should say 1 is prime, 2 is prime, 3 is prime, 
 4 is not prime up to 10.
 This iz not homewurk I just thout of it myself. Lol.

/* Sure Mike, Happy to help!
   This program implements a blindingly fast O(n^n) algorithm
   to find prime numbers, using an elegant recursive method. */
int _(int n, int m, int d, int t)
{
int r;

if (t) return d?1+_(n,m,d-1,d):n?_(n-1,m,m,n):0;
for(r=m!=n; d*(tn); ++t)
r = _(n,_(t,m,0,1),d-1,0)|!_(t,1,t,0);
return r*n;
}


/*--
  Print primes up to the requested value
*/
int main(int argc, char* argv[])
{
int max;
scanf(%d, max);
for(int n = 2; n = max; n++)
printf(%d is%s prime\n,n, _(n,1,n,0)?: not);

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: help me debug this

2011-01-17 Thread juver++
Got AC with your code with small corrections to the output - 
don't use getchar();
output specification says:  Each line of output should be followed by a 
blank line (so, add blank line to match the sample output)
you print a whitespace after each number, so the last character in your line 
is a whitespace (but it is wrong, so take a care of this)

-- 
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: help me debug this

2011-01-17 Thread ankit sablok
i improved upon my code but still i get a presentation error dunno wts the
judge judging it shows me the correct way when i output test cases on my
compiler but on the judge it says wrong answer or presentation error

#includeiostream
#includecstdio
#includevector
#includealgorithm
#includecmath

using namespace std;

int prime(int N,int C);// the function used to print the cut primes

int main()
{
int N,C;
vectorintv;// used for holding the test cases

while(scanf(%d %d,N,C)==2)
{
  v.push_back(N);v.push_back(C);
}

int i;// counter

for(i=0;iv.size();i+=2)
prime(v[i],v[i+1]);

return 0;
}
int prime(int N,int C)
{
vectorintp;
vectorints;

p.clear();s.clear();

int i,j,k;// counters

for(i=0;i=N;i++)
p.push_back(i);

for(i=2;ip.size();i++)
{
 for(j=2;i*jp.size();j++)
 p[i*j]=0;
}

   for(i=0;ip.size();i++)
   {
  if(p[i]!=0)
  s.push_back(i);
   }

   printf(%d %d: ,N,C);

   if((2*C)s.size())
   {
 for(i=0;is.size();i++)
 printf(%d ,s[i]);
   }

   else if((s.size())%2==0)
   {
 // the evaluate the number of prime numbers to be left out
 j=(s.size()-2*C)/2;
 for(i=j;i(j+2*C);i++)
 printf(%d ,s[i]);
   }

   else
   {
   j=(s.size()-2*C+1)/2;
   for(i=j;i(j+2*C-1);i++)
   printf(%d ,s[i]);
   }
   printf(\n\n);

   return 0;
}


On Tue, Jan 18, 2011 at 1:05 AM, juver++ avpostni...@gmail.com wrote:

 Got AC with your code with small corrections to the output -
 don't use getchar();
 output specification says:  Each line of output should be followed by a
 blank line (so, add blank line to match the sample output)
 you print a whitespace after each number, so the last character in your
 line is a whitespace (but it is wrong, so take a care of this)

 --
 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.comalgogeeks%2bunsubscr...@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: help me debug this

2011-01-17 Thread juver++
Redirect your output to the file, and you'll see that at the end of line you 
have extra blank.
You need to write something like this (in all sections):
for(i=j;i(j+2*C-1);i++) {
 if (i != j) printf( );
 printf(%d,s[i]); // note there is no space
}

-- 
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: Help with Increment Operators in C!

2010-08-29 Thread jagadish
@Dave: Thanks alot for enlightening us!

@Manju: ya.. you are right. The same was stated by me in the my prev
reply! :-)

On Aug 29, 10:50 pm, Manjunath Manohar manjunath.n...@gmail.com
wrote:
 it is compiler dependant da..the evaluation of this kind of expressions

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@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: Help with Increment Operators in C!

2010-08-28 Thread Chi
In php it is 19.

?php
$x=5;
printf(%d,($x++ + ++$x + $x++));
?


On Aug 28, 1:35 pm, jagadish jagadish1...@gmail.com wrote:
 I ran this code..

 int main() { int x=5;
 printf(%d,(x++ + ++x + x++));

 }

 The output printed was 18 instead of 19.. Should it not be 19?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@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: Help with Increment Operators in C!

2010-08-28 Thread jagadish
Ya after some reading i got to know that it was implementation
dependent..
And that the answer is undefined!


On Aug 28, 5:07 pm, Chi c...@linuxdna.com wrote:
 In php it is 19.

 ?php
 $x=5;
 printf(%d,($x++ + ++$x + $x++));
 ?

 On Aug 28, 1:35 pm, jagadish jagadish1...@gmail.com wrote:

  I ran this code..

  int main() { int x=5;
  printf(%d,(x++ + ++x + x++));

  }

  The output printed was 18 instead of 19.. Should it not be 19?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@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: Help with Increment Operators in C!

2010-08-28 Thread Dave
Your code violates the C standard, which says:

Between the previous and next sequence point an object shall have its
stored value modified at most once by the evaluation of an expression.
Furthermore, the prior value shall be read only to determine the value
to be stored.

Regarding postfix increment operators, the standard also states that
The side effect of updating the stored value of the operand shall
occur between the previous and the next sequence point. Updating x in
your example does not necessarily occur before the next time x is
used.

The results of code that violates the C standard are compiler-
dependent.

Dave

On Aug 28, 6:35 am, jagadish jagadish1...@gmail.com wrote:
 I ran this code..

 int main() { int x=5;
 printf(%d,(x++ + ++x + x++));

 }

 The output printed was 18 instead of 19.. Should it not be 19?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@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: Help

2008-02-09 Thread [EMAIL PROTECTED]

GOOD ONE-
Data Structures , Algorithms and Applications in C++ by Sartaj Sahani


On Feb 7, 1:58 pm, Atul Aggarwal [EMAIL PROTECTED] wrote:
 Hello Everybody,

 I am beginner in Algorithms. Which book I should prefer for understanding
 basic algos? Also tell me some good book for graph Theory and its basic
 algos.

 Thanx in advance.

 Atul Aggarwal
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: Help

2008-02-09 Thread gurbinder dhillon

corman for algorithms

On 2/9/08, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 GOOD ONE-
 Data Structures , Algorithms and Applications in C++ by Sartaj Sahani


 On Feb 7, 1:58 pm, Atul Aggarwal [EMAIL PROTECTED] wrote:
  Hello Everybody,
 
  I am beginner in Algorithms. Which book I should prefer for understanding
  basic algos? Also tell me some good book for graph Theory and its basic
  algos.
 
  Thanx in advance.
 
  Atul Aggarwal
 



-- 
Gurbinder Singh
placement-info.blogspot.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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: Help

2008-02-08 Thread subhojit ban
I can vouch for 'algorithm design' by Jon Klienberg if CLR becomes a bit
heavy.


On Feb 7, 2008 11:13 PM, dor [EMAIL PROTECTED] wrote:


 I used Cormen as an intro to algorithms (Thomas H. Cormen, Charles E.
 Leiserson, Ronald L. Rivest, and Cliff Stein, Introduction to
 Algorithms 2nd edition, published by MIT Press and McGraw-Hill).

 On Feb 7, 1:58 pm, Atul Aggarwal [EMAIL PROTECTED] wrote:
  Hello Everybody,
 
  I am beginner in Algorithms. Which book I should prefer for
 understanding
  basic algos? Also tell me some good book for graph Theory and its basic
  algos.
 
  Thanx in advance.
 
  Atul Aggarwal
 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: Help

2008-02-07 Thread dor

I used Cormen as an intro to algorithms (Thomas H. Cormen, Charles E.
Leiserson, Ronald L. Rivest, and Cliff Stein, Introduction to
Algorithms 2nd edition, published by MIT Press and McGraw-Hill).

On Feb 7, 1:58 pm, Atul Aggarwal [EMAIL PROTECTED] wrote:
 Hello Everybody,

 I am beginner in Algorithms. Which book I should prefer for understanding
 basic algos? Also tell me some good book for graph Theory and its basic
 algos.

 Thanx in advance.

 Atul Aggarwal
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: help with serie-parallel recognition algorithm

2007-11-14 Thread Dave

Series-parallel graphs may be recognized in linear time and their
series-parallel decomposition may be constructed in linear time as
well. See en.wikipedia.org/wiki/Series-parallel_graph. Reference 3 in
that article may be what you are looking for.

Dave

On Nov 14, 5:31 am, fpalamariu [EMAIL PROTECTED] wrote:
 Hi,

 i need a little help with an algorithm... an algorithm to recognize a
 series-parallel graph using (a adaptation probably) the algorithm for
 detecting articulation points in a graph. I have no ideea how this
 finally algoritm might look i've open a lot of books on graph
 theory data design... and nothing...

 so i ask for your help... because my algorithm solving abilities sucks
 hard.

 thank's


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: Help! - rectangle packing problem

2007-06-20 Thread Ramaswamy R
I am not sure of a solution for this, but ain't this an NP-complete problem?

On 6/19/07, ihinayana [EMAIL PROTECTED] wrote:


 Description:
 Given a group of rectangles with different integer width and
 height,such as 5*4, 2*3,1*7,etc. The total number of rectangles is
 like 10 or more.The problem is how to find a bigger rectangle with a
 minimal area which can hold all those given ones. To fix them in,those
 rectangles can be rotated with 90 degree and the order is regardless.

 Did anybody solve a similar problem?


 



-- 
Chaos is the rule in nature, not an exception

http://ramaswamy.r.googlepages.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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: help me with finding the time complexcity

2007-05-29 Thread BiGYaN

On May 28, 6:21 pm, sl7fat [EMAIL PROTECTED] wrote:
 hi i have an algorthim code and i have to find the time complixcity of
 the code so can you plz help me ASAP the code is written done ,,
 # include iostream.h

 void main()
 {

 int a[10][4]=
 {{ 16,17,19,13},
 {18,14,15,19},
 {18,20,20,19},
 {13,14,15,10},
 {20,17,19,19},
 {18,13,18,19},
 {18,10,15,12},
 {12,14,15,11},
 {12,16,17,18},
 {18,11,15,10}} ;

 int i,j,max,min;
 float avg,sum;

 for(i=0;i10;i++)
 {

 for(j=0;j4;j++)
 {

 cout  a[i][j] ;
 }
 cout  \n;
 }

 for(i=0;i4;i++)
 {
 max= a[0][i];
 min= a[0][i];
 sum=0;

 for(j=1;j10;j++)
 {

 sum= sum+a[j][i];
 if(a[j][i]max)
 max=a[j][i];

 if(a[j][i]min)
 min=a[j][i];
 }

 avg= sum/10;

 cout  The average Grade for Exam i+1  is:   
 avg\n;
 cout   The minimum Grade for Exam i+1  is:   
 min\n;
 cout  The maximum Grade for Exam i+1  is:   
 max\n\n;

 }

 for(i=0;i10;i++)
 {
 min= a[i][0];
 sum=0;
 for(j=0;j4;j++)
 {
 sum= sum+a[i][j];
 if ( mina[i][j])
 min= a[i][j];

 }
 sum= sum-min;

 cout   The summation of the best 3 grades for student No 
  i
 +1  is:   sum\n;
 }

 }

 thanx alot :D

O(n^2)  there is no variable here  so what exactly were u
asking?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: help me with finding the time complexcity

2007-05-28 Thread Satya

since your input is of fixed size, your algorithm always runs in
constant time. If the # of students and # of courses are variable, the
algorithm is O(n^2).

satya.

On 5/28/07, sl7fat [EMAIL PROTECTED] wrote:

 hi i have an algorthim code and i have to find the time complixcity of
 the code so can you plz help me ASAP the code is written done ,,
 # include iostream.h

 void main()
 {

 int a[10][4]=
 {{ 16,17,19,13},
 {18,14,15,19},
 {18,20,20,19},
 {13,14,15,10},
 {20,17,19,19},
 {18,13,18,19},
 {18,10,15,12},
 {12,14,15,11},
 {12,16,17,18},
 {18,11,15,10}} ;


 int i,j,max,min;
 float avg,sum;


 for(i=0;i10;i++)
 {

 for(j=0;j4;j++)
 {

 cout  a[i][j] ;
 }
 cout  \n;
 }

 for(i=0;i4;i++)
 {
 max= a[0][i];
 min= a[0][i];
 sum=0;

 for(j=1;j10;j++)
 {

 sum= sum+a[j][i];
 if(a[j][i]max)
 max=a[j][i];

 if(a[j][i]min)
 min=a[j][i];
 }

 avg= sum/10;

 cout  The average Grade for Exam i+1  is:   
 avg\n;
 cout   The minimum Grade for Exam i+1  is:   
 min\n;
 cout  The maximum Grade for Exam i+1  is:   
 max\n\n;


 }

 for(i=0;i10;i++)
 {
 min= a[i][0];
 sum=0;
 for(j=0;j4;j++)
 {
 sum= sum+a[i][j];
 if ( mina[i][j])
 min= a[i][j];

 }
 sum= sum-min;

 cout   The summation of the best 3 grades for student No 
  i
 +1  is:   sum\n;
 }

 }

 thanx alot :D


 



-- 
...what's remarkable, is that atoms have assembled into entities which
are somehow able to ponder their origins.
--
http://cs.uic.edu/~spopuri

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: help me with finding the time complexcity

2007-05-28 Thread sl7fat

thanx for ur help :D

On May 28, 5:22 pm, Satya [EMAIL PROTECTED] wrote:
 since your input is of fixed size, your algorithm always runs in
 constant time. If the # of students and # of courses are variable, the
 algorithm is O(n^2).

 satya.

 On 5/28/07, sl7fat [EMAIL PROTECTED] wrote:







  hi i have an algorthim code and i have to find the time complixcity of
  the code so can you plz help me ASAP the code is written done ,,
  # include iostream.h

  void main()
  {

  int a[10][4]=
  {{ 16,17,19,13},
  {18,14,15,19},
  {18,20,20,19},
  {13,14,15,10},
  {20,17,19,19},
  {18,13,18,19},
  {18,10,15,12},
  {12,14,15,11},
  {12,16,17,18},
  {18,11,15,10}} ;

  int i,j,max,min;
  float avg,sum;

  for(i=0;i10;i++)
  {

  for(j=0;j4;j++)
  {

  cout  a[i][j] ;
  }
  cout  \n;
  }

  for(i=0;i4;i++)
  {
  max= a[0][i];
  min= a[0][i];
  sum=0;

  for(j=1;j10;j++)
  {

  sum= sum+a[j][i];
  if(a[j][i]max)
  max=a[j][i];

  if(a[j][i]min)
  min=a[j][i];
  }

  avg= sum/10;

  cout  The average Grade for Exam i+1  is:   
  avg\n;
  cout   The minimum Grade for Exam i+1  is:   
  min\n;
  cout  The maximum Grade for Exam i+1  is:   
  max\n\n;

  }

  for(i=0;i10;i++)
  {
  min= a[i][0];
  sum=0;
  for(j=0;j4;j++)
  {
  sum= sum+a[i][j];
  if ( mina[i][j])
  min= a[i][j];

  }
  sum= sum-min;

  cout   The summation of the best 3 grades for student No 
   i
  +1  is:   sum\n;
  }

  }

  thanx alot :D

 --
 ...what's remarkable, is that atoms have assembled into entities which
 are somehow able to ponder their origins.
 --http://cs.uic.edu/~spopuri- 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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: help making regular expression

2007-03-15 Thread Pradeep Muthukrishnan
I think a regular expression is just too hard, a CFG might be easier . Let
me know if you have a solution for regular expression

On 3/14/07, Ravi [EMAIL PROTECTED] wrote:


 what will be a regular expression(non-UNIXone please) for the set of
 languages which have number of 0s divisible by 5 and number of 1s
 divisible by 2. The set of alphabets is {0,1}.

 Please tell how you arrived at the solution.


 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: help making regular expression

2007-03-15 Thread Karthik Singaram L

A DFA is possible I guess which is interesting, see if the following
DFA works, since the existence of the DFA relates to the existence of
a Regular Expression Describing the language

State/Input 01
q00  q10 q01
q10  q20 q11
q20  q30 q21
q30  q40 q31
q40  q00 q41

q01  q11 q00
q11  q21 q10
q21  q31 q20
q31  q41 q30
q41  q01 q40

The final state is q00.

In this DFA the first subscript denotes the number of zeros % 5 and
the second describes the number of ones % 2

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: help making regular expression

2007-03-15 Thread Karthik Singaram L

If the DFA works then it can be converted to a regular expression
using standard techniques like the one described in
http://www.cs.colostate.edu/~whitley/CS301/L3.pdf

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: help making regular expression

2007-03-15 Thread Rajiv Mathews

On 3/15/07, Ravi [EMAIL PROTECTED] wrote:

 what will be a regular expression(non-UNIX one please) for the set of
 languages which have number of 0s divisible by 5 and number of 1s
 divisible by 2. The set of alphabets is {0,1}.


The following is based on `Parallel Regular Expressions'. If I
remember correctly, PREs have been proven to be equivalent to the set
of `Regular Languages'.

So assuming you're equipped with that,
(a) 0s div by 5 --- (0)* -- R_a (Regular expression a)
(b) 1s div by 2 --- (11)* -- R_b

Now PREs define an operator called `shuffle' which basically causes an
`interleave' of strings from both languages.
So based on whatever the notation is for writing down an interleave,
the required PRE will be SHUFFLE(R_a, R_b).

For more information on Parallel Regular Expressions, their
equivalence to Regular Languages refer to
www.cct.lsu.edu/personal/estrabd/papers/paper333final.pdf
PREs basically provide this additional tool of shuffling, which much
like non-determinism (in finite state machines) turns out to NOT
provide any additional power in accepting languages.


-- 


Regards,
Rajiv Mathews

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: help =/

2006-10-08 Thread Spiritus

1. u should calculate the k variable, that is
if i+j=3 (i=1, j=2, or vice versa) then k=3
if i+j=4 (i=1, j=3, or vice versa) then k=2
if i+j=5 (i=2, j=3, or vice versa) then k=1

2. the last question give the answer to the last 2:
T(m) =  1 if n = 1
2*T(m - 1) + 1 if n  1
is the reccurence relation

T(m) = 2^m - 1 is the explicit formula.

by induction:
let's say T(k)=2^k - 1
we need to prove that T(k+1)=2^(k+1) -1
T(k+1)=2*T(k)+1from the reccurence relation
but, we already have T(k)
T(k+1)=2*(2^k-1)+1=
   2*2^k  -2  +1=
   2^(k+1) -1
What we needed to prove!
We just have to show that its true for k=1:
by definition T(1)=1  ==  2^k - 1 2^1-1=2-1=1

ok?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups-beta.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: help

2006-07-24 Thread gupta

hi frnz...

i'm very glad to c this site..

i'm a beginner can anyone suggest me a good book for DATA
STRUCTURES..., presently i'm practicing C++.

i'm very much thankful to u, if u do this...


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: help

2006-07-24 Thread Sriram Narasimhan
Hi 
 there are plenty of websites that fetch you data and i feel that everything is just a click away.So just choose books if you want else just start learning via tutorials.

All the best.

Sriram.N
On 7/9/06, hosseingt [EMAIL PROTECTED] wrote:
hii'm a begginer.can anyone guide me how to start in algorithms?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/algogeeks  -~--~~~~--~~--~--~---


[algogeeks] Re: help

2006-07-09 Thread adak

There is a lot of detail available on-line. If you google Dictionary
of Algorithms and Data Structures, and visit there, you'll be amazed
at the depth of the info.

A good book (not too hard, but something that covers the basics), is a
great asset to have. Perhaps someone here can recommend a good one, not
too technical, for a beginner.

What you want to avoid is the black box idea, in which you give the
program input, and await the answer, and nothing more.

Because all too often, the computer will be made to do a fantastic
amount of extra work, simply because the program it's running, isn't
smartly designed.

Two algorithms that always fascinate me, are binary search, and
Quicksort. I can remember playing the kid's game guess a number
between 1 and 10, and here's the algorithm that copied a smart kid's
idea for guessing a number, but now it's so much faster, in the
computer! And so powerful.

I'd start with working through the binary search of a sorted array (or
list), and be sure you understand every aspect of it. Not only because
it's a beautiful algo and still heavily used today, but also because
it's basic strategy of divide and conquer, repeating as needed, is
used in all kinds of algorithms. It is a very common theme in effective
algorithms.

Then, I'd look at Quicksort, and really dig into it. It's another
divide and conquer algo, but it uses the stack for each recursive
call (by all means, study the recursive Quicksort), to remember and
restore the values it needs for it's pointers. To understand the power
of recursion in a simple program, d/l a copy of The Towers of Hanoi.

A keen appreciation of scale is needed here, alway.. ANY sorting algo
will readily handle a list of 50 items, in almost no time. But when the
number of items has scaled up to 500,000 or 500 million, it's a WHOLE
different matter, isn't it?  :-)

Indeed, you may not see or appreciate the value of a binary search or
quicksort algorithm on a small number of items. It's when you scale it
up into the 100's of thousands or more, that the true power of them
smack you right upside your aha! point in your brain.

Sudoku puzzles are another example where a good algorithm is keenly
noticed. A good program will solve most puzzles in less than a second
or two, depending on the amount of output they give to the screen and
file.

A poor algo may cause the same computer system to requires several
minutes or even hours of computation, to solve the very same puzzle.
These programs typically ignore the logical inferences that would
reduce the number of possible solutions, and work to solve the puzzle
by more brute force methods. When you have a puzzle with 99 squares,
and 50 of those squares may have unknown values (1-9),  well, what is
50 ^ 9th power?  Breaks my calculator, for sure!

Good luck, and have fun!

Adak


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: Help me with this problem

2006-06-22 Thread adak


Norbert wrote:
 I'm unable to solve this problem correctly. Please help me:

 You have chess board of size N x M and a lot of bricks of size K x 1.
 How many bricks can you place on this board (brick edges must be
 pallarel to board edges)

 Thanks for help

Chessboards are always perfectly square, :) but anyway.

The problem is that you may have wasted space. Consider an 8 x 8
chessboard (standard size), where the bricks occupy 3 sqrs. in length,
and 1 in width.

11122234
77788834
999aaa34
bbbccc**
dddeee**
ggghhh56
kkksss56
... etc.

The ** area is wasted, even though the area is sufficient for another
brick (and then some), but it can't fit one in due to the constraint of
the length of the brick.

The program to calculate the number of bricks doesn't need to try every
possible combination, it merely needs to take the physical constraints
of the bricks dimensions, into account. Likewise if the space was in a
corner. Hard work getting those bricks to bend 90 degrees!

Adak


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: Help me with this problem

2006-06-22 Thread [EMAIL PROTECTED]

If M = N and M = K, then the solution is
N * (M/K) + (M - M/K*K) * (N/K)

Use integer division


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: Help me with this problem

2006-06-22 Thread Feng

On 6/23/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

If M = N and M = K, then the solution isN * (M/K) + (M - M/K*K) * (N/K)Use integer division


This solution is not corrent.

for example, M = N = 4, K = 2
N * (M/K) + (M - M/K*K) * (N/K) = 4 * ( 4 / 2 ) + ( 4 - 4 / 2 * 2 ) * ( 4 / 2 ) = 8

But the number of placement is greater than 8

1122
3344
5566
7788


1322
1344
5566
7788


1124
3324
5566
7788


1324
1324
5566
7788
.. easy to see that we can get another 4 ways of placement following upper mode

But another group of placements is like this:


1223
1443
5566
7788

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/algogeeks  -~--~~~~--~~--~--~---


[algogeeks] Re: Help me with this problem

2006-06-17 Thread prashant bhargava
if the question is complete then the answer shd' be (N/K) * M bricksam i right??On 6/17/06, Norbert 
[EMAIL PROTECTED] wrote:I'm unable to solve this problem correctly. Please help me:
You have chess board of size N x M and a lot of bricks of size K x 1.How many bricks can you place on this board (brick edges must bepallarel to board edges)Thanks for helpRegards,Prashant Bhargava ***--***--***--***--***--***--***Plz do visitwww.hemantdesign.com/prashant

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/algogeeks  -~--~~~~--~~--~--~---


[algogeeks] Re: Help me with this problem

2006-06-17 Thread Norbert

Sorry, you're wrong. Consider board of size N = 1, M = 5 and K = 2.
If you round down (N/K) then you have RESULT = 0. If you round up then
you have 5. Also wrong.

On 6/17/06, prashant bhargava [EMAIL PROTECTED] wrote:
 if the question is complete then the answer shd' be (N/K) * M bricks

 am i right??



 On 6/17/06, Norbert  [EMAIL PROTECTED] wrote:
 

 I'm unable to solve this problem correctly. Please help me:

 You have chess board of size N x M and a lot of bricks of size K x 1.
 How many bricks can you place on this board (brick edges must be
 pallarel to board edges)

 Thanks for help



 Regards,
 Prashant Bhargava
 ***--***--***--***--***--***--***
 Plz do visit
 www.hemantdesign.com/prashant
  


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: Help me with this problem

2006-06-17 Thread Norbert

There's another example if you use floating point arithmetic. N = 10,
M = 10, K = 4. Correct answer is 24, not 25

On 6/17/06, Norbert [EMAIL PROTECTED] wrote:
 Sorry, you're wrong. Consider board of size N = 1, M = 5 and K = 2.
 If you round down (N/K) then you have RESULT = 0. If you round up then
 you have 5. Also wrong.

 On 6/17/06, prashant bhargava [EMAIL PROTECTED] wrote:
  if the question is complete then the answer shd' be (N/K) * M bricks
 
  am i right??
 
 
 
  On 6/17/06, Norbert  [EMAIL PROTECTED] wrote:
  
 
  I'm unable to solve this problem correctly. Please help me:
 
  You have chess board of size N x M and a lot of bricks of size K x 1.
  How many bricks can you place on this board (brick edges must be
  pallarel to board edges)
 
  Thanks for help
 
 
 
  Regards,
  Prashant Bhargava
  ***--***--***--***--***--***--***
  Plz do visit
  www.hemantdesign.com/prashant

 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: Help me with this problem

2006-06-17 Thread prashant bhargava
Could u plz explain how u r getting the answer 24 (for ur 2nd reply) ?? I really didn't understand.plz explainOn 6/17/06, Norbert 
[EMAIL PROTECTED] wrote:There's another example if you use floating point arithmetic. N = 10,
M = 10, K = 4. Correct answer is 24, not 25On 6/17/06, Norbert [EMAIL PROTECTED] wrote: Sorry, you're wrong. Consider board of size N = 1, M = 5 and K = 2.
 If you round down (N/K) then you have RESULT = 0. If you round up then you have 5. Also wrong. On 6/17/06, prashant bhargava [EMAIL PROTECTED]
 wrote:  if the question is complete then the answer shd' be (N/K) * M bricks   am i right?? On 6/17/06, Norbert  
[EMAIL PROTECTED] wrote: I'm unable to solve this problem correctly. Please help me:   You have chess board of size N x M and a lot of bricks of size K x 1.
  How many bricks can you place on this board (brick edges must be  pallarel to board edges)   Thanks for help Regards,
  Prashant Bhargava  ***--***--***--***--***--***--***  Plz do visit  www.hemantdesign.com/prashant  
 -- I am extraordinarily patient, provided I get my own way in the end.Regards,Prashant Bhargava ***--***--***--***--***--***--***Plz do visit
www.hemantdesign.com/prashant

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/algogeeks  -~--~~~~--~~--~--~---


[algogeeks] Re: Help on modular arithmetic

2006-04-26 Thread Mikey

The answer to the first question is 2.  When you take the modulus of a
negative number, think of it as rounding down to a multiple of the
divisor and taking the remainder.  If you round down -22 to a multiple
of 3, you get -24, and the difference between -22 and -24 is 2, your
remainder.

I'm not sure about having a negative modulus, but since you know the
answer, I'm assuming it's the same as the first problem, except you
take the opposite of the remainder, so 22 % 3 is 1, but the opposite of
what's left would leave you 2.

I have no clue about the third, but my guess is 1.  My assumption is
that the two will cancel each other out and cause you to perform a
regular modulus, 22 % 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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---