src/problems/seto.lisp @ e3aefcbf364c
Cache Uniprot results on the filesystem
This will make only the first `(run-tests)` on a given computer take forever,
instead of the first `(run-tests)` of a given Lisp session. It will also
hopefully make the Uniprot folks not hate me.
author |
Steve Losh <steve@stevelosh.com> |
date |
Fri, 24 Jan 2020 23:05:16 -0500 |
parents |
2735aa6aab79 |
children |
(none) |
(defpackage :rosalind/seto (:use :cl :rosalind :losh :iterate))
(in-package :rosalind/seto)
(defparameter *input*
"10
{1, 2, 3, 4, 5}
{2, 8, 5, 10}")
(defparameter *output*
"{1, 2, 3, 4, 5, 8, 10}
{2, 5}
{1, 3, 4}
{8, 10}
{6, 7, 8, 9, 10}
{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*
*output*
(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 --------------------------------------------------------------------