# HG changeset patch # User Steve Losh # Date 1579923739 18000 # Node ID 0a5694fe577c0ddfbd2897d76dc484eb49773f58 # Parent 888f5c30c9495df8ce303cd3c06474b352e470fc MMCH diff -r 888f5c30c949 -r 0a5694fe577c src/problems/mmch.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/problems/mmch.lisp Fri Jan 24 22:42:19 2020 -0500 @@ -0,0 +1,36 @@ +(defpackage :rosalind/mmch (:use :cl :rosalind :losh :iterate)) +(in-package :rosalind/mmch) + +(defparameter *input* ">Rosalind_92 +AUGCUUC") + +(defparameter *output* "6") + +;; We can attack this similarly to PMCH. +;; +;; Consider the A/U graph, and assume without loss of generality that the number +;; of As is less than or equal to the number of Us. For each A, we choose +;; a U to pair it with like in PMCM, but this time we don't have enough A's to +;; get the full factorial. Instead we get U(U-1)(U-2)…(U-(A-1)) which we can +;; just multiply out. +;; +;; … why did I get a dynamic programming achievement on Rosalind for solving +;; this problem? + +(defun pairings (a b) + (when (< b a) + (rotatef a b)) + (iterate (repeat a) + (for n :downfrom b) + (multiplying n))) + +(define-problem mmch (data stream) *input* *output* + (let* ((bases (nth-value 1 (u:read-fasta data))) + (freqs (frequencies bases))) + (* (pairings (gethash #\A freqs) + (gethash #\U freqs)) + (pairings (gethash #\C freqs) + (gethash #\G freqs))))) + +#; Scratch -------------------------------------------------------------------- +(problem-mmch) diff -r 888f5c30c949 -r 0a5694fe577c src/utils.lisp --- a/src/utils.lisp Mon Jan 20 14:19:26 2020 -0500 +++ b/src/utils.lisp Fri Jan 24 22:42:19 2020 -0500 @@ -530,7 +530,10 @@ (defun solve% (problem) (with-open-file (input (problem-data-path problem)) - (pbcopy (aesthetic-string (funcall problem input))))) + (let ((result (aesthetic-string (funcall problem input)))) + (pbcopy result) + (format t "Copied the following to clipboard:~%~A~%" result) + (values)))) (defmacro solve (name) (assert (symbolp name) ()