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
#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)] |
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 | |
#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) | |
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://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 = {} |
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://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)) |
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 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) |
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://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__": |
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
#------------------------------------------------------------------------------- | |
# Name: module1 | |
# Purpose: | |
# | |
# Author: MWoods | |
# | |
# Created: 09/06/2015 | |
# Copyright: (c) MWoods 2015 | |
# Licence: <your licence> | |
#------------------------------------------------------------------------------- |
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 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) |
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
# Back-Propagation Neural Networks | |
# | |
# Written in Python. See http://www.python.org/ | |
# Placed in the public domain. | |
# Neil Schemenauer <[email protected]> | |
import math | |
import random | |
import string |
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
# --------------- | |
# 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. |