+----+----+----+----+
|AN | ?? | IP | ST |
+----+----+----+----+
| ?? | ?? |??? |??? |
+----+----+----+----+
| ?? | ?? |??? |??? |
+----+----+----+----+
| ?? | ?? |PUZ |ZLE |
+----+----+----+----+
Replace each letter with a different digit in the above 4x4 grid such that:
- Each of the four rows and each of the four columns are in arithmetic sequence.
- None of the numbers can contain any leading zero.
- Each question mark denotes any digit whether same or different.
*** Adapted from Andrey Bogdanov, which appeared in an Internet competition.
DefDbl A-Z
Dim crlf$
Function mform$(x, t$)
a$ = Format$(x, t$)
If Len(a$) < Len(t$) Then a$ = Space$(Len(t$) - Len(a$)) & a$
mform$ = a$
End Function
Private Sub Form_Load()
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
DoEvents
a$ = "1234567890": h$ = a$
Do
If Mid(a$, 1, 1) <> "0" And Mid(a$, 3, 1) <> "0" And Mid(a$, 5, 1) <> "0" And Mid(a$, 4, 1) <> "0" And Mid(a$, 8, 1) <> "0" Then
an = Val(Mid(a$, 1, 2))
ip = Val(Mid(a$, 3, 2))
st = Val(Mid(a$, 5, 2))
puz = 100 * Val(Mid(a$, 4, 1)) + Val(Mid(a$, 7, 2))
zle = 100 * (puz Mod 10) + Val(Mid(a$, 9, 2))
c4inc = (zle - st) / 3
If c4inc = Int(c4inc) Then
c3inc = (puz - ip) / 3
If c3inc = Int(c3inc) Then
r1c2 = an + st - ip
If ip - an = 2 * (st - ip) Then
r4inc = zle - puz
r4c1 = puz - 2 * r4inc
r4c2 = puz - r4inc
c1inc = (r4c1 - an) / 3
c2inc = (r4c2 - r1c2) / 3
If c1inc = Int(c1inc) And c2inc = Int(c2inc) Then
r2c1 = an + c1inc: r3c1 = r2c1 + c1inc
r2c2 = r1c2 + c2inc: r3c2 = r2c2 + c2inc
r2c3 = ip + c3inc: r3c3 = r2c3 + c3inc
r2c4 = st + c4inc: r3c4 = r2c4 + c4inc
If r2c4 - r2c3 = r2c3 - r2c2 And r2c3 - r2c2 = r2c2 - r2c1 Then
If r3c4 - r3c3 = r3c3 - r3c2 And r3c3 - r3c2 = r3c2 - r3c1 Then
If r4c1 > 9 And r4c2 < 100 And r2c4 > 99 Then
Text1.Text = Text1.Text & "ANIPSTUZLE" + crlf
Text1.Text = Text1.Text & a$ & crlf & crlf
Text1.Text = Text1.Text & mform(an, "###0") & mform(r1c2, "###0") & mform(ip, "###0") & mform(st, "###0") + crlf + crlf
Text1.Text = Text1.Text & mform(r2c1, "###0") & mform(r2c2, "###0") & mform(r2c3, "###0") & mform(r2c4, "###0") + crlf + crlf
Text1.Text = Text1.Text & mform(r3c1, "###0") & mform(r3c2, "###0") & mform(r3c3, "###0") & mform(r3c4, "###0") + crlf + crlf
Text1.Text = Text1.Text & mform(r4c1, "###0") & mform(r4c2, "###0") & mform(puz, "###0") & mform(zle, "###0") + crlf + crlf
DoEvents
End If
End If
End If
End If
End If
End If
End If
End If
permute a$
Loop Until a$ = h$
End Sub
finds
the letter correspondences are:
ANIPSTUZLE
9581746230
and the completed grid is:
95 88 81 74
72 90 108 126
49 92 135 178
26 94 162 230
|
Posted by Charlie
on 2014-05-30 12:01:48 |