about summary refs log tree commit diff stats
path: root/janet/tmplt
diff options
context:
space:
mode:
authorelioat <hi@eli.li>2023-07-13 09:34:30 -0400
committerelioat <hi@eli.li>2023-07-13 09:34:30 -0400
commit0133554853b588aa70eaeb0eaba16d5fdc24b8d3 (patch)
tree97894a9d821e60e0b8f331920ab6be6764edab53 /janet/tmplt
parente8af8b886ac22084d0ff0f53dde392a3c40cd6a6 (diff)
downloadtour-0133554853b588aa70eaeb0eaba16d5fdc24b8d3.tar.gz
*
Diffstat (limited to 'janet/tmplt')
-rw-r--r--janet/tmplt/.gitignore2
-rw-r--r--janet/tmplt/README.md5
-rw-r--r--janet/tmplt/project.janet13
-rw-r--r--janet/tmplt/src/app.janet18
-rw-r--r--janet/tmplt/test/sum.janet4
5 files changed, 42 insertions, 0 deletions
diff --git a/janet/tmplt/.gitignore b/janet/tmplt/.gitignore
new file mode 100644
index 0000000..4bbe471
--- /dev/null
+++ b/janet/tmplt/.gitignore
@@ -0,0 +1,2 @@
+jpm_tree
+jpm_tree/*
\ No newline at end of file
diff --git a/janet/tmplt/README.md b/janet/tmplt/README.md
new file mode 100644
index 0000000..cb39b33
--- /dev/null
+++ b/janet/tmplt/README.md
@@ -0,0 +1,5 @@
+# starting place
+
+start with a `jpm -l deps` to install local deppendencies
+
+then try a `jpm -l test` to run the local tests with `judge`.
\ No newline at end of file
diff --git a/janet/tmplt/project.janet b/janet/tmplt/project.janet
new file mode 100644
index 0000000..65f7b78
--- /dev/null
+++ b/janet/tmplt/project.janet
@@ -0,0 +1,13 @@
+# project file
+(declare-project
+  :name "template"
+  :description "a starting place for new projects"
+  :dependencies [
+    {:url "https://github.com/ianthehenry/judge.git"
+     :tag "v2.6.1"} # a fun testing framework
+  ])
+
+(declare-source
+  :source ["/src/app.janet"])
+
+(task "test" [] (shell "jpm_tree/bin/judge")) # use the judge test runner instead of the one baked into jpm
diff --git a/janet/tmplt/src/app.janet b/janet/tmplt/src/app.janet
new file mode 100644
index 0000000..f67e8e3
--- /dev/null
+++ b/janet/tmplt/src/app.janet
@@ -0,0 +1,18 @@
+(defn sum3
+  "Solve the 3SUM problem in O(n^2) time."
+  [s]
+  (def tab @{})
+  (def solutions @{})
+  (def len (length s))
+  (for k 0 len
+    (put tab (s k) k))
+  (for i 0 len
+    (for j 0 len
+      (def k (get tab (- 0 (s i) (s j))))
+      (when (and k (not= k i) (not= k j) (not= i j))
+        (put solutions {i true j true k true} true))))
+  (map keys (keys solutions)))
+
+(let [arr @[2 4 1 3 8 7 -3 -1 12 -5 -8]]
+  (printf "3sum of %j: " arr)
+  (printf "%j" (sum3 arr)))
\ No newline at end of file
diff --git a/janet/tmplt/test/sum.janet b/janet/tmplt/test/sum.janet
new file mode 100644
index 0000000..be82870
--- /dev/null
+++ b/janet/tmplt/test/sum.janet
@@ -0,0 +1,4 @@
+(use /src/app)
+(use judge)
+
+(test (sum3 arr))
\ No newline at end of file