about | help | code help+videos | done | prefs |
If a number is "civil" return its civil number. Otherwise return zero. A number is "civil" if, through a recursive process, the resulting single-digit number is a prime. The recursive process is to multiply all of the digits of the number together repeatedly until a single digit number is obtained. If that ultimate single digit number is a prime, you return it. If it is not a prime, you return a zero. The only single digit prime numbers are 2, 3, 5, and 7. For example: If the input parameter is 623, you would first find the product of all those digits, which is 6*2*3=36. That is not yet a single digit, so you now find the product of the digits in 36. 3*6=18. That is still not a single digit, so you find the product of the digits in 18. 1*8=8. Now you have a single digit, but it is not a prime, so return 0. Here is another example: Given 35, you would find 15, then 5, which is prime, so you would return 5. Look at the test data for further examples. FYI: By definition, 1 is NOT prime. test2020_11_12_HL_civilNum(1) → 0 test2020_11_12_HL_civilNum(2) → 2 test2020_11_12_HL_civilNum(4) → 0 ...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: 290
Copyright Nick Parlante 2017 - privacy