『今週の問題』第188回 解答


◆兵庫県 sinapusu さんからの解答

Option Explicit
’ExcelVBAコード
Dim point As Long
Dim numbers(9) As Long
Dim times(9) As Long
Dim time_forst
Dim j As Long
Sub main()
time_forst = Array(0, 3, 1, 3, 1, 3, 3, 3, 3, 3)
Dim i
j = 0
For i = 0 To 9
      times(i) = time_forst(i)
      numbers(i) = 0
Next
point = 0


Do While point > -1
If Value_Max = True Then
Move_Back
    Else
    If numbers(times(point)) = 0 Then
        Move_Next
    Else
       times(point) = times(point) + 1
    End If
End If
DoEvents
Loop
End Sub

Function Value_Max()
Dim a
    a = True
    If (point Mod 2) = 1 Then
        If times(point) > 2 And times(point) < 10 Then a = False
    ElseIf point = 6 Or point = 8 Then
        If times(point) > 2 And times(point) < 6 Then a = False
    ElseIf point = 2 Or point = 4 Then
        If times(point) > 0 And times(point) < 3 Then a = False
    Else
        If times(point) = 0 Then a = False
    End If
Value_Max = a
End Function

Sub Move_Next()
    If point > 8 Then
            putDate
            point = 9
            numbers(times(point)) = 0
            times(point) = times(point) + 1
        Else
            numbers(times(point)) = 1
            point = point + 1
            times(point) = time_forst(point)
    End If
End Sub

Sub Move_Back()
If point < 1 Then
        point = point - 1
    Else
        point = point - 1
        numbers(times(point)) = 0
        times(point) = times(point) + 1
    End If
End Sub
Sub putDate()

Dim i
Dim s

s = times(0) & times(1) & "月" & times(2) & times(3) & "日" & times(4) & times(5) & "時" & times(6) & times(7) & "分" & times(8) & times(9) & "秒"
If IsDate(s) Then
j = j + 1
Cells(j, 1) = CDate(s)
Else
'Debug.Print s
End If
End Sub


 ◆ 問題へもどる

 ◆ 今週の問題

数学の部屋へもどる