Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

126 lines
2.7 KiB
Markdown

---
id: 69c5f3d787b1725d5f00c8bd
title: "Challenge 259: FizzBuzz Explosion"
challengeType: 29
dashedName: 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"`
So after 1 step, `"fizzbuzz"` turns into `"fifizzzbuzzfizzzz"`, which has 9 `"z"`'s.
# --hints--
`explode_fizzbuzz(9)` should return `1`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(explode_fizzbuzz(9), 1)`)
}})
```
`explode_fizzbuzz(15)` should return `2`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(explode_fizzbuzz(15), 2)`)
}})
```
`explode_fizzbuzz(51)` should return `3`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(explode_fizzbuzz(51), 3)`)
}})
```
`explode_fizzbuzz(52)` should return `4`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(explode_fizzbuzz(52), 4)`)
}})
```
`explode_fizzbuzz(359)` should return `5`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(explode_fizzbuzz(359), 5)`)
}})
```
`explode_fizzbuzz(789)` should return `6`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(explode_fizzbuzz(789), 6)`)
}})
```
`explode_fizzbuzz(54482)` should return `11`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(explode_fizzbuzz(54482), 11)`)
}})
```
`explode_fizzbuzz(1000000)` should return `14`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(explode_fizzbuzz(1000000), 14)`)
}})
```
# --seed--
## --seed-contents--
```py
def explode_fizzbuzz(target_z_count):
return target_z_count
```
# --solutions--
```py
def explode_fizzbuzz(target_z_count):
s = "fizzbuzz"
steps = 0
while s.count('z') < target_z_count:
next_s = ""
for i, c in enumerate(s):
pos = i + 1
if pos % 15 == 0:
next_s += "fizzbuzz"
elif pos % 3 == 0:
next_s += "fizz"
elif pos % 5 == 0:
next_s += "buzz"
else:
next_s += c
s = next_s
steps += 1
return steps
```