Loading...
    • 開発者ガイド
    • API リファレンス
    • MCP
    • リソース
    • リリースノート
    Search...
    ⌘K
    リソース
    概要用語集システムプロンプト
    プロンプトライブラリCosmic KeystrokesCorporate clairvoyantWebsite wizardExcel 数式エキスパートGoogle Apps scripterPython バグバスタータイムトラベルコンサルタントストーリーテリングの相棒出典を明記SQL ソーサラー夢の解釈者ダジャレ名人料理クリエイターかばん語詩人Hal のユーモアヘルパーLaTeX の達人ムードカラライザーGit gud直喩の達人倫理的ジレンマナビゲーター会議の書記慣用句イルミネーターコードコンサルタント関数ファブリケーター新語クリエイターCSV コンバーター絵文字エンコーダー文章ポリッシャー多角的視点の考察トリビアジェネレーターマインドフルネスメンター小学2年生向け簡略化VR フィットネスイノベーターPII クリーナーメモの達人キャリアコーチ採点の達人早口言葉面接質問クラフター文法の精霊なぞなぞコード解説者エイリアン人類学者データオーガナイザーブランドビルダー効率性エスティメーターレビュー分類器方向デコーダーモチベーションの女神メール抽出ツールマスターモデレーター授業プランナーソクラテスの賢者頭韻の錬金術師未来のファッションアドバイザー多言語スーパーパワー製品ネーミングのプロ哲学的考察スプレッドシートソーサラーSF シナリオシミュレーターアダプティブエディターBabel's broadcastsツイートのトーン検出空港コードアナリスト
    Console
    Log in
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Partners

    • Amazon Bedrock
    • Google Cloud's Vertex AI

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Help and security

    • Availability
    • Status
    • Support
    • Discord

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    プロンプトライブラリ

    関数ファブリケーター

    詳細な仕様に基づいてPython関数を作成します。

    このプロンプトを開発者向けコンソールにコピーして、ぜひお試しください!

    内容
    Systemあなたのタスクは、提供された自然言語のリクエストに基づいてPython関数を作成することです。リクエストには、入力パラメータや期待される戻り値を含む、関数の望ましい機能が記述されます。与えられた仕様に従って関数を実装し、エッジケースの処理、必要なバリデーションの実行、Pythonプログラミングのベストプラクティスに従うようにしてください。ロジックを説明し、他の開発者が実装を理解するのを助けるために、コードに適切なコメントを含めてください。
    User数独パズルを解くことができる関数が欲しいです。この関数は9x9の数独グリッドを入力として受け取り、空のセルは値0で表されます。関数はバックトラッキングアルゴリズムを使用してパズルを解き、解かれたグリッドを返す必要があります。パズルが解けない場合はNoneを返す必要があります。また、入力グリッドが有効な数独パズルであることを検証する必要もあります。

    出力例

    Python
    def solve_sudoku(grid):
       def is_valid(row, col, num):
           # Check if the number is valid in the current row and column
           for i in range(9):
               if grid[row][i] == num or grid[i][col] == num:
                   return False
    
           # Check if the number is valid in the current 3x3 subgrid
           start_row, start_col = (row // 3) * 3, (col // 3) * 3
           for i in range(3):
               for j in range(3):
                   if grid[start_row + i][start_col + j] == num:
                       return False
    
           return True
    
       def backtrack(row, col):
           # If we have filled all cells, the puzzle is solved
           if row == 9:
               return True
    
           # Move to the next row if we have reached the end of the current row
           if col == 9:
               return backtrack(row + 1, 0)
    
           # If the current cell is already filled, move to the next cell
           if grid[row][col] != 0:
               return backtrack(row, col + 1)
    
           # Try filling the current cell with numbers from 1 to 9
           for num in range(1, 10):
               if is_valid(row, col, num):
                   grid[row][col] = num
                   if backtrack(row, col + 1):
                       return True
                   grid[row][col] = 0
    
           # If no valid number is found, backtrack
           return False
    
       # Validate the input grid
       if not all(len(row) == 9 and all(0 <= cell <= 9 for cell in row) for row in grid):
           return None
    
       # Start the backtracking algorithm
       if backtrack(0, 0):
           return grid
       else:
           return None
    

    APIリクエスト

    Was this page helpful?

    • APIリクエスト