Skip to content

Instantly share code, notes, and snippets.

View fakemonk1's full-sized avatar

Ashish Gupta fakemonk1

  • Meta
  • London
View GitHub Profile
  • Create a conda environment first with python version 3.7

conda create --name ml_env python=3.7

  • Install jupterlab to use Jupyter notebook and install dependencies

conda install -c conda-forge jupyterlab

def astar_search(graph, start, goal):
path = []
explored_nodes = list()
if start == goal:
return path, explored_nodes
path.append(start)
path_cost = get_manhattan_heuristic(start, goal)
def get_manhattan_heuristic(node, goal):
i, j = divmod(int(node), 8)
i_goal, j_goal = divmod(int(goal), 8)
i_delta = abs(i - i_goal)
j_delta = abs(j - j_goal)
manhattan_dist = i_delta + j_delta
return manhattan_dist
def uniform_cost_search(graph, start, goal):
path = []
explored_nodes = list()
if start == goal:
return path, explored_nodes
path.append(start)
path_cost = 0
def uniform_cost_search(graph, start, goal):
path = []
explored_nodes = list()
if start == goal:
return path, explored_nodes
path.append(start)
path_cost = 0
@fakemonk1
fakemonk1 / DQN_Algo_Lunar_Lander
Last active August 23, 2019 19:49
DQN Algorithm for Lunar Lander
initialize replay memory R
initialize action-value function Q (with random weights)
observe initial state s
repeat
select an action a
with probability ϵ select a random action
otherwise select a= argmaxa′Q(s,a′)
carry out action a
observe reward rr and new state s’
store experience <s,a,r,s> in replay memory R
@fakemonk1
fakemonk1 / Codility-demo2.java
Created March 20, 2017 22:39
Codility Demo 2 Solution
//This is 100% marks solution for the demo test PrefixSet https://codility.com/demo/take-sample-test/ps/
import java.util.Hashtable;
class Solution2 {
public int solution(int[] A) {
Hashtable<Integer, Integer> map = new Hashtable<>();
for(int i : A){
if(map.containsKey(i)){
map.put(i, map.get(i) +1);
}else{
map.put(i, 1);
@fakemonk1
fakemonk1 / Codility-demo.java
Last active October 13, 2022 03:06
Codility Demo Test - Java Solution
// 100% marks solution for the github demo test
// Find an index in an array such that its prefix sum equals its suffix sum.
class Solution {
public int solution(int[] A) {
if(A.length == 0){
return -1;
}
long leftSum = 0;
long rightSum = getSum(A);