2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに

さくらのAI Engineを使って、C#のプログラムを私が実装したものと、さくらのAI Engine で自動生成したプログラムを比較してみました。

私が実装したソースコード

私が実装したソースコードは以下の通りです。

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        // 自分の得意な言語で
        // Let's チャレンジ!!

        // 標準入力から1行読み込む(例:"1000000" のような数値文字列を想定)
        var s = Console.ReadLine();

        // 文字列を1文字ずつのリスト(char型)に変換する
        // 例:"1000000" → ['1','0','0','0','0','0','0']
        List<char> array1 = s.ToList();

        // 入力文字列の長さを取得する
        int leng = s.Length;

        // 出力用の文字列(カンマ区切りの結果を組み立てる)
        var ans = "";

        // 末尾から3桁ごとにカンマ(,)を挿入する
        // 開始位置: leng - 3(末尾から3桁目の位置)
        // 条件: i > 0(先頭より前には入れない)
        // 更新: i を 3 ずつ減らす(3桁ごと)
        for(int i = leng - 3; i > 0; i = i - 3){
            // 指定した位置 i にカンマを挿入する
            array1.Insert(i, ',');
        }

        // リストの各文字を順番に連結して、1つの文字列にする
        foreach(char c in array1){
            ans += c;
        }

        // カンマ区切りにした結果を出力する
        // 例:"1000000" → "1,000,000"
        Console.WriteLine(ans);
    }    
}

さくらのAI Engineで実装したソースコード

using System;
using System.Text;

class Program
{
    static void Main()
    {
        // 入力を文字列として受け取る
        string n = Console.ReadLine();

        // 3 文字ずつ取り出してカンマで結合する
        var result = new StringBuilder();

        for (int i = 0; i < n.Length; i += 3)
        {
            // 最初以外の場合は前にカンマを入れる
            if (i > 0)
            {
                result.Append(',');
            }

            // 3 文字分を追加する
            result.Append(n.Substring(i, 3));
        }

        Console.WriteLine(result.ToString());
    }
}

私が実装したプログラム

私が実装したプログラムは文字列をchar型のListに変換し、配列の要素の大きさを取得し、3ずつ減らした要素番号に繰り返しカンマを入れ、3ずつ減らしたカウント変数が0より大きい間、繰り返しています。

さくらのAI Engineでプロンプトを実行してできたプログラム

さくらのAI EngineのAIで生成したプログラムは,3 文字ずつ取り出してカンマで結合しています。

最後に

自分で実装したプログラムと、さくらのAI Engineで自動生成したプログラムを比較してみました。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?