blob_id stringlengths 40 40 | repo_name stringlengths 11 42 | path stringlengths 6 141 | length_bytes int64 327 5.33k | score float64 3.52 4.16 | int_score int64 4 4 | content stringlengths 327 5.33k |
|---|---|---|---|---|---|---|
b7b944e5d5dd1cd1b41952c55bc13c348f905024 | Oyekunle-Mark/Graphs | /projects/ancestor/ancestor.py | 1,360 | 3.671875 | 4 | from graph import Graph
from util import Stack
def earliest_ancestor(ancestors, starting_node):
# FIRST REPRESENT THE INPUT ANCESTORS AS A GRAPH
# create a graph instance
graph = Graph()
# loop through ancestors and add every number as a vertex
for parent, child in ancestors:
# add the pa... |
150d0efefb3c712edc14a5ff039ef2082c43152b | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/111_Minimum_Depth_of_Binary_Tree.py | 1,281 | 4.03125 | 4 | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
c_ Solution o..
# def minDepth(self, root):
# """
# :type root: TreeNode
# :rtype: int
# """
# # Recursio... |
039dd3727cdd229548d94108ee220efa4a5b4838 | mertdemirlicakmak/project_euler | /problem_5.py | 1,144 | 4.0625 | 4 | """"2520 is the smallest number that can be divided by each of the numbers
from 1 to 10 without any remainder.
What is the smallest positive number that is evenly
divisible by all of the numbers from 1 to 20?"""
# This function returns the smallest number that is divisible to
# 1 to num
def find_smallest_divisible(nu... |
0437daed01bce0f5a3046616917a2c29a1ed15d0 | zhouyuhangnju/freshLeetcode | /Combination Sum.py | 1,252 | 3.71875 | 4 | def combinationSum(candidates, target):
"""
:type candidates: List[int]
:type target: int
:rtype: List[List[int]]
"""
res = []
candidates = sorted(candidates)
def combinationRemain(remain, curr_res):
if remain == 0:
res.append(curr_res)
return
... |
246130cc6d8d3b7c3fee372774aa2f93018f4e35 | alexleversen/AdventOfCode | /2020/08-2/main.py | 1,119 | 3.625 | 4 | import re
file = open('input.txt', 'r')
lines = list(file.readlines())
def testTermination(swapLine):
if(lines[swapLine][0:3] == 'acc'):
return False
instructionIndex = 0
instructionsVisited = []
acc = 0
while(True):
if(instructionIndex == len(lines)):
return acc
... |
f9af5624fe12b3c6bd0c359e5162b7f9f48234e7 | Yarin78/yal | /python/yal/fenwick.py | 1,025 | 3.765625 | 4 | # Datastructure for storing and updating integer values in an array in log(n) time
# and answering queries "what is the sum of all value in the array between 0 and x?" in log(n) time
#
# Also called Binary Indexed Tree (BIT). See http://codeforces.com/blog/entry/619
class FenwickTree:
def __init__(self, exp):
... |
25ce186e86fc56201f52b12615caa13f98044d99 | travisoneill/project-euler | /python/007.py | 327 | 3.953125 | 4 | from math import sqrt
def is_prime(n):
if n < 2: return False
for i in range(2, int(sqrt(n)) + 1):
if n % i == 0:
return False
return True
def nth_prime(n):
count = 2
i = 3
while count < n:
i+=2
if is_prime(i):
count += 1
print(i)
nth_prime(... |
5bb4299f898d7a3957d4a0fd1ed4eb151ab44b47 | efeacer/EPFL_ML_Labs | /Lab04/template/least_squares.py | 482 | 3.5625 | 4 | # -*- coding: utf-8 -*-
"""Exercise 3.
Least Square
"""
import numpy as np
def compute_error_vector(y, tx, w):
return y - tx.dot(w)
def compute_mse(error_vector):
return np.mean(error_vector ** 2) / 2
def least_squares(y, tx):
coefficient_matrix = tx.T.dot(tx)
constant_vector = tx.T.dot(y)
... |
0a186e9f92527a8509f7082f2f4065d3b366e957 | vinnyatanasov/naive-bayes-classifier | /nb.py | 3,403 | 3.6875 | 4 | """
Naive Bayes classifier
- gets reviews as input
- counts how many times words appear in pos/neg
- adds one to each (to not have 0 probabilities)
- computes likelihood and multiply by prior (of review being pos/neg) to get the posterior probability
- in a balanced dataset, prior is the same for both, so we ignore it... |
ceca83f8d1a6d0dbc027ad04a7632bb8853bc17f | harshablast/numpy_NN | /nn.py | 2,183 | 3.734375 | 4 | import numpy as np
def sigmoid(x):
return 1 / (1 + np.exp(-x))
def d_sigmoid(x):
return x * (1 - x)
def relu(x):
return x * (x > 0)
def d_relu(x):
return 1 * (x > 0)
class neural_network:
def __init__(self, nodes):
self.input_dim = nodes[0]
self.HL01_dim = nodes[1]
... |
235fee728f7853aa65b05a101deeb1dfeb5ebf8f | syurskyi/Python_Topics | /125_algorithms/_examples/_algorithms_challenges/leetcode/leetCode/DynamicProgramming/198_HouseRobber.py | 469 | 3.609375 | 4 | #! /usr/bin/env python
# -*- coding: utf-8 -*-
class Solution(object):
# Dynamic Programming
def rob(self, nums):
if not nums:
return 0
pre_rob = 0
pre_not_rob = 0
for num in nums:
cur_rob = pre_not_rob + num
cur_not_rob = max(pre_rob, pre_no... |
0d0892bf443e39c3c5ef078f2cb846370b7852e9 | JakobLybarger/Graph-Pathfinding-Algorithms | /dijkstras.py | 1,297 | 4.15625 | 4 | import math
import heapq
def dijkstras(graph, start):
distances = {} # Dictionary to keep track of the shortest distance to each vertex in the graph
# The distance to each vertex is not known so we will just assume each vertex is infinitely far away
for vertex in graph:
distances[vertex] = math.... |
c3626ea1efb1c930337e261be165d048d842d15a | Razorro/Leetcode | /72. Edit Distance.py | 3,999 | 3.515625 | 4 | """
Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.
You have the following 3 operations permitted on a word:
Insert a character
Delete a character
Replace a character
Example 1:
Input: word1 = "horse", word2 = "ros"
Output: 3
Explanation:
horse -> rorse (rep... |
b3a6e632568dd13f128eda2cba96293e2bd0d3cd | sniperswang/dev | /leetcode/L265/test.py | 1,452 | 3.640625 | 4 | """
There are a row of n houses, each house can be painted with one of the k colors.
The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color.
The cost of painting each house with a certain color is represented by a n x k ... |
a1b41adcda2d3b3522744e954cf8ae2f901c6b01 | drunkwater/leetcode | /medium/python3/c0099_209_minimum-size-subarray-sum/00_leetcode_0099.py | 798 | 3.546875 | 4 | # DRUNKWATER TEMPLATE(add description and prototypes)
# Question Title and Description on leetcode.com
# Function Declaration and Function Prototypes on leetcode.com
#209. Minimum Size Subarray Sum
#Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which... |
40a908c9b3cf99674e66b75f56809d485f0a81f9 | Gborgman05/algs | /py/populate_right_pointers.py | 1,019 | 3.859375 | 4 | """
# Definition for a Node.
class Node:
def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None):
self.val = val
self.left = left
self.right = right
self.next = next
"""
class Solution:
def connect(self, root: 'Optional[Node]') -> 'Option... |
c2f622f51bbddc54b0199c4e0e2982bc2ebfa030 | qdm12/courses | /Fundamental Algorithms/Lesson-03/algorithms.py | 2,479 | 3.875 | 4 | from operator import itemgetter
from math import floor
def radix_sort_alpha(words):
l = len(words[0])
for w in words:
if len(w) != l:
raise Exception("All words should be of same length")
for i in range(l, 0, -1):
words = sorted(words, key=itemgetter(i - 1))
... |
baa6b0b8905dfc9e832125196f3503f271557273 | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/leetCode/Array/SlidingWindowMaximum.py | 2,656 | 4.03125 | 4 | """
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Return the max sliding window.
Example:
Input: nums = [1,3,-1,-3,5,3,6,7], and k = 3
O... |
8496596aefa39873f8321a61d361bf209e54dcbd | syurskyi/Python_Topics | /125_algorithms/_exercises/templates/_algorithms_challenges/leetcode/LeetCode_with_solution/108_Convert_Sorted_Array_to_Binary_Search_Tree.py | 977 | 3.859375 | 4 | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
c_ Solution o..
# def sortedArrayToBST(self, nums):
# """
# :type nums: List[int]
# :rtype: TreeNode
# """
# ... |
0be537def5f8cc9ba9218267bf774b28ee44d4c7 | SoumyaMalgonde/AlgoBook | /python/graph_algorithms/Dijkstra's_Shortest_Path_Implementation_using_Adjacency_List.py | 2,933 | 3.921875 | 4 | class Node_Distance :
def __init__(self, name, dist) :
self.name = name
self.dist = dist
class Graph :
def __init__(self, node_count) :
self.adjlist = {}
self.node_count = node_count
def Add_Into_Adjlist(self, src, node_dist) :
if src not in self.adjlist :
... |
8130b1edf4df29a9ab76784289a22d5fb90863e7 | ridhishguhan/faceattractivenesslearner | /Classify.py | 1,158 | 3.6875 | 4 | import numpy as np
import Utils
class Classifier:
training = None
train_arr = None
classes = None
def __init__(self, training, train_arr, CLASSES = 3):
self.training = training
self.train_arr = train_arr
self.classes = CLASSES
#KNN Classification method
def OneNNClassi... |
fa0a2e8e0ec8251c6d735b02dfa1d7a94e09c6b2 | paul0920/leetcode | /question_leetcode/1488_2.py | 1,538 | 3.984375 | 4 | import collections
import heapq
rains = [1, 2, 0, 0, 2, 1]
# 0 1 2 3 4 5
rains = [10, 20, 20, 0, 20, 10]
# min heap to track the days when flooding would happen (if lake not dried)
nearest = []
# dict to store all rainy days
# use case: to push the subsequent rainy days into the heap for wet lakes... |
ef0440b8ce5c5303d75b1d297e323a1d8b92d619 | AndreiBoris/sample-problems | /python/0200-numbers-of-islands/number-of-islands.py | 5,325 | 3.84375 | 4 | from typing import List
LAND = '1'
WATER = '0'
# TODO: Review a superior solutions
def overlaps(min1, max1, min2, max2):
overlap = max(0, min(max1, max2) - max(min1, min2))
if overlap > 0:
return True
if min1 == min2 or min1 == max2 or max1 == min2 or max1 == max2:
return True
if (min... |
227925521077e04140edcb13d50808695efd39a5 | erikseulean/machine_learning | /python/linear_regression/multivariable.py | 1,042 | 3.671875 | 4 | import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
iterations = 35
alpha = 0.1
def read_data():
data = np.loadtxt('data/housing_prices.in', delimiter=',')
X = data[:, [0,1]]
y = data[:, 2]
y.shape = (y.shape[0], 1)
return X, y
def normalize(X):
return (X - X.mean(0))/X.s... |
c7b567bde9e143c404c3670793576644a26f6142 | AhmadQasim/Battleships-AI | /gym-battleship/gym_battleship/envs/battleship_env.py | 4,760 | 3.53125 | 4 | import gym
import numpy as np
from abc import ABC
from gym import spaces
from typing import Tuple
from copy import deepcopy
from collections import namedtuple
Ship = namedtuple('Ship', ['min_x', 'max_x', 'min_y', 'max_y'])
Action = namedtuple('Action', ['x', 'y'])
# Extension: Add info for when the ship is sunk
cl... |
Annoy-DataSync First 25 Records Subset
This dataset contains the first 25 records (lines) from the Annoy-DataSync dataset source file rawcode_1k.jsonl.
Statistics
- Number of records: 25
- Total file size: 53487 bytes
- SHA256 checksum:
f221a5cd87d95371f331bb23018f67a5f783a1687b30bbbb6aa640e28b9e34f2
Source
Original file: https://raw.githubusercontent.com/hdqtoolathlon/Annoy-DataSync/main/data/rawcode_1k.jsonl
Usage
This subset is intended for reproducible testing and demonstration purposes.
Dataset Structure
The dataset contains a single JSONL file: rawcode_first25.jsonl. Each line is a JSON object representing a code snippet with metadata.
- Downloads last month
- 13