Skip to content

Instantly share code, notes, and snippets.

# ---------------
# User Instructions
#
# In this problem, you will be using many of the tools and techniques
# that you developed in unit 3 to write a grammar that will allow
# us to write a parser for the JSON language.
#
# You will have to visit json.org to see the JSON grammar. It is not
# presented in the correct format for our grammar function, so you
# will need to translate it.
@mkowoods
mkowoods / bpnn.py
Created June 14, 2015 20:35
Back-Propagation Neural Networks by Neil Schemenauer
# Back-Propagation Neural Networks
#
# Written in Python. See http://www.python.org/
# Placed in the public domain.
# Neil Schemenauer <nas@arctrix.com>
import math
import random
import string
from functools import update_wrapper
def decorator(d):
def _d(fn):
return update_wrapper(d(fn), fn)
update_wrapper(_d, d)
return _d
def decorator(d):
return lambda fn: update_wrapper(d(fn), fn)
@mkowoods
mkowoods / AITowersOfHanoi.py
Last active August 29, 2015 14:22
AI Approach to Towers of Hanoi through Search
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: MWoods
#
# Created: 09/06/2015
# Copyright: (c) MWoods 2015
# Licence: <your licence>
#-------------------------------------------------------------------------------
#http://www.reddit.com/r/dailyprogrammer/comments/38yy9s/20150608_challenge_218_easy_making_numbers/
def get_palindromic_number(num_str, max_iter = 1000):
i = 0
while not (num_str == num_str[::-1]) and i < max_iter:
num_str = str(int(num_str) + int(num_str[::-1]))
i += 1
return (None if i == max_iter else num_str) , i
if __name__ == "__main__":
@mkowoods
mkowoods / cryptoarithmetic.py
Created June 4, 2015 23:12
Quick Solution to Cryptarithmetic with generators
import string
equation = 'ODD + ODD == EVEN'
translator = (string.maketrans('ODEVN', str(o)+str(d)+str(e)+str(v)+str(n))
for o in range(10)
for d in range(10)
for e in range(10)
for v in range(10)
for n in range(10)
#http://www.reddit.com/r/dailyprogrammer/comments/38fjll/20150603_challenge_217_intermediate_space_code/
decoders = {
'Omicron V' : lambda coded : "".join([chr(c ^ int('0b10000', 2)) for c in coded]),
'Hoth' : lambda coded : "".join([chr(c - 10) for c in coded]),
'Ryza' : lambda coded : "".join([chr(c + 1) for c in coded]),
'Htrae' : lambda coded : "".join([chr(c) for c in coded[::-1]])
}
englishiness = lambda sentence : sum([c.isalpha() or c.isspace() for c in sentence])/float(len(sentence))
#http://www.reddit.com/r/dailyprogrammer/comments/3840rp/20150601_challenge_217_easy_lumberjack_pile/
import heapq
class LogPile:
#Used a min-heap based on value and position to order the locations
def __init__(self, path):
self.size = None
self.logs_to_add = None
self.logs = {}
@mkowoods
mkowoods / daily_programmer_20150525.py
Created May 28, 2015 01:01
part 1 of 3 for Texas Hold Em Daily Programmer Project
import random
#https://www.reddit.com/r/dailyprogrammer/comments/378h44/20150525_challenge_216_easy_texas_hold_em_1_of_3/
class Deck:
def __init__(self):
self.deck = [(rank, suit) for rank in range(1, 14) for suit in ["S", "C", "D", "H"]]
random.shuffle(self.deck)
#Answer to https://www.reddit.com/r/dailyprogrammer/comments/3629st/20150515_challenge_214_hard_chester_the_greedy/
#Needs to be further optimized and revisit quadtree implementation (use a bounded quadtree instead or a k-d tree
import heapq
from collections import deque
import random
start = [0.5, 0.5]
food = [(0.9, 0.7), (0.7, 0.7), (0.1, 0.1), (0.4, 0.1), (0.6, 0.6), (0.8, 0.8)]