Skip to content

Instantly share code, notes, and snippets.

View sundeepblue's full-sized avatar
🎯
Focusing

Protoss In Matrix sundeepblue

🎯
Focusing
View GitHub Profile
@sundeepblue
sundeepblue / min-char-rnn.py
Created June 18, 2019 20:03 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@sundeepblue
sundeepblue / pg-pong.py
Created February 17, 2018 04:02 — forked from karpathy/pg-pong.py
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward
@sundeepblue
sundeepblue / client.py
Last active August 29, 2015 14:10 — forked from EyalAr/client.py
from subprocess import Popen, PIPE
from time import sleep
# run the shell as a subprocess:
p = Popen(['python', 'shell.py'],
stdin = PIPE, stdout = PIPE, stderr = PIPE, shell = False)
# issue command:
p.stdin.write('command\n')
# let the shell output the result:
sleep(0.1)
@sundeepblue
sundeepblue / find the minimal difference between two sorted arrays elements
Last active December 1, 2019 01:53
find the minimal difference between two sorted arrays elements
int find_min_diff(vector<int>& A, vector<int>& B) {
if(A.empty() || B.empty()) return -1;
int m = A.size(), n = B.size();
int i = 0, j = 0;
int min_diff = INT_MAX;
while(i < m && j < n) {
int diff = abs(A[i] - B[j]);
min_diff = min(min_diff, diff);
if(min_diff == 0) return 0;
@sundeepblue
sundeepblue / Kth maximal element of sum of two arrays
Last active August 29, 2015 14:01
Kth maximal element of sum of two arrays
// http://stackoverflow.com/questions/5212037/find-the-pair-across-2-arrays-with-kth-largest-sum
// result may not be correct!!!!!!!!!!!!!!!!!
// 6/6/2015. attempted to calculate time complexity seems to be:
// log1 + log2 + ... + logk = logk! = O(klogk)
// here is how to calculate logk!
// http://stackoverflow.com/questions/2095395/is-logn-%CE%98n-logn
// http://ballinger.disted.camosun.bc.ca/math126/lognfactorial.pdf
@sundeepblue
sundeepblue / detect the longest cycle in an array
Created May 15, 2014 17:36
graph, detect the longest cycle in an array
void dfs(int start, int idx, int a[], int N, bool *visited, int& len) {
if(idx >= N) {
len = 1;
return;
}
visited[idx] = true;
len++;
//if(start == a[idx]) return;
if(visited[a[idx]] == false) {
@sundeepblue
sundeepblue / detect cycle in array
Created May 15, 2014 16:04
detect cycle in array
/*
Given an array of integers where each element points to the index of the next element
how would you detect if there is a cycle in this array
Note: if the element of array is in range[0, n-1], where n is the length of array, then there must be at least one cycle.
Thus, the element may be negative or out of range[0,n-1]
/*
bool has_cycle_in_array(int a[], int N) {
if(N == 1) return false;
int slow = 0, fast = 0;
// tournament tree
// threaded binary tree
#define MAXV 1000
bool processed[MAXV+1];
bool discovered[MAXV+1];
int parent[MAXV+1];
struct edgenode {
int y;
int weight;
edgenode *next;