過去ログ

???
Option Explicit: Dim a(5) As Integer
Sub Macro1()
Cells(1, 1).Value = 0
Call saiki(1)
End Sub
Sub saiki(ByVal n As Integer)
Dim sum As Integer, j As Integer
a(n) = 1
While a(n) <= 5
If onaji(n) = 0 Then
If n < 5 - 1 Then
Call saiki(n + 1)
Else
a(5) = 5
For j = 1 To 5 - 1 : a(5) = a(5) + j - a(j) : Next j
sum = 0
For j = 1 To 5 - 1
sum = sum + Abs(a(j) - a(j+1))
Next j
If sum Mod 2 = 0 Then
Cells(1, 1).Value = Cells(1, 1).Value + 1
For j = 1 To 5
Cells(Cells(1, 1).Value, j + 1).Value = a(j)
Next j
Cells(Cells(1, 1).Value, 7).Value = sum
End If
End If
End If
a(n) = a(n) + 1
Wend
End Sub
Private Function onaji(ByVal n As Integer) As Integer
Dim j As Integer
onaji = 0 : j = 1
While onaji = 0 And j < n
If a(j) = a(n) Then onaji = 1 Else j = j + 1
Wend
End Function
   12月24日(木) 9:01:47     44008

過去問題一覧へ戻る