about | help | code help+videos | done | prefs |
Write a method called StarWarsChallenge. There are two input parameters, representing the Sith and the Jedi. One battle consists of finding the sum of the digits of these two numbers. The number with the greater sum wins the battle. In ties, no one wins. Once a battle is complete, the next battle is done with the product of the digits of the previous numbers. For every battle a Sith wins, he earns a -1. For every battle a Jedi wins, he earns a +1. The final score is the sum of all the scores of the battles. This process stops when either of the battle numbers is less than 10. You MUST use recursion to solve AT LEAST part of this problem. Here is more information to clarify: Suppose the Sith number is 158 and the Jedi number is 273. 1+5+8=14, 2+7+3=12. 14>12 so the Sith wins the first battle. The next battle is done with the Sith number 40 (1*5*8) and the Jedi number 42 (2*7*3). 4+0=4, 4+2=6. 6>4 so the Jedi wins this battle. The next battle is done with the Sith number 0 (4*0) and the Jedi number 8 (4*2). 8>0 so the Jedi win this battle. So the final score is -1+1+1 = 1. Return 1. StarWarsChallenge(158, 273) → 1 StarWarsChallenge(273, 158) → -1 StarWarsChallenge(124, 492) → 2 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 350
Copyright Nick Parlante 2017 - privacy