Skip to content

Instantly share code, notes, and snippets.

View chasingmaxwell's full-sized avatar
🤘

Peter Sieg chasingmaxwell

🤘
View GitHub Profile
@chasingmaxwell
chasingmaxwell / breadth-first-search.js
Created October 16, 2020 21:12
Implementation of breadth-first search in JavaScript.
// Implementation of breadth-first search in JavaScript.
function breadthFirstSearch(g, start, end) {
const queue = [[start]];
const visited = {};
while (queue.length > 0) {
const path = queue.shift();
const node = path[path.length - 1];
if (node === end) {
console.log("number of steps:", path.length - 1);
@chasingmaxwell
chasingmaxwell / heapsort.js
Last active October 16, 2020 21:10
Implementation of heapsort in JavaScript.
// Implementation of heapsort in JavaScript.
LENGTH = 1e2;
MAX = 2e4;
MIN = 1;
function generateInput(min, max, length) {
const res = [];
while (res.length < length) {
res.push(Math.round(Math.random() * (max - min) + min));
@chasingmaxwell
chasingmaxwell / bubblesort.js
Created July 25, 2020 22:05
Implementation of bubblesort in JavaScript. This might take a while...
// Implementation of bubblesort in JavaScript. This might take a while...
LENGTH = 1e5;
MAX = 2e4;
MIN = 1;
function generateInput(min, max, length) {
const res = [];
while (res.length < length) {
res.push(Math.round(Math.random() * (max - min) + min));
@chasingmaxwell
chasingmaxwell / addEmUp.js
Last active July 22, 2020 14:43
Various ways to add up matching integers in a string.
/**
* Add each integer in a string which matches the next integer in the string.
*
* @param {string} input A string of integers to add up.
* @param {boolean} circular Indicates whether we should wrap around to the
* beginning of the input string when evaluating the last integer.
*/
function addEmUpNext(input, circular = false) {
let res = 0;
for (let i = 0; i < input.length; i++) {
// The Tron Problem
// Greetings future Episource employee! You have been "randomly" selected to participate in the 11th annual Tron games!
// Don't worry, you won't be actually playing the games. You'll be judging the battles after the fact!
// Let me take a quick second to brief you on the Tron Standard Rules(TSRs).
// 1) The game is played on a standard 10x10 board
// 2) Player 1 starts on position 0x0 (top left corner). Player 2 starts on position 9x9 (bottom right corner).
// 3) At each turn, a player may move up, down, left, or right on the board.
// These steps are held in an array and take the form 'u', 'd', 'l', and 'r' respectively.
// 4) If a player crosses a previous path of another player, including themselves, they are eliminated.
@chasingmaxwell
chasingmaxwell / README.md
Created July 8, 2020 14:51
The Knight's tour problem in JavaScript.

Knight's Tour

This is an implementation of The Knight's Tour problem/solution in JavaScript.

To run:

node tour.js
@chasingmaxwell
chasingmaxwell / removeOverlap.js
Last active May 19, 2020 22:40
Prompt for Four Kitchens JavaScript Practice Group 2020.05.20
/* @flow */
export type Range<P> = {
payload: P,
start: number,
end: number,
priority: number,
};
/**
@chasingmaxwell
chasingmaxwell / quickSort.ts
Last active April 3, 2020 19:07
An implementation of quicksort in TypeScript - warning: this is probably bad
const MIN = -1e3;
const MAX = 1e3;
const SIZE = 1e6;
/**
* Get a random number between min and max.
*
* @param min the minimum integer possible.
* @param max the maximum integer possible.
*/

Keybase proof

I hereby claim:

  • I am chasingmaxwell on github.
  • I am chasingmaxwell (https://keybase.io/chasingmaxwell) on keybase.
  • I have a public key ASDl1c23JXkhGJWAgdOl3278WFaTeBATR0O7MvtzTKDrzAo

To claim this, I am signing this object:

@chasingmaxwell
chasingmaxwell / lambda-duration
Last active March 10, 2022 03:50
AWS CloudWatch Insight Queries
filter @type = "REPORT"
| stats
avg(@billedDuration) as Average,
percentile(@billedDuration, 99) as NinetyNinth,
percentile(@billedDuration, 95) as NinetyFifth,
percentile(@billedDuration, 90) as Ninetieth
by bin(30m)