Skip to content

Instantly share code, notes, and snippets.

View spiterman's full-sized avatar
🏠
Working from home

Sergey Piterman spiterman

🏠
Working from home
View GitHub Profile
@spiterman
spiterman / functionTrees.js
Created August 17, 2018 23:38
Functional Programming Applied to a Binary Search Tree
class TreeNode {
constructor(val) {
this.val = val;
this.left = null;
this.right = null;
}
}
class BST {
constructor() {
class Organism {
constructor(r, g, b) {
this.r = r;
this.g = g;
this.b = b;
this.mutationSize = 10; //Must be greater than 2
}
reproduce() {
// Prevents negative numbers from appearing
let newR = Math.max(this.r + this.mutateTrait(), 0);
class Environment {
constructor(r, g, b, startingOrganisms) {
this.r = r;
this.g = g;
this.b = b;
this.organisms = [];
this.weaknesses = [];
this.startingOrganisms = startingOrganisms;
this.addOrganisms(this.startingOrganisms);
this.generationTime = 1
class Organism {
constructor(r, g, b) {
this.r = r;
this.g = g;
this.b = b;
this.mutationSize = 20; //Must be greater than 2
}
reproduce() {
// Prevents negative numbers from appearing
let newR = Math.max(this.r + this.mutateTrait(), 0);
@spiterman
spiterman / GeneticAlgorithm.js
Created September 27, 2018 02:28
Genetic Algorithm v.2.0
class Organism {
constructor(r, g, b) {
this.r = r;
this.g = g;
this.b = b;
this.mutationSize = 20; //Must be greater than 2
}
reproduce() {
// Prevents negative numbers from appearing
let newR = Math.max(this.r + this.mutateTrait(), 0);
function minimumWindowSubstring(str, substr) {
let lettersSeen = {};
let lettersNeeded = {};
let lettersMissing = 0;
for(let i = 0; i < substr.length; i++) {
if(substr[i] in lettersNeeded){
lettersNeeded[substr[i]] += 1;
} else {
lettersNeeded[substr[i]] = 1;
@spiterman
spiterman / hackathon_how_to.md
Created November 12, 2018 20:36 — forked from sergmetelin/hackathon_how_to.md
Hackathon Getting Started guide

About EOSIO

The EOS.IO software introduces a new blockchain architecture designed to enable vertical and horizontal scaling of decentralized applications. This is achieved by creating an operating system-like construct upon which applications can be built. The software provides accounts, authentication, databases, asynchronous communication and the scheduling of applications across many CPU cores or clusters. The resulting technology is a blockchain architecture that may ultimately scale to millions of transactions per second, eliminates user fees, and allows for quick and easy deployment and maintenance of decentralized applications, in the context of a governed blockchain.

About this guide:

Full documentation can be found at https://developers.eos.io/

This means your portal is correctly setup for the hackathon.

@spiterman
spiterman / MergeKSortedArrays.js
Created November 27, 2018 05:29
How to Merge K Sorted Arrays Efficiently
// Space: O(NK) (Plus O(K) for the heap)
// Time: O(NK log(K))
function mergeKSorted(arrays) {
let result = [];
let minHeap = [];
arrays.forEach((array, index) => {
minHeap.push({
function houseRobberRecursive(arr) {
function stealFromHouse(index) {
if(index >= arr.length) {
return 0;
}
return Math.max(arr[index] + stealFromHouse(index + 2), stealFromHouse(index + 1));
}
return stealFromHouse(0);
}
let counter = 0;
function houseRobberRecursive(arr) {
function stealFromHouse(index) {
if(index >= arr.length) {
counter++;
return 0;
}
return Math.max(arr[index] + stealFromHouse(index + 2), stealFromHouse(index + 1));
}