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 paip.eliza | |
(:require [clojure.string :as string]) | |
(:gen-class)) | |
(defn index-of | |
"Returns the index of item. If start is given indexes prior to | |
start are skipped." | |
([coll item] (.indexOf coll item)) | |
([coll item start] |
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
{ | |
"metadata": { | |
"name": "" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ |
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
# -*- coding: utf-8 -*- | |
""" | |
Created on Thu Jun 27 09:46:27 2013 | |
@author: joshua | |
""" | |
import matplotlib.pyplot as plt | |
vectors = [[1, 2], [3, 4], [-2, -4]] |
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
import random | |
def initialize_urn(): | |
reds = ["red" for i in range(50)] | |
blacks = ["black" for i in range(50)] | |
return reds + blacks | |
def get_pair(urn): | |
choice_1 = random.choice(urn) | |
urn.remove(choice_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
from math import sqrt | |
# A dictionary of movie critics and their ratings of a small set of movies | |
critics={'Lisa Rose': {'Lady in the Water': 2.5, 'Snakes on a Plane': 3.5, | |
'Just My Luck': 3.0, 'Superman Returns': 3.5, 'You, Me and Dupree': 2.5, | |
'The Night Listener': 3.0}, | |
'Gene Seymour': {'Lady in the Water': 3.0, 'Snakes on a Plane': 3.5, | |
'Just My Luck': 1.5, 'Superman Returns': 5.0, 'The Night Listener': 3.0, | |
'You, Me and Dupree': 3.5}, | |
'Michael Phillips': {'Lady in the Water': 2.5, 'Snakes on a Plane': 3.0, |
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
""" | |
Student was an AI program developed in the late sixties which used | |
pattern matching to solve basic algebraic word problems. This an | |
attempt to implement Student in Python through study of the Common | |
Lisp imlpementation outlined in Paradigms of Artificial Intelligence | |
Programming: Case Studies in Common Lisp (PAIP) by Peter Norvig. | |
""" | |
import operator | |
import re |
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
import datetime | |
from dateutil.relativedelta import relativedelta | |
def relative_month(d, months): | |
"""Accepts a datetime or date object and returns another datetime object. | |
The returned datetime is the start of the datetime n months away. This does | |
not have side effects. | |
Args: | |
d - a date or datetime object |
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 input-question () | |
(print "Please enter a question which has a yes answer for your word. This question should result in a no for the incorrect word given earlier:") | |
(read-line)) | |
(defun input-chosen-word () | |
(print "Please enter the word that you chose at the start of the game:") | |
(read-line)) | |
(defun input-question-answer (question) | |
(print question) |
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
(use 'clojure.contrib.math) | |
(def factorial | |
(fn [n] | |
(loop [cnt n acc 1] | |
(if (zero? cnt) | |
acc | |
(recur (dec cnt) (* acc cnt)))))) | |
(defn perm |
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 C_yx [m1 m2 y x num-cols num-rows] | |
(reduce + | |
(map * | |
(map #(nth (nth m1 y) %1) (range num-cols)) | |
(map #(nth (nth m2 %1) x) (range num-rows))))) | |
(defn multiply [m1 m2] | |
(let [num-rows (count m1) num-cols (count (first m1))] | |
(for [y (range num-rows)] | |
(for [x (range num-cols)] |
NewerOlder