Skip to content

Instantly share code, notes, and snippets.

View craftybones's full-sized avatar

Srijayanth Sridhar craftybones

  • Bangalore, India
View GitHub Profile
(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))))))
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]);
(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)
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;
}
table {
text-align: center;
}
td {
padding: 20px;
}
@craftybones
craftybones / ns-cheatsheet.clj
Created November 3, 2016 19:02 — forked from ghoseb/ns-cheatsheet.clj
Clojure ns syntax cheat-sheet
;;
;; 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.
; 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
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++) {
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?
(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