← Back to challenges

Fives and Threes Only

JavaScriptHardalgebraalgorithmsrecursionvalidation

Instructions

Starting with either 3 or 5 and given these operations:

  • add 5
  • multiply by 3

You should say if it is possible to reach the target number n.

Examples

only5and3(14) ➞ true
// 14 = 3*3 + 5

only5and3(25) ➞ true
// 25 = 5+5+5+5+5

only5and3(7) ➞ false
// There exists no path to the target number 7

Notes

You can solve this problem by recursion or algebra.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.