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
double *randomVector(double v[2], int x, int y){ | |
/* generates two coordinates on a unit circle which are used | |
* for the 4 vectors from each grid point. | |
*/ | |
srand(time(NULL)); | |
double r; | |
int cont = 1; | |
/* http://burtleburtle.net/bob/rand/unitvec.html */ | |
do { | |
double m = (double)rand()/(double)(RAND_MAX-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
#include <stdio.h> | |
#include <time.h> | |
#include <stdlib.h> | |
#include <math.h> | |
double fRand(double min, double max){ | |
double f = (double)rand()/RAND_MAX; | |
return min+f*(max-min); | |
} |
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 itertools | |
import os, sys | |
import numpy | |
def get_data_range(filename): | |
start = ''.join([n for n in itertools.takewhile(lambda x: x != ",", open(filename).read())]) | |
end = ''.join(list(reversed([n for n in itertools.takewhile(lambda x: x != ",", reversed(open(filename).read()))]))) | |
ret = [start, end] | |
return eval(min(ret)), eval(max(ret)[:-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
def sieve(limit): | |
""" | |
Performs the Sieve of Eratosthenes | |
:return: A list of prime numbers less than a given limit | |
""" | |
numbers = [True] * (limit + 1) | |
for i in range(2, int(math.sqrt(limit))): | |
if numbers[i]: | |
j_increment = lambda j: [int(math.pow(j, 2) + (n * j)) for n in | |
itertools.takewhile(lambda x: int(math.pow(j, 2) + (x * j)) <= limit, |
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 nltk | |
def noun_with_adjectives(sentence): | |
""" selects the first occurrence of a noun in a sentence | |
with any accompanying adjectives """ | |
tags = nltk.pos_tag(sentence.split(" ")) | |
phrase = [] | |
for tag in tags: | |
if tag[1] in ["JJ", "JJS", "JJR"]: | |
phrase.append(tag[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
while self.counter <= self.limit: | |
for k in range(self.delta): | |
if self.counter in data: | |
self.output.append([self.current_x, self.current_y, self.counter]) | |
self.counter += 1 | |
self.next_point() | |
if self.side % 2 == 0: | |
self.delta += 1 | |
self.direction = (self.direction + 1) % 4 | |
self.side += 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
(defn square-root | |
([c] (square-root c 1e-15)) | |
([c epsilon] | |
(loop [t (double c)] | |
(if (float= t (/ c t) epsilon) | |
t | |
(recur (double (/ (+ t (/ c t)) 2)))) ))) | |
(defn ^:static is-prime? [^long n] | |
(if (<= n 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
(define (is-prime n) | |
(if (<= n 3) | |
(>= n 2) | |
(if (or (= (modulo n 2) 0) (= (modulo n 3) 0)) | |
#f | |
(do ((i 5 (+ i 6))) ((> i (+ (sqrt n) 1))) | |
(if (or (= (modulo n i) 0) (= (modulo n (+ i 2)) 0)) | |
#f))) #t)) | |
(define (main args) |
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 srfi-1) | |
(require-extension srfi-1) | |
(define (is-prime? n) | |
(cond | |
((<= n 3) (>= n 2)) | |
((or (= (modulo n 2) 0) (= (modulo n 3) 0)) #f) | |
(else (do ((i 5 (+ i 6))) ((> i (+ (sqrt n) 1))) | |
(if (or (= (modulo n i) 0) (= (modulo n (+ i 2)) 0)) | |
#f)) #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
with open('three.txt', 'r') as h: | |
data = h.read() | |
print(math.ceil(1.25 * (abs(data.count('^') - data.count('v') * data.count('<') - data.count('>')) >> 11) - 1)) |
OlderNewer