Skip to content

Instantly share code, notes, and snippets.

View fernandzad's full-sized avatar
JavaScript, Go and C#

Adrián fernandzad

JavaScript, Go and C#
View GitHub Profile
@fernandzad
fernandzad / .eslintrc.js
Created September 23, 2022 18:38
ESLint file and configuration
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
settings: {
@fernandzad
fernandzad / binarySearch.js
Created June 8, 2021 02:23
This is the implementation of a binary search in JavaScript
const binarySearch = (sortedArray, item) => {
let start = 0;
let end = sortedArray.length - 1;
let middle = Math.floor((start + end) / 2);
while (start <= end) {
if (sortedArray[middle] === item) return true;
else if (item > sortedArray[middle])
start = middle + 1;
else
@fernandzad
fernandzad / BFS.js
Last active June 8, 2021 01:43
This is the implementation of a basic BFS in JavaScript
let visited = [];
for (let i = 1; i <= 8; i++) visited[i] = 0;
const graph = [[], [2, 3, 4], [5, 6], [7, 8], [8]];
const bfs = (source, graph) => {
let queue = [];
queue.push(source);
visited[source] = 1;
while(queue.length > 0) {
@fernandzad
fernandzad / workerpools.go
Created March 25, 2021 03:02
This a program in Go that creates worker pools that generates random numbers
// All material is licensed under the Apache License Version 2.0, January 2004
// http://www.apache.org/licenses/LICENSE-2.0
// Write a program that creates a fixed set of workers to generate random
// numbers. Discard any number divisible by 2. Continue receiving until 100
// numbers are received. Tell the workers to shut down before terminating.
package main
import (
"fmt"
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"value": "dev"
},
"keyValueNames": {
"value": [
"myKeyDev$labelProd",
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"configStoreName": {
"type": "string",
"metadata": {
"description": "Specifies the name of the App Configuration store."
}
},
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> mp;
vector<int>answer;
for (int i=0;i<nums.size();i++)
mp[nums[i]] = i;
int y = 0;
for (int i=0;i<nums.size();i++) {
y = target - nums[i];
//Knapsack Problem el problema de la mochila!
#include<stdio.h>
#include<algorithm>
#include <string.h>
using namespace std;
int G, MW, N, T, sum_values;
int dp(int,int);
struct Bag {
int price, weight;
values = [60, 10, 12]
weights = [10, 20, 30]
totalWeight = 50
n = len(values)
memo = [[-1 for i in range(100)] for j in range(100)]
def knapSack(totalWeight, i):
if memo[totalWeight][i] != -1:
return memo[totalWeight][i]
values = [60, 10, 12]
weights = [40, 20, 30]
totalWeight = 50
n = len(values)
def knapSack(totalWeight, i):
if i == n or totalWeight <= 0:
return 0