+ 2

I came across this question in one of my challenges and i could not wrap my head around it.

Anyone to help how we arrive to '2' as the output https://code.sololearn.com/cgg6bldSNBVW/?ref=app

11th Aug 2020, 6:19 AM
Omari Suleiman Mwakaribu
Omari Suleiman Mwakaribu - avatar
9 Respostas
+ 9
sum (4,2) = 1 + sum(3,1) = 1 + (1 + sum(2,0)) # now it will hit the base case = 1 + (1 + 0) = 2
11th Aug 2020, 6:25 AM
Arsenic
Arsenic - avatar
+ 4
True Õmmy ok...last test: Did you understand that this is an implenentation of the function min(a, b) for a, b > 0? if not it might be a good challenge to.
11th Aug 2020, 6:45 AM
Oma Falk
Oma Falk - avatar
+ 2
It's recursion The function is calling itself and running like a loop untill the condition is meet
11th Aug 2020, 6:21 AM
Jayp
Jayp - avatar
+ 2
Thank you all for your answers, Arsenic you made it crystal clear.
11th Aug 2020, 6:31 AM
Omari Suleiman Mwakaribu
Omari Suleiman Mwakaribu - avatar
+ 2
Thank you Oma Falk i understand now
11th Aug 2020, 9:00 AM
Omari Suleiman Mwakaribu
Omari Suleiman Mwakaribu - avatar
+ 1
Oma Falk That sounds better!
11th Aug 2020, 9:33 AM
Alexander Thiem
Alexander Thiem - avatar
+ 1
Alexander Thiem thanks for checking.
11th Aug 2020, 10:04 AM
Oma Falk
Oma Falk - avatar
0
Oma Falk an implementation for difference? No appearently not Input:4,1 does not result in 3......
11th Aug 2020, 9:03 AM
Alexander Thiem
Alexander Thiem - avatar
0
Alexander Thiem typo it was min
11th Aug 2020, 9:22 AM
Oma Falk
Oma Falk - avatar