anonymous コラッツ予想 計算過程:行方向へ出力
VBA
Option Explicit

Sub main()
    Cells.ClearContents
    
    Const tryMin As Variant = 1 '試行数値の最初の数値
    Const tryTimes As Long = 1000 'tyrMinから何番目まで計算したいか。※上限16384(Excelの最大列数)
    
    Const culcTiemsCapa As Long = 1000 '計算回数許容範囲
    '※処理速度に影響を与えるため、tryMin + tryTimis < 100000000までは1000固定
    
    
    Range("A1").Resize(culcTiemsCapa + 2, tryTimes) = CollatzFullVertical(tryMin, tryTimes, culcTiemsCapa)
                
End Sub

'計算過程:行方向へ出力
Function CollatzFullVertical( _
    ByVal tryMin As Variant, _
    ByVal tryTimes As Long, _
    ByVal culcTiemsCapa As Long) _
    As Variant
    
    Dim tryMax As Variant: tryMax = tryMin + tryTimes - 1
    ReDim arr(culcTiemsCapa + 1, tryTimes - 1) As Variant
    Dim i As Variant, j As Long
    Dim n As Variant, row As Long, col As Long
    
    
    For i = tryMin To tryMax
        n = i
        row = 1
        arr(row, col) = n
        Do While n <> 1
            If Right(n, 1) Mod 2 = 0 Then 'Rigth関数はオーバーフロー対策
                n = n / 2
            Else
                n = n * 3 + 1
            End If
            row = row + 1
            arr(row, col) = n
        Loop
        arr(0, col) = row - 1 & "回"
        'このループはスピルで使用する場合はあった方が良い。スピルで使用しない場合はなくても良い
        For j = row + 1 To culcTiemsCapa + 1
            arr(j, col) = ""
        Next
        '--------------------------------------------
        col = col + 1
    Next
    CollatzFullVertical = arr
End Function
anonymous コラッツ予想 計算回数のみ出力
VBA
Option Explicit


Sub main()
    Cells.ClearContents
    
    Const tryMin As Variant = 1 '試行数値の最初の数値
    Const tryTimes As Long = 1000 'tyrMinから何番目まで計算したいか。
        
    Range("A1").Resize(tryTimes, 2) = CollatzOnlyResult(tryMin, tryTimes)
                
End Sub

'計算回数のみ出力
Function CollatzOnlyResult( _
    ByVal tryMin As Variant, _
    ByVal tryTimes As Long) _
    As Variant
    
    Dim tryMax As Variant: tryMax = tryMin + tryTimes - 1
    ReDim arr(tryTimes - 1, 1) As Variant
    Dim i As Variant, n As Variant, cnt As Long, row As Long
    
    
    For i = tryMin To tryMax
        n = i
        cnt = 0
        arr(row, 0) = n
        Do While n <> 1
            If Right(n, 1) Mod 2 = 0 Then 'Rigth関数はオーバーフロー対策
                n = n / 2
            Else
                n = n * 3 + 1
            End If
            cnt = cnt + 1
        Loop
        arr(row, 1) = cnt & "回"
        row = row + 1
    Next
    CollatzOnlyResult = arr
End Function


anonymous コラッツ予想 計算過程:列方向へ出力
VBA
Option Explicit

Sub main()
    Cells.ClearContents
    
    Const tryMin As Variant = 1 '試行数値の最初の数値
    Const tryTimes As Long = 1000 'tyrMinから何番目まで計算したいか。
    
    Const culcTiemsCapa As Long = 1000 '計算回数許容範囲 ※処理速度に影響を与えるため、tryMinに応じて要変更
    '※culcTiemsCapaの上限16382(Excelの最大列数-2)
    
    Range("A1").Resize(tryTimes, culcTiemsCapa + 2) = CollatzFullHorizontal(tryMin, tryTimes, culcTiemsCapa)
                
End Sub

'計算過程:列方向へ出力
Function CollatzFullHorizontal( _
    ByVal tryMin As Variant, _
    ByVal tryTimes As Long, _
    ByVal culcTiemsCapa As Long) _
    As Variant
    
    Dim tryMax As Variant: tryMax = tryMin + tryTimes - 1
    ReDim arr(tryTimes - 1, culcTiemsCapa + 1) As Variant
    Dim i As Variant, j As Long
    Dim n As Variant, row As Long, col As Long
    
    
    For i = tryMin To tryMax
        n = i
        col = 1
        arr(row, col) = n
        Do While n <> 1
            If Right(n, 1) Mod 2 = 0 Then 'Rigth関数はオーバーフロー対策
                n = n / 2
            Else
                n = n * 3 + 1
            End If
            col = col + 1
            arr(row, col) = n
        Loop
        arr(row, 0) = col - 1 & "回"
        'このループはスピルで使用する場合はあった方が良い。スピルで使用しない場合はなくても良い
        For j = col + 1 To culcTiemsCapa + 1
            arr(row, j) = ""
        Next
        '--------------------------------------------
        row = row + 1
    Next
    CollatzFullHorizontal = arr
End Function




anonymous コラッツ予想 計算過程:行方向へ出力
VBA
Option Explicit

Sub main()
    Cells.ClearContents
    
    Const tryMin As Variant = 1 '試行数値の最初の数値
    Const tryTimes As Long = 1000 'tyrMinから何番目まで計算したいか。※上限16384(Excelの最大列数)
    
    Const culcTiemsCapa As Long = 1000 '計算回数許容範囲 ※処理速度に影響を与えるため、tryMinに応じて要変更
    
    
    Range("A1").Resize(culcTiemsCapa + 2, tryTimes) = CollatzFullVertical(tryMin, tryTimes, culcTiemsCapa)
                
End Sub

'計算過程:行方向へ出力
Function CollatzFullVertical( _
    ByVal tryMin As Variant, _
    ByVal tryTimes As Long, _
    ByVal culcTiemsCapa As Long) _
    As Variant
    
    Dim tryMax As Variant: tryMax = tryMin + tryTimes - 1
    ReDim arr(culcTiemsCapa + 1, tryTimes - 1) As Variant
    Dim i As Variant, j As Long
    Dim n As Variant, row As Long, col As Long
    
    
    For i = tryMin To tryMax
        n = i
        row = 1
        arr(row, col) = n
        Do While n <> 1
            If Right(n, 1) Mod 2 = 0 Then 'Rigth関数はオーバーフロー対策
                n = n / 2
            Else
                n = n * 3 + 1
            End If
            row = row + 1
            arr(row, col) = n
        Loop
        arr(0, col) = row - 1 & "回"
        'このループはスピルで使用する場合はあった方が良い。スピルで使用しない場合はなくても良い
        For j = row + 1 To culcTiemsCapa + 1
            arr(j, col) = ""
        Next
        '--------------------------------------------
        col = col + 1
    Next
    CollatzFullVertical = arr
End Function
anonymous No title
VBA
Option Explicit

Sub main()
    Cells.ClearContents
    
    Const tryMin As Variant = 1 '試行数値の最初の数値
    Const tryTimes As Long = 1000 'tyrMinから何番目まで計算したいか。※上限16384(Excelの最大列数)
    
    Const culcTiemsCapa As Long = 1000 '計算回数許容範囲 ※処理速度に影響を与えるため、tryMinに応じて要変更
    'culcTiemsCapa = 1000で tryMin = 10000000程度までは実行可能か
    
    Range("A1").Resize(culcTiemsCapa + 2, tryTimes) = collatz(tryMin, tryTimes, culcTiemsCapa)
                
End Sub

Function collatz( _
    ByVal tryMin As Variant, _
    ByVal tryTimes As Long, _
    ByVal culcTiemsCapa As Long) _
    As Variant
    
    Dim tryMax As Variant: tryMax = tryMin + tryTimes - 1
    ReDim arr(culcTiemsCapa + 1, tryTimes - 1) As Variant
    Dim i As Variant, j As Long
    Dim n As Variant, row As Long, col As Long
    
    
    For i = tryMin To tryMax
        n = i
        row = 1
        arr(row, col) = n
        Do While n <> 1
            If Right(n, 1) Mod 2 = 0 Then 'Rigth関数はオーバーフロー対策
                n = n / 2
            Else
                n = n * 3 + 1
            End If
            row = row + 1
            arr(row, col) = n
        Loop
        arr(0, col) = row - 1 & "回"
        'このループはスピルで使用する場合はあった方が良い。スピルで使用しない場合はなくても良い
        For j = row + 1 To culcTiemsCapa + 1
            arr(j, col) = ""
        Next
        '--------------------------------------------
        col = col + 1
    Next
    collatz = arr
End Function


anonymous No title
VBA
Option Explicit

Sub main()
    Cells.ClearContents
    
    Const tryMin As Variant = 1 '試行数値の最初の数値
    Const tryTimes As Long = 1000 'tyrMinから何番目まで計算したいか。※上限16384(Excelの最大列数)
    
    Const culcTiemsCapa As Long = 1000 '計算回数許容範囲 ※処理速度に影響を与えるため、tryMinに応じて要変更
    'culcTiemsCapa = 1000で tryMin = 10000000程度までは実行可能か
    
    Range("A1").Resize(culcTiemsCapa + 2, tryTimes) = collatz(tryMin, tryTimes, culcTiemsCapa)
                
End Sub

Function collatz( _
    ByVal tryMin As Variant, _
    ByVal tryTimes As Long, _
    ByVal culcTiemsCapa As Long) _
    As Variant
    
    Dim tryMax As Variant: tryMax = tryMin + tryTimes - 1
    ReDim arr(culcTiemsCapa + 1, tryTimes - 1) As Variant
    Dim i As Variant, j As Long
    Dim n As Variant, row As Long, col As Long
    
    
    For i = tryMin To tryMax
        n = i
        row = 1
        arr(row, col) = n
        Do While n <> 1
            If Right(n, 1) Mod 2 = 0 Then 'Rigth関数はオーバーフロー対策
                n = n / 2
            Else
                n = n * 3 + 1
            End If
            row = row + 1
            arr(row, col) = n
        Loop
        arr(0, col) = row - 1 & "回"
        'このループはスピルで使用する場合はあった方が良い。スピルで使用しない場合はなくても良い
        For j = row + 1 To culcTiemsCapa
            arr(j, col) = ""
        Next
        '--------------------------------------------
        col = col + 1
    Next
    collatz = arr
End Function


anonymous No title
VBA
Option Explicit

Sub main()
    Cells.ClearContents
    
    Const tryMin As Variant = 27 '試行数値の最初の数値
    Const tryTimes As Long = 1 'tyrMinから何番目まで計算したいか。※上限16384(Excelの最大列数)
    
    Const culcTiemsCapa As Long = 111 '計算回数許容範囲 ※処理速度に影響を与えるため、tryMinに応じて要変更
    'culcTiemsCapa = 1000で tryMin = 10000000程度までは実行可能か
    
    Range("A1").Resize(culcTiemsCapa + 2, tryTimes) = collatz(tryMin, tryTimes, culcTiemsCapa)
                
End Sub

Function collatz( _
    ByVal tryMin As Variant, _
    ByVal tryTimes As Long, _
    ByVal culcTiemsCapa As Long) _
    As Variant
    
    Dim tryMax As Variant: tryMax = tryMin + tryTimes - 1
    ReDim arr(culcTiemsCapa + 1, tryTimes - 1) As Variant
    Dim i As Variant, j As Long
    Dim n As Variant, row As Long, col As Long
    
    
    For i = tryMin To tryMax
        n = i
        row = 1
        arr(row, col) = n
        Do While n <> 1
            If Right(n, 1) Mod 2 = 0 Then 'Rigth関数はオーバーフロー対策
                n = n / 2
            Else
                n = n * 3 + 1
            End If
            row = row + 1
            arr(row, col) = n
        Loop
        arr(0, col) = row - 1 & "回"
        'このループはスピルで使用する場合はあった方が良い。スピルで使用しない場合はなくても良い
        For j = row + 1 To culcTiemsCapa
            arr(j, col) = ""
        Next
        '--------------------------------------------
        col = col + 1
    Next
    collatz = arr
End Function


anonymous No title
VBA
Option Explicit

Sub main()
    Cells.ClearContents
    
    Const tryMin As Variant = 1 '試行数値の最初の数値
    Const tryTimes As Long = 1000 'tyrMinから何番目まで計算したいか。※上限16384(Excelの最大列数)
    
    Const culcTiemsCapa As Long = 1000 '計算回数許容範囲 ※処理速度に影響を与えるため、tryMinに応じて要変更
    'culcTiemsCapa = 1000で tryMin = 10000000程度までは実行可能か
    
    Range("A1").Resize(culcTiemsCapa, tryTimes) = collatz(tryMin, tryTimes, culcTiemsCapa)
                
End Sub

Function collatz( _
    ByVal tryMin As Variant, _
    ByVal tryTimes As Long, _
    ByVal culcTiemsCapa As Long) _
    As Variant
    
    Dim tryMax As Variant: tryMax = tryMin + tryTimes - 1
    ReDim arr(culcTiemsCapa, tryTimes - 1) As Variant
    Dim i As Variant, j As Long
    Dim n As Variant, row As Long, col As Long
    
    
    For i = tryMin To tryMax
        n = i
        row = 1
        arr(row, col) = n
        Do While n <> 1
            If Right(n, 1) Mod 2 = 0 Then 'Rigth関数はオーバーフロー対策
                n = n / 2
            Else
                n = n * 3 + 1
            End If
            row = row + 1
            arr(row, col) = n
        Loop
        arr(0, col) = row - 1 & "回"
        'このループはスピルで使用する場合はあった方が良い。スピルで使用しない場合はなくても良い
        For j = row + 1 To culcTiemsCapa
            arr(j, col) = ""
        Next
        '--------------------------------------------
        col = col + 1
    Next
    collatz = arr
End Function
anonymous No title
VBA
Option Explicit

Sub main()
    Cells.ClearContents
    
    Const tryMin As Variant = 10000000 '試行数値の最初の数値
    Const tryTimes As Long = 100 'tyrMinから何番目まで計算したいか。※上限16384(Excelの最大列数)
    
    Const culcTiemsCapa As Long = 1000 '計算回数許容範囲 ※処理速度に影響を与えるため、tryMinに応じて要変更
    'culcTiemsCapa = 1000で tryMin = 10000000程度までは実行可能か
    
    Range("A1").Resize(culcTiemsCapa, tryTimes) = collatz(tryMin, tryTimes, culcTiemsCapa)
                
End Sub

Function collatz( _
    ByVal tryMin As Variant, _
    ByVal tryTimes As Long, _
    ByVal culcTiemsCapa As Long) _
    As Variant
    
    Dim tryMax As Variant: tryMax = tryMin + tryTimes - 1
    ReDim arr(culcTiemsCapa, tryTimes - 1) As Variant
    Dim i As Variant, j As Long
    Dim n As Variant, row As Long, col As Long
    
    
    For i = tryMin To tryMax
        n = i
        row = 1
        arr(row, col) = n
        Do While n <> 1
            If Right(n, 1) Mod 2 = 0 Then 'Rigth関数はオーバーフロー対策
                n = n / 2
            Else
                n = n * 3 + 1
            End If
            row = row + 1
            arr(row, col) = n
        Loop
        arr(0, col) = row - 1 & "回"
        'このループはスピルで使用する場合はあった方が良い。スピルで使用しない場合はなくても良い
        For j = row + 1 To culcTiemsCapa
            arr(j, col) = ""
        Next
        '--------------------------------------------
        col = col + 1
    Next
    collatz = arr
End Function

anonymous No title
VBA
Option Explicit

Sub main()
    Cells.ClearContents
    
    Const tryMin As Variant = 1 '試行数値の最初の数値
    Const tryTimes As Long = 1000 'tyrMinから何番目まで計算したいか。※上限16384(Excelの最大列数)
    
    Const culcTiemsCapa As Long = 1000 '計算回数許容範囲 ※処理速度に影響を与えるため、tryMinに応じて要変更
    'culcTiemsCapa = 1000で tryMin = 10000000程度までは実行確認済み
    
    Range("A1").Resize(culcTiemsCapa, tryTimes) = collatz(tryMin, tryTimes, culcTiemsCapa)
                
End Sub

Function collatz( _
    ByVal tryMin As Variant, _
    ByVal tryTimes As Long, _
    ByVal culcTiemsCapa As Long) _
    As Variant
    
    Dim tryMax As Variant: tryMax = tryMin + tryTimes - 1
    ReDim arr(culcTiemsCapa, tryTimes - 1) As Variant
    Dim i As Variant, j As Long
    Dim n As Variant, row As Long, col As Long
    
    
    For i = tryMin To tryMax
        n = i
        row = 1
        arr(row, col) = n
        Do While n <> 1
            If Right(n, 1) Mod 2 = 0 Then
                n = n / 2
            Else
                n = n * 3 + 1
            End If
            row = row + 1
            arr(row, col) = n
        Loop
        arr(0, col) = row - 1 & "回"
        'このループはスピルで使用する場合はあった方が良い。スピルで使用しない場合はなくても良い
        For j = row + 1 To culcTiemsCapa
            arr(j, col) = ""
        Next
        '--------------------------------------------
        col = col + 1
    Next
    collatz = arr
End Function

Don't you submit code?
Submit