Skip to content

Instantly share code, notes, and snippets.

@CITGuru
Created April 30, 2020 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CITGuru/a74efa6e34a5d6fb34154ffb02ba5634 to your computer and use it in GitHub Desktop.
Save CITGuru/a74efa6e34a5d6fb34154ffb02ba5634 to your computer and use it in GitHub Desktop.
let panelsArrangement = []
const ucheSolution = (area) => {
// Uchenna Jeremiah
// https://gist.github.com/ucejtech/74a7b9f408e0f5081ea2c6ac63140764
'use strict'
if (area >= 1 && area <= 1000000) {
let nArea = Math.pow(Math.trunc(Math.sqrt(area)), 2)
panelsArrangement.push(nArea)
// use recursion to recalculate for new Area
ucheSolution(area - nArea)
}
return panelsArrangement
}
const jsDevilSolution = (area) => {
// https://gist.github.com/js-devil/3544f509e791b2439fecb1eab5bc920b
// Yeshua
let a = [];
while (area >= 1) {
square = Math.pow(Math.floor(Math.sqrt(area)), 2);
area = area - square;
a = [...a, square];
}
return a;
};
const amosSolution = (area) =>{
// Adebare Amos
// https://gist.github.com/InfoTechDrive/24d4a28d023da7cd6e1acaa7c876bfcd
let squareArray = [];
const calcSqrs = (area) => {
let root = Math.trunc(Math.sqrt(area));
root *=root;
squareArray.push(root);
if(root == area){
return;
}else if(area - root == 1){
squareArray.push(1);
return;
}else{
calcSqrs((area - root))
}
}
calcSqrs(area);
return squareArray;
}
const faithSolution = area => {
// https://gist.github.com/codemutatio/55b8bce5efdd257aa5da479fec26b0dd
// Faith Adekunle Omojola
let num = area;
const squarePanel = [];
while (num > 0) {
const root = Math.sqrt(num);
const int = Math.pow(Math.floor(root), 2);
squarePanel.push(int);
num = num - int;
};
return squarePanel
};
console.time('ucheSolution')
// Test Case
console.log(`
Uchenna Jeremiah
https://gist.github.com/ucejtech/74a7b9f408e0f5081ea2c6ac63140764
`)
console.log(ucheSolution(15324))
console.log(ucheSolution(12))
console.log(ucheSolution(2982))
console.log(ucheSolution(9))
// Stop Timer
console.timeEnd('ucheSolution')
console.time('jsDevilSolution')
// Test Case
console.log(`
https://gist.github.com/js-devil/3544f509e791b2439fecb1eab5bc920b
Yeshua
`)
console.log(jsDevilSolution(15324))
console.log(jsDevilSolution(12))
console.log(jsDevilSolution(2982))
console.log(jsDevilSolution(9))
// Stop Timer
console.timeEnd('jsDevilSolution')
console.time('amosSolution')
// Test Case
console.log(`
Adebare Amos
https://gist.github.com/InfoTechDrive/24d4a28d023da7cd6e1acaa7c876bfcd
`)
console.log(amosSolution(15324))
console.log(amosSolution(12))
console.log(amosSolution(2982))
console.log(amosSolution(9))
// Stop Timer
console.timeEnd('amosSolution')
console.time('faithSolution')
// Test Case
console.log(`
https://gist.github.com/codemutatio/55b8bce5efdd257aa5da479fec26b0dd
Faith Adekunle Omojola`)
console.log(faithSolution(15324))
console.log(faithSolution(12))
console.log(faithSolution(2982))
console.log(faithSolution(9))
// Stop Timer
console.timeEnd('faithSolution')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment