Created
          December 5, 2013 11:09 
        
      - 
      
 - 
        
Save bendisposto/7803638 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | (ns muster.core) | |
| ;; Aufgabe 1 | |
| (defn rev-interleave [col n] | |
| (apply map list (partition n col))) | |
| (defn myflatten [col] | |
| (mapcat #(if (coll? %) (myflatten %) [%]) col)) | |
| ;; Aufgabe 2 | |
| (defn ! [n] (reduce *' (range 1 (inc n)))) | |
| (defn vz [n] (if (even? n) 1 -1)) | |
| (defn zwein+1 [n] (inc (* 2 n))) | |
| (defn z [x n] (Math/pow x (zwein+1 n))) | |
| (defn step [x] | |
| (fn [[g n]] | |
| (let [ps (* (vz n) (/ (z x n) (! (zwein+1 n))))] | |
| [(+ g ps) (inc n)]))) | |
| (defn abs [x] (if (< x 0) (* -1 x) x)) | |
| (defn fixedpoint [F guess eps?] | |
| (let [guess' (F guess)] | |
| (if (eps? guess' guess) | |
| guess | |
| (recur F guess' eps?)))) | |
| (defn taylor-eps? [eps] | |
| (fn [[g' _] [g _]] (let [dg (- g' g)] | |
| (< (abs (- g' g)) eps )))) | |
| (defn sin [x eps] | |
| (first (fixedpoint (step x) [0 0] (taylor-eps? eps)))) | |
| ;; Aufgabe 3 | |
| (defn trans [v] (apply map str v)) | |
| (defn sidestep [v] (map #(.replaceAll % " M|M " "MM") v)) | |
| (defn won? [& v] (some #(re-find #"KM|MK" (pr-str %)) v)) | |
| (defn pstep [v] (-> v sidestep trans sidestep trans)) | |
| (defn path? [v] | |
| (let [fp (fixedpoint pstep v =)] | |
| (won? fp (trans fp)))) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment