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 | |
def roll_dice(number,sides): | |
for i in range(0,number): | |
rolled = random.randint(1,sides) | |
print("You rolled {}!".format(rolled)) | |
while True: | |
number = int(input("How many dice do you want to roll? ")) | |
sides = int(input("How many sides on each dice? ")) |
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 random import choice | |
import time | |
def hit_or_stick(): | |
while sum(your_cards)<22: | |
response = raw_input("Would you like to hit or stick? ") | |
if response.lower() == "hit": | |
your_cards.append(choice(cards)) | |
print("Drawing...") | |
time.sleep(0.5) |
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
char *strstr(const char *haystack, const char *needle) | |
{ | |
size_t h_len = strlen(haystack); | |
size_t n_len = strlen(needle); | |
size_t i, j; | |
for (i = 0; i < h_len; i++) | |
{ | |
size_t found = 0; | |
for (j = 0; j < n_len; j++) | |
{ |
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 <string.h> | |
#include <stdbool.h> | |
bool strend(const char *s, const char *t) | |
{ | |
size_t slen = strlen(s); | |
size_t tlen = strlen(t); | |
if (tlen > slen) return false; | |
else return !strcmp(s + (slen - tlen), t); |
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
euclidian = lambda v1,v2: (sum([(a-b)**2 for a,b in zip(v1,v2)])**0.5) | |
print(euclidian([0.4,0.2,0.3],[0.5,0.6,0.7])) #0.574456264654 |
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 <stdlib.h> | |
#include <stdio.h> | |
typedef struct Array { | |
int* arr; | |
size_t length; | |
} Array; | |
Array* newArray(int len) | |
{ |
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
for (char c = 33; c < 126; c++) | |
{ | |
cout << dec << int(c) << hex << " " << int(hex) << int(c) << " " << oct << int(c) << " " << c << "\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
#ifdef _WIN32 | |
#include <Windows.h> | |
#define muhSleep(x) Sleep((x)) | |
#else | |
#include <unistd.h> | |
#define muhSleep(x) sleep((x)) | |
#endif | |
void fillOffsets( int **offsets, char *str ) | |
{ |
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 re | |
from sys import stdout | |
from random import randint, choice | |
from collections import defaultdict | |
#http://theorangeduck.com/page/17-line-markov-chain | |
#http://theorangeduck.com/media/uploads/other_stuff/poetry.zip | |
with open('poetry.txt') as f: | |
words = re.split(' +', f.read()) |
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 get_num_params(model): | |
param_count = 0 | |
for param in model.parameters(): | |
param_count += np.product(param.data.shape) | |
return param_count |
OlderNewer