From 87fd77bbfda09ae557d39ddec4d90409b02c094a Mon Sep 17 00:00:00 2001
From: p9malino26 <pm3g19@soton.ac.uk>
Date: Mon, 26 Apr 2021 19:58:33 +0100
Subject: [PATCH] Created solutions for all five problems

---
 solutions/pr1.cql | 6 ++++++
 solutions/pr2.cql | 5 +++++
 solutions/pr3.cql | 6 ++++++
 solutions/pr4.cql | 9 +++++++++
 solutions/pr5.cql | 5 +++++
 5 files changed, 31 insertions(+)
 create mode 100644 solutions/pr1.cql
 create mode 100644 solutions/pr2.cql
 create mode 100644 solutions/pr3.cql
 create mode 100644 solutions/pr4.cql
 create mode 100644 solutions/pr5.cql

diff --git a/solutions/pr1.cql b/solutions/pr1.cql
new file mode 100644
index 0000000..f9bfb75
--- /dev/null
+++ b/solutions/pr1.cql
@@ -0,0 +1,6 @@
+.in
+A:2, # declare input files and their numbers of cols in .in section
+B:2
+
+.out # statements for the query are in .out section
+A x B; # returns the cartesian product of the two sets (conjunction)
\ No newline at end of file
diff --git a/solutions/pr2.cql b/solutions/pr2.cql
new file mode 100644
index 0000000..8406adf
--- /dev/null
+++ b/solutions/pr2.cql
@@ -0,0 +1,5 @@
+.in
+A:3
+
+.out
+filter((r) -> isSubstring(r[1], r[2]));
\ No newline at end of file
diff --git a/solutions/pr3.cql b/solutions/pr3.cql
new file mode 100644
index 0000000..89efa96
--- /dev/null
+++ b/solutions/pr3.cql
@@ -0,0 +1,6 @@
+.in
+A:3
+
+.out
+filter (\r -> r[2] == r[3]); # data the the function works on (e.g. input set this time) goes in [], extra info (e.g. predicate in this case) goes in ()
+map(\r -> r[3,1]); # can also be map[\_](\r ...), where \_ is output of last operation. 
diff --git a/solutions/pr4.cql b/solutions/pr4.cql
new file mode 100644
index 0000000..7bfc9d1
--- /dev/null
+++ b/solutions/pr4.cql
@@ -0,0 +1,9 @@
+.in
+P: 4,
+Q: 4
+
+.out
+P x Q;
+filter(\r -> r[4] == r[5]);
+let func f(x,y) = if (empty(x)) then y else x;
+map(\r -> [r[1], f(r[2], r[6]), f(r[3], r[7]), f(r[4], r[8]));
\ No newline at end of file
diff --git a/solutions/pr5.cql b/solutions/pr5.cql
new file mode 100644
index 0000000..e18dc7a
--- /dev/null
+++ b/solutions/pr5.cql
@@ -0,0 +1,5 @@
+.in
+A:1
+
+.out
+map[A](\r -> [r[1],"0",r[1]]);
\ No newline at end of file
-- 
GitLab