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
93 lines
1.7 KiB
Markdown
93 lines
1.7 KiB
Markdown
---
|
|
id: 69bc6cb30c1d112a2e110a09
|
|
title: "Challenge 252: Unique Stair Climber"
|
|
challengeType: 29
|
|
dashedName: challenge-252
|
|
---
|
|
|
|
# --description--
|
|
|
|
Given a number of stairs, return how many distinct ways someone can climb them taking either 1 or 2 steps at a time.
|
|
|
|
# --hints--
|
|
|
|
`get_unique_climbs(4)` should return `5`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(get_unique_climbs(4), 5)`)
|
|
}})
|
|
```
|
|
|
|
`get_unique_climbs(5)` should return `8`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(get_unique_climbs(5), 8)`)
|
|
}})
|
|
```
|
|
|
|
`get_unique_climbs(10)` should return `89`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(get_unique_climbs(10), 89)`)
|
|
}})
|
|
```
|
|
|
|
`get_unique_climbs(18)` should return `4181`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(get_unique_climbs(18), 4181)`)
|
|
}})
|
|
```
|
|
|
|
`get_unique_climbs(29)` should return `832040`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(get_unique_climbs(29), 832040)`)
|
|
}})
|
|
```
|
|
|
|
`get_unique_climbs(50)` should return `20365011074`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(get_unique_climbs(50), 20365011074)`)
|
|
}})
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```py
|
|
def get_unique_climbs(steps):
|
|
|
|
return steps
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```py
|
|
def get_unique_climbs(steps):
|
|
if steps <= 0:
|
|
return 0
|
|
if steps == 1:
|
|
return 1
|
|
if steps == 2:
|
|
return 2
|
|
prev2, prev1 = 1, 2
|
|
for _ in range(3, steps + 1):
|
|
prev2, prev1 = prev1, prev2 + prev1
|
|
return prev1
|
|
```
|