Skip to content

Instantly share code, notes, and snippets.

(defn fact [x]
(if (< x 2) ;; the <= avoids error if non-integer is entered.
1
(* x (fact (dec x)))))
(fact 10)
;;3628800
(ns student.dialect
(use: [clojure.contrib.str-utils :only [str-join]]))
(defn babyize [s] "replace l and r with w if first letter of each word"
(let [b-word (fn [[first-letter & word]]
(let [new-first (cond (some #{first-letter} [\l \r]) \w
(some #{first-letter} [\L \R]) \W
:else first-letter)]
(apply str new-first word)))]
(str-join " " (map b-word (.split s " ")))))
;;problem 2 sum even fibonacci #s up to 4000000
(defn fib-seq []
(let [step (fn [pair]
[(last pair) (+ (first pair) (last pair))])]
(map first (iterate step [0 1]))))
(def fibs (fib-seq))
(apply + (filter even? (take-while #(<= % 4000000) fibs)))
;;problem 3 largest prime factor of 600851475143
(defn prime? [x]
(if (>= x 2) (zero? (count (filter #(divides? x %) (range 2 (inc (int (sqrt x))))))) false))
(defn get-biggest-prime-factor [x]
(if (prime? x)
x
(/ x (first
;;problem 3 largest prime factor of 600851475143
(defn prime? [x]
(if (>= x 2)
(zero?
(count
(filter #(divides? x %)
(range 2 (inc (int (sqrt x)))))))
false))
(ns student.dialect
(:use [clojure.contrib.str-utils :only [str-join]]
[clojure.contrib.math :only [sqrt lcm]]
[clojure.contrib.lazy-seqs :only [primes]]))
(defn babyize [s] "replace l and r with w if first letter of each word"
(let [b-word (fn [[first-letter & word]]
(let [new-first (cond (some #{first-letter} [\l \r]) \w
(some #{first-letter} [\L \R]) \W
:else first-letter)]
//pseudo code beloew
array = 1 2 3 4 1 2 3 4 5 1 2 3
//should print at the end 1 2 3 4 5 with count 5
max = 1
maxstart = 0
maxend = 0
(ns student.learning
(:refer-clojure :exclude [get])
(:use [clojure.contrib.str-utils :only [str-join]]
[clojure.contrib.math :only [sqrt lcm]]
[clojure.contrib.lazy-seqs :only [primes]]))
(defn babyize [s] "replace l and r with w if first letter of each word"
(let [b-word (fn [[first-letter & word]]
(let [new-first (cond (some #{first-letter} [\l \r]) \w
(some #{first-letter} [\L \R]) \W
(ns student.learning
(:refer-clojure :exclude [get])
(:use [clojure.contrib.str-utils :only [str-join]]
[clojure.contrib.math :only [sqrt lcm]]
[clojure.contrib.lazy-seqs :only [primes]]))
(defn babyize [s] "replace l and r with w if first letter of each word"
(let [b-word (fn [[first-letter & word]]
(let [new-first (cond (some #{first-letter} [\l \r]) \w
(some #{first-letter} [\L \R]) \W
(ns attendance.core
(:use karras.core
karras.collection
karras.sugar
compojure.core
ring.adapter.jetty
hiccup.core)
(:require [compojure.route :as route]))
(defn home []