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 commentsGroup

Number Manipulation IV
- 15 Problems
- 30 Finishers
- Pattern Sum
- Smallest n, for n! to have m trailing zero digits
- Still more miles to go before I sleep
- Convert from Base 10 to base 5
- Numbers on 7-segment
- Expand 10^n to Powers of 4
- Muphry's Law of MATLAB
- Lunar Arithmetic (Addition)
- Lunar Arithmetic (Multiplication)
- Permutation Via Multiplication
- The last non-zero digit of a factorial
- The number of trailing zero digit of a factorial
- Whole Number Concatenator
- Whole Number Un-Concatenator
- Smallest n, for n! to have m trailing zero digits
- Better Index Number
Problem Recent Solvers220
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!