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
(ns rewrite.ex | |
(:require [clojure.core.logic :refer [defnc fnc]] | |
[termito.core :refer [defrules simplify simplify-one]])) | |
(defnc numberc [x] | |
(number? x)) | |
(defrules bad | |
[:dog :cat] | |
[:cat :dog]) |
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
In[1]:= sum[m_, 0] := m; | |
sum[m_, s[n_]] := s[sum[m, n]]; | |
In[3]:= sum[s[s[0]], s[s[s[s[0]]]]] | |
Out[3]= s[s[s[s[s[s[0]]]]]] | |
In[4]:= map[f_, {}] := {}; | |
map[f_, {x_, xs___}] := Prepend[map[f, {xs}], f[x]]; |
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
(ns randomstuff.match | |
(:require [clojure.core.match :refer [match]])) | |
(defn card_color [[suit value]] | |
(match [suit value] | |
[:diamonds _] :red | |
[:hearts _] :red | |
:else :black)) ;; or [_ _] |
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
(* SML playing a *) | |
fun fac 0 = 1 | |
| fac n = n * fac (n - 1); | |
fun div_by n x = | |
x mod n = 0; | |
val div_3 = div_by 3; | |
val div_5 = div_by 5; |
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
(defmulti fact1 identity) | |
(defmethod fact1 0 [_] 1) | |
(defmethod fact1 :default [n] (* n (fact1 (dec n)))) | |
(defmulti fizzbuzz | |
(fn [n] | |
[(zero? (mod n 3)) | |
(zero? (mod n 5))])) |
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
;; austin clojure meetup hacking | |
;; ---------------------------------------- | |
;; just merge 2 seqs | |
(defn merge2 [s1 s2] | |
(if (seq s1) | |
(when (seq s2) | |
(let [i1 (first s1) |
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
;; http://gigasquidsoftware.com/blog/2014/11/13/clojure-fizzbuzz-without-conditionals | |
(defn fb [n] | |
(or (->> (map #(str %1 %2) | |
(cycle [nil nil "fizz"]) (cycle [nil nil nil nil "buzz"])) | |
(take n) | |
last | |
not-empty) | |
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
-- exercise 1 | |
toDigitsRev n = if (n <= 0) | |
then [] | |
else (n `mod` 10) : (toDigitsRev (n `div` 10)) | |
toDigits = reverse . toDigitsRev | |
-- exercise 2 |
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
public class Game { | |
// https://gist.github.com/orb/ | |
public static void main(String[] args) { | |
char[][] board = new char[20][40]; | |
initBoard(board); | |
int x = 5; | |
int y = 5; | |
int xspeed = 1; | |
int yspeed = -1; |
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
(ns jaspertest.core | |
(:import [net.sf.jasperreports.engine JasperFillManager JasperExportManager JasperCompileManager]) | |
(:require [clojure.java.io :as io])) | |
(defn java-hashmap [results-map] | |
(let [hashmap-reducer (fn [m [k v]] (doto m (.put (name k) v)))] | |
(reduce hashmap-reducer (java.util.HashMap.) results-map))) | |
(def mock-data |