Skip to content

Commit

Permalink
the program is now fully working
Browse files Browse the repository at this point in the history
  • Loading branch information
tjira committed Dec 16, 2023
1 parent 01820e1 commit b9cc598
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 1,731 deletions.
124 changes: 124 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Release

on:
push:
tags:
- '*'

permissions:
contents: write

env:
BUILD_TYPE: Release

jobs:
build_linux_x86-64:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Configure Sudokuer
run: cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build Sudokuer
run: cmake --build build --parallel 2

- name: Rename Executable
run: mv bin/sudokuer bin/sudokuer_linux_x86-64

- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
path: bin/sudokuer_linux_x86-64

build_linux_x86-64_openmp:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Configure Sudokuer
run: cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DGOMP=ON

- name: Build Sudokuer
run: cmake --build build --parallel 2

- name: Rename Executable
run: mv bin/sudokuer bin/sudokuer_linux_x86-64_openmp

- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
path: bin/sudokuer_linux_x86-64_openmp

build_windows_x86-64:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3

- name: Install Packages
run: pip install jinja2

- name: Configure Sudokuer
run: cmake -B build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build Sudokuer
run: cmake --build build --parallel 2

- name: Rename Executable
run: mv bin/sudokuer.exe bin/sudokuer_windows_x86-64.exe

- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
path: bin/sudokuer_windows_x86-64.exe

release:
runs-on: ubuntu-latest
needs: [build_linux_x86-64, build_linux_x86-64_openmp, build_windows_x86-64]

steps:
- uses: actions/checkout@v3

- name: Download Artifacts
uses: actions/download-artifact@v3

- name: Copy x86-64 Binaries to the Root Folder
run: |
cp artifact/sudokuer_linux_x86-64 sudokuer && cp artifact/sudokuer_windows_x86-64.exe sudokuer.exe
- name: Create x86-64 Packages
run: |
zip -r sudokuer_windows_x86-64.zip sudokuer.exe LICENSE.md
tar -czf sudokuer_linux_x86-64.tar.gz sudokuer LICENSE.md
- name: Copy x86-64_openmp Binaries to the Root Folder
run: |
cp artifact/sudokuer_linux_x86-64_openmp sudokuer
- name: Create x86-64_openmp Packages
run: |
tar -czf sudokuer_linux_x86-64_openmp.tar.gz sudokuer LICENSE.md
- name: Release linux_x86-64 Version of Sudokuer
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{secrets.GITHUB_TOKEN}}
file: sudokuer_linux_x86-64.tar.gz
tag: ${{github.ref}}

- name: Release linux_x86-64_openmp Version of Sudokuer
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{secrets.GITHUB_TOKEN}}
file: sudokuer_linux_x86-64_openmp.tar.gz
tag: ${{github.ref}}

- name: Release windows_x86-64 Version of Sudokuer
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{secrets.GITHUB_TOKEN}}
file: sudokuer_windows_x86-64.zip
tag: ${{github.ref}}
24 changes: 20 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.16)
set(CMAKE_CXX_STANDARD 20)
include(FetchContent)
project(Sudokuer)

# set output flags
Expand All @@ -8,7 +9,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# set compiler flags
set(CMAKE_CXX_FLAGS_DEBUG "-g -pg -O0 -fprofile-arcs -ftest-coverage -Wall -Wextra")
set(CMAKE_CXX_FLAGS_RELEASE "-s -O3")
set(CMAKE_CXX_FLAGS_RELEASE "-s -mavx -O3")

# set the variable that contains the compile flags
if(${CMAKE_BUILD_TYPE} STREQUAL Debug)
Expand All @@ -17,11 +18,26 @@ elseif(${CMAKE_BUILD_TYPE} STREQUAL Release)
set(CXXFLAGS ${CMAKE_CXX_FLAGS_RELEASE})
endif()

# static link on windows
if (WIN32)
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -static")
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -static")
endif()

# declare libraries
FetchContent_Declare(argparse SYSTEM GIT_REPOSITORY https://github.com/p-ranav/argparse.git GIT_TAG ac4c578f6020d5164f66ccb26b4727dea657a12b)

# fetch the libraries
FetchContent_MakeAvailable(argparse)

# include necessary directories
include_directories(include lib)
include_directories(include ${argparse_SOURCE_DIR}/include/argparse)

# find the necessary packages
find_package(OpenMP)
# find OpenMP if enabled
if (${GOMP})
find_package(OpenMP REQUIRED)
endif()
unset(GOMP CACHE)

# add fractoid executable
add_executable(sudokuer src/main.cpp src/sudoku.cpp)
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
<h1 align="center">Sudokuer</h1>

<p align="center">
<a href="https://github.com/tjira/sudokuer/pulse">
<img src="https://img.shields.io/github/last-commit/tjira/sudokuer?logo=github&logoColor=white&style=for-the-badge"/>
</a>
<a href="https://github.com/tjira/sudokuer/blob/master/LICENSE.md">
<img src="https://img.shields.io/github/license/tjira/sudokuer?logo=gitbook&logoColor=white&style=for-the-badge"/>
</a>
<a href="https://github.com/tjira/sudokuer/stargazers">
<img src="https://img.shields.io/github/stars/tjira/sudokuer?logo=apachespark&logoColor=white&style=for-the-badge"/>
</a>
<a href="https://github.com/tjira/sudokuer">
<img src="https://img.shields.io/github/languages/code-size/tjira/sudokuer?logo=databricks&logoColor=white&style=for-the-badge"/>
</a>
<br>
<a href="https://github.com/tjira/sudokuer/releases/latest">
<img src="https://img.shields.io/github/v/release/tjira/sudokuer?display_name=tag&logo=sharp&logoColor=white&style=for-the-badge"/>
</a>
<a href="https://github.com/tjira/sudokuer/releases/latest">
<img src="https://img.shields.io/github/downloads/tjira/sudokuer/total?logo=markdown&logoColor=white&style=for-the-badge"/>
</a>
</p>

<p align="center">
As the name suggests, this software can generate a valid sudoku boards with arbitrary number of solutions.
</p>

## ⭐ Credits

* [argparse](https://github.com/p-ranav/argparse) - Argument Parser for Modern C++.
10 changes: 7 additions & 3 deletions include/sudoku.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ class Sudoku {

// generators and solvers
bool valid(size_t i, size_t j, int n) const;
bool backtrack(unsigned seed, int nsol);
void eliminate(unsigned seed);
bool backtrack(unsigned seed, int nsol = 0);
void eliminate(unsigned seed, int nsol = 1);

// getters
size_t nsol() const {return solutions.size();} std::string string() const;
Sudoku solution(int i) const {return Sudoku(solutions.at(i));}

// operators
friend std::ostream& operator<<(std::ostream& os, const Sudoku& sudoku);
int operator()(size_t i, size_t j) const {return board.at(i).at(j);}
int& operator()(size_t i, size_t j) {return board.at(i).at(j);}

private:
public:
Board board; std::vector<Board> solutions;
std::vector<std::pair<int, int>> empty;
};
Loading

0 comments on commit b9cc598

Please sign in to comment.