Cody

Problem 2051. is the number happy?

Solution 3303123

Submitted on 21 Oct 2020 by Wesley Maa
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 = 1; y_correct = 1; assert(isequal(ishappy(n),y_correct))

prev = [] tf = 1

2   Pass
n = 2; y_correct = 0; assert(isequal(ishappy(n),y_correct))

prev = [] prev = 2 sum = 0 sum = 4 y = 0 x = 4 n = 4 prev = 2 4 sum = 0 sum = 16 y = 0 x = 16 n = 16 prev = 2 4 16 sum = 0 sum = 36 y = 1 sum = 37 y = 0 x = 37 n = 37 prev = 2 4 16 37 sum = 0 sum = 49 y = 3 sum = 58 y = 0 x = 58 n = 58 prev = 2 4 16 37 58 sum = 0 sum = 64 y = 5 sum = 89 y = 0 x = 89 n = 89 prev = 2 4 16 37 58 89 sum = 0 sum = 81 y = 8 sum = 145 y = 0 x = 145 n = 145 prev = 2 4 16 37 58 89 145 sum = 0 sum = 25 y = 14 sum = 41 y = 1 sum = 42 y = 0 x = 42 n = 42 prev = 2 4 16 37 58 89 145 42 sum = 0 sum = 4 y = 4 sum = 20 y = 0 x = 20 n = 20 prev = 2 4 16 37 58 89 145 42 20 sum = 0 sum = 0 y = 2 sum = 4 y = 0 x = 4 n = 4 tf = 0

3   Pass
n = 31; y_correct = 1; assert(isequal(ishappy(n),y_correct))

prev = [] prev = 31 sum = 0 sum = 1 y = 3 sum = 10 y = 0 x = 10 n = 10 prev = 31 10 sum = 0 sum = 0 y = 1 sum = 1 y = 0 x = 1 n = 1 tf = 1

4   Pass
n = 13; y_correct = 1; assert(isequal(ishappy(n),y_correct))

prev = [] prev = 13 sum = 0 sum = 9 y = 1 sum = 10 y = 0 x = 10 n = 10 prev = 13 10 sum = 0 sum = 0 y = 1 sum = 1 y = 0 x = 1 n = 1 tf = 1

5   Pass
n = 11; y_correct = 0; assert(isequal(ishappy(n),y_correct))

prev = [] prev = 11 sum = 0 sum = 1 y = 1 sum = 2 y = 0 x = 2 n = 2 prev = 11 2 sum = 0 sum = 4 y = 0 x = 4 n = 4 prev = 11 2 4 sum = 0 sum = 16 y = 0 x = 16 n = 16 prev = 11 2 4 16 sum = 0 sum = 36 y = 1 sum = 37 y = 0 x = 37 n = 37 prev = 11 2 4 16 37 sum = 0 sum = 49 y = 3 sum = 58 y = 0 x = 58 n = 58 prev = 11 2 4 16 37 58 sum = 0 sum = 64 y = 5 sum = 89 y = 0 x = 89 n = 89 prev = 11 2 4 16 37 58 89 sum = 0 sum = 81 y = 8 sum = 145 y = 0 x = 145 n = 145 prev = 11 2 4 16 37 58 89 145 sum = 0 sum = 25 y = 14 sum = 41 y = 1 sum = 42 y = 0 x = 42 n = 42 prev = 11 2 4 16 37 58 89 145 42 sum = 0 sum = 4 y = 4 sum = 20 y = 0 x = 20 n = 20 prev = 11 2 4 16 37 58 89 145 42 20 sum = 0 sum = 0 y = 2 sum = 4 y = 0 x = 4 n = 4 tf = 0

6   Pass
n = 101; y_correct = 0; assert(isequal(ishappy(n),y_correct))

prev = [] prev = 101 sum = 0 sum = 1 y = 10 sum = 1 y = 1 sum = 2 y = 0 x = 2 n = 2 prev = 101 2 sum = 0 sum = 4 y = 0 x = 4 n = 4 prev = 101 2 4 sum = 0 sum = 16 y = 0 x = 16 n = 16 prev = 101 2 4 16 sum = 0 sum = 36 y = 1 sum = 37 y = 0 x = 37 n = 37 prev = 101 2 4 16 37 sum = 0 sum = 49 y = 3 sum = 58 y = 0 x = 58 n = 58 prev = 101 2 4 16 37 58 sum = 0 sum = 64 y = 5 sum = 89 y = 0 x = 89 n = 89 prev = 101 2 4 16 37 58 89 sum = 0 sum = 81 y = 8 sum = 145 y = 0 x = 145 n = 145 prev = 101 2 4 16 37 58 89 145 sum = 0 sum = 25 y = 14 sum = 41 y = 1 sum = 42 y = 0 x = 42 n = 42 prev = 101 2 4 16 37 58 89 145 42 sum = 0 sum = 4 y = 4 sum = 20 y = 0 x = 20 n = 20 prev = 101 2 4 16 37 58 89 145 42 20 sum = 0 sum = 0 y = 2 sum = 4 y = 0 x = 4 n = 4 tf = 0

7   Pass
n = 100; y_correct = 1; assert(isequal(ishappy(n),y_correct))

prev = [] prev = 100 sum = 0 sum = 0 y = 10 sum = 0 y = 1 sum = 1 y = 0 x = 1 n = 1 tf = 1

8   Pass
n = 130; y_correct = 1; assert(isequal(ishappy(n),y_correct))

prev = [] prev = 130 sum = 0 sum = 0 y = 13 sum = 9 y = 1 sum = 10 y = 0 x = 10 n = 10 prev = 130 10 sum = 0 sum = 0 y = 1 sum = 1 y = 0 x = 1 n = 1 tf = 1

9   Pass
n = 230; y_correct = 1; assert(isequal(ishappy(n),y_correct))

prev = [] prev = 230 sum = 0 sum = 0 y = 23 sum = 9 y = 2 sum = 13 y = 0 x = 13 n = 13 prev = 230 13 sum = 0 sum = 9 y = 1 sum = 10 y = 0 x = 10 n = 10 prev = 230 13 10 sum = 0 sum = 0 y = 1 sum = 1 y = 0 x = 1 n = 1 tf = 1

10   Pass
n = 190; y_correct = 1; assert(isequal(ishappy(n),y_correct))

prev = [] prev = 190 sum = 0 sum = 0 y = 19 sum = 81 y = 1 sum = 82 y = 0 x = 82 n = 82 prev = 190 82 sum = 0 sum = 4 y = 8 sum = 68 y = 0 x = 68 n = 68 prev = 190 82 68 sum = 0 sum = 64 y = 6 sum = 100 y = 0 x = 100 n = 100 prev = 190 82 68 100 sum = 0 sum = 0 y = 10 sum = 0 y = 1 sum = 1 y = 0 x = 1 n = 1 tf = 1

11   Pass
n = 290; y_correct = 0; assert(isequal(ishappy(n),y_correct))

prev = [] prev = 290 sum = 0 sum = 0 y = 29 sum = 81 y = 2 sum = 85 y = 0 x = 85 n = 85 prev = 290 85 sum = 0 sum = 25 y = 8 sum = 89 y = 0 x = 89 n = 89 prev = 290 85 89 sum = 0 sum = 81 y = 8 sum = 145 y = 0 x = 145 n = 145 prev = 290 85 89 145 sum = 0 sum = 25 y = 14 sum = 41 y = 1 sum = 42 y = 0 x = 42 n = 42 prev = 290 85 89 145 42 sum = 0 sum = 4 y = 4 sum = 20 y = 0 x = 20 n = 20 prev = 290 85 89 145 42 20 sum = 0 sum = 0 y = 2 sum = 4 y = 0 x = 4 n = 4 prev = 290 85 89 145 42 20 4 sum = 0 sum = 16 y = 0 x = 16 n = 16 prev = 290 85 89 145 42 20 4 16 sum = 0 sum = 36 y = 1 sum = 37 y = 0 x = 37 n = 37 prev = 290 85 89 145 42 20 4 16 37 sum = 0 sum = 49 y = 3 sum = 58 y = 0 x = 58 n = 58 prev = 290 85 89 145 42 20 4 16 37 58 sum = 0 sum = 64 y = 5 sum = 89 y = 0 x = 89 n = 89 tf = 0

12   Pass
n = 998; y_correct = 1; assert(isequal(ishappy(n),y_correct))

prev = [] prev = 998 sum = 0 sum = 64 y = 99 sum = 145 y = 9 sum = 226 y = 0 x = 226 n = 226 prev = 998 226 sum = 0 sum = 36 y = 22 sum = 40 y = 2 sum = 44 y = 0 x = 44 n = 44 prev = 998 226 44 sum = 0 sum = 16 y = 4 sum = 32 y = 0 x = 32 n = 32 prev = 998 226 44 32 sum = 0 sum = 4 y = 3 sum = 13 y = 0 x = 13 n = 13 prev = 998 226 44 32 13 sum = 0 sum = 9 y = 1 sum = 10 y = 0 x = 10 n = 10 prev = 998 226 44 32 13 10 sum = 0 sum = 0 y = 1 sum = 1 y = 0 x = 1 n = 1 tf = 1

Community Treasure Hunt

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

Start Hunting!