dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
2.1 KiB
2.1 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 69c5f3d787b1725d5f00c8bd | Challenge 259: FizzBuzz Explosion | 28 | challenge-259 |
--description--
Given an integer, return the number of steps it takes to turn the word "fizzbuzz" into a string with at least the given number of "z"'s using the following rules:
- Start with the string
"fizzbuzz". - Each step, apply the standard FizzBuzz rules using the letter position in the string (the first
"f"is position 1).- If the letter position is divisible by 3, replace the letter with
"fizz" - If it's divisible by 5, replace the letter with
"buzz" - If it's divisible by 3 and 5, replace the letter with
"fizzbuzz"
- If the letter position is divisible by 3, replace the letter with
So after 1 step, "fizzbuzz" turns into "fifizzzbuzzfizzzz", which has 9 "z"'s.
--hints--
explodeFizzbuzz(9) should return 1.
assert.equal(explodeFizzbuzz(9), 1);
explodeFizzbuzz(15) should return 2.
assert.equal(explodeFizzbuzz(15), 2);
explodeFizzbuzz(51) should return 3.
assert.equal(explodeFizzbuzz(51), 3);
explodeFizzbuzz(52) should return 4.
assert.equal(explodeFizzbuzz(52), 4);
explodeFizzbuzz(359) should return 5.
assert.equal(explodeFizzbuzz(359), 5);
explodeFizzbuzz(789) should return 6.
assert.equal(explodeFizzbuzz(789), 6);
explodeFizzbuzz(54482) should return 11.
assert.equal(explodeFizzbuzz(54482), 11);
explodeFizzbuzz(1000000) should return 14.
assert.equal(explodeFizzbuzz(1000000), 14);
--seed--
--seed-contents--
function explodeFizzbuzz(targetZCount) {
return targetZCount;
}
--solutions--
function explodeFizzbuzz(targetZCount) {
let str = "fizzbuzz";
let steps = 0;
while ((str.match(/z/g) || []).length < targetZCount) {
let next = "";
for (let i = 0; i < str.length; i++) {
const pos = i + 1;
if (pos % 15 === 0) next += "fizzbuzz";
else if (pos % 3 === 0) next += "fizz";
else if (pos % 5 === 0) next += "buzz";
else next += str[i];
}
str = next;
steps++;
}
return steps;
}