id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > mar5_2020_bonus_digitSum
prev  |  next  |  chance

Write a RECURSIVE method that returns 'true' if it is possible to reach the 'target' number by adding any combination of digits from 'num' but WITHOUT using the single digit in 'dig'. Return false otherwise. As preconditions, you may assume 'num' and 'target' are positive. You may also assume that 'dig' is a single non-negative digit. For example, 7 can be reached by adding some of the digits of 1258 (2+5=7) as long as 'dig' is not 2 or 5, but 12 cannot be reached using the digits of 1258 (possible sums are 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16) no matter what 'dig' is. Your solution MUST be a truly recursive solution to earn credit. You might want to use a helper method just to make the method name much shorter. This one counts as BONUS for all levels of programming, including HL. HINT: I used BACKTRACK RECURSION. My helper method, which really did the work of the problem, only had a few lines of code.


mar5_2020_bonus_digitSum(14298, 45, 3) → false
mar5_2020_bonus_digitSum(1258, 7, 3) → true
mar5_2020_bonus_digitSum(1258, 12, 6) → false

...Save, Compile, Run (ctrl-enter)

public boolean mar5_2020_bonus_digitSum(int num, int target, int dig) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 410

Copyright Nick Parlante 2017 - privacy