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

80 lines
1.4 KiB
Markdown

---
id: 681cb1b0dab50c87ddb2e51b
title: "Challenge 10: 3 Strikes"
challengeType: 29
dashedName: challenge-10
---
# --description--
Given an integer between 1 and 10,000, return a count of how many numbers from 1 up to that integer whose square contains at least one digit 3.
# --hints--
`squares_with_three(1)` should return `0`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(squares_with_three(1), 0)`)
}})
```
`squares_with_three(10)` should return `1`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(squares_with_three(10), 1)`)
}})
```
`squares_with_three(100)` should return `19`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(squares_with_three(100), 19)`)
}})
```
`squares_with_three(1000)` should return `326`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(squares_with_three(1000), 326)`)
}})
```
`squares_with_three(10000)` should return `4531`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(squares_with_three(10000), 4531)`)
}})
```
# --seed--
## --seed-contents--
```py
def squares_with_three(n):
return n
```
# --solutions--
```py
def squares_with_three(n):
count = 0
for i in range(1, n + 1):
square = i * i
if '3' in str(square):
count += 1
return count
```