Jump to:
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
#!/usr/bin/env python | |
"""An implementation of the IBM Model 1 expectation-maximization | |
algorithm for learning word alignments. | |
""" | |
from collections import defaultdict | |
import copy | |
import itertools | |
import operator |
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
config/install.sh: Using shell /bin/sh. | |
config/install.sh: SML root is /usr/local/Cellar/smlnj/110.74/libexec. | |
config/install.sh: Installation directory is /usr/local/Cellar/smlnj/110.74/libexec. | |
config/install.sh: Installing version 110.74. | |
config/install.sh: URL of source archive is http://smlnj.cs.uchicago.edu/dist/working/110.74/. | |
config/install.sh: Script /usr/local/Cellar/smlnj/110.74/libexec/bin/.arch-n-opsys reports ARCH=x86; OPSYS=darwin; HEAP_SUFFIX=x86-darwin. | |
/usr/local/Cellar/smlnj/110.74/libexec/config/unpack: Fetching run-time from http://smlnj.cs.uchicago.edu/dist/working/110.74/. Please stand by... | |
/usr/local/Cellar/smlnj/110.74/libexec/config/unpack: Trying runtime.tgz ... | |
/usr/local/Cellar/smlnj/110.74/libexec/config/unpack: Fetching runtime.tgz was a success. | |
/usr/local/Cellar/smlnj/110.74/libexec/config/unpack: Un-GZIP-ing and un-TAR-ing run-time archive. |
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
(defrecord BinaryTree [key left right])) | |
(defn insert [tree val] | |
(if (nil? tree) | |
(BinaryTree. val nil nil) | |
(let [key (:key tree)] | |
(cond | |
(< key val) (BinaryTree. key | |
(:left tree) | |
(insert (:right tree) val)) |
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 euler.utils.derivative | |
(:use clojure.contrib.math)) | |
(defn take-with-epsilon | |
"Take from a list of numbers xs until two numbers are within the epsilon eps. | |
Check a maximum of `limit` times. Returns the last number of the satisfying | |
pair or nil of no match is found." | |
[xs eps limit] | |
(let [next (rest xs)] |
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 Leibniz { | |
public static void main(String[] args) { | |
Leibniz test = new Leibniz(); | |
System.out.println(test.leibnizPi(0)); | |
System.out.println(test.leibnizPi(-1)); | |
System.out.println(test.leibnizPi(-4)); | |
} | |
public double leibnizPi(int accuracy) { | |
double target_accuracy = Math.pow(10, accuracy); |
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
(use 'clojure.contrib.math) | |
(defn leibniz-pi [accuracy] | |
(let [target-accuracy (expt 10 accuracy)] | |
(loop [acc 1.0 sub 3 sign -1] | |
(let [attempt (* 4.0 acc)] | |
(if (> (abs (- attempt Math/PI)) target-accuracy) | |
(recur (+ acc (* sign (/ 1.0 sub))) (+ 2 sub) (- sign)) | |
attempt))))) |
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
import java.util.Properties; | |
import javax.mail.Authenticator; | |
import javax.mail.Message; | |
import javax.mail.MessagingException; | |
import javax.mail.PasswordAuthentication; | |
import javax.mail.Session; | |
import javax.mail.Transport; | |
import javax.mail.internet.InternetAddress; | |
import javax.mail.internet.MimeMessage; | |
import javax.mail.internet.MimeMessage.RecipientType; |
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
;; (split 3 [1 2 3 4 5 6]) => [[1 2 3] [4 5 6]] | |
;; (split 1 [:a :b :c :d]) => [[:a] [:b :c :d]] | |
(defn split [n xs] | |
(loop [acc '(), inacc '(), flxs (first xs), lxs (rest xs), cnt n] | |
(print acc inacc cnt "\n") | |
(if (nil? flxs) | |
(reverse (conj acc (reverse inacc))) | |
(if (zero? cnt) | |
(recur (conj acc (reverse inacc)) nil flxs lxs -1) |
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
(fn [thefn] | |
(fn [& args] | |
(apply thefn (reverse args)))) |