rosalind / src / rosalind / p007.clj

(ns rosalind.p007
  (:require [clojure.string :as s]))

(def sample "0.23 0.31 0.75")

(defn content-probs [gcc]
  (let [gc (/ gcc 2)
        at (/ (- 1 gcc) 2)]
    {:g gc
     :c gc
     :a at
     :t at}))

(defn chance-of-twice [prob]
  (* prob prob))

(defn solve [s]
  (let [gccs (map #(Float/parseFloat %)
                  (s/split (s/trim s) #"\s+"))]
  (println (s/join " "
                   (for [gcc gccs]
                     (reduce + (map chance-of-twice
                                    (vals (content-probs gcc)))))))))

(solve sample)

(solve (slurp "/Users/sjl/Downloads/rosalind_prob.txt")) 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.