Skip to content

Instantly share code, notes, and snippets.

@mooreniemi
mooreniemi / newpopalg.rb
Created May 2, 2012 01:33
new alg test
require 'date'
require 'csv'
#Given a csv file output from Sermo App at https://app.sermo.com/reporting/reports/post_summary_by_date
#we need a csv of the posts in order of popularity, with the addition of a bayesian average to respond to different days.
#constructor of my post object with the csv fields to hold all the attributes
class Post <
# a post has csv categories a-q
@mooreniemi
mooreniemi / output.rb
Created May 7, 2012 20:42
csv to array to txt
require 'date'
require 'csv'
class Post <
# a Person has a first name, last name, and city
Struct.new(:title, :link, :cats, :publish_date, :avg_rating, :comments, :votes, :username, :specialty, :pop)
end
@mooreniemi
mooreniemi / postpropay.rb
Created May 8, 2012 20:58
post promo payment
require 'date'
require 'csv'
#Given a csv file output from Sermo App at https://app.sermo.com/reporting/reports/post_summary_by_date
#we need a csv of the Post Promo contest winners (base $15 and grand prize $30) by the week's targeted specialties.
#We need to only pay members once, and only pay them for posts which received 10 comments and an average rating of at least 3 stars.
#Specialties targeted were sent an automated e-mail from Exact Target to remind them it was their day to participate.
#You will only need to tell this program what the file name from the Sermo app was, and it will output a payment csv file for you!
#constructor of my post object with the csv fields to hold all the attributes
def getGuessedWord(secretWord, lettersGuessed):
'''
secretWord: string, the word the user is guessing
lettersGuessed: list, what letters have been guessed so far
returns: string, comprised of letters and underscores that represents
what letters in secretWord have been guessed so far.
'''
count = 0
blank = ['_'] * len(secretWord)
#print blank
def getAvailableLetters(lettersGuessed):
'''
lettersGuessed: list, what letters have been guessed so far
returns: string, comprised of letters that represents what letters have not
yet been guessed.
'''
# FILL IN YOUR CODE HERE...
L2 = []
import string
for c in string.ascii_lowercase:
@mooreniemi
mooreniemi / hangman
Created October 23, 2012 01:14
600x
def hangman(secretWord):
'''
secretWord: string, the secret word to guess.
Starts up an interactive game of Hangman.
* At the start of the game, let the user know how many
letters the secretWord contains.
* Ask the user to supply one guess (i.e. letter) per round.
def compChooseWord(hand, wordList):
"""
Given a hand and a wordList, find the word that gives
the maximum value score, and return it.
This word should be calculated by considering all the words
in the wordList.
If no words in the wordList can be made from the hand, return None.
@mooreniemi
mooreniemi / findBestShift
Created November 9, 2012 00:14
600x PS5
def findBestShift(wordList, text):
"""
Finds a shift key that can decrypt the encoded text.
text: string
returns: 0 <= int < 26
"""
### TODO
bestShift=0
ValidWords=0
@mooreniemi
mooreniemi / PS7
Created November 25, 2012 20:12
600x
class RectangularRoom(object):
"""
A RectangularRoom represents a rectangular region containing clean or dirty
tiles.
A room has a width and a height and contains (width * height) tiles. At any
particular time, each of these tiles is either clean or dirty.
"""
def __init__(self, width, height):
"""
@mooreniemi
mooreniemi / PS7-3
Created November 26, 2012 01:45
600x
# === Problem 3
def runSimulation(num_robots, speed, width, height, min_coverage, num_trials,
robot_type):
"""
Runs NUM_TRIALS trials of the simulation and returns the mean number of
time-steps needed to clean the fraction MIN_COVERAGE of the room.
The simulation is run with NUM_ROBOTS robots of type ROBOT_TYPE, each with
speed SPEED, in a room of dimensions WIDTH x HEIGHT.