My first attempt was to permute the ten digits to find a perfect square whose square root was tested for being strobogrammatic. It failed as I had a bug in my test for strobogrammaticity. It's the same test I used in the successful program, below, but this time I successfully debugged it. (When looking for ix2, in the set of valid digits is was taking all the digits from i onward, rather than the single digit pointed at by i.) I thought that I'd need pandigitals larger than 10 digits long (with repeated digits).
Doing the check for strobogrammaticity first made it easier to debug, as the check was missing a lot of valid numbers.
strobo square
99066 9814072356 This is the one desired.
961196 923897750416
1910161 3648715045921
1968961 3876807419521
2061902 4251439857604
2281822 5206711639684
2528252 6392058175504
2668992 7123518296064
2698692 7282938510864
2892682 8367609153124
2920262 8527930148644
5612195 31496732718025
5625295 31643943837025
5811185 33769871104225
6210129 38565702196641
6212129 38590546712641
6581859 43320867895881
6651599 44243769256801
6808089 46350075831921
8105018 65691316780324
8161918 66616905438724
8268928 68375170269184
8508058 72387050931364
8511158 72439810500964
8521258 72611837902564
8558558 73248915039364
8682898 75392717678404
8888888 79012329876544
8891688 79062115489344
9150516 83731943066256
9152516 83768549130256
9528256 90787662401536
9608096 92315508745216
9611196 92375088550416
9910166 98211390147556
9921266 98431519042756
9965966 99320478313156
9990666 99813407123556
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For stroboNum = 31992 To 9999999
pandig = stroboNum * stroboNum
good = 1
strobo$ = LTrim(Str(stroboNum))
For i = 1 To (Len(strobo) + 1) / 2
ix = InStr("1256890", Mid(strobo, i, 1))
If ix > 0 Then
ix2 = InStr("1259860", Mid(strobo, Len(strobo) + 1 - i, 1))
If ix2 <> ix Then good = 0: Exit For
Else
good = 0: Exit For
End If
Next
If good Then
pan$ = LTrim(Str(pandig))
ReDim had(9)
For i = 1 To Len(pan)
had(Val(Mid(pan, i, 1))) = 1
Next
For i = 0 To 9
If had(i) = 0 Then good = 0: Exit For
Next
If good Then
Text1.Text = Text1.Text & strobo & " " & pandig & crlf
End If
End If
DoEvents
Next stroboNum
Text1.Text = Text1.Text & crlf & " done"
End Sub
|
Posted by Charlie
on 2017-08-26 16:31:15 |