Problem 44706. The Deadly Sin
Melvyn and Banner are fighting over chocolates. Melvyn has X chocolates, while Banner has Y. Whoever has a lesser number of chocolates eats as many chocolates as he has from the other's collection. This eatfest war continues till either they have the same number of chocolates, or at least one of them is left with no chocolates. Can you help Eliza predict the total number of chocolates they'll be left with at the end of their war?
Example
Input: x = [5 3]
Explanation: Denoting Melvyn as M, Banner as B
M=5, B=3 - Banner eats 3 chocolates of Melvyn.
M=2, B=3 - Melvyn eats 2 chocolates of Banner.
M=2, B=1 - Banner eats 1 chocolate of Melvyn.
M=1, B=1 - Since they have the same no of candies, they stop quarreling.
Total candies left: 2
Output: y = 2
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers27
Suggested Problems
-
Remove any row in which a NaN appears
8762 Solvers
-
387 Solvers
-
Project Euler: Problem 10, Sum of Primes
2086 Solvers
-
Set the array elements whose value is 13 to 0
1433 Solvers
-
533 Solvers
More from this Author2
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!