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 4digit 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 doubledigit numbers have been removed to prevent future confusion. Also, additional singledigit test cases have been added.
Solution Comments
Show commentsProblem Recent Solvers210
Suggested Problems

Find the sum of all the numbers of the input vector
47237 Solvers

Implement simple rotation cypher
1050 Solvers

Create an nbyn null matrix and fill with ones certain positions
563 Solvers

Write a function man that takes a row vector v and returns a matrix H as follows..
603 Solvers

6717 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!