This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const edgesExample = [ | |
[1, 4, 3], [1, 3, 6], | |
[2, 1, 3], | |
[3, 4, 2], | |
[4, 3, 1], [4, 2, 1], | |
[5, 2, 4], [5, 4, 2], | |
]; | |
function dp(start, edges) { | |
const memo = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const textFromInternet = 'In computer science, mathematics, management science, economics and bioinformatics, dynamic programming (also known as dynamic optimization) is a method for solving a complex problem by breaking it down into a collection of simpler subproblems, solving each of those subproblems just once, and storing their solutions. The next time the same subproblem occurs, instead of recomputing its solution, one simply looks up the previously computed solution, thereby saving computation time at the expense of (it is hoped) a modest expenditure in storage space. (Each of the subproblem solutions is indexed in some way, typically based on the values of its input parameters, so as to facilitate its lookup.) The technique of storing solutions to subproblems instead of recomputing them is called "memoization".'; | |
const LINE_LENGTH = 90; | |
function calcBadness(line) { | |
const diff = LINE_LENGTH - line.length; | |
if (diff >= 0) { | |
return Math.pow((LINE_LENGTH - line.length), 2); | |
} | |
return Number.MAX_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solveTopDown(n, memo) { | |
if (memo[n]) return memo[n]; | |
const result = solveTopDown(n - 1, memo) + solveTopDown(n - 2, memo); | |
memo[n] = result; | |
return result; | |
} | |
function topDown(n) { | |
return solveTopDown(n, { 1: 1, 2: 1 }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mergeSort :: (Ord a) => [a] -> [a] | |
mergeSort [] = [] | |
mergeSort [x] = [x] | |
mergeSort arr = merge(firHalfArr, secHalfArr) | |
where arrHalfLength = div (length arr) 2 | |
firHalfArr = mergeSort (take arrHalfLength arr) | |
secHalfArr = mergeSort (drop arrHalfLength arr) | |
merge (a, []) = a | |
merge ([], b) = b | |
merge ((a1:aLeft), (b1:bLeft)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
quickSort :: (Ord a) => [a] -> [a] | |
quickSort [] = [] | |
quickSort [x] = [x] | |
quickSort (x:arrLeft) = smallerOnes ++ [x] ++ largerOnes | |
where smallerOnes = quickSort [ele | ele <- arrLeft, ele <= x] | |
largerOnes = quickSort [ele | ele <- arrLeft, ele > x] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bubbleSort :: (Ord a) => [a] -> [a] | |
bubbleSort [] = [] | |
bubbleSort [x] = [x] | |
bubbleSort (x:y:arrLeft) = bubbleSort(init bubbled) ++ [last bubbled] | |
where (smaller,bigger) = if(x <= y) then (x, y) else (y, x) | |
bubbled = [smaller] ++ bubbleSort (bigger:arrLeft) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
insertSort :: (Ord a) => [a] -> [a] | |
insertSort [] = [] | |
insertSort (firEle:arrLeft) = insert firEle (insertSort arrLeft) | |
where insert a [] = [a] | |
insert a (b:c) | |
| a < b = a : b : c | |
| otherwise = b : insert a c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Particle { | |
private posX: number; | |
private posY: number; | |
private speedX = 0; | |
private speedY = 0; | |
private sprite: PIXI.Sprite; | |
private container: PIXI.Container; | |
constructor(container: PIXI.Container, baseTexture: PIXI.BaseTexture, posX: number, posY: number) { | |
this.sprite = new PIXI.Sprite(new PIXI.Texture(baseTexture)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tube { | |
private x: number; | |
private y: number; | |
private innerDistance = 80; | |
private tubeWidth = 20; | |
private sprite = new PIXI.Graphics(); | |
reset(x: number = canvasWidthHeight + 20) { | |
this.x = x; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const canvasWidthHeight = 512; | |
const BIRD_FRAME_LIST = [ | |
'./images/frame-1.png', | |
'./images/frame-2.png', | |
'./images/frame-3.png', | |
'./images/frame-4.png', | |
]; | |
class Bird { | |
private sprite = new PIXI.Sprite(); |