commit db96d762add6f00a352663dd6ffd591e9b24e583 Author: wi11-holdsworth <83637728+wi11-holdsworth@users.noreply.github.com> Date: Tue Aug 26 20:23:31 2025 +1000 init diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92b2793 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.direnv diff --git a/README.md b/README.md new file mode 100644 index 0000000..ac8b09f --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# Project 1: Maths Puzzles + +## Math Puzzle +- each digit must be 1-9 +- each row contains no repeated digit +- each column contains no repeated digit +- all squares on the diagonal line from top left corner to bottom right corner must contain the same value +- the heading of each row holds either: + - the sum of all the digits in that row + - the product of all the digits in that row +- the heading of each column holds either: + - the sum of all the digits in that column + - the product of all the digits in that column + +## Input +A math puzzle with most/all squares empty **except** for the headings + +## Solution + +### Structure +A predicate `puzzle_solution/1` which holds when the argument is a solved math puzzle + +### Approach +Utilise constraint logic programming +1. unify all squares on the diagonal +2. check rows are valid + 1. all distinct + 2. sum to heading + 3. product to head +3. check columns are valid via `transpose/2` diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..9464e76 --- /dev/null +++ b/flake.lock @@ -0,0 +1,25 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1746904237, + "narHash": "sha256-3e+AVBczosP5dCLQmMoMEogM57gmZ2qrVSrmq9aResQ=", + "rev": "d89fc19e405cb2d55ce7cc114356846a0ee5e956", + "revCount": 797896, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.797896%2Brev-d89fc19e405cb2d55ce7cc114356846a0ee5e956/0196c1a7-7ad3-74a9-9d50-1b854aca6d6c/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/0.1" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b31b6ce --- /dev/null +++ b/flake.nix @@ -0,0 +1,20 @@ +{ + description = "A Nix-flake-based Swi-prolog development environment"; + + inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1"; + + outputs = inputs: + let + supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + forEachSupportedSystem = f: inputs.nixpkgs.lib.genAttrs supportedSystems (system: f { + pkgs = import inputs.nixpkgs { inherit system; }; + }); + in + { + devShells = forEachSupportedSystem ({ pkgs }: { + default = pkgs.mkShell { + packages = with pkgs; [ swi-prolog ]; + }; + }); + }; +}