src/problems/perm.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 86d92162dc1f
(defpackage :rosalind/perm (:use :cl :rosalind :losh :iterate))
(in-package :rosalind/perm)

(defparameter *input* "3")

(defparameter *output* "6
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1")


(define-problem perm (data string) *input* *output*
  (let* ((n (parse-integer data))
         (count (u:factorial n))
         (perms (u:permutations (alexandria:iota n :start 1))))
    (format nil "~D~%~{~A~^~%~}"
            count
            ;; sort to ensure consistent output for the unit test
            (sort (mapcar (u:curry #'str:join " ") perms) #'string<))))