From eac87fb5ac750ab04a6644f66ea93f63ea1c279f Mon Sep 17 00:00:00 2001 From: Zaira <33151350+zairahira@users.noreply.github.com> Date: Fri, 3 Oct 2025 18:47:17 +0500 Subject: [PATCH] feat(curriculum): add dynamic programming lab (#62462) --- client/i18n/locales/english/intro.json | 82 ++++++++++--- .../lab-nth-fibonacci-number/index.md | 9 ++ .../68de7360e1832ea180577a8a.md | 116 ++++++++++++++++++ .../blocks/lab-nth-fibonacci-number.json | 15 +++ .../superblocks/full-stack-developer.json | 1 + 5 files changed, 206 insertions(+), 17 deletions(-) create mode 100644 client/src/pages/learn/full-stack-developer/lab-nth-fibonacci-number/index.md create mode 100644 curriculum/challenges/english/blocks/lab-nth-fibonacci-number/68de7360e1832ea180577a8a.md create mode 100644 curriculum/structure/blocks/lab-nth-fibonacci-number.json diff --git a/client/i18n/locales/english/intro.json b/client/i18n/locales/english/intro.json index 9404c0f04f7..cbde6141af8 100644 --- a/client/i18n/locales/english/intro.json +++ b/client/i18n/locales/english/intro.json @@ -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": { diff --git a/client/src/pages/learn/full-stack-developer/lab-nth-fibonacci-number/index.md b/client/src/pages/learn/full-stack-developer/lab-nth-fibonacci-number/index.md new file mode 100644 index 00000000000..f79063c7bc9 --- /dev/null +++ b/client/src/pages/learn/full-stack-developer/lab-nth-fibonacci-number/index.md @@ -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. diff --git a/curriculum/challenges/english/blocks/lab-nth-fibonacci-number/68de7360e1832ea180577a8a.md b/curriculum/challenges/english/blocks/lab-nth-fibonacci-number/68de7360e1832ea180577a8a.md new file mode 100644 index 00000000000..02e2ea3991b --- /dev/null +++ b/curriculum/challenges/english/blocks/lab-nth-fibonacci-number/68de7360e1832ea180577a8a.md @@ -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] +``` + diff --git a/curriculum/structure/blocks/lab-nth-fibonacci-number.json b/curriculum/structure/blocks/lab-nth-fibonacci-number.json new file mode 100644 index 00000000000..d43269f9870 --- /dev/null +++ b/curriculum/structure/blocks/lab-nth-fibonacci-number.json @@ -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 +} diff --git a/curriculum/structure/superblocks/full-stack-developer.json b/curriculum/structure/superblocks/full-stack-developer.json index a764b697025..e58973c335d 100644 --- a/curriculum/structure/superblocks/full-stack-developer.json +++ b/curriculum/structure/superblocks/full-stack-developer.json @@ -777,6 +777,7 @@ "comingSoon": true, "blocks": [ "lecture-understanding-dynamic-programming", + "lab-nth-fibonacci-number", "review-dynamic-programming", "quiz-dynamic-programming" ]