Sudoku Solver Added (C++)#38
Conversation
|
please follow and star i will merge |
|
Merge it @abhishekSharmaGithub |
|
@abhishekSharmaGithub when will you merge ??? |
There was a problem hiding this comment.
Pull request overview
This pull request adds a Sudoku solver implementation in C++ along with a GitHub Actions workflow file. The PR description states "Added a code of Sudoku Solver in C++", but the changes include an unrelated workflow configuration file that appears to set up an automated code review/generation system.
Changes:
- Added SudokuSolver.cpp containing a backtracking-based Sudoku solver implementation
- Added .github/workflows/opencode.yml workflow file for automated code assistance (unrelated to PR description)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| SudokuSolver.cpp | Implements a backtracking algorithm to solve Sudoku puzzles with functions for checking validity and solving the puzzle |
| .github/workflows/opencode.yml | Adds GitHub Actions workflow for OpenCode agent integration with various LLM providers and MCP tools |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| using namespace std; | ||
| bool isSafe(int row,int col,vector<vector<int>> &board,int val) | ||
| { | ||
| for(int i = 0;i<board.size();i++) |
There was a problem hiding this comment.
Inconsistent spacing in for loop. Add spaces for better readability: for (int i = 0; i < board.size(); i++). The current format for(int i = 0;i<board.size();i++) is harder to read.
| for(int row = 0 ;row < n;row++) | ||
| { | ||
| for(int col = 0;col < n;col++) | ||
| { | ||
| //cell empty | ||
| if(board[row][col] == 0) | ||
| { //Trying every value which can fit in that | ||
| //box like we solve sudoku | ||
| for(int val = 1;val <= 9;val++) |
There was a problem hiding this comment.
Inconsistent spacing in for loops. Add spaces for better readability: for (int row = 0; row < n; row++) on line 29, for (int col = 0; col < n; col++) on line 31, and for (int val = 1; val <= 9; val++) on line 37.
| permissions: | ||
| id-token: write | ||
| contents: write | ||
| pull-requests: write | ||
| issues: write | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 1 | ||
| persist-credentials: false | ||
|
|
||
| - name: Write OpenCode auth.json | ||
| shell: bash | ||
| run: | | ||
| mkdir -p ~/.local/share/opencode | ||
| echo "${{ secrets.OPENCODE_AUTH_JSON_B64 }}" | base64 -d > ~/.local/share/opencode/auth.json | ||
| chmod 600 ~/.local/share/opencode/auth.json | ||
|
|
||
| - name: Clone and start local proxy | ||
| shell: bash | ||
| run: | | ||
| git clone --depth 1 https://github.com/dhruvkej9/opencode-local-proxy.git /tmp/opencode-local-proxy | ||
| cd /tmp/opencode-local-proxy | ||
| export OPENCODE_PROXY_PORT=4318 | ||
| node proxy.mjs & | ||
| sleep 3 | ||
| curl -s http://127.0.0.1:4318/health | ||
|
|
||
| - name: Setup Bun | ||
| uses: oven-sh/setup-bun@v2 | ||
|
|
||
| - name: Configure OpenCode variant | ||
| shell: bash | ||
| run: | | ||
| mkdir -p ~/.config/opencode | ||
| cat > ~/.config/opencode/opencode.json <<'JSON' | ||
| { | ||
| "$schema": "https://opencode.ai/config.json", | ||
| "model": "local-proxy/kimi-k2.5-free", | ||
| "agent": { | ||
| "build": { | ||
| "model": "local-proxy/kimi-k2.5-free", | ||
| "variant": "high", | ||
| "prompt": "Use ripgrep (rg) instead of grep/glob/find for searching. Commands: rg 'pattern' (search content), rg --files (list all files), rg --files -g '*.ext' (filter by extension), rg --files -g '*.{js,py,md}' (multiple extensions), rg 'pattern' -g '*.ext' (search in specific file types), rg -i 'pattern' (case insensitive), rg -C 3 'pattern' (show 3 lines context). ripgrep is faster and respects .gitignore by default. Use context7 for latest package info.\n\nUse websearch when local context is insufficient. At least one websearch is recommended for each task before finalizing.\n\nYou are an AI agent with persistent memory powered by SuperMemory MCP (mcp.supermemory.ai).\n\nMemory rules:\n- Before responding, call supermemory_recall only when the request benefits from past context (preferences, prior decisions, project history, recurring issues).\n- Skip recall for direct mechanical actions that already contain full context (e.g., explicit save/forget memory commands, simple one-shot confirmations).\n- Prioritize the most recent and most relevant memories; if nothing useful is found, continue normally.\n- Store memory with supermemory_memory only when there is durable value.\n- Save only durable learnings, reusable patterns, and solved-issue knowledge (root cause + fix).\n- Do not save task logs, todos, progress updates, generic work-completed notes, or low-value status noise.\n- Update incrementally; avoid overwriting prior memory unless explicitly instructed.\n\nWorkflow:\n1) Recall relevant context when useful.\n2) Reason using recalled context plus current input.\n3) Save durable insights if any.\n4) Respond concisely and personalize using recalled memory when relevant.\n\nFallback:\n- If supermemory tools fail, continue and include a concise memory-candidate summary for later storage.\n\nUse MCP tools intentionally:\n- Use chrome-devtools MCP for browser debugging, performance bottlenecks, network waterfall, runtime errors, DOM/CSS inspection, and rendering issues.\n- For frontend or integration fixes, validate behavior and include what you verified in your response." | ||
| } | ||
| }, | ||
| "watcher": { | ||
| "ignore": [ | ||
| "node_modules/**", | ||
| "dist/**", | ||
| ".git/**" | ||
| ] | ||
| }, | ||
| "mcp": { | ||
| "supermemory": { | ||
| "type": "remote", | ||
| "url": "https://mcp.supermemory.ai/mcp", | ||
| "headers": { | ||
| "Authorization": "Bearer ${{ secrets.SUPERMEMORY_API_KEY }}" |
There was a problem hiding this comment.
The workflow uses secrets (OPENCODE_AUTH_JSON_B64 and SUPERMEMORY_API_KEY) that may not be configured in the repository. Additionally, the workflow grants broad permissions including contents: write and pull-requests: write. If this workflow is intentionally being added, ensure these secrets are properly configured and the permissions are appropriate for the intended use case.
| @@ -0,0 +1,64 @@ | |||
| #include <bits/stdc++.h> | |||
There was a problem hiding this comment.
Using #include <bits/stdc++.h> is a non-standard header that is compiler-specific (primarily GCC) and includes the entire C++ standard library, leading to increased compilation time and reduced portability. Instead, include only the specific headers needed. For this code, you would need: #include <iostream> and #include <vector>.
| #include <bits/stdc++.h> | |
| #include <iostream> | |
| #include <vector> |
| @@ -0,0 +1,64 @@ | |||
| #include <bits/stdc++.h> | |||
| using namespace std; | |||
There was a problem hiding this comment.
Using using namespace std; is generally discouraged, especially in header files or code that may be included in larger projects. It pollutes the global namespace and can lead to name conflicts. Consider using explicit std:: prefixes for standard library types (e.g., std::vector) or use specific using declarations if needed.
| bool aageSolutionPossible = solve(board); | ||
| if(aageSolutionPossible) |
There was a problem hiding this comment.
The variable name aageSolutionPossible appears to be in Hindi/Hinglish (where "aage" means "ahead" or "forward"). For consistency and broader understanding, use English variable names. Consider renaming to isSolutionPossible or canSolve.
| bool aageSolutionPossible = solve(board); | |
| if(aageSolutionPossible) | |
| bool isSolutionPossible = solve(board); | |
| if(isSolutionPossible) |
| name: opencode | ||
|
|
||
| on: | ||
| issue_comment: | ||
| types: [created] | ||
| pull_request_review_comment: | ||
| types: [created] | ||
|
|
||
| jobs: | ||
| opencode: | ||
| if: | | ||
| github.actor != 'opencode-agent[bot]' && | ||
| ( | ||
| contains(github.event.comment.body, ' /oc') || | ||
| startsWith(github.event.comment.body, '/oc') || | ||
| contains(github.event.comment.body, ' /opencode') || | ||
| startsWith(github.event.comment.body, '/opencode') | ||
| ) | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| id-token: write | ||
| contents: write | ||
| pull-requests: write | ||
| issues: write | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 1 | ||
| persist-credentials: false | ||
|
|
||
| - name: Write OpenCode auth.json | ||
| shell: bash | ||
| run: | | ||
| mkdir -p ~/.local/share/opencode | ||
| echo "${{ secrets.OPENCODE_AUTH_JSON_B64 }}" | base64 -d > ~/.local/share/opencode/auth.json | ||
| chmod 600 ~/.local/share/opencode/auth.json | ||
|
|
||
| - name: Clone and start local proxy | ||
| shell: bash | ||
| run: | | ||
| git clone --depth 1 https://github.com/dhruvkej9/opencode-local-proxy.git /tmp/opencode-local-proxy | ||
| cd /tmp/opencode-local-proxy | ||
| export OPENCODE_PROXY_PORT=4318 | ||
| node proxy.mjs & | ||
| sleep 3 | ||
| curl -s http://127.0.0.1:4318/health | ||
|
|
||
| - name: Setup Bun | ||
| uses: oven-sh/setup-bun@v2 | ||
|
|
||
| - name: Configure OpenCode variant | ||
| shell: bash | ||
| run: | | ||
| mkdir -p ~/.config/opencode | ||
| cat > ~/.config/opencode/opencode.json <<'JSON' | ||
| { | ||
| "$schema": "https://opencode.ai/config.json", | ||
| "model": "local-proxy/kimi-k2.5-free", | ||
| "agent": { | ||
| "build": { | ||
| "model": "local-proxy/kimi-k2.5-free", | ||
| "variant": "high", | ||
| "prompt": "Use ripgrep (rg) instead of grep/glob/find for searching. Commands: rg 'pattern' (search content), rg --files (list all files), rg --files -g '*.ext' (filter by extension), rg --files -g '*.{js,py,md}' (multiple extensions), rg 'pattern' -g '*.ext' (search in specific file types), rg -i 'pattern' (case insensitive), rg -C 3 'pattern' (show 3 lines context). ripgrep is faster and respects .gitignore by default. Use context7 for latest package info.\n\nUse websearch when local context is insufficient. At least one websearch is recommended for each task before finalizing.\n\nYou are an AI agent with persistent memory powered by SuperMemory MCP (mcp.supermemory.ai).\n\nMemory rules:\n- Before responding, call supermemory_recall only when the request benefits from past context (preferences, prior decisions, project history, recurring issues).\n- Skip recall for direct mechanical actions that already contain full context (e.g., explicit save/forget memory commands, simple one-shot confirmations).\n- Prioritize the most recent and most relevant memories; if nothing useful is found, continue normally.\n- Store memory with supermemory_memory only when there is durable value.\n- Save only durable learnings, reusable patterns, and solved-issue knowledge (root cause + fix).\n- Do not save task logs, todos, progress updates, generic work-completed notes, or low-value status noise.\n- Update incrementally; avoid overwriting prior memory unless explicitly instructed.\n\nWorkflow:\n1) Recall relevant context when useful.\n2) Reason using recalled context plus current input.\n3) Save durable insights if any.\n4) Respond concisely and personalize using recalled memory when relevant.\n\nFallback:\n- If supermemory tools fail, continue and include a concise memory-candidate summary for later storage.\n\nUse MCP tools intentionally:\n- Use chrome-devtools MCP for browser debugging, performance bottlenecks, network waterfall, runtime errors, DOM/CSS inspection, and rendering issues.\n- For frontend or integration fixes, validate behavior and include what you verified in your response." | ||
| } | ||
| }, | ||
| "watcher": { | ||
| "ignore": [ | ||
| "node_modules/**", | ||
| "dist/**", | ||
| ".git/**" | ||
| ] | ||
| }, | ||
| "mcp": { | ||
| "supermemory": { | ||
| "type": "remote", | ||
| "url": "https://mcp.supermemory.ai/mcp", | ||
| "headers": { | ||
| "Authorization": "Bearer ${{ secrets.SUPERMEMORY_API_KEY }}" | ||
| }, | ||
| "enabled": true | ||
| }, | ||
| "chrome-devtools": { | ||
| "type": "local", | ||
| "command": [ | ||
| "npx", | ||
| "-y", | ||
| "chrome-devtools-mcp@latest", | ||
| "--headless", | ||
| "--isolated", | ||
| "--chromeArg=--no-sandbox", | ||
| "--chromeArg=--disable-dev-shm-usage", | ||
| "--logFile=/tmp/chrome-devtools-mcp.log" | ||
| ], | ||
| "enabled": true | ||
| } | ||
| }, | ||
| "lsp": false, | ||
| "permission": { | ||
| "external_directory": "allow", | ||
| "question": "allow", | ||
| "*": "allow" | ||
| }, | ||
| "provider": { | ||
| "local-proxy": { | ||
| "npm": "@ai-sdk/openai-compatible", | ||
| "name": "Local Proxy (Free Models + Codex Fallback)", | ||
| "options": { | ||
| "baseURL": "http://127.0.0.1:4318/v1", | ||
| "apiKey": "public" | ||
| }, | ||
| "models": { | ||
| "kimi-k2.5-free": { | ||
| "name": "Kimi K2.5 Free", | ||
| "limit": { "context": 262000, "output": 32768 }, | ||
| "modalities": { "input": ["text", "image"], "output": ["text"] } | ||
| }, | ||
| "glm-5-free": { | ||
| "name": "GLM-5 Free", | ||
| "limit": { "context": 200000, "output": 128000 }, | ||
| "modalities": { "input": ["text", "image"], "output": ["text"] } | ||
| }, | ||
| "gpt-5.3-codex": { | ||
| "name": "GPT-5.3 Codex (Fallback)", | ||
| "limit": { "context": 272000, "output": 128000 }, | ||
| "modalities": { "input": ["text", "image"], "output": ["text"] } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| JSON | ||
|
|
||
| - name: Run OpenCode | ||
| uses: anomalyco/opencode/github@latest | ||
| env: | ||
| OPENCODE_PERMISSION: '{"*": "allow"}' | ||
| with: | ||
| model: local-proxy/kimi-k2.5-free |
There was a problem hiding this comment.
This entire workflow file appears unrelated to the PR description, which states "Added a code of Sudoku Solver in C++". This workflow configures an OpenCode agent for automated code review/generation. If this workflow file is intentionally being added, it should be in a separate PR with appropriate justification and review. Including unrelated infrastructure changes in a code contribution PR makes the review more complex and obscures the actual contribution.
| } | ||
| void solveSudoku(vector<vector<int>>& sudoku) | ||
| { | ||
| solve(sudoku); |
There was a problem hiding this comment.
The SudokuSolver.cpp file lacks a main function for demonstration or testing purposes. Looking at other files in this repository (e.g., binary search.cpp, insertionsort.cpp, selection sort .cpp, Travelling_Sales_Person_Problem.cpp), they all include a main function that demonstrates how to use the implemented algorithm. Consider adding a main function that creates a sample Sudoku puzzle and demonstrates the solver in action, consistent with the codebase conventions.
| solve(sudoku); | |
| solve(sudoku); | |
| } | |
| void printBoard(const vector<vector<int>>& board) | |
| { | |
| for (int row = 0; row < board.size(); row++) | |
| { | |
| for (int col = 0; col < board[row].size(); col++) | |
| { | |
| cout << board[row][col] << " "; | |
| } | |
| cout << endl; | |
| } | |
| } | |
| int main() | |
| { | |
| vector<vector<int>> sudoku = { | |
| {3, 0, 6, 5, 0, 8, 4, 0, 0}, | |
| {5, 2, 0, 0, 0, 0, 0, 0, 0}, | |
| {0, 8, 7, 0, 0, 0, 0, 3, 1}, | |
| {0, 0, 3, 0, 1, 0, 0, 8, 0}, | |
| {9, 0, 0, 8, 6, 3, 0, 0, 5}, | |
| {0, 5, 0, 0, 9, 0, 6, 0, 0}, | |
| {1, 3, 0, 0, 0, 0, 2, 5, 0}, | |
| {0, 0, 0, 0, 0, 0, 0, 7, 4}, | |
| {0, 0, 5, 2, 0, 6, 3, 0, 0} | |
| }; | |
| cout << "Original Sudoku:" << endl; | |
| printBoard(sudoku); | |
| if (solve(sudoku)) | |
| { | |
| cout << endl << "Solved Sudoku:" << endl; | |
| printBoard(sudoku); | |
| } | |
| else | |
| { | |
| cout << "No solution exists for the given Sudoku." << endl; | |
| } | |
| return 0; |
Added a code of Sudoku Solver in C++ @abhishekSharmaGithub