This file contains 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
(defn fact [x] | |
(if (< x 2) ;; the <= avoids error if non-integer is entered. | |
1 | |
(* x (fact (dec x))))) | |
(fact 10) | |
;;3628800 |
This file contains 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 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 " "))))) |
This file contains 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
;;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))) |
This file contains 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
;;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 |
This file contains 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
;;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)) |
This file contains 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 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)] |
This file contains 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
//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 | |
This file contains 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 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 |
This file contains 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 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 |
This file contains 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 attendance.core | |
(:use karras.core | |
karras.collection | |
karras.sugar | |
compojure.core | |
ring.adapter.jetty | |
hiccup.core) | |
(:require [compojure.route :as route])) | |
(defn home [] |
OlderNewer