This file contains hidden or 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 | |
| num_sticks = 22 | |
| num_states = num_sticks + 6 | |
| num_actions = 3 | |
| action_list = range(num_actions) | |
| num_iterations = 10000 | |
| gamma = 0.1 | |
| alpha = 0.5 |
This file contains hidden or 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
| void sample(int * samples, size_t n, size_t N) { | |
| size_t t = 0, m = 0; | |
| while(m < n) | |
| { | |
| double u = rand() / (double)RAND_MAX; | |
| if((N-t)*u >= n-m) t++; | |
| else samples[m++] = t++; | |
| } | |
| } |
This file contains hidden or 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 <string.h> | |
| int main() { | |
| char s[] = "hello world!"; | |
| int n = strlen(s); | |
| // reverse string in-place. | |
| int i, j, t; |
This file contains hidden or 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> | |
| void shuffle(int *array, size_t n) | |
| { | |
| if (n > 1) { | |
| size_t i; | |
| for (i = 0; i < n - 1; i++) { | |
| size_t j = i + rand() / (RAND_MAX / (n - i) + 1); | |
| int t = array[j]; | |
| array[j] = array[i]; |
This file contains hidden or 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 | |
| class Trie: | |
| def __init__(self): | |
| self.children = [None]*10 | |
| def insert(self, i, n): | |
| if n == 1: | |
| self.children[i] = True | |
| else: | |
| d = i / 10**(n-1) |
This file contains hidden or 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> | |
| #define N 20 | |
| #define K 5 | |
| // reverses letters in indices s[from:to] | |
| void reverse_string(char * s, int from, int to) | |
| { | |
| char * p1 = s + from; | |
| char * p2 = s + to; |
This file contains hidden or 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
| sudo ./NVIDIA-Linux-x86_64-319.23.run -e -Z --opengl-headers |
This file contains hidden or 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
| NVCC = /usr/local/cuda/bin/nvcc | |
| all: vecadd | |
| %.o : %.cu | |
| $(NVCC) -c $< -o $@ | |
| vecadd : vecadd.o | |
| $(NVCC) $^ -o $@ |
This file contains hidden or 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 <Servo.h> | |
| Servo tilt, roll; | |
| int pos=0; | |
| void setup() { | |
| Serial.begin(9600); | |
| tilt.attach(3); | |
| roll.attach(5); | |
| pinMode(9, OUTPUT); | |
| pinMode(10, OUTPUT); |
This file contains hidden or 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 <GL/glut.h> | |
| void draw(void) | |
| { | |
| glClearColor(0,1,0,1); | |
| glClear(GL_COLOR_BUFFER_BIT ); | |
| glFlush(); | |
| } | |
| int main(int argc, char **argv) |