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
# Uses newton's method and DeMoivre's Theorem to find all n roots of a given | |
# number. | |
from cmath import * | |
y = 27+0j # Value to find the nth root of | |
n = 3 # Which root to find | |
theta = (2 * pi) / n | |
THRESHHOLD = .00000000001 | |
def f(x): | |
return x**n - y |
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 GPG import GPG | |
>>> gpg = GPG() | |
>>> key = "/home/nick/Desktop/joelkey.txt" | |
>>> result = gpg.import_key(key,is_file=True) | |
>>> gpg.list_keys()[2] | |
{'dummy': '', 'keyid': '7EA878DD4B83D0DE', 'expires': '1250998404', 'length': '1024', 'ownertrust': '-', 'algo': '17', 'fingerprint': 'B082991111D8165938164F4A7EA878DD4B83D0DE', 'date': '1250393604', 'trust': '-', 'type': 'pub', 'uids': ['', 'Testing (This is just a test!) <test@example.com>']} | |
>>> print1 = gpg.list_keys()[2]['fingerprint'] | |
>>> print1 | |
'B082991111D8165938164F4A7EA878DD4B83D0DE' | |
>>> result = gpg.encrypt("Hello!", print1,always_trust=True) |
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
DEBUG = False | |
def partial_digest(L): | |
L.sort() | |
width = L[-1] # Last Element | |
del L[-1] | |
X = [0, width] | |
place(L,X) | |
def place(L,X): |
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
# Thought of this simple technique for differentiating polynomial functions | |
# while not paying attention in my Differential Equations class | |
def differentiate(f): | |
f = f[0:-1] # Remove last value since it's a constant | |
for i in range(0, len(f)): | |
f[i] = f[i] * (len(f) - i) | |
return f | |
f = [1, 2, 1] # Represents x^2+2x+1 | |
print differentiate(f) == [2,2] # 2x + x |
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
def gcd(a, b): | |
# Make sure a is greater than b | |
if(a < b): | |
a, b = b, a | |
if a % b == 0: | |
print b | |
return | |
gcd(b, a % b) | |
gcd(3,5) # Prints 1 | |
gcd(2,6) # Prints 2 |
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
# Determines whether or not n is of the form a**b | |
from math import ceil | |
from math import log | |
from math import pow | |
def is_power(n): | |
a = 2 | |
b = ceil(log(n) / log(2)) | |
while b > 1: |
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 math import floor | |
from math import pow | |
def is_power(n): | |
b, l, u = 2, 1, n | |
while(True): | |
a = floor((l + u) / 2) | |
if a == l or a == u: | |
b = b + 1 | |
l = 1 |
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
replacements = { 'a': ['@', '4'], 'e': ['3'], 'i': ['!', '1'], 'o': ['0'] } | |
word = list('I am an awesome person') | |
for index, letter in enumerate(word): | |
if letter.lower() in replacements: | |
n = len(replacements[letter.lower()]) | |
word[index] = replacements[letter.lower()][index % n] | |
print newWord # Prints '! @m 4n @w3s0m3 p3rs0n' |
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
#include <iostream> | |
#include <math.h> | |
using namespace std; | |
int main() | |
{ | |
int n = 32; | |
int exp = (int)ceil(log(n)/log(2)); | |
int x = (int)pow(2, exp); |
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
<html> | |
<head> | |
<script type="text/javascript"> | |
// Author: Nick Peters | |
// Date: 02/14/11 | |
// Based on http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life | |
// Demo at http://www.nickpeters.net/life.html | |
var WIDTH = 100; | |
var HEIGHT = 100; | |
var state = new Array(WIDTH); |
OlderNewer