This question actually had 2 parts, and i got the first one right but cant seem to get the second one right with my same logic.
We call a number memorable if every digit in the number is either a 1 or adjacent to a 1. For example, the numbers 111, 81, 101, and 1771 are all memorable, but the numbers 12321, 786, 140, and 1999 are not memorable.
How many positive 2-digit numbers are memorable?
I got 18 for this and it was right because i literally wrote them down and counted them
How many positive 3-digit numbers are memorable?
I couldn't really do that for 3-digit numbers...
a=1;b=0;c=0;p=0; cycle:d=a*100+b*10+c;if( b==1or b==1 and c==1 , goto loop, goto next); loop:printd,", ",;p=p+1; next:c++;if(c<10, goto cycle, 0);c=0;b++;if(b<10, goto cycle, 0);b=0;c=0;a++;if(a<10, goto cycle,0);print"Total = ",p
OUTPUT:
1 - There are 18 2-digit "memorable" integers.
2 - There are 99 3-digit "memorable" integers.
(10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 31, 41, 51, 61, 71, 81, 91, 101, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 121, 131, 141, 151, 161, 171, 181, 191, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919) = 117 such numbers.
a=1;b=0;c=0;p=0; cycle:d=a*100+b*10+c;if( b==1or b==1 and c==1 , goto loop, goto next); loop:printd,", ",;p=p+1; next:c++;if(c<10, goto cycle, 0);c=0;b++;if(b<10, goto cycle, 0);b=0;c=0;a++;if(a<10, goto cycle,0);print"Total = ",p
OUTPUT:
1 - There are 18 2-digit "memorable" integers.
2 - There are 99 3-digit "memorable" integers.
(10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 31, 41, 51, 61, 71, 81, 91, 101, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 121, 131, 141, 151, 161, 171, 181, 191, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919) = 117 such numbers.