Skip to content

Instantly share code, notes, and snippets.

kevchn /
Last active Apr 10, 2018
Brute-Force Random Policy Search on Cartpole
import gym
import numpy as np
env = gym.make('CartPole-v0')
def run_episode(params):
total_reward = 0
observation = env.reset()
while True:
action = 0 if (params @ observation) < 0 else 1
kevchn /
Created Sep 8, 2017
Determine if a LinkedList is a Palindrome Recursively
def isLinkedListPalindromeRecursive(ll):
Recursively (recurse halfway (left), then pass down the next node (right) when recursing back through the stack)
This is the same as creating a stack in the first half and iterating through the next and popping
time: o(n)
space: o(n)
where n is the # of nodes in the list
return recurse(ll.head, lengthOfList(ll), [None])
You can’t perform that action at this time.