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
| (defn get-max-prime-factor [num cur limit] | |
| (if (> cur limit) | |
| num | |
| (if (= num cur) | |
| num | |
| (if (zero? (mod num cur)) | |
| (get-max-prime-factor (/ num cur) cur limit) | |
| (get-max-prime-factor num (inc cur) limit))))) | |
| (defn max-prime-factor [num] |
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
| (defn get-max-prime-factor [num cur] | |
| (if (= num cur) | |
| num | |
| (if (zero? (mod num cur)) | |
| (get-max-prime-factor (/ num cur) cur) | |
| (get-max-prime-factor num (inc cur))))) | |
| (get-max-prime-factor 600851475143 2) |
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
| (defn get-largest-prime-factor [num] | |
| (let [q (long (Math/sqrt num)) ; we don't need to check further than this | |
| factor? (fn [a b] (zero? (rem a b)))] ; utility helper fn | |
| (loop [n num d 2] ; starting iteration: n := num d := 2 | |
| (cond | |
| (> d q) n ; we're done if we've reached the limit (sqrt(num)) | |
| (= d n) n ; or the two tested numbers are equal (for the inner iteration) | |
| (factor? n d) (recur (/ n d) d) ; if n is divisible by d, let's divide it and iterate | |
| true (recur n (inc d)))))) ; try with a bigger d |
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
| (reduce + (take-while (partial >= 4000000) | |
| (filter even? fibo))) |
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
| (def fibo (lazy-cat [0 1] | |
| (map + fibo (rest fibo)))) |
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
| (reduce + (set (concat (range 0 1000 3) (range 0 1000 5)))) |
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
| (reduce + (filter #(or (zero? (mod % 3)) (zero? (mod % 5))) (range 1000))) |
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
| (apply + (filter #(zero? (min (mod % 3) (mod % 5))) (range 1000))) |
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
| var HelloMessage = React.createClass({ | |
| render: function () { | |
| return <h1>Hello {this.props.message}!</h1>; | |
| } | |
| }); | |
| React.render(<HelloMessage message="World" />, document.body); |
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
| var ToggleText = React.createClass({ | |
| getInitialState: function () { | |
| return { | |
| showDefault: true | |
| } | |
| }, | |
| toggle: function (e) { | |
| // Prevent following the link. | |
| e.preventDefault(); |