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 sum-nums-mod-3-5 | |
[n] | |
(reduce + | |
(filter #(or (zero? (mod % 3)) (zero? (mod % 5))) | |
(range n)))) |
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 rpn | |
[& exprs] | |
(cond (one? (count exprs)) (first exprs) | |
(zero? (count exprs)) 0 | |
:else | |
(let [nums (take-while number? exprs) | |
etc (drop (count nums) exprs) | |
op (first etc)] | |
(recur (cons (apply op nums) | |
(rest etc)))))) |
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
;; want this behavior | |
(defn iof | |
[val coll] | |
(lazy-seq | |
(loop [coll coll idx 0] | |
(cond | |
(empty? coll) '() | |
(= val (first coll)) (cons idx (recur val (rest coll) (inc idx))) | |
:else (recur val (rest coll) (inc idx)))))) |
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
#include <stdio.h> | |
#include <time.h> | |
#include <stdlib.h> | |
int main(int argc, char **argv){ | |
long iterations = atoi(argv[1]); | |
double sum = 0; | |
long ans, i, j = 0; | |
long seed = time((time_t *) NULL); |
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 sum | |
[& s] | |
(reduce + s)) | |
(defn prod | |
[& s] | |
(reduce * s)) | |
(defn sigma | |
[s f] |
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 f [n] | |
(lazy-seq | |
(loop [n n] | |
(if (zero? n) [] | |
(cons n (f (dec n)))))) |
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
(def groups {:particles | |
[#'chemicalj.atom/make-atom | |
#'chemicalj.molocule/make-molocule etc] | |
{:simulations […]}) | |
(use-groups …intern the vars in the given vector(s) into the current ns) |
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
from string import split | |
import sys | |
# supports ^, $, |, c (literal), . (wildcard), *, +, ? | |
# !supports char classes, escaped specials, grouping | |
def match(regexp, text): | |
if '|' in regexp: | |
for r in split(regexp, '|'): | |
if match(r, text): return True |
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
(defun partial (f &rest args) | |
(lambda (&rest mrgs) | |
(apply 'f (append args mrgs)))) |
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
(doto frame | |
(.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE) | |
(.setFocusable true) | |
(init-jframe-key-bindings! | |
{"RIGHT" [:next-view to-next-view] | |
"LEFT" [:prev-view to-previous-view] |
OlderNewer