Skip to content

Instantly share code, notes, and snippets.

@jColeChanged
jColeChanged / eliza.clj
Last active February 26, 2021 04:02
Subset of Eliza Chatbot in Clojure
(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]
@jColeChanged
jColeChanged / ipython notebook test file
Created August 24, 2013 23:13
A test gist to see how to share python notebooks.
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
# -*- 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]]
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)
@jColeChanged
jColeChanged / gist:5810617
Last active December 18, 2015 16:19
A simple recommendation engine that I learned to make while reading Programming Collective Intelligence
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,
@jColeChanged
jColeChanged / student.py
Created May 28, 2013 21:04
An implementation of Student, a program capable of solving basic math problems in which a variable needs to be isolated
"""
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
@jColeChanged
jColeChanged / month_utils.py
Created June 22, 2012 00:21
These are a few helper functions I ended up wanting while working with months while doing freelance work. I'm putting them up here since, though simple, they ended up being useful enough that if I ever work with dates again I'll probably end up using them
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
@jColeChanged
jColeChanged / 20 Questions in Common Lisp
Created August 6, 2011 00:30
Just Wrote the Game Twenty Questions in Common Lisp
(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)
(use 'clojure.contrib.math)
(def factorial
(fn [n]
(loop [cnt n acc 1]
(if (zero? cnt)
acc
(recur (dec cnt) (* acc cnt))))))
(defn perm
@jColeChanged
jColeChanged / gist:939383
Created April 24, 2011 07:03
My attempt at matrix multiplication in Clojure
(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)]