- 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
conda
environment first with python version 3.7conda create --name ml_env python=3.7
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 | |
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 |
//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); |
// 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); |