Skip to content

Instantly share code, notes, and snippets.

View pricklywiggles's full-sized avatar
💭
If less is more then what is nothing?

Gustavo Gallegos pricklywiggles

💭
If less is more then what is nothing?
View GitHub Profile
@pricklywiggles
pricklywiggles / rotate90
Created January 25, 2021 19:46
Casidoo-180
const rotate = v => {
let n = v.length-1;
for (let y=0; y < Math.floor(v.length/2); y++) {
for (let x=0+y; x < v.length-y-1; x++) {
[v[y][x], v[n-x][y], v[n-y][n-x], v[x][n-y]] = [v[n-x][y], v[n-y][n-x], v[x][n-y], v[y][x]]
}
}
return v;
}
@pricklywiggles
pricklywiggles / HashMap.js
Created January 21, 2021 22:39
Casidoo-179
// Our HashMap can have up to 5077 entries
const MAX_INDEX = 5077;
// helpers
let isMultipleOf = k => n => n%k === 0
let isMultipleOfFour = isMultipleOf(4);
// hash function for strings using 4 char word folding
let hash = s => {
let total = 0;
// Given an array of integers representing the number of consecutive 1s immediately stacked vertically at this index
// calculate the largest area by grabbing the largest of all rectangular areas calculated at each index.
let largestRowArea = row => {
let largestArea = 0;
row.forEach((value, i) => {
let area = value;
if (value != 0) {
for(let j=i-1; j>=0; j--) {
if (row[j] < value) break;
area += value;
@pricklywiggles
pricklywiggles / canToggle.js
Created January 5, 2021 20:57
Cassidoo-177
function canReach([sx,sy], [dx,dy]) {
return Math.sqrt((sx-dx)**2 + Math.abs(sy-dy)**2) < 5
}
function canToggle({ switch: current, hub, light: end }) {
if (canReach(current, end))
return true;
if (hub.length == 0) return false;
for(let [i,node] of hub.entries()) {
if (canReach(current, node)) {