|
??? |
|
エクセルのマクロ
最初、三角形の判定を、三角不等式|a−b|<c<a+bでやったのですが、だめでした。 辺の長さを求める際に、不正確な切り捨て計算をやってしまったのですね。 Option Explicit '16(0,3) 17(1,3) 18(2,3) 19(3,3) 20(4,3) '11(0,2) 12(1,2) 13(2,2) 14(3,2) 15(4,2) '06(0,1) 07(1,1) 08(2,1) 09(3,1) 10(4,1) '01(0,0) 02(1,0) 03(2,0) 04(3,0) 05(4,0) Sub Macro1() Cells(1, 1).Value = 0 Dim n1 As Integer, n2 As Integer, n3 As Integer Dim n1x As Integer, n1y As Integer Dim n2x As Integer, n2y As Integer Dim n3x As Integer, n3y As Integer For n1 = 1 To 20 - 2 n1x = xy(n1, 1): n1y = xy(n1, 2) For n2 = n1 + 1 To 20 - 1 n2x = xy(n2, 1): n2y = xy(n2, 2) For n3 = n2 + 1 To 20 n3x = xy(n3, 1): n3y = xy(n3, 2) If (n2y - n1y) * (n3x - n2x) <> (n3y - n2y) * (n2x - n1x) Then Cells(1, 1).Value = Cells(1, 1).Value + 1 Cells(Cells(1, 1).Value, 2).Value = Str(n1) + "(" + Str(n1x) + "," + Str(n1y) + ")" Cells(Cells(1, 1).Value, 3).Value = Str(n2) + "(" + Str(n2x) + "," + Str(n2y) + ")" Cells(Cells(1, 1).Value, 4).Value = Str(n3) + "(" + Str(n3x) + "," + Str(n3y) + ")" End If Next n3 Next n2 Next n1 End Sub Private Function xy(ByVal n As Integer, ByVal j As Integer) As Integer If j = 1 Then xy = (n - 1) Mod 5 Else xy = (n - 1) \ 5 End If End Function |
|
8月1日(木) 10:45:53
40776 |