src/problems/lexv.lisp @ 870270771fde
PDST
author |
Steve Losh <steve@stevelosh.com> |
date |
Sun, 19 Jan 2020 21:14:53 -0500 |
parents |
2735aa6aab79 |
children |
(none) |
(defpackage :rosalind/lexv (:use :cl :rosalind :losh :iterate))
(in-package :rosalind/lexv)
(defparameter *input*
"D N A
3")
(defparameter *output*
"D
DD
DDD
DDN
DDA
DN
DND
DNN
DNA
DA
DAD
DAN
DAA
N
ND
NDD
NDN
NDA
NN
NND
NNN
NNA
NA
NAD
NAN
NAA
A
AD
ADD
ADN
ADA
AN
AND
ANN
ANA
AA
AAD
AAN
AAA
")
(define-problem lexv (data stream) *input* *output*
(let* ((alphabet (remove #\space (read-line data)))
(n (read data))
(string (make-string n)))
(with-output-to-string (s)
(recursively ((n n)
(i 0))
(unless (zerop i)
;; The empty string *is* first, lexicographically, but I don't think
;; they accept it in the answer for some reason.
(write-string string s :end i)
(terpri s))
(unless (zerop n)
(map nil (lambda (ch)
(setf (aref string i) ch)
(recur (1- n) (1+ i)))
alphabet))))))