Share Code Quickly

What is Harigami?

Harigami is a simple source code sharing service. You can share source code by an URL which is issued after submission.
You can also run your source code online such as Python, Ruby, JavaScript and so on.
For free.Use for code review.
Preferences
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
PHP
<!DOCTYPE html>
<HTML>
<head>
<meta charset="UTF-8">
<title>kadai_2</title>
</head>
<body>

  <script type="text/javascript">
   function check(){
     if(window.confirm('本当に削除しますか?')){
       return true;
     }else{
       window.alert('キャンセルされました');
       return false;
     }
   }
 </script>

  <?php
  if(isset($_POST["name"]) && isset($_POST["comment"]) && isset($_POST["pass"]) && empty($_POST["num"])){
    if(!empty($_POST["name"]) && !empty($_POST["comment"])){
      $name=$_POST["name"];
      $comment=$_POST["comment"];
        $datefile="kadai_2-6.txt";
        $date=date("Y-m-d");
        $fp=fopen($datefile,"a");
        $num=count(file($datefile));
        $num++;
        $pass=$_POST["pass"];
        $newdate=$num."<>".$name."<>".$comment."<>".$date."<>".$pass."<>"."\n";
        fwrite($fp,$newdate);
        fclose($fp);
        }
      else{
        echo "未入力です。";
      }
    }






    $datefile="kadai_2-6.txt";
    if(isset($_POST["delete"]) && isset($_POST["delete_pass"])){
    if (!empty($_POST["delete"]) && !empty($_POST["delete_pass"])) {
      $delete = $_POST["delete"];
      $delete_pass=$_POST["delete_pass"];
      $delCon =file($datefile);
      $fp = fopen($datefile, "w");
      for ($j = 0; $j < count($delCon); $j++) {
        $delDate = explode("<>", $delCon[$j]);
        if ($delDate[0]== $delete && $delDate[4]==$delete_pass) {
          echo "削除しました。";
          for ($j = 0; $j < count($delCon); $j++) {
            $delDate = explode("<>", $delCon[$j]);
            if($delDate[0]> $delete){
              $delDate[0]=$delDate[0]-1;
            fwrite($fp,$delDate[0]."<>".$delDate[1]."<>".$delDate[2]."<>".$delDate[3]."<>".$delDate[4]."<>"."\n");
            }
          }
          break;
        }
        else if($delDate[0]== $delete && $delDate[4]!=$delete_pass){
          echo "パスワードが間違っています。";
          fwrite($fp,$delCon[$j]);
        }
        else{
          fwrite($fp,$delCon[$j]);
        }
      }
      fclose($fp);
    }
    else if(empty($_POST["delete"]) && !empty($_POST["delete_pass"])){
      echo "削除対象番号を入力してください。";
    }
    else if(!empty($_POST["delete"]) && empty($_POST["delete_pass"])){
      echo "パスワードを入力してください。";
    }
    else{
      echo "未入力です。";
    }
  }




  $datefile="kadai_2-6.txt";
  if(isset($_POST["edit"]) && isset($_POST["edit_pass"])){
    if (!empty($_POST["edit"]) && !empty($_POST["edit_pass"])) {
    $edit=$_POST["edit"];
    $edit_pass=$_POST["edit_pass"];
    $editCon=file($datefile);
    for($i=0;$i<count($editCon);$i++) {
      $editDate=explode("<>",$editCon[$i]);
      if ($edit==$editDate[0] && $edit_pass==$editDate[4]){
      $edit_num=$editDate[0];
      $edit_name=$editDate[1];
      $edit_comment=$editDate[2];
      $edit_ID=$editDate[4];
      break;
            }
      else if($edit==$editDate[0] && $edit_pass!=$editDate[4]){
        echo "パスワードが間違っています。";
      }
          }
        }
        else if(empty($_POST["edit"]) && !empty($_POST["edit_pass"])){
          echo "編集対象番号を入力してください。";
        }
        else if(!empty($_POST["edit"]) && empty($_POST["edit_pass"])){
          echo "パスワードを入力してください。";
        }
        else{
          echo "未入力です。";
        }
       }

       if(!empty($_POST["name"]) && !empty($_POST["comment"]) && !empty($_POST["num"])){
         $name=$_POST["name"];
         $comment=$_POST["comment"];
         $num=$_POST["num"];
         $date=date("Y-m-d");
         $pass=$_POST["pass"];
         $editCon=file($datefile);
         $fp=fopen($datefile,"w");
         for($i=0;$i<count($editCon);$i++) {
           $editDate=explode("<>",$editCon[$i]);
           if ($editDate[0]==$num) {
             fwrite($fp,$num."<>".$name."<>".$comment."<>".$date."<>".$pass."<>"."\n");
           }
          else{
            fwrite($fp,$editCon[$i]);
          }
        }
        fclose($fp);
      }

  ?>



<h1>簡易掲示板</h1>
<p>ーーーーーーーーーーーーーー</p>
  <form action="kadai_2-6.php" method="post">
    <input type="hidden" name="num" value="<?php if(isset($edit_num)){echo $edit_num;}?>">
    <p>・名前</p>
      <input type="text" name="name" value="<?php if(isset($edit_name)){echo $edit_name;}?>">
      <p>・コメント</p>
    <textarea name="comment"><?php if(isset($edit_comment)){echo $edit_comment;}?></textarea>
      <p>pw:</p>
    <input type="text" name="pass" value="<?php if(isset($edit_ID)){echo $edit_ID;}?>">
      <br>
      <input type="submit"  value="投稿">
      </br>
  </form>
<p>ーーーーーーーーーーーーーー</p>
  <form action="kadai_2-6.php" method="post" onSubmit="return check()">
      <p>・削除対象番号</p>
      <input type="text" name="delete">
      <br>
      pw:<input type="text" name="delete_pass">
      </br>
      <input type="submit" value="削除">

  </form>
<p>ーーーーーーーーーーーーーー</p>
  <form action="kadai_2-6.php" method="post">
    <p>・編集対象番号</p>
    <input type="text" name="edit">
    <br>
    pw:<input type="text" name="edit_pass">
    </br>
    <input type="submit" value="編集">

  </form>

  <p>ーーーーー投稿一覧ーーーーー</p>

  <?php

    $datefile="kadai_2-6.txt";
    if(file_exists($datefile)){
    $line = file($datefile);
    foreach($line as $value){
      $array = explode("<>",$value);
      echo "$array[0] . $array[1] . $array[2] . $array[3]";
      echo "<br>";
    }
  }


  ?>

</body>
</html>
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

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 - 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 = 0
        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
        'このループはスピルで使用する場合はあった方が良い。スピルで使用しない場合はなくても良い
        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, 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 = 0
        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
        'このループはスピルで使用する場合はあった方が良い
        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 = 10000000  '試行数値の最初の数値
    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 - 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 = 0
        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
        'このループはスピルで使用する場合はあった方が良い
        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 '計算回数許容範囲
    
    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 - 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 = 0
        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
        For j = row + 1 To culcTiemsCapa - 1 'このループはスピルで使用する場合はあった方が良い
            arr(j, col) = ""
        Next
        col = col + 1
    Next
    collatz = arr
End Function
年末年始は機械学習・深層学習を勉強しませんか?
広告
未経験から最短でエンジニアへの転職を目指すなら