|
| 1 | + |
| 2 | + |
| 3 | +' ------------------------------------------------ |
| 4 | +Sub Button1_OnClick() |
| 5 | + For number = 0 To 999 |
| 6 | + code = Text.Repeat(0, 3 - Text.GetLength(number)) & number |
| 7 | + If Distinct(code) And |
| 8 | + Inplace(code, 682, 1) And |
| 9 | + Misplaced(code, 614, 1) And |
| 10 | + Misplaced(code, 206, 2) And |
| 11 | + Reject(code, 738) = False And |
| 12 | + Misplaced(code, 780, 1) Then |
| 13 | + Forms.ShowMessage("Code: " + code, "Message") |
| 14 | + EndIf |
| 15 | + Next |
| 16 | +EndSub |
| 17 | + |
| 18 | +' ------------------------------------------------ |
| 19 | +Function Distinct(code) |
| 20 | + Return code[1] <> code[2] And |
| 21 | + code[1] <> code[2] And |
| 22 | + code[2] <> code[3] |
| 23 | +EndFunction |
| 24 | + |
| 25 | +' ------------------------------------------------ |
| 26 | +Function Inplace(code, clue, count) |
| 27 | + n = 0 |
| 28 | + For i = 1 To 3 |
| 29 | + If code[i] = clue[i] Then |
| 30 | + n = n + 1 |
| 31 | + EndIf |
| 32 | + Next |
| 33 | + Return n = count |
| 34 | +EndFunction |
| 35 | + |
| 36 | +' ------------------------------------------------ |
| 37 | +Function Misplaced(code, clue, count) |
| 38 | + n = 0 |
| 39 | + For i = 1 To 3 |
| 40 | + If code[i] = clue[i] Then |
| 41 | + Return False |
| 42 | + EndIf |
| 43 | + If Text.Contains(clue, code[i]) Then |
| 44 | + n = n + 1 |
| 45 | + EndIf |
| 46 | + Next |
| 47 | + Return n = count |
| 48 | +EndFunction |
| 49 | + |
| 50 | + |
| 51 | +' ------------------------------------------------ |
| 52 | +Function Reject(code, clue) |
| 53 | + ForEach digit In clue |
| 54 | + If Text.Contains(code, digit) Then |
| 55 | + Return True |
| 56 | + EndIf |
| 57 | + Next |
| 58 | + Return False |
| 59 | +EndFunction |
| 60 | + |
0 commit comments