Cody

# Problem 2051. is the number happy?

Solution 1627373

Submitted on 14 Sep 2018 by Michael Cappello
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))

h = Columns 1 through 15 1 7 10 13 19 23 28 31 32 44 49 68 70 79 82 Columns 16 through 30 86 91 94 97 100 103 109 129 130 133 139 167 176 188 190 Columns 31 through 45 192 193 203 208 219 226 230 236 239 262 263 280 291 293 301 Columns 46 through 60 302 310 313 319 320 326 329 331 338 356 362 365 367 368 376 Columns 61 through 75 379 383 386 391 392 397 404 409 440 446 464 469 478 487 490 Columns 76 through 90 496 536 556 563 565 566 608 617 622 623 632 635 637 638 644 Columns 91 through 105 649 653 655 656 665 671 673 680 683 694 700 709 716 736 739 Columns 106 through 120 748 761 763 784 790 793 802 806 818 820 833 836 847 860 863 Columns 121 through 135 874 881 888 899 901 904 907 910 912 913 921 923 931 932 937 Columns 136 through 143 940 946 964 970 973 989 998 1000 tf = logical 1

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

h = Columns 1 through 15 1 7 10 13 19 23 28 31 32 44 49 68 70 79 82 Columns 16 through 30 86 91 94 97 100 103 109 129 130 133 139 167 176 188 190 Columns 31 through 45 192 193 203 208 219 226 230 236 239 262 263 280 291 293 301 Columns 46 through 60 302 310 313 319 320 326 329 331 338 356 362 365 367 368 376 Columns 61 through 75 379 383 386 391 392 397 404 409 440 446 464 469 478 487 490 Columns 76 through 90 496 536 556 563 565 566 608 617 622 623 632 635 637 638 644 Columns 91 through 105 649 653 655 656 665 671 673 680 683 694 700 709 716 736 739 Columns 106 through 120 748 761 763 784 790 793 802 806 818 820 833 836 847 860 863 Columns 121 through 135 874 881 888 899 901 904 907 910 912 913 921 923 931 932 937 Columns 136 through 143 940 946 964 970 973 989 998 1000 tf = logical 0

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

h = Columns 1 through 15 1 7 10 13 19 23 28 31 32 44 49 68 70 79 82 Columns 16 through 30 86 91 94 97 100 103 109 129 130 133 139 167 176 188 190 Columns 31 through 45 192 193 203 208 219 226 230 236 239 262 263 280 291 293 301 Columns 46 through 60 302 310 313 319 320 326 329 331 338 356 362 365 367 368 376 Columns 61 through 75 379 383 386 391 392 397 404 409 440 446 464 469 478 487 490 Columns 76 through 90 496 536 556 563 565 566 608 617 622 623 632 635 637 638 644 Columns 91 through 105 649 653 655 656 665 671 673 680 683 694 700 709 716 736 739 Columns 106 through 120 748 761 763 784 790 793 802 806 818 820 833 836 847 860 863 Columns 121 through 135 874 881 888 899 901 904 907 910 912 913 921 923 931 932 937 Columns 136 through 143 940 946 964 970 973 989 998 1000 tf = logical 1

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

h = Columns 1 through 15 1 7 10 13 19 23 28 31 32 44 49 68 70 79 82 Columns 16 through 30 86 91 94 97 100 103 109 129 130 133 139 167 176 188 190 Columns 31 through 45 192 193 203 208 219 226 230 236 239 262 263 280 291 293 301 Columns 46 through 60 302 310 313 319 320 326 329 331 338 356 362 365 367 368 376 Columns 61 through 75 379 383 386 391 392 397 404 409 440 446 464 469 478 487 490 Columns 76 through 90 496 536 556 563 565 566 608 617 622 623 632 635 637 638 644 Columns 91 through 105 649 653 655 656 665 671 673 680 683 694 700 709 716 736 739 Columns 106 through 120 748 761 763 784 790 793 802 806 818 820 833 836 847 860 863 Columns 121 through 135 874 881 888 899 901 904 907 910 912 913 921 923 931 932 937 Columns 136 through 143 940 946 964 970 973 989 998 1000 tf = logical 1

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

h = Columns 1 through 15 1 7 10 13 19 23 28 31 32 44 49 68 70 79 82 Columns 16 through 30 86 91 94 97 100 103 109 129 130 133 139 167 176 188 190 Columns 31 through 45 192 193 203 208 219 226 230 236 239 262 263 280 291 293 301 Columns 46 through 60 302 310 313 319 320 326 329 331 338 356 362 365 367 368 376 Columns 61 through 75 379 383 386 391 392 397 404 409 440 446 464 469 478 487 490 Columns 76 through 90 496 536 556 563 565 566 608 617 622 623 632 635 637 638 644 Columns 91 through 105 649 653 655 656 665 671 673 680 683 694 700 709 716 736 739 Columns 106 through 120 748 761 763 784 790 793 802 806 818 820 833 836 847 860 863 Columns 121 through 135 874 881 888 899 901 904 907 910 912 913 921 923 931 932 937 Columns 136 through 143 940 946 964 970 973 989 998 1000 tf = logical 0

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

h = Columns 1 through 15 1 7 10 13 19 23 28 31 32 44 49 68 70 79 82 Columns 16 through 30 86 91 94 97 100 103 109 129 130 133 139 167 176 188 190 Columns 31 through 45 192 193 203 208 219 226 230 236 239 262 263 280 291 293 301 Columns 46 through 60 302 310 313 319 320 326 329 331 338 356 362 365 367 368 376 Columns 61 through 75 379 383 386 391 392 397 404 409 440 446 464 469 478 487 490 Columns 76 through 90 496 536 556 563 565 566 608 617 622 623 632 635 637 638 644 Columns 91 through 105 649 653 655 656 665 671 673 680 683 694 700 709 716 736 739 Columns 106 through 120 748 761 763 784 790 793 802 806 818 820 833 836 847 860 863 Columns 121 through 135 874 881 888 899 901 904 907 910 912 913 921 923 931 932 937 Columns 136 through 143 940 946 964 970 973 989 998 1000 tf = logical 0

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

h = Columns 1 through 15 1 7 10 13 19 23 28 31 32 44 49 68 70 79 82 Columns 16 through 30 86 91 94 97 100 103 109 129 130 133 139 167 176 188 190 Columns 31 through 45 192 193 203 208 219 226 230 236 239 262 263 280 291 293 301 Columns 46 through 60 302 310 313 319 320 326 329 331 338 356 362 365 367 368 376 Columns 61 through 75 379 383 386 391 392 397 404 409 440 446 464 469 478 487 490 Columns 76 through 90 496 536 556 563 565 566 608 617 622 623 632 635 637 638 644 Columns 91 through 105 649 653 655 656 665 671 673 680 683 694 700 709 716 736 739 Columns 106 through 120 748 761 763 784 790 793 802 806 818 820 833 836 847 860 863 Columns 121 through 135 874 881 888 899 901 904 907 910 912 913 921 923 931 932 937 Columns 136 through 143 940 946 964 970 973 989 998 1000 tf = logical 1

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

h = Columns 1 through 15 1 7 10 13 19 23 28 31 32 44 49 68 70 79 82 Columns 16 through 30 86 91 94 97 100 103 109 129 130 133 139 167 176 188 190 Columns 31 through 45 192 193 203 208 219 226 230 236 239 262 263 280 291 293 301 Columns 46 through 60 302 310 313 319 320 326 329 331 338 356 362 365 367 368 376 Columns 61 through 75 379 383 386 391 392 397 404 409 440 446 464 469 478 487 490 Columns 76 through 90 496 536 556 563 565 566 608 617 622 623 632 635 637 638 644 Columns 91 through 105 649 653 655 656 665 671 673 680 683 694 700 709 716 736 739 Columns 106 through 120 748 761 763 784 790 793 802 806 818 820 833 836 847 860 863 Columns 121 through 135 874 881 888 899 901 904 907 910 912 913 921 923 931 932 937 Columns 136 through 143 940 946 964 970 973 989 998 1000 tf = logical 1

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

h = Columns 1 through 15 1 7 10 13 19 23 28 31 32 44 49 68 70 79 82 Columns 16 through 30 86 91 94 97 100 103 109 129 130 133 139 167 176 188 190 Columns 31 through 45 192 193 203 208 219 226 230 236 239 262 263 280 291 293 301 Columns 46 through 60 302 310 313 319 320 326 329 331 338 356 362 365 367 368 376 Columns 61 through 75 379 383 386 391 392 397 404 409 440 446 464 469 478 487 490 Columns 76 through 90 496 536 556 563 565 566 608 617 622 623 632 635 637 638 644 Columns 91 through 105 649 653 655 656 665 671 673 680 683 694 700 709 716 736 739 Columns 106 through 120 748 761 763 784 790 793 802 806 818 820 833 836 847 860 863 Columns 121 through 135 874 881 888 899 901 904 907 910 912 913 921 923 931 932 937 Columns 136 through 143 940 946 964 970 973 989 998 1000 tf = logical 1

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

h = Columns 1 through 15 1 7 10 13 19 23 28 31 32 44 49 68 70 79 82 Columns 16 through 30 86 91 94 97 100 103 109 129 130 133 139 167 176 188 190 Columns 31 through 45 192 193 203 208 219 226 230 236 239 262 263 280 291 293 301 Columns 46 through 60 302 310 313 319 320 326 329 331 338 356 362 365 367 368 376 Columns 61 through 75 379 383 386 391 392 397 404 409 440 446 464 469 478 487 490 Columns 76 through 90 496 536 556 563 565 566 608 617 622 623 632 635 637 638 644 Columns 91 through 105 649 653 655 656 665 671 673 680 683 694 700 709 716 736 739 Columns 106 through 120 748 761 763 784 790 793 802 806 818 820 833 836 847 860 863 Columns 121 through 135 874 881 888 899 901 904 907 910 912 913 921 923 931 932 937 Columns 136 through 143 940 946 964 970 973 989 998 1000 tf = logical 1

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

h = Columns 1 through 15 1 7 10 13 19 23 28 31 32 44 49 68 70 79 82 Columns 16 through 30 86 91 94 97 100 103 109 129 130 133 139 167 176 188 190 Columns 31 through 45 192 193 203 208 219 226 230 236 239 262 263 280 291 293 301 Columns 46 through 60 302 310 313 319 320 326 329 331 338 356 362 365 367 368 376 Columns 61 through 75 379 383 386 391 392 397 404 409 440 446 464 469 478 487 490 Columns 76 through 90 496 536 556 563 565 566 608 617 622 623 632 635 637 638 644 Columns 91 through 105 649 653 655 656 665 671 673 680 683 694 700 709 716 736 739 Columns 106 through 120 748 761 763 784 790 793 802 806 818 820 833 836 847 860 863 Columns 121 through 135 874 881 888 899 901 904 907 910 912 913 921 923 931 932 937 Columns 136 through 143 940 946 964 970 973 989 998 1000 tf = logical 0

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

h = Columns 1 through 15 1 7 10 13 19 23 28 31 32 44 49 68 70 79 82 Columns 16 through 30 86 91 94 97 100 103 109 129 130 133 139 167 176 188 190 Columns 31 through 45 192 193 203 208 219 226 230 236 239 262 263 280 291 293 301 Columns 46 through 60 302 310 313 319 320 326 329 331 338 356 362 365 367 368 376 Columns 61 through 75 379 383 386 391 392 397 404 409 440 446 464 469 478 487 490 Columns 76 through 90 496 536 556 563 565 566 608 617 622 623 632 635 637 638 644 Columns 91 through 105 649 653 655 656 665 671 673 680 683 694 700 709 716 736 739 Columns 106 through 120 748 761 763 784 790 793 802 806 818 820 833 836 847 860 863 Columns 121 through 135 874 881 888 899 901 904 907 910 912 913 921 923 931 932 937 Columns 136 through 143 940 946 964 970 973 989 998 1000 tf = logical 1

### Community Treasure Hunt

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

Start Hunting!