Advertisement
montana_1

Untitled

Jan 27th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. (defn maxmul7
  3.     "A function to return the greatest multiple of 7 in a defined range inclusive"
  4.     [min max]
  5.     (if (and (and (>= max 7) (<= min (- max (mod max 7)))) (>= min 7)) (- max (mod max 7)) nil)
  6. )
  7.  
  8. (maxmul7 15 21)
  9.  
  10.  
  11.  
  12. (defn sumcube [min max]
  13.     "A function to sum the cubes in a given range inclusive"
  14.     (loop [step min total 0]
  15.         (if (< max step)
  16.             total
  17.             (recur (inc step) (+ total (Math/pow step 3)))
  18.         )
  19.     )
  20. )
  21.  
  22.  
  23. (sumcube 1 3)
  24.  
  25. (defn drop2nd
  26.     [plist]
  27.     (if (< (count plist) 3)
  28.         (println "less than three")
  29.         ;greater than or equal to three
  30.         (loop [step 0 nlist '()]
  31.             (if (< step (- (count plist) 0))
  32.                 (if (= step 1)
  33.                     (recur (inc step) nlist)
  34.                     (recur (inc step) (conj nlist (nth plist step)))
  35.                 )
  36.                 nlist
  37.             )
  38.         )
  39.     )
  40. )
  41.  
  42. (drop2nd '(1 2 3 4 5))
  43.  
  44. (defn devisors
  45.     [num]
  46.     (loop [step 1 plist '()]
  47.         (if (<= step (/ num 2) )
  48.             (if (= 0 (mod num step))
  49.                 (recur (inc step) (conj plist step))
  50.                 (recur (inc step) plist)
  51.             )
  52.             plist
  53.         )
  54.     )
  55. )
  56. (defn sumList
  57.     [plist]
  58.     (loop [step 0 total 0]
  59.         (if (<= step (count plist))
  60.             (recur (inc step) (+ total step))
  61.             total
  62.         )
  63.     )
  64. )
  65. (defn perfect
  66.     [num]
  67.     (if (= num (sumList (devisors num)))
  68.         true
  69.         false
  70.     )
  71.  
  72. )
  73.  
  74. (perfect 6)
  75.  
  76.  
  77. (defn ave
  78.   [plist]
  79.   (/ (sumList plist) (count plist))
  80. )
  81.  
  82. (defn sumXMSquared
  83.   [plist]
  84.   (let [mean (ave plist)]
  85.     (loop [step 0 total 0]
  86.       (if (< step (count plist))
  87.         (recur (inc step) (+ total (Math/pow (- (nth plist step) mean) 2) ) )
  88.         total
  89.       )
  90.     )
  91.   )
  92. )
  93.  
  94. (defn stdDiv
  95.   [plist]
  96.   (Math/sqrt (/ (sumXMSquared plist) (- (count plist) 1)) )
  97. )
  98.  
  99. (ave '(1 2 3 4 5))
  100.  
  101. (stdDiv '(1 2 3 4))
  102.  
  103.  
  104. (defn occur
  105.   [el coll]
  106.   (loop [step 0]
  107.     (if (< step (count coll))
  108.       (if (= el (nth coll step))
  109.         step
  110.         (recur (inc step))
  111.       )
  112.       nil
  113.     )
  114.   )
  115. )
  116.  
  117. (occur 7 '(1 2 3 4 5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement