dbd94aef5f92

SETO
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Fri, 20 Dec 2019 17:12:23 -0500
parents 049e0d632763
children dbd7237ece35
branches/tags (none)
files src/problems/seto.lisp

Changes

--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/problems/seto.lisp	Fri Dec 20 17:12:23 2019 -0500
@@ -0,0 +1,42 @@
+(in-package :rosalind)
+
+(defparameter *input-seto*
+  "10
+{1, 2, 3, 4, 5}
+{2, 8, 5, 10}")
+
+(defparameter *output-seto*
+  "{1, 2, 3, 4, 5, 8, 10}
+{2, 5}
+{1, 3, 4}
+{8, 10}
+{8, 9, 10, 6, 7}
+{1, 3, 4, 6, 7, 9}")
+
+(defun set-string (set)
+  ;; Sort for consistent unit test output.
+  (format nil "{~{~D~^, ~}}" (sort (copy-seq set) #'<)))
+
+(defun parse-set (string)
+  (mapcar #'parse-integer (ppcre:all-matches-as-strings "\\d+" string)))
+
+(define-problem seto (data stream)
+    *input-seto*
+    *output-seto*
+  (let ((u (alexandria:iota (read data) :start 1))
+        (a (parse-set (read-line data)))
+        (b (parse-set (read-line data))))
+    (_ (list (union a b) ; to hell with it, we'll just use CL's built-in stuff
+             (intersection a b)
+             (set-difference a b)
+             (set-difference b a)
+             (set-difference u a)
+             (set-difference u b))
+      (mapcar #'set-string _)
+      (str:join (string #\newline) _))))
+
+
+#; Scratch --------------------------------------------------------------------
+
+(problem-seto)
+;; (solve sset)