Cody

Problem 45250. Be happy

Solution 2816914

Submitted on 10 Aug 2020 by Alfonso Nieto-Castanon
  • Size: 36
  • This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
n =11123; b=10; y_correct = 0; assert(isequal(be_happy(n,b),y_correct))

ans = 1 11123 ans = 1 11123 16 ans = 1 11123 16 37 ans = 1 11123 16 37 58 ans = 1 11123 16 37 58 89 ans = 1 11123 16 37 58 89 145 ans = 1 11123 16 37 58 89 145 42 ans = 1 11123 16 37 58 89 145 42 20 ans = 1 11123 16 37 58 89 145 42 20 4

2   Pass
n = 347; b=6; y_correct = 1; assert(isequal(be_happy(n,b),y_correct))

ans = 1 347 ans = 1 347 44 ans = 1 347 44 6

3   Pass
n = 998; b=10; y_correct = 1; assert(isequal(be_happy(n,b),y_correct))

ans = 1 998 ans = 1 998 226 ans = 1 998 226 44 ans = 1 998 226 44 32 ans = 1 998 226 44 32 13 ans = 1 998 226 44 32 13 10

4   Pass
n = 1234; b=4; y_correct = 1; assert(isequal(be_happy(n,b),y_correct))

ans = 1 1234 ans = 1 1234 15 ans = 1 1234 15 18 ans = 1 1234 15 18 5 ans = 1 1234 15 18 5 2 ans = 1 1234 15 18 5 2 4

5   Pass
n = 149121303586; b=10; y_correct = 0; assert(isequal(be_happy(n,b),y_correct))

ans = 1.0e+11 * 0.0000 1.4912 ans = 1.0e+11 * 0.0000 1.4912 0.0000 ans = 1.0e+11 * 0.0000 1.4912 0.0000 0.0000 ans = 1.0e+11 * 0.0000 1.4912 0.0000 0.0000 0.0000 ans = 1.0e+11 * 0.0000 1.4912 0.0000 0.0000 0.0000 0.0000 ans = 1.0e+11 * 0.0000 1.4912 0.0000 0.0000 0.0000 0.0000 0.0000 ans = 1.0e+11 * 0.0000 1.4912 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ans = 1.0e+11 * 0.0000 1.4912 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ans = 1.0e+11 * 0.0000 1.4912 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ans = 1.0e+11 * 0.0000 1.4912 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ans = 1.0e+11 * 0.0000 1.4912 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ans = 1.0e+11 * 0.0000 1.4912 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ans = 1.0e+11 * 0.0000 1.4912 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ans = 1.0e+11 * 0.0000 1.4912 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ans = 1.0e+11 * 0.0000 1.4912 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

6   Pass
n =742356; b=3; y_correct = 0; assert(isequal(be_happy(n,b),y_correct))

ans = 1 742356 ans = 1 742356 20 ans = 1 742356 20 8

7   Pass
n = 14916; b=7; y_correct = 0; assert(isequal(be_happy(n,b),y_correct))

ans = 1 14916 ans = 1 14916 86 ans = 1 14916 86 30 ans = 1 14916 86 30 20 ans = 1 14916 86 30 20 40 ans = 1 14916 86 30 20 40 50 ans = 1 14916 86 30 20 40 50 2 ans = 1 14916 86 30 20 40 50 2 4 ans = 1 14916 86 30 20 40 50 2 4 16 ans = 1 14916 86 30 20 40 50 2 4 16 8

8   Pass
n = 3148; b=6; y_correct = 0; assert(isequal(be_happy(n,b),y_correct))

ans = 1 3148 ans = 1 3148 37 ans = 1 3148 37 2 ans = 1 3148 37 2 4 ans = 1 3148 37 2 4 16 ans = 1 3148 37 2 4 16 20 ans = 1 3148 37 2 4 16 20 13 ans = 1 3148 37 2 4 16 20 13 5 ans = 1 3148 37 2 4 16 20 13 5 25 ans = 1 3148 37 2 4 16 20 13 5 25 17 ans = 1 3148 37 2 4 16 20 13 5 25 17 29 ans = 1 3148 37 2 4 16 20 13 5 25 17 29 41 ans = 1 3148 37 2 4 16 20 13 5 25 17 29 41 26

9   Pass
n = 3148; b=7; y_correct = 0; assert(isequal(be_happy(n,b),y_correct))

ans = 1 3148 ans = 1 3148 32

10   Pass
n = 3148; b=13; y_correct = 1; assert(isequal(be_happy(n,b),y_correct))

ans = 1 3148 ans = 1 3148 94 ans = 1 3148 94 58 ans = 1 3148 94 58 52 ans = 1 3148 94 58 52 16 ans = 1 3148 94 58 52 16 10 ans = 1 3148 94 58 52 16 10 289 ans = 1 3148 94 58 52 16 10 289 91 ans = 1 3148 94 58 52 16 10 289 91 49 ans = 1 3148 94 58 52 16 10 289 91 49 298 ans = 1 3148 94 58 52 16 10 289 91 49 298 443 ans = 1 3148 94 58 52 16 10 289 91 49 298 443 69 ans = 1 3148 94 58 52 16 10 289 91 49 298 443 69 41 ans = 1 3148 94 58 52 16 10 289 91 49 298 443 69 41 13

Suggested Problems

More from this Author149

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!