Merge branch 'master' of ssh://gitea.calebfontenot.com:25566/CCF_100/NoMoreAcronyms

This commit is contained in:
Chloe Fontenot 🏳️‍⚧️ 2023-04-08 22:25:57 -05:00
commit fc4436cf9f

View File

@ -153,14 +153,15 @@ function design3(input) {
function design4(input) { function design4(input) {
let outputString = ""; let outputString = "";
let radius = input.length +1; let outputLine = "";
let radius = (input.length + 1);
let mid = radius; let mid = radius;
if (mid % 2 == 1) { if (mid % 2 == 1) {
var spaceOffset = " "; var spaceOffset = " ";
} else { } else {
var spaceOffset = ""; var spaceOffset = "";
} }
console.log(radius, mid);
// dist represents distance to the center // dist represents distance to the center
let dist = parseFloat(0); let dist = parseFloat(0);
let space = "" let space = ""
@ -168,33 +169,42 @@ function design4(input) {
space += " "; space += " ";
} }
// for horizontal movement // for horizontal movement
for (let i = 0; i <= 2 * radius; i++) { var i;
if (i != mid) { var j;
let lineHasInput = false;
for (i = 0; i <= 2 * radius; i++) {
lineHasInput = false;
if (Math.trunc(i) != mid) {
// for vertical movement // for vertical movement
for (let j = 0; j <= 2 * radius; j++) { for (j = 0; j <= 2 * radius; j++) {
dist = Math.sqrt( dist = Math.sqrt(
(i - radius / 2) * (i - radius / 2) + ((i - radius) * (i - radius) * 4) +
(j - radius) * (j - radius) (j - radius) * (j - radius)
); );
//console.log(i, j, radius, dist);
// dist should be in the range (radius - 0.5) // dist should be in the range (radius - 0.5)
// and (radius + 0.5) to print stars(*) // and (radius + 0.5) to print stars(*)
if (dist > radius - 0.5 && dist < radius + 0.5) { if (dist > radius - 1 && dist < radius + 1) { //&& dist > radius - 1
outputString += "*"; lineHasInput = true;
outputLine += "·";
} else { } else {
outputString += " "; outputLine += " ";
} }
} }
} else { } else {
outputString += "*" + space + input + space + spaceOffset + "*"; lineHasInput = true;
outputLine += "·" + space + input + space + spaceOffset + "·";
} }
//console.log(i, j, outputLine);
outputString += "\n"; if (lineHasInput) {
outputString += outputLine + "\n";
}
outputLine = "";
} }
return outputString; return outputString;
} }
//console.log(design4("super long test string super long test string"));
//"super long test string super long test string"