RECTSQ, am I unable to understand?

Thanks! :smiley:

@hruday no need to do ans=finder(a,b). ans is a global variable so that is not required, for those who will say global variable will produce problems for more than 1 cases, please read the code it is initialized to 0 for every new case.
Thank You :slight_smile:

My logic is to divide the biggest side with smallest side the result will be the number of squares that can be formed within, for eg: 15/10 = 1.5 = 1(int) therefore 1 square of 10x10 is eliminated (since k = 1 and b = 10 therefore I subtract that with a (=15) to get 5, then I get a 5x10 rectangle (which is true, thats what I should get) and then I call finder again and solve 5x10 likewise (recursion) :slight_smile:

@vehemos

ans may be a global variable,but if you don’t assign anything to ans it will always print a garbage value.

@hruday please read the comment and code xD I already assigned 0 to it and it will never print garbage value :stuck_out_tongue:

I looked at 2 codes one of them had something like a^=b^=c and the other one will win #1 in world obfuscation challenge cuz of its indentation xD Then I gave up on reading others code, but in past whenever I got stuck that’s what I used to (and will keep doing :P)

1 Like

How are you able to ask questions with low karma ? Amazing :smiley:

Lol hahaha. Sad luck! I got the simplest code possible in first try. Well, on average, it takes around 6-7 tries to get an understandable code. Or, keep track of some good coders and see if one of them solved the question.

Karma requirement to ask Q is just 3, thats why :stuck_out_tongue:

he using recursion, the function should have void as a return type, but works anyways

@divyansh_gaba7 please explain to @vehemos that he is not assigning the value returned by the function finder to ans.

@vehemos if you don’t know then try to learn from others but don’t tell that others are wrong without knowing

global variables are assigned to zero by default. He is initializing it before every function call from main. only wrong thing he is doing is he doesn’t have finder as void return type, which btw doesn’t really matter except its not good practice.

Function finder is returning an integer so it should have return type integer.But there should be some variable in the main function to catch that integer returned by finder.

you don’t understand his function it seems :(. The actual result is already stored in global variable “ans” which he prints. Finder always returns 0.

oh yes,sorry i didn’t see that.he is adding k to ans.

@vehemos if you don’t know then try to learn from others but don’t tell that others are wrong without knowing” @hruday968 ok, I’m listening tell me where I’m wrong, but just 1 thing ans=finder WILL NOT WORK cuz it reutrn 0 when recursion is finished, I may not be better than you but I am aware of what I wrote, but if you still find it wrong tell me why it is and I will remove/improve on it Thanks.
@divyansh_gaba7 I didn’t know it was bad practice sorry, initially I was returning via that finder function only but afterwards I declared global to make it simpler, that’s why the int remained.

Okay got it @vijju123

@vehemos sorry i didn’t see this thing (ans+=k) and thought you was wrong.

@hruday968 np it happens, though you did make me bang my head over wall thinking why I should do ans = finder :stuck_out_tongue: I had to retest my code 3 times to gain my confidence back xD Happy Coding! :smiley:

1 Like