Problem 44523. Pattern Sum
Write a function which receives two single digit positive integers, (k and m) as parameters and calculates the total sum as: k + kk + kkk + .... (the last number in the sequence should have m digits) For example, if the two integers are: (4, 5). Your function should return the total sum of: 4 + 44 + 444 + 4444 + 44444. Notice the last number in this sequence has 5 digits. The return value should be 49380.
Solution Stats
Problem Comments
-
4 Comments
After some experimentation, I found that you need to multiplying the digit by the increasing powers of 10. The first term is a*10^0. The second term is a*10^1. The third term is a*10^2, and so on. So (10,4) would be 10+100+1000+10000. Granted, the problem statement says "single digit" so 10 and 56 shouldn't really be valid numbers, but we've all messed up problem descriptions and test suites before.
if there are number like "10", "56" in test suite, what's the point for mentioning "single digit positive integers"? is there any misunderstanding about "single digit" between different culture?
The test cases with double-digit numbers have been removed to prevent future confusion. Also, additional single-digit test cases have been added.
Solution Comments
Show commentsProblem Recent Solvers217
Suggested Problems
-
The Goldbach Conjecture, Part 2
2366 Solvers
-
484 Solvers
-
527 Solvers
-
344 Solvers
-
Pernicious Anniversary Problem
822 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!