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
epsilon = 0.01 | |
y = 1234567.0 | |
guess = y/2.0 | |
while abs(guess*guess - y) >= epsilon: | |
guess = guess - (((guess**2) - y)/(2*guess)) | |
print(guess) | |
print('Square root of ' + str(y) + ' is about ' + str(guess)) |
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
x = 1234567 | |
epsilon = 0.01 | |
numGuesses = 0 | |
low = 0.0 | |
high = x | |
ans = (high + low)/2.0 | |
while abs(ans**2 - x) >= epsilon: | |
print('low = ' + str(low) + ' high = ' + str(high) + ' ans = ' + str(ans)) | |
numGuesses += 1 | |
if ans**2 < 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
num = 256 | |
if num < 0: | |
isNeg = True | |
num = abs(num) | |
else: | |
isNeg = False | |
result = '' | |
if num == 0: | |
result = '0' |
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 a(x, y, z): | |
if x: | |
return y | |
else: | |
return z | |
def b(q, r): | |
return a(q>r, q, r) | |
print(a(False, 2, 3)) |
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
The value for these configuration variables is a list of colors (at most two) and attributes (at most one), separated by spaces. The colors accepted are normal, black, red, green, yellow, blue, magenta, cyan and white; the attributes are bold, dim, ul, blink and reverse. The first color given is the foreground; the second is the background. The position of the attribute, if any, doesn't matter. | |
http://git-scm.com/docs/git-config |
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 <cstdio> | |
const int MAX_N = 50; | |
int main() { | |
int n, m, k[MAX_N]; | |
scanf("%d %d", &n, &m); | |
for (int i = 0; i < n; i++) { | |
scanf("%d", &k[i]); | |
} |
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 <algorithm> | |
#include <iostream> | |
using namespace std; | |
const int MAX_N = 100; | |
int n, m, k[MAX_N]; | |
int kk[MAX_N * MAX_N]; |
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 three4doller(num): | |
return (num%3)*round(1/3.0, 2)+(num/3)*1 | |
print three4doller(1) | |
print three4doller(2) | |
print three4doller(3) | |
print three4doller(4) | |
print three4doller(5) | |
print three4doller(6) |
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
# 1 pound == 16 ounces | |
def ounce2pound(ounce): | |
return ounce/16.0 | |
def cost(ounces): | |
return round(1.99*ounce2pound(ounces), 2) | |
print cost(1) | |
print cost(2) | |
print cost(3) |
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 chop(target, search_array): | |
if target in search_array: | |
return search_array.index(target) | |
else: | |
return -1 |
OlderNewer