A Cell.qll => Cell.qll +45 -0
@@ 0,0 1,45 @@
+class Coordinate extends int {
+ Coordinate() {
+ this in [0..6]
+ }
+}
+
+class Cell extends string {
+ Coordinate x;
+ Coordinate y;
+
+ Coordinate getX() { result = x }
+ Coordinate getY() { result = y }
+
+ Cell() { this = x.toString() + y.toString() }
+
+ predicate sameRow(Cell c) {
+ x = c.getX()
+ }
+
+ predicate sameColumn(Cell c) {
+ y = c.getY()
+ }
+
+ predicate adjacent(Cell c) {
+ exists(
+ int i, int j
+ | i in [-1..1] and j in [-1..1]
+ | x + i = c.getX() and y + j = c.getY()
+ )
+ }
+}
+
+predicate allDifferentRowsColumnsAndNotAdjacent(
+ Cell c1, Cell c2, Cell c3, Cell c4, Cell c5, Cell c6, Cell c7
+) {
+ forall(
+ Cell a, Cell b
+ | a in [ c1, c2, c3, c4, c5, c6, c7 ] and
+ b in [ c1, c2, c3, c4, c5, c6, c7 ] and
+ a != b
+ | not a.sameRow(b) and
+ not a.sameColumn(b) and
+ not a.adjacent(b)
+ )
+}
A Queens.ql => Queens.ql +13 -0
@@ 0,0 1,13 @@
+import Cell
+import Zones
+
+from
+ Cell queen_1, Cell queen_2, Cell queen_3, Cell queen_4, Cell queen_5, Cell queen_6, Cell queen_7
+where (
+ allDifferentRowsColumnsAndNotAdjacent(
+ queen_1, queen_2, queen_3, queen_4, queen_5, queen_6, queen_7
+ )
+ and
+ inEachZone(queen_1, queen_2, queen_3, queen_4, queen_5, queen_6, queen_7)
+)
+select queen_1, queen_2, queen_3, queen_4, queen_5, queen_6, queen_7
M README.md => README.md +7 -0
@@ 3,4 3,11 @@
```shell
# get a working environment
nix develop
+codeql pack install
+
+# create an empty database, to run queries against
+codeql database create --language=javascript-typescript empty.db
+
+# run the query
+codeql query run Queens.ql --database=empty.db
```
A Zones.qll => Zones.qll +29 -0
@@ 0,0 1,29 @@
+import Cell
+
+predicate inEachZone(Cell c1, Cell c2, Cell c3, Cell c4, Cell c5, Cell c6, Cell c7) {
+ Z::getSet("purple").contains(c1) and
+ Z::getSet("orange").contains(c2) and
+ Z::getSet("blue").contains(c3) and
+ Z::getSet("green").contains(c4) and
+ Z::getSet("pink").contains(c5) and
+ Z::getSet("grey").contains(c6) and
+ Z::getSet("cay").contains(c7)
+}
+
+Cell getAValue(string zone) {
+ zone = "purple" and result = ["00",]
+ or
+ zone = "orange" and result = ["01", "10", "11", "12", "21",]
+ or
+ zone = "blue" and result = ["02", "03", "13", "20", "22", "23", "30", "31", "32",]
+ or
+ zone = "green" and result = ["04", "05", "06", "14", "16", "24", "26", "36", "46",]
+ or
+ zone = "pink" and result = ["33", "34", "43",]
+ or
+ zone = "grey" and result = ["15", "25", "35", "44", "45", "51", "52", "53", "54",]
+ or
+ zone = "cay" and result = ["40", "41", "42", "50", "55", "56", "60", "61", "62", "63", "64", "65", "66",]
+}
+
+module Z = QlBuiltins::InternSets<string, Cell, getAValue/1>;
A codeql-pack.lock.yml => codeql-pack.lock.yml +24 -0
@@ 0,0 1,24 @@
+---
+lockVersion: 1.0.0
+dependencies:
+ codeql/dataflow:
+ version: 1.0.4
+ codeql/javascript-all:
+ version: 1.1.1
+ codeql/mad:
+ version: 1.0.4
+ codeql/regex:
+ version: 1.0.4
+ codeql/ssa:
+ version: 1.0.4
+ codeql/tutorial:
+ version: 1.0.4
+ codeql/typetracking:
+ version: 1.0.4
+ codeql/util:
+ version: 1.0.4
+ codeql/xml:
+ version: 1.0.4
+ codeql/yaml:
+ version: 1.0.4
+compiled: false
A qlpack.yml => qlpack.yml +7 -0
@@ 0,0 1,7 @@
+---
+library: false
+warnOnImplicitThis: false
+name: pamplemousse/queens
+version: 0.0.1
+dependencies:
+ codeql/javascript-all: "*"