Skip to content

Instantly share code, notes, and snippets.

#include <cs50.h>
#include <stdio.h>
#include <string.h>
// Max voters and candidates
#define MAX_VOTERS 100
#define MAX_CANDIDATES 9
// preferences[i][j] is jth preference for voter i
int preferences[MAX_VOTERS][MAX_CANDIDATES];
@TomDeBeauchamp
TomDeBeauchamp / MIT 6.189 Cipher.py
Last active December 19, 2015 02:08
This was my code for the Secret Messages problem from MIT's OCW Gentle Intro to Comp Sci via Python class, the first problem set, optional material.
letter = "a"
# converts a letter to ascii code
ascii_code = ord(letter)
# converts ascii code to a letter
letter_res = chr(ascii_code)
encoded_phrase = ""
phrase = raw_input("Type the phrase you'd like to see encoded. ")
@TomDeBeauchamp
TomDeBeauchamp / zeller.py
Created June 26, 2013 23:39
MIT 6.189 from the first problem set, the optional Zeller Algorithm
def zeller(A,B,C,D):
if A == 1 or A == 2:
A+=10
C-=1
else:
A-=2
W = (13*A-1) / 5
X = C / 4
Y = D / 4
Z = W + X + Y + B + C - 2*D
def roots(a,b,c):
d = b**2-4*a*c
#print d
if d < 0:
return "Too complex.", "d =" + str(d)
elif d == 0:
r1=-b/2*a
return r1, "d =" + str(d)
else:
@TomDeBeauchamp
TomDeBeauchamp / 6.189 Homework 2.3 Math Module.py
Last active December 18, 2015 22:38
6.189 Homework 2.3 Math Module
### The following are my attempts at homework 2.3 for MIT 6.189
###http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2011/assignments/MIT6_189IAP11_hw2.pdf
### Everything here works, and evaluates correctly, but I'd love some feedback.
### Particularly with understanding the intention behind the multadd method.
### In a few of my examples I use it essentially just to generate a sum (multiplying said sum by one).
### Is there a saavier way to use this, more in keeping with the spirit of the exercise?
## 1 - multadd function
##### YOUR CODE HERE #####