Skip to content

Instantly share code, notes, and snippets.

View craftybones's full-sized avatar

Srijayanth Sridhar craftybones

  • Bangalore, India
View GitHub Profile
(defn prime-candidates
([] (lazy-seq (list* 2 3 (prime-candidates 1))))
([x] (lazy-seq (list* (dec (* x 6)) (inc (* x 6)) (prime-candidates (inc x))))))
(defn prime-candidates-less-than
[threshold]
(take-while (partial >= threshold) (prime-candidates)))
(defn is-prime?
[x]
@craftybones
craftybones / 00_destructuring.md
Created June 4, 2016 06:11 — forked from john2x/00_destructuring.md
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors

if ([ "$LEIN_FAST_TRAMPOLINE" != "" ] || [ -r .lein-fast-trampoline ]) &&
[ -r project.clj ]; then
INPUTS="$@ $(cat project.clj) $LEIN_VERSION $(cat "$LEIN_HOME/profiles.clj")"
(ns Player
(:gen-class))
(def xDirs {1 "E" 0 "" -1 "W"})
(def yDirs {1 "S" 0 "" -1 "N"})
(def offsets {1 inc 0 identity -1 dec})
(defn -main [& args]
(let [[lightX lightY initialTX initialTY] (repeatedly 4 read)
tX (atom initialTX)
tY (atom initialTY)]
(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
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?
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++) {
; 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
@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.
table {
text-align: center;
}
td {
padding: 20px;
}