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
| (ns learning-reagent.core | |
| (:require [reagent.core :as reagent])) | |
| ;; ------------------------- | |
| ;; Views | |
| (defn fibo | |
| ([] (fibo 1 1)) | |
| ([s1 s2] (lazy-seq (cons s1 (fibo s2 (+ s1 s2)))))) |
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 fibo=function(n) { | |
| if (n<=0) | |
| return []; | |
| if(n<3) | |
| return [1,0].slice(0,n); | |
| var a=Array.apply(null,new Array(n-2)); | |
| return a.reduce(function(l,x){ | |
| l.unshift(l[0]+l[1]); | |
| return l; | |
| },[1,0]); |
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 fibo [s1 s2] | |
| (lazy-seq (cons s1 (fibo s2 (+ s1 s2))))) | |
| (defn fibo-even (comp (partial filter even?) fibo)) | |
| (def fibonacci (fibo 1 1)) | |
| (def fibonacci-even (fibo-even 1 1)) | |
| (take 10 fibonacci) |
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 printFibo=function(n) { | |
| var s1=0; | |
| var s2=1; | |
| var s3; | |
| for (var i = 0; i < n; i++) { | |
| console.log(s2); | |
| s3=s1+s2; | |
| s1=s2; | |
| s2=s1+s2; | |
| } |
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
| table { | |
| text-align: center; | |
| } | |
| td { | |
| padding: 20px; | |
| } |
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
| ;; | |
| ;; NS CHEATSHEET | |
| ;; | |
| ;; * :require makes functions available with a namespace prefix | |
| ;; and optionally can refer functions to the current ns. | |
| ;; | |
| ;; * :import refers Java classes to the current namespace. | |
| ;; | |
| ;; * :refer-clojure affects availability of built-in (clojure.core) | |
| ;; functions. |
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
| ; first argument to list is always a function | |
| (println "Hello World") | |
| ; + - * and / are functions! | |
| (+ 2 3) | |
| (- 2 3) | |
| (* 3 4) | |
| (/ 10 5) | |
| ; They can take multiple arguments |
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 isPrime=function(x){ | |
| for (var i = 2; i <= Math.sqrt(x); i++) { | |
| if(x%i==0){return false;} | |
| } | |
| return true; | |
| } | |
| var primeFactors=function(x) { | |
| var factors=[]; | |
| for (var i = 2; i <= x; i++) { |
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
| class Fixnum | |
| def is_prime? | |
| 2.upto(self-1).none? do |y| | |
| self%y==0 | |
| end | |
| end | |
| def prime_factors | |
| 2.upto(self).select do |x| | |
| self%x==0 && x.is_prime? |
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
| (ns jitu-problem.core | |
| (:require [clojure.math.numeric-tower :as math] | |
| [clojure.set :as cset]) | |
| (:gen-class)) | |
| (defn divisible-by? | |
| [x y] | |
| (zero? (rem y x))) | |
| (defn prime-candidates |