mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-11 22:01:07 -04:00
feat(curriculum): add dynamic programming lab (#62462)
This commit is contained in:
@@ -2371,7 +2371,10 @@
|
||||
"Open up this page to review concepts around the basics of HTML elements, semantic HTML, tables, forms and accessibility."
|
||||
]
|
||||
},
|
||||
"qpra": { "title": "30", "intro": [] },
|
||||
"qpra": {
|
||||
"title": "30",
|
||||
"intro": []
|
||||
},
|
||||
"lecture-understanding-computer-internet-and-tooling-basics": {
|
||||
"title": "Understanding Computer, Internet, and Tooling Basics",
|
||||
"intro": [
|
||||
@@ -4118,7 +4121,10 @@
|
||||
"Open up this page to review all of the concepts taught including variables, strings, booleans, functions, objects, arrays, debugging, working with the DOM and more."
|
||||
]
|
||||
},
|
||||
"kagw": { "title": "258", "intro": [] },
|
||||
"kagw": {
|
||||
"title": "258",
|
||||
"intro": []
|
||||
},
|
||||
"lecture-introduction-to-javascript-libraries-and-frameworks": {
|
||||
"title": "Introduction to JavaScript Libraries and Frameworks",
|
||||
"intro": [
|
||||
@@ -4391,11 +4397,26 @@
|
||||
"In this lesson, you will learn about TypeScript configuration files and how to use them."
|
||||
]
|
||||
},
|
||||
"trvf": { "title": "293", "intro": [] },
|
||||
"kwmg": { "title": "294", "intro": [] },
|
||||
"nodx": { "title": "295", "intro": [] },
|
||||
"erfj": { "title": "296", "intro": [] },
|
||||
"muyw": { "title": "297", "intro": [] },
|
||||
"trvf": {
|
||||
"title": "293",
|
||||
"intro": []
|
||||
},
|
||||
"kwmg": {
|
||||
"title": "294",
|
||||
"intro": []
|
||||
},
|
||||
"nodx": {
|
||||
"title": "295",
|
||||
"intro": []
|
||||
},
|
||||
"erfj": {
|
||||
"title": "296",
|
||||
"intro": []
|
||||
},
|
||||
"muyw": {
|
||||
"title": "297",
|
||||
"intro": []
|
||||
},
|
||||
"review-typescript": {
|
||||
"title": "Typescript Review",
|
||||
"intro": [
|
||||
@@ -4413,8 +4434,14 @@
|
||||
"Review the Front End Libraries concepts to prepare for the upcoming quiz."
|
||||
]
|
||||
},
|
||||
"rdzk": { "title": "301", "intro": [] },
|
||||
"vtpz": { "title": "302", "intro": [] },
|
||||
"rdzk": {
|
||||
"title": "301",
|
||||
"intro": []
|
||||
},
|
||||
"vtpz": {
|
||||
"title": "302",
|
||||
"intro": []
|
||||
},
|
||||
"lecture-introduction-to-python": {
|
||||
"title": "Introduction to Python",
|
||||
"intro": [
|
||||
@@ -4605,7 +4632,10 @@
|
||||
"title": "Placeholder - Waiting for title",
|
||||
"intro": [""]
|
||||
},
|
||||
"lab-placeholder-oop-3": { "title": "", "intro": [""] },
|
||||
"lab-placeholder-oop-3": {
|
||||
"title": "",
|
||||
"intro": [""]
|
||||
},
|
||||
"review-object-oriented-programming": {
|
||||
"title": "Object Oriented Programming Review",
|
||||
"intro": [
|
||||
@@ -4739,7 +4769,10 @@
|
||||
"In this lab, you will implement the Depth-First Search Algorithm."
|
||||
]
|
||||
},
|
||||
"lab-n-queens-problem": { "title": "", "intro": [""] },
|
||||
"lab-n-queens-problem": {
|
||||
"title": "",
|
||||
"intro": [""]
|
||||
},
|
||||
"review-graphs-and-trees": {
|
||||
"title": "Graphs and Trees Review",
|
||||
"intro": [
|
||||
@@ -4760,7 +4793,9 @@
|
||||
},
|
||||
"lab-nth-fibonacci-number": {
|
||||
"title": "Build an Nth Fibonacci Number Calculator",
|
||||
"intro": [""]
|
||||
"intro": [
|
||||
"In this lab you will implement a Fibonacci sequence calculator using a dynamic programming approach."
|
||||
]
|
||||
},
|
||||
"review-dynamic-programming": {
|
||||
"title": "Dynamic Programming Review",
|
||||
@@ -5035,7 +5070,10 @@
|
||||
"title": "Alphabet and Accents",
|
||||
"intro": ["", ""]
|
||||
},
|
||||
"es-a1-learn-punctuation": { "title": "Punctuation", "intro": ["", ""] },
|
||||
"es-a1-learn-punctuation": {
|
||||
"title": "Punctuation",
|
||||
"intro": ["", ""]
|
||||
},
|
||||
"es-a1-quiz-alphabet-accent-and-punctuation-quiz": {
|
||||
"title": "Alphabet, Accent and Punctuation Quiz",
|
||||
"intro": ["", ""]
|
||||
@@ -5044,8 +5082,14 @@
|
||||
"title": "Introducing Yourself Basics",
|
||||
"intro": ["", ""]
|
||||
},
|
||||
"es-a1-learn-meet-luna": { "title": "Meet Luna", "intro": ["", ""] },
|
||||
"es-a1-learn-meet-mateo": { "title": "Meet Mateo", "intro": ["", ""] },
|
||||
"es-a1-learn-meet-luna": {
|
||||
"title": "Meet Luna",
|
||||
"intro": ["", ""]
|
||||
},
|
||||
"es-a1-learn-meet-mateo": {
|
||||
"title": "Meet Mateo",
|
||||
"intro": ["", ""]
|
||||
},
|
||||
"es-a1-learn-meet-julieta": {
|
||||
"title": "Meet Julieta",
|
||||
"intro": ["", ""]
|
||||
@@ -5219,7 +5263,9 @@
|
||||
"part-12": "Containers",
|
||||
"part-13": "Using Relational Databases"
|
||||
},
|
||||
"modules": { "basic-html": "Basic HTML" },
|
||||
"modules": {
|
||||
"basic-html": "Basic HTML"
|
||||
},
|
||||
"module-intros": {
|
||||
"basic-html": {
|
||||
"title": "Basic HTML",
|
||||
@@ -5232,7 +5278,9 @@
|
||||
"daily-coding-challenge": {
|
||||
"title": "Daily Coding Challenge",
|
||||
"blocks": {
|
||||
"daily-coding-challenge": { "title": "Daily Coding Challenge" }
|
||||
"daily-coding-challenge": {
|
||||
"title": "Daily Coding Challenge"
|
||||
}
|
||||
}
|
||||
},
|
||||
"misc-text": {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
title: Introduction to the Implement a Fibonacci Sequence Calculator
|
||||
block: lab-nth-fibonacci-number
|
||||
superBlock: full-stack-developer
|
||||
---
|
||||
|
||||
## Introduction to the Implement a Fibonacci Sequence Calculator
|
||||
|
||||
In this lab you will implement a Fibonacci sequence calculator using a dynamic programming approach.
|
||||
@@ -0,0 +1,116 @@
|
||||
---
|
||||
id: 68de7360e1832ea180577a8a
|
||||
title: Build an Nth Fibonacci Number Calculator
|
||||
challengeType: 27
|
||||
dashedName: build-an-nth-fibonacci-number-calculator
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab.
|
||||
|
||||
**User Stories:**
|
||||
|
||||
1. You should create a function named `fibonacci`.
|
||||
2. You should define a list named `sequence` within the `fibonacci` function, and it should be initialized with the values `[0, 1]`.
|
||||
3. The `fibonacci` function should accept one parameter, a positive integer `n`.
|
||||
4. Calling `fibonacci(n)` should use a dynamic programming approach to compute and return the `n`-th number from the Fibonacci sequence, where each number is the sum of the two preceding numbers.
|
||||
5. Each computed number at the position `n` in the Fibonacci sequence should be stored in the `sequence` list at index `n - 1`.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a function named `fibonacci`.
|
||||
|
||||
```js
|
||||
({ test: () => runPython(`assert _Node(_code).has_function("fibonacci")`) })
|
||||
```
|
||||
|
||||
Your `fibonacci` function should take a single parameter.
|
||||
|
||||
```js
|
||||
({ test: () => runPython(`
|
||||
from inspect import signature
|
||||
sig = signature(fibonacci)
|
||||
assert len(sig.parameters) == 1
|
||||
`) })
|
||||
```
|
||||
|
||||
You should have a list named `sequence` within the `fibonacci` function initialized to `[0, 1]`.
|
||||
|
||||
```js
|
||||
({ test: () => runPython(`assert _Node(_code).find_function("fibonacci").has_stmt("sequence = [0, 1]")`) })
|
||||
```
|
||||
|
||||
`fibonacci(0)` should return `0`.
|
||||
|
||||
```js
|
||||
({ test: () => runPython(`assert fibonacci(0) == 0`) })
|
||||
```
|
||||
|
||||
`fibonacci(1)` should return `1`.
|
||||
|
||||
```js
|
||||
({ test: () => runPython(`assert fibonacci(1) == 1`) })
|
||||
```
|
||||
|
||||
`fibonacci(2)` should return `1`.
|
||||
|
||||
```js
|
||||
({ test: () => runPython(`assert fibonacci(2) == 1`) })
|
||||
```
|
||||
|
||||
`fibonacci(3)` should return `2`.
|
||||
|
||||
```js
|
||||
({ test: () => runPython(`assert fibonacci(3) == 2`) })
|
||||
```
|
||||
|
||||
`fibonacci(5)` should return `5`.
|
||||
|
||||
```js
|
||||
({ test: () => runPython(`assert fibonacci(5) == 5`) })
|
||||
```
|
||||
|
||||
`fibonacci(10)` should return `55`.
|
||||
|
||||
```js
|
||||
({ test: () => runPython(`assert fibonacci(10) == 55`) })
|
||||
```
|
||||
|
||||
`fibonacci(15)` should return `610`.
|
||||
|
||||
```js
|
||||
({ test: () => runPython(`assert fibonacci(15) == 610`) })
|
||||
```
|
||||
|
||||
You should not use recursion in your code.
|
||||
|
||||
```js
|
||||
({ test: () => runPython(`
|
||||
assert not _Node(_code).find_function("fibonacci").find_body().block_has_call("fibonacci")
|
||||
`) })
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```py
|
||||
def fibonacci(n):
|
||||
sequence = [0, 1]
|
||||
|
||||
if n < 2:
|
||||
return sequence[n]
|
||||
|
||||
for i in range(2, n + 1):
|
||||
sequence.append(sequence[i - 1] + sequence[i - 2])
|
||||
|
||||
return sequence[n]
|
||||
```
|
||||
|
||||
15
curriculum/structure/blocks/lab-nth-fibonacci-number.json
Normal file
15
curriculum/structure/blocks/lab-nth-fibonacci-number.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "Build an Nth Fibonacci Number Calculator",
|
||||
"isUpcomingChange": true,
|
||||
"dashedName": "lab-nth-fibonacci-number",
|
||||
"helpCategory": "Python",
|
||||
"blockLayout": "link",
|
||||
"challengeOrder": [
|
||||
{
|
||||
"id": "68de7360e1832ea180577a8a",
|
||||
"title": "Build an Nth Fibonacci Number Calculator"
|
||||
}
|
||||
],
|
||||
"blockType": "lab",
|
||||
"usesMultifileEditor": true
|
||||
}
|
||||
@@ -777,6 +777,7 @@
|
||||
"comingSoon": true,
|
||||
"blocks": [
|
||||
"lecture-understanding-dynamic-programming",
|
||||
"lab-nth-fibonacci-number",
|
||||
"review-dynamic-programming",
|
||||
"quiz-dynamic-programming"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user