Return Last 50 posts First 100 posts

I have no Idea what algorithm this should be.

1 Name: Anonymous : 2015-11-22 17:38
to all the coders out there, what does this code do? I have no Idea what algorithm this should be...

private static int rec(int x, int y) {
if (x == y || y == 0) {
return 1;
}
if (x < 0) {
return rec(-x, y);
}
if (y < 0) {
return rec(x, -y);
}
if (x < y) {
return rec(y, x);
}
return rec(x - 1, y - 1) + rec(x - 1, y);
}

https://ideone.com/hvWiyX
2 Name: Anonymous : 2015-11-22 17:38
push
3 Name: Anonymous : 2015-11-22 17:38
Something to do with drawing a rectangle I guess, but dont see the draw function anywhere though...did you look it up on google?
4 Name: Anonymous : 2015-11-22 17:38
It looks like it's just an example of a recursive method.

The method takes in two numbers with a base case that if both of the numbers are the same or the second number is 0, then the value of that function call is 1.

Otherwise it ensures that there are no negative numbers in the input and that the first value is always the largest. If those conditions are met it adds together the recursive call of the values when they're each one smaller and the recursive call of the values when only x is one smaller.

The final return has two recursive calls. The first one will reach the base case when y == 0 and the second call will reach the base case whenever x == y.

Other than that it doesn't really do anything well-known that I can think of.
5 Name: Anonymous : 2015-11-22 17:38
It's a recursive method. You have two inputs, x and y. If x is less than 0, the method calls itself with the negative value of x (or by multiplying x by -1). Same goes for y if y is less than 0. However if x is less than y, it switches the values and calls the method again. In the end of all things it calls itself my decrementing the original value and adding the value of a second decremented value where y isn't changed.
6 Name: Anonymous : 2015-11-22 17:39
>>1
like >>3 said, it's drawing some type of rectangle, but i don't see a function, like something you'd see done in directx in c++, made for this, it's not rendering anything, you need a rendering function.
7 Name: Anonymous : 2015-11-22 17:39
okay so basically I know how it works, I just don't see what algorithm is behind it...

so basically >>4 is my problem.

thank you for helping guys
8 Name: Anonymous : 2015-11-22 17:39
>>6
welp, i was wrong, i don't know java anyways.
9 Name: Anonymous : 2015-11-22 17:40
>>6
>>3
nothing to do with drawing a rectangle, it returns an integer value.

for example rec(3,5) returns 10
10 Name: Anonymous : 2015-11-22 17:41
>>9
yeyeyeyeye >>8
11 Name: Anonymous : 2015-11-22 17:41
this is a recursive function running untill there x==y or y==0 condition is met and the entire function tree "folds" back to its origin
12 Name: Anonymous : 2015-11-22 17:41
>>7
where's the condition for this? this program is nonsensical recursion example.
}
return rec(x - 1, y - 1) + rec(x - 1, y);
}
13 Name: Anonymous : 2015-11-22 17:41
>>12
you're stupid. this has the condition that no other condition was met

as simple as that
14 Name: Anonymous : 2015-11-22 17:42
op add System.out.println("x is" + x + " y is" + y);

to understand the function better
15 Name: Anonymous : 2015-11-22 17:50
>>14
gets me nowhere... sadly
16 Name: Anonymous : 2015-11-22 17:51
Oh I remember this one, it's called something something theorem don't give a fuck.
17 Name: Anonymous : 2015-11-22 17:54
>>16
...
18 Name: Anonymous : 2015-11-22 17:54
nobody?
19 Name: Anonymous : 2015-11-22 17:54
looks like every elite hacker of anonymous is busy fighting isis
20 Name: Anonymous : 2015-11-22 17:55
>>17
Somewhere in this book http://www.amazon.com/Discrete-Mathematics-Applications-Kenneth-Rosen/dp/0072899050
21 Name: Anonymous : 2015-11-22 17:56
>>20
http://www.amazon.com/Discrete-Mathematics-Applications-Kenneth-Rosen/dp/0072899050

lol fuck it, Not gonna read 300 pages just for this one exercise... But thanks for the help man
22 Name: Anonymous : 2016-01-21 12:36
https://en.wikipedia.org/wiki/Binomial_coefficient
23 Name: Anonymous : 2017-03-09 05:15
>>1
It's for testing how well a language can execute terribly written code

Return Last 50 posts First 100 posts

Name: