Arrange the nine non-zero decimal digits in a certain order
e.g.
abcdefghi.
Now evaluate
abc*cba+def*fed+ghi*ihg Call the result
R and the number of distinct digits in it
D(R).
Example: for concatenation
125736849 R=1339330 and
D(R)=4
a, What concatenation, if any, results in
D(R)=7?
b. For what concatenation(s) the
D(R) is minimal?
Rem: Due to symmetry there will be multiple solutions, please list the lowest one only.
DefDbl A-Z
Dim crlf$, used(9)
Private Sub Form_Load()
ChDir "C:\Program Files (x86)\DevStudio\VB\projects\flooble"
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
DoEvents
minr = 99
n$ = "123456789": hold$ = n$
Do
a = Val(Mid(n$, 1, 1))
b = Val(Mid(n$, 2, 1))
c = Val(Mid(n$, 3, 1))
d = Val(Mid(n$, 4, 1))
e = Val(Mid(n$, 5, 1))
f = Val(Mid(n$, 6, 1))
g = Val(Mid(n$, 7, 1))
h = Val(Mid(n$, 8, 1))
i = Val(Mid(n$, 9, 1))
If a < d And d < g And a < c And d < f And g < i Then
t1 = 100 * a + 10 * b + c
t2 = 100 * c + 10 * b + a
t3 = 100 * d + 10 * e + f
t4 = 100 * f + 10 * e + d
t5 = 100 * g + 10 * h + i
t6 = 100 * i + 10 * h + g
Sum = t1 * t2 + t3 * t4 + t5 * t6
s$ = LTrim(Str(Sum))
ReDim ct(9)
For j = 1 To Len(s$)
ct(Val(Mid(s$, j, 1))) = ct(Val(Mid(s$, j, 1))) + 1
Next
r = 0
For j = 0 To 9
If ct(j) > 0 Then r = r + 1
Next
If r < minr Then minr = r
If r = 7 Then
Text1.Text = Text1.Text & n$ & " " & Str(t1 * t2) & Str(t3 * t4) & Str(t5 * t6) & " " & Str(Sum) & crlf
DoEvents
End If
End If
permute n$
Loop Until n$ = hold$
Text1.Text = Text1.Text & "------------" & Str(minr) & crlf: DoEvents
n$ = "123456789": hold$ = n$
Do
a = Val(Mid(n$, 1, 1))
b = Val(Mid(n$, 2, 1))
c = Val(Mid(n$, 3, 1))
d = Val(Mid(n$, 4, 1))
e = Val(Mid(n$, 5, 1))
f = Val(Mid(n$, 6, 1))
g = Val(Mid(n$, 7, 1))
h = Val(Mid(n$, 8, 1))
i = Val(Mid(n$, 9, 1))
If a < d And d < g And a < c And d < f And g < i Then
t1 = 100 * a + 10 * b + c
t2 = 100 * c + 10 * b + a
t3 = 100 * d + 10 * e + f
t4 = 100 * f + 10 * e + d
t5 = 100 * g + 10 * h + i
t6 = 100 * i + 10 * h + g
Sum = t1 * t2 + t3 * t4 + t5 * t6
s$ = LTrim(Str(Sum))
ReDim ct(9)
For j = 1 To Len(s$)
ct(Val(Mid(s$, j, 1))) = ct(Val(Mid(s$, j, 1))) + 1
Next
r = 0
For j = 0 To 9
If ct(j) > 0 Then r = r + 1
Next
If r = minr Then
Text1.Text = Text1.Text & n$ & " " & Str(t1 * t2) & Str(t3 * t4) & Str(t5 * t6) & " " & Str(Sum) & crlf
DoEvents
End If
End If
permute n$
Loop Until n$ = hold$
Text1.Text = Text1.Text & crlf
Text1.Text = Text1.Text & crlf & "done"
End Sub
finds
for D(R) = 7:
abcdefghi first second third sum
term term term
123478659 39483 417772 630004 1087259
123596748 39483 414220 633556 1087259
123647859 39483 482662 822922 1345067
124568739 52204 491320 692443 1235967
124658739 52204 563248 692443 1307895
125437689 65125 320758 679354 1065237
125639748 65125 598104 633556 1296785
125649738 65125 613954 617706 1296785
128356749 105088 232468 709303 1046859
134527698 57754 382075 625408 1065237
134628759 57754 518728 726363 1302845
134658729 57754 563248 675783 1296785
135487629 71685 381808 582454 1035947
135629748 71685 582454 633556 1287695
135649728 71685 613954 602056 1287695
136275849 85816 157300 804852 1047968
136425789 85816 222700 778743 1087259
136529748 85816 489325 633556 1208697
142538697 34222 449230 554812 1038264
142598637 34222 535210 468832 1038264
142637859 34222 468832 822922 1325976
143576829 48763 388800 769312 1206875
143628759 48763 518728 726363 1293854
145236879 78445 149152 859662 1087259
145329768 78445 303667 665856 1047968
145629738 78445 582454 617706 1278605
145638729 78445 533368 675783 1287596
145639728 78445 598104 602056 1278605
146329758 93586 303667 649606 1046859
152437689 38152 320758 679354 1038264
154369728 69454 355347 602056 1026857
154637829 69454 468832 769312 1307598
154638729 69454 533368 675783 1278605
157264839 117907 121968 786982 1026857
158326749 134458 203098 709303 1046859
163528749 58843 435600 709303 1203746
163547829 58843 407515 769312 1235670
164528739 75604 435600 692443 1203647
167245839 127087 132790 786982 1046859
173256849 64183 166912 804852 1035947
173428659 64183 352672 630004 1046859
175439628 99925 410026 518728 1028679
176235849 118096 125020 804852 1047968
192546738 55872 352170 617706 1025748
214576839 88168 388800 786982 1263950
215468739 110080 404352 692443 1206875
216439578 132192 410026 505750 1047968
216479538 132192 466546 449230 1047968
216495738 132192 294030 617706 1043928
216548739 132192 463060 692443 1287695
216549738 132192 518805 617706 1268703
217349658 154504 329107 563248 1046859
217465839 154504 262260 786982 1203746
218437569 177016 320758 549085 1046859
219354768 199728 160362 665856 1025946
219435678 199728 232290 593928 1025946
234617859 101088 441772 822922 1365782
235417869 125020 297738 841192 1263950
235419687 125020 382966 539982 1047968
235489617 125020 481176 441772 1047968
237548619 173484 463060 567004 1203548
243567819 83106 433755 751842 1268703
246317859 157932 226021 822922 1206875
246539718 157932 503965 586606 1248503
247516839 183274 317340 786982 1287596
247518639 183274 422170 598104 1203548
253618749 89056 504288 709303 1302647
253648719 89056 548208 659323 1296587
254316789 114808 193708 778743 1087259
257416839 193264 255424 786982 1235670
263415789 95206 213310 778743 1087259
263519748 95206 474885 633556 1203647
264517839 121968 369655 786982 1278605
267415839 203454 213310 786982 1203746
276438519 185472 365292 474885 1025649
284356719 136888 232468 659323 1028679
314568729 129682 491320 675783 1296785
314586729 129682 401410 675783 1206875
315428769 161595 352672 743623 1257890
315467829 161595 356788 769312 1287695
316457829 193708 344578 769312 1307598
316475829 193708 272650 769312 1235670
317428659 226021 352672 630004 1208697
317489526 226021 481176 328750 1035947
318526749 258534 328750 709303 1296587
318547629 258534 407515 582454 1248503
324518769 137052 422170 743623 1302845
324568719 137052 491320 659323 1287695
325467819 169975 356788 751842 1278605
325469718 169975 452116 586606 1208697
326419587 203098 382966 460795 1046859
326419758 203098 382966 649606 1235670
328516749 269944 317340 709303 1296587
329416758 303667 255424 649606 1208697
329485617 303667 283240 441772 1028679
349516728 329107 317340 602056 1248503
349518627 329107 422170 455202 1206479
349528617 329107 435600 441772 1206479
356418729 232468 340252 675783 1248503
356427819 232468 309148 751842 1293458
376415829 253048 213310 769312 1235670
386419527 263638 382966 382075 1028679
389425617 382387 222700 441772 1046859
395428617 234235 352672 441772 1028679
397415628 314821 213310 518728 1046859
and the minimum is 2:
------------ 2
134269578 57754 258778 505750 822282
136278495 85816 242416 294030 622262
143287569 48763 224434 549085 822282
146287395 93586 224434 234235 552255
152368479 38152 317584 466546 822282
154237689 69454 173484 679354 922292
154238697 69454 198016 554812 822282
154297368 69454 235224 317584 622262
156297384 101556 235224 185472 522252
157264389 117907 121968 382387 622262
157298364 117907 265816 168532 552255
163247589 58843 183274 580165 822282
164278395 75604 242416 234235 552255
173296485 64183 204832 283240 552255
174285396 81954 165870 274428 522252
175283496 99925 108106 344224 552255
175289364 99925 283798 168532 552255
179254386 173809 114808 263638 552255
179263485 173809 95206 283240 552255
184265397 88504 148930 314821 552255
186273495 126666 101556 294030 522252
186297354 126666 235224 160362 522252
189264375 185409 121968 214875 522252
197245386 155827 132790 263638 552255
198235476 176418 125020 320824 622262
198253467 176418 89056 356788 622262
198276354 176418 185472 160362 522252
214367859 88168 280021 822922 1191111
215368497 110080 317584 394618 822282
215398467 110080 355414 356788 822282
314527689 129682 382075 679354 1191111
The multiple results are not the result of symmetry as only one of each set of 48 symmetric solutions is shown, by requiring a < d < g and a < c, d < f and g < i.
|
Posted by Charlie
on 2014-10-21 15:30:43 |