All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Minimum Integer (Posted on 2014-02-28)
Determine the smallest positive integer whose first 6 multiples (including itself) contain the digit 2.

 No Solution Yet Submitted by K Sengupta No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
 re: Brute force solution | Comment 2 of 4 |
(In reply to Brute force solution by tomarken)

I'm not familiar with Python programming, but the below is a program in Quick Basic 4.5. For example I don't know what determines the end of the Python While loop, or the extent of the conditionality of the If, or the For.  Indentation as in the below program would help the uninitiated see the extent of these constructs.

The only logical difference in mine is the avoidance of multiplications, by adding to the multiples from the preceding iteration of the identity of the initial number. There's no List function in Basic. I take it that "not in" applies to the individual elements of the list so that if any one has a failure to find the 2, the not in comes out as true.

I also let the program continue on to further values whose multiples lacked 2's.  The STOP command allows the user to continue processing by typing CONT; if I had wanted to exercise that option I would have coded ct MOD 44 = 0 rather than ct > 44 so as to keep pausing after each successive screenful.

DEFDBL A-Z
CLS
DIM s1 AS STRING, s2 AS STRING, s3 AS STRING, s4 AS STRING, s5 AS STRING, s6 AS STRING
x1 = 2: x2 = 4: x3 = 6: x4 = 8: x5 = 10: x6 = 12
DO
s1 = STR\$(x1): s2 = STR\$(x2): s3 = STR\$(x3): s4 = STR\$(x4): s5 = STR\$(x5): s6 = STR\$(x6)
IF INSTR(s1, "2") > 0 THEN
IF INSTR(s2, "2") > 0 THEN
IF INSTR(s3, "2") > 0 THEN
IF INSTR(s4, "2") > 0 THEN
IF INSTR(s5, "2") > 0 THEN
IF INSTR(s6, "2") > 0 THEN
PRINT x1; x2; x3; x4; x5; x6
ct = ct + 1
IF ct > 44 THEN STOP
END IF
END IF
END IF
END IF
END IF
END IF
x1 = x1 + 1
x2 = x2 + 2
x3 = x3 + 3
x4 = x4 + 4
x5 = x5 + 5
x6 = x6 + 6
LOOP

642  1284  1926  2568  3210  3852
2064  4128  6192  8256  10320  12384
4062  8124  12186  16248  20310  24372
4123  8246  12369  16492  20615  24738
4128  8256  12384  16512  20640  24768
4132  8264  12396  16528  20660  24792
4206  8412  12618  16824  21030  25236
4213  8426  12639  16852  21065  25278
4231  8462  12693  16924  21155  25386
4256  8512  12768  17024  21280  25536
4263  8526  12789  17052  21315  25578
4281  8562  12843  17124  21405  25686
4312  8624  12936  17248  21560  25872
4321  8642  12963  17284  21605  25926
5142  10284  15426  20568  25710  30852
5214  10428  15642  20856  26070  31284
5412  10824  16236  21648  27060  32472
5421  10842  16263  21684  27105  32526
5426  10852  16278  21704  27130  32556
5642  11284  16926  22568  28210  33852
5762  11524  17286  23048  28810  34572
6042  12084  18126  24168  30210  36252
6204  12408  18612  24816  31020  37224
6242  12484  18726  24968  31210  37452
6254  12508  18762  25016  31270  37524
6402  12804  19206  25608  32010  38412
6412  12824  19236  25648  32060  38472
6420  12840  19260  25680  32100  38520
6421  12842  19263  25684  32105  38526
6422  12844  19266  25688  32110  38532
6427  12854  19281  25708  32135  38562
6432  12864  19296  25728  32160  38592
6442  12884  19326  25768  32210  38652
6642  13284  19926  26568  33210  39852
7124  14248  21372  28496  35620  42744
7125  14250  21375  28500  35625  42750
8562  17124  25686  34248  42810  51372
10423  20846  31269  41692  52115  62538
10428  20856  31284  41712  52140  62568
10432  20864  31296  41728  52160  62592
10542  21084  31626  42168  52710  63252
10642  21284  31926  42568  53210  63852
12043  24086  36129  48172  60215  72258
12054  24108  36162  48216  60270  72324
12064  24128  36192  48256  60320  72384

 Posted by Charlie on 2014-02-28 12:39:24

 Search: Search body:
Forums (0)