Skip to content

Queen problem solutions #60

Queen problem solutions

Queen problem solutions #60

Workflow file for this run

name: Queen problem solutions
on:
workflow_dispatch:
inputs:
maximum_n:
description: Solutions for N from 0 to maximum_n (both inclusive).
default: 10
type: number
run_cpp_solution:
description: Run the C++ solution.
default: true
type: boolean
run_python_solution:
description: Run the Python solution.
default: true
type: boolean
run_rust_solution:
description: Run the Rust solution.
default: true
type: boolean
jobs:
checkout-scripts:
runs-on: ubuntu-latest
steps:
- name: checkout scripts
uses: actions/checkout@v4
with:
ref: main
sparse-checkout: scripts
- name: share scripts artifacts
uses: actions/upload-artifact@v4
with:
name: scripts
path: scripts
run-cpp-solution:
runs-on: ubuntu-latest
needs:
- checkout-scripts
if: ${{ inputs.run_cpp_solution }}
steps:
- name: checkout solutions
uses: actions/checkout@v4
with:
ref: develop/queen
- name: fetch scripts
uses: actions/download-artifact@v4
with:
name: scripts
path: scripts
- name: setup clang
uses: egor-tensin/setup-clang@v1
with:
version: 15
- name: build and run solution
run: |
clang++ -std=c++20 -Wall -O3 ./c++/queen.cc -o ./c++/queen
chmod +x ./scripts/execution_time.bash
for (( n = 0; n <= ${{ inputs.maximum_n }}; n++)); do
if command_output=$(./scripts/execution_time.bash ./c++/queen $n); then
execution_time=$(echo "$command_output" | tail -n 1)
printf "%s,%d,%d\n" "C++" "$n" "$execution_time" >> cpp_times.csv
fi
done
- name: share result artifacts
uses: actions/upload-artifact@v4
with:
name: cpp_times
path: cpp_times.csv
run-python-solution:
runs-on: ubuntu-latest
needs:
- checkout-scripts
if: ${{ inputs.run_python_solution }}
steps:
- name: checkout solutions
uses: actions/checkout@v4
with:
ref: develop/queen
- name: fetch scripts
uses: actions/download-artifact@v4
with:
name: scripts
- name: setup python
uses: actions/setup-python@v5
with:
python-version: '>=3.6'
- name: run solution
shell: bash
run: |
for (( n = 0; n <= ${{ inputs.maximum_n }}; n++)); do
if command_output=$(./scripts/execution_time.bash \
python ./python/queen.py -n $n); then
execution_time=$(echo "$command_output" | tail -n 1)
printf "%s,%d,%d\n" "Python" "$n" "$execution_time" >> python_times.csv
fi
done
- name: share result artifacts
uses: actions/upload-artifact@v4
with:
name: python_times
path: python_times.csv
run-rust-solution:
runs-on: ubuntu-latest
needs:
- checkout-scripts
if: ${{ inputs.run_rust_solution }}
steps:
- name: checkout solutions
uses: actions/checkout@v4
with:
ref: develop/queen
- name: fetch scripts
uses: actions/download-artifact@v4
with:
name: scripts
- name: setup rust toolchain
uses: actions-rust-lang/[email protected]
- name: build and run solution
run: |
rustc -O ./rust/queen.rs -o ./rust/queen
for (( n = 0; n <= ${{ inputs.maximum_n }}; n++)); do
if command_output=$(./scripts/execution_time.bash ./rust/queen $n); then
execution_time=$(echo "$command_output" | tail -n 1)
printf "%s,%d,%d\n" "Rust" "$n" "$execution_time" >> rust_times.csv
fi
done
- name: share result artifacts
uses: actions/upload-artifact@v4
with:
name: rust_times
path: rust_times.csv
update-artifacts:
runs-on: ubuntu-latest
needs:
- checkout-scripts
- run-cpp-solution
- run-python-solution
- run-rust-solution
if: ${{ always() && !cancelled() && !contains(needs.*.result, 'failure') }}
steps:
- name: checkout artifacts
uses: actions/checkout@v4
with:
ref: artifacts
- name: fetch scripts
uses: actions/download-artifact@v4
with:
name: scripts
- name: fetch cpp results
if: ${{ inputs.run_cpp_solution }}
uses: actions/download-artifact@v4
with:
name: cpp_times
- name: fetch python results
if: ${{ inputs.run_python_solution }}
uses: actions/download-artifact@v4
with:
name: python_times
- name: fetch rust results
if: ${{ inputs.run_rust_solution }}
uses: actions/download-artifact@v4
with:
name: rust_times
- name: append results
run: |
if [ -f cpp_times.csv ]; then
cat cpp_times.csv >> artifacts/queen.csv
fi
if [ -f python_times.csv ]; then
cat python_times.csv >> artifacts/queen.csv
fi
if [ -f rust_times.csv ]; then
cat rust_times.csv >> artifacts/queen.csv
fi
- name: setup python
uses: actions/setup-python@v5
with:
python-version: '>=3.6'
- name: update plots
shell: bash
run: |
python -m pip install pandas matplotlib
python ./scripts/plot.py \
--input-csv-file artifacts/queen.csv \
--output-svg-files-path artifacts/
- name: compute run timestamp
shell: bash
id: commit-timestamp
run: |
echo "timestamp=$(date +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: commit updated results
uses: stefanzweifel/[email protected]
with:
commit_message: updated results at ${{ steps.commit-timestamp.outputs.timestamp }}
branch: artifacts
file_pattern: artifacts/*