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
Please include an explanation of how the results are obtained when a has more than one digit. Based on your existing Problem Statement pattern_sum(10,4) should be equal to EITHER 10 + 1010 + 101010 + 10101010 = 10203040 (if repeating 4 times) OR 10 + 1010 = 1020 (if ending the sequence with a 4-digit number).
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 Solvers214
Suggested Problems
-
Remove any row in which a NaN appears
8588 Solvers
-
2476 Solvers
-
Create a square matrix of multiples
475 Solvers
-
8991 Solvers
-
Get the elements of diagonal and antidiagonal for any m-by-n matrix
476 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!