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
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
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
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
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
var inputs = document.querySelectorAll(".input pre"); | |
for (var i = 0; i < inputs.length; i++) { | |
var s = inputs[i].innerHTML; | |
s = s.replace(/<br>/g, "\n"); | |
console.log(s) | |
// decode html entities | |
var div = document.createElement("div"); | |
div.innerHTML = s; |
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
// Parsing a graph from the input, then, dfs to walk through the map. | |
package main | |
import ( | |
"fmt" | |
) | |
var ( | |
braceOpenASC = "("[0] | |
braceCloseASC = ")"[0] |
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
// Retry the first time time-out | |
document.querySelectorAll('.build-details-pipeline-job-state-timed_out, .build-details-pipeline-job-state-failed').forEach(d => { | |
d.querySelector('i').click(); | |
d.querySelector('a[href$=retry]').click(); | |
}); |
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 AWS = require("aws-sdk"); | |
const polly = new AWS.Polly(); | |
const bucketName = "polly-voice-notes"; | |
const pollyCommonParas = { | |
OutputFormat: "mp3", | |
VoiceId: "Matthew", | |
OutputS3BucketName: bucketName | |
}; |
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 path = require("path"); | |
const AWS = require("aws-sdk"); | |
const fs = require("fs"); | |
const fsPromises = fs.promises; | |
const polly = new AWS.Polly(); | |
const s3 = new AWS.S3(); | |
const bucketName = "polly-voice-notes"; | |
const notesDir = "notes"; | |
const manifestFileKey = 'manifest.json'; |