Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn maxmul7
- "A function to return the greatest multiple of 7 in a defined range inclusive"
- [min max]
- (if (and (and (>= max 7) (<= min (- max (mod max 7)))) (>= min 7)) (- max (mod max 7)) nil)
- )
- (maxmul7 15 21)
- (defn sumcube [min max]
- "A function to sum the cubes in a given range inclusive"
- (loop [step min total 0]
- (if (< max step)
- total
- (recur (inc step) (+ total (Math/pow step 3)))
- )
- )
- )
- (sumcube 1 3)
- (defn drop2nd
- [plist]
- (if (< (count plist) 3)
- (println "less than three")
- ;greater than or equal to three
- (loop [step 0 nlist '()]
- (if (< step (- (count plist) 0))
- (if (= step 1)
- (recur (inc step) nlist)
- (recur (inc step) (conj nlist (nth plist step)))
- )
- nlist
- )
- )
- )
- )
- (drop2nd '(1 2 3 4 5))
- (defn devisors
- [num]
- (loop [step 1 plist '()]
- (if (<= step (/ num 2) )
- (if (= 0 (mod num step))
- (recur (inc step) (conj plist step))
- (recur (inc step) plist)
- )
- plist
- )
- )
- )
- (defn sumList
- [plist]
- (loop [step 0 total 0]
- (if (<= step (count plist))
- (recur (inc step) (+ total step))
- total
- )
- )
- )
- (defn perfect
- [num]
- (if (= num (sumList (devisors num)))
- true
- false
- )
- )
- (perfect 6)
- (defn ave
- [plist]
- (/ (sumList plist) (count plist))
- )
- (defn sumXMSquared
- [plist]
- (let [mean (ave plist)]
- (loop [step 0 total 0]
- (if (< step (count plist))
- (recur (inc step) (+ total (Math/pow (- (nth plist step) mean) 2) ) )
- total
- )
- )
- )
- )
- (defn stdDiv
- [plist]
- (Math/sqrt (/ (sumXMSquared plist) (- (count plist) 1)) )
- )
- (ave '(1 2 3 4 5))
- (stdDiv '(1 2 3 4))
- (defn occur
- [el coll]
- (loop [step 0]
- (if (< step (count coll))
- (if (= el (nth coll step))
- step
- (recur (inc step))
- )
- nil
- )
- )
- )
- (occur 7 '(1 2 3 4 5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement