From 1ef3cc1e7a01d752bc39663833fca1fe42625d27 Mon Sep 17 00:00:00 2001 From: Tom <20648924+moT01@users.noreply.github.com> Date: Fri, 29 Aug 2025 11:56:31 -0500 Subject: [PATCH] feat(curriculum): more daily challenges (#61959) --- .../68adce01c0e1144d0a902956.md | 72 ++++++++++ .../68adce01c0e1144d0a902958.md | 90 +++++++++++++ .../68adce01c0e1144d0a90295a.md | 74 ++++++++++ .../68adce01c0e1144d0a90295c.md | 110 +++++++++++++++ .../68adce01c0e1144d0a90295e.md | 91 +++++++++++++ .../68adce01c0e1144d0a902957.md | 80 +++++++++++ .../68adce01c0e1144d0a902959.md | 112 ++++++++++++++++ .../68adce01c0e1144d0a90295b.md | 82 ++++++++++++ .../68adce01c0e1144d0a90295d.md | 126 ++++++++++++++++++ .../68adce01c0e1144d0a90295f.md | 105 +++++++++++++++ .../daily-coding-challenges-javascript.json | 20 +++ .../daily-coding-challenges-python.json | 20 +++ 12 files changed, 982 insertions(+) create mode 100644 curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a902956.md create mode 100644 curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a902958.md create mode 100644 curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a90295a.md create mode 100644 curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a90295c.md create mode 100644 curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a90295e.md create mode 100644 curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a902957.md create mode 100644 curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a902959.md create mode 100644 curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a90295b.md create mode 100644 curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a90295d.md create mode 100644 curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a90295f.md diff --git a/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a902956.md b/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a902956.md new file mode 100644 index 00000000000..e638f055fec --- /dev/null +++ b/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a902956.md @@ -0,0 +1,72 @@ +--- +id: 68adce01c0e1144d0a902956 +title: "JavaScript Challenge 25: Vowel Repeater" +challengeType: 28 +dashedName: javascript-challenge-25 +--- + +# --description-- + +Given a string, return a new version of the string where each vowel is duplicated one more time than the previous vowel you encountered. For instance, the first vowel in the sentence should remain unchanged. The second vowel should appear twice in a row. The third vowel should appear three times in a row, and so on. + +- The letters `a`, `e`, `i`, `o`, and `u`, in either uppercase or lowercase, are considered vowels. +- The original vowel should keeps its case. +- Repeated vowels should be lowercase. +- All non-vowel characters should keep their original case. + +# --hints-- + +`repeatVowels("hello world")` should return `"helloo wooorld"`. + +```js +assert.equal(repeatVowels("hello world"), "helloo wooorld"); +``` + +`repeatVowels("freeCodeCamp")` should return `"freeeCooodeeeeCaaaaamp"`. + +```js +assert.equal(repeatVowels("freeCodeCamp"), "freeeCooodeeeeCaaaaamp"); +``` + +`repeatVowels("AEIOU")` should return `"AEeIiiOoooUuuuu"`. + +```js +assert.equal(repeatVowels("AEIOU"), "AEeIiiOoooUuuuu"); +``` + +`repeatVowels("I like eating ice cream in Iceland")` should return `"I liikeee eeeeaaaaatiiiiiing iiiiiiiceeeeeeee creeeeeeeeeaaaaaaaaaam iiiiiiiiiiin Iiiiiiiiiiiiceeeeeeeeeeeeelaaaaaaaaaaaaaand"`. + +```js +assert.equal(repeatVowels("I like eating ice cream in Iceland"), "I liikeee eeeeaaaaatiiiiiing iiiiiiiceeeeeeee creeeeeeeeeaaaaaaaaaam iiiiiiiiiiin Iiiiiiiiiiiiceeeeeeeeeeeeelaaaaaaaaaaaaaand"); +``` + +# --seed-- + +## --seed-contents-- + +```js +function repeatVowels(str) { + + return str; +} +``` + +# --solutions-- + +```js +function repeatVowels(str) { + const vowels = "aeiouAEIOU"; + let count = 0; + let result = ""; + + for (let char of str) { + result += char; + if (vowels.includes(char)) { + result += char.repeat(count).toLowerCase(); + count++; + } + } + + return result; +} +``` diff --git a/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a902958.md b/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a902958.md new file mode 100644 index 00000000000..79826d88ba3 --- /dev/null +++ b/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a902958.md @@ -0,0 +1,90 @@ +--- +id: 68adce01c0e1144d0a902958 +title: "JavaScript Challenge 26: IPv4 Validator" +challengeType: 28 +dashedName: javascript-challenge-26 +--- + +# --description-- + +Given a string, determine if it is a valid IPv4 Address. A valid IPv4 address consists of four integer numbers separated by dots (`.`). Each number must satisfy the following conditions: + +- It is between 0 and 255 inclusive. +- It does not have leading zeros (e.g. 0 is allowed, 01 is not). +- Only numeric characters are allowed. + +# --hints-- + +`isValidIPv4("192.168.1.1")` should return `true`. + +```js +assert.isTrue(isValidIPv4("192.168.1.1")); +``` + +`isValidIPv4("0.0.0.0")` should return `true`. + +```js +assert.isTrue(isValidIPv4("0.0.0.0")); +``` + +`isValidIPv4("255.01.50.111")` should return `false`. + +```js +assert.isFalse(isValidIPv4("255.01.50.111")); +``` + +`isValidIPv4("255.00.50.111")` should return `false`. + +```js +assert.isFalse(isValidIPv4("255.00.50.111")); +``` + +`isValidIPv4("256.101.50.115")` should return `false`. + +```js +assert.isFalse(isValidIPv4("256.101.50.115")); +``` + +`isValidIPv4("192.168.101.")` should return `false`. + +```js +assert.isFalse(isValidIPv4("192.168.101.")); +``` + +`isValidIPv4("192168145213")` should return `false`. + +```js +assert.isFalse(isValidIPv4("192168145213")); +``` + +# --seed-- + +## --seed-contents-- + +```js +function isValidIPv4(ipv4) { + + return ipv4; +} +``` + +# --solutions-- + +```js +function isValidIPv4(ipv4) { + const parts = ipv4.split("."); + + if (parts.length !== 4) return false; + + for (let part of parts) { + if (!/^\d+$/.test(part)) return false; + + const num = Number(part); + if (num < 0 || num > 255) return false; + + if (part.length > 1 && part.startsWith("0")) return false; + } + + return true; +} +``` diff --git a/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a90295a.md b/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a90295a.md new file mode 100644 index 00000000000..5feebe21d33 --- /dev/null +++ b/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a90295a.md @@ -0,0 +1,74 @@ +--- +id: 68adce01c0e1144d0a90295a +title: "JavaScript Challenge 27: Matrix Rotate" +challengeType: 28 +dashedName: javascript-challenge-27 +--- + +# --description-- + +Given a matrix (an array of arrays), rotate the matrix 90 degrees clockwise and return it. For instance, given `[[1, 2], [3, 4]]`, which looks like this: + +| 1 | 2 | +|---|---| +| 3 | 4 | + +You should return `[[3, 1], [4, 2]]`, which looks like this: + +| 3 | 1 | +|---|---| +| 4 | 2 | + +# --hints-- + +`rotate([[1]])` should return `[[1]]`. + +```js +assert.deepEqual(rotate([[1]]), [[1]]); +``` + +`rotate([[1, 2], [3, 4]])` should return `[[3, 1], [4, 2]]`. + +```js +assert.deepEqual(rotate([[1, 2], [3, 4]]), [[3, 1], [4, 2]]); +``` + +`rotate([[1, 2, 3], [4, 5, 6], [7, 8, 9]])` should return `[[7, 4, 1], [8, 5, 2], [9, 6, 3]]`. + +```js +assert.deepEqual(rotate([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), [[7, 4, 1], [8, 5, 2], [9, 6, 3]]); +``` + +`rotate([[0, 1, 0], [1, 0, 1], [0, 0, 0]])` should return `[[0, 1, 0], [0, 0, 1], [0, 1, 0]]`. + +```js +assert.deepEqual(rotate([[0, 1, 0], [1, 0, 1], [0, 0, 0]]), [[0, 1, 0], [0, 0, 1], [0, 1, 0]]); +``` + +# --seed-- + +## --seed-contents-- + +```js +function rotate(matrix) { + + return matrix; +} +``` + +# --solutions-- + +```js +function rotate(matrix) { + const n = matrix.length; + const result = Array.from({ length: n }, () => Array(n).fill(0)); + + for (let i = 0; i < n; i++) { + for (let j = 0; j < n; j++) { + result[j][n - 1 - i] = matrix[i][j]; + } + } + + return result; +} +``` diff --git a/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a90295c.md b/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a90295c.md new file mode 100644 index 00000000000..ced2e3eb980 --- /dev/null +++ b/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a90295c.md @@ -0,0 +1,110 @@ +--- +id: 68adce01c0e1144d0a90295c +title: "JavaScript Challenge 28: Roman Numeral Parser" +challengeType: 28 +dashedName: javascript-challenge-28 +--- + +# --description-- + +Given a string representing a Roman numeral, return its integer value. + +Roman numerals consist of the following symbols and values: + +| Symbol | Value | +|--------|-------| +| I | 1 | +| V | 5 | +| X | 10 | +| L | 50 | +| C | 100 | +| D | 500 | +| M | 1000 | + +- Numerals are read left to right. If a smaller numeral appears before a larger one, the value is subtracted. Otherwise, values are added. + +# --hints-- + +`parseRomanNumeral("III")` should return `3`. + +```js +assert.equal(parseRomanNumeral("III"), 3); +``` + +`parseRomanNumeral("IV")` should return `4`. + +```js +assert.equal(parseRomanNumeral("IV"), 4); +``` + +`parseRomanNumeral("XXVI")` should return `26`. + +```js +assert.equal(parseRomanNumeral("XXVI"), 26); +``` + +`parseRomanNumeral("XCIX")` should return `99`. + +```js +assert.equal(parseRomanNumeral("XCIX"), 99); +``` + +`parseRomanNumeral("CDLX")` should return `460`. + +```js +assert.equal(parseRomanNumeral("CDLX"), 460); +``` + +`parseRomanNumeral("DIV")` should return `504`. + +```js +assert.equal(parseRomanNumeral("DIV"), 504); +``` + +`parseRomanNumeral("MMXXV")` should return `2025`. + +```js +assert.equal(parseRomanNumeral("MMXXV"), 2025); +``` + +# --seed-- + +## --seed-contents-- + +```js +function parseRomanNumeral(numeral) { + + return numeral; +} +``` + +# --solutions-- + +```js +function parseRomanNumeral(numeral) { + const romanMap = { + I: 1, + V: 5, + X: 10, + L: 50, + C: 100, + D: 500, + M: 1000 + }; + + let total = 0; + + for (let i = 0; i < numeral.length; i++) { + const current = romanMap[numeral[i]]; + const next = romanMap[numeral[i + 1]]; + + if (next && current < next) { + total -= current; + } else { + total += current; + } + } + + return total; +} +``` diff --git a/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a90295e.md b/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a90295e.md new file mode 100644 index 00000000000..4476a96e36e --- /dev/null +++ b/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68adce01c0e1144d0a90295e.md @@ -0,0 +1,91 @@ +--- +id: 68adce01c0e1144d0a90295e +title: "JavaScript Challenge 29: Acronym Builder" +challengeType: 28 +dashedName: javascript-challenge-29 +--- + +# --description-- + +Given a string containing one or more words, return an acronym of the words using the following constraints: + +- The acronym should consist of the first letter of each word capitalized, unless otherwise noted. +- The acronym should ignore the first letter of these words unless they are the first word of the given string: `a`, `for`, `an`, `and`, `by`, and `of`. +- The acronym letters should be returned in order they are given. +- The acronym should not contain any spaces. + +# --hints-- + +`buildAcronym("Search Engine Optimization")` should return `"SEO"`. + +```js +assert.equal(buildAcronym("Search Engine Optimization"), "SEO"); +``` + +`buildAcronym("Frequently Asked Questions")` should return `"FAQ"`. + +```js +assert.equal(buildAcronym("Frequently Asked Questions"), "FAQ"); +``` + +`buildAcronym("National Aeronautics and Space Administration")` should return `"NASA"`. + +```js +assert.equal(buildAcronym("National Aeronautics and Space Administration"), "NASA"); +``` + +`buildAcronym("Federal Bureau of Investigation")` should return `"FBI"`. + +```js +assert.equal(buildAcronym("Federal Bureau of Investigation"), "FBI"); +``` + +`buildAcronym("For your information")` should return `"FYI"`. + +```js +assert.equal(buildAcronym("Light Amplification by Stimulated Emission of Radiation"), "LASER"); +``` + +`buildAcronym("By the way")` should return `"BTW"`. + +```js +assert.equal(buildAcronym("By the way"), "BTW"); +``` + +`buildAcronym("An unstoppable herd of waddling penguins overtakes the icy mountains and sings happily")` should return `"AUHWPOTIMSH"`. + +```js +assert.equal(buildAcronym("An unstoppable herd of waddling penguins overtakes the icy mountains and sings happily"), "AUHWPOTIMSH"); +``` + +# --seed-- + +## --seed-contents-- + +```js +function buildAcronym(str) { + + return str; +} +``` + +# --solutions-- + +```js +function buildAcronym(str) { + const smallWords = ["a", "for", "an", "and", "by", "of"]; + const words = str.split(" "); + let acronym = ""; + + for (let i = 0; i < words.length; i++) { + const word = words[i]; + const lowerWord = word.toLowerCase(); + + if (i === 0 || !smallWords.includes(lowerWord)) { + acronym += word[0].toUpperCase(); + } + } + + return acronym; +} +``` diff --git a/curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a902957.md b/curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a902957.md new file mode 100644 index 00000000000..9938f082955 --- /dev/null +++ b/curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a902957.md @@ -0,0 +1,80 @@ +--- +id: 68adce01c0e1144d0a902957 +title: "Python Challenge 25: Vowel Repeater" +challengeType: 29 +dashedName: python-challenge-25 +--- + +# --description-- + +Given a string, return a new version of the string where each vowel is duplicated one more time than the previous vowel you encountered. For instance, the first vowel in the sentence should remain unchanged. The second vowel should appear twice in a row. The third vowel should appear three times in a row, and so on. + +- The letters `a`, `e`, `i`, `o`, and `u`, in either uppercase or lowercase, are considered vowels. +- The original vowel should keeps its case. +- Repeated vowels should be lowercase. +- All non-vowel characters should keep their original case. + +# --hints-- + +`repeat_vowels("hello world")` should return `"helloo wooorld"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(repeat_vowels("hello world"), "helloo wooorld")`) +}}) +``` + +`repeat_vowels("freeCodeCamp")` should return `"freeeCooodeeeeCaaaaamp"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(repeat_vowels("freeCodeCamp"), "freeeCooodeeeeCaaaaamp")`) +}}) +``` + +`repeat_vowels("AEIOU")` should return `"AEeIiiOoooUuuuu"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(repeat_vowels("AEIOU"), "AEeIiiOoooUuuuu")`) +}}) +``` + +`repeat_vowels("I like eating ice cream in Iceland")` should return `"I liikeee eeeeaaaaatiiiiiing iiiiiiiceeeeeeee creeeeeeeeeaaaaaaaaaam iiiiiiiiiiin Iiiiiiiiiiiiceeeeeeeeeeeeelaaaaaaaaaaaaaand"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(repeat_vowels("I like eating ice cream in Iceland"), "I liikeee eeeeaaaaatiiiiiing iiiiiiiceeeeeeee creeeeeeeeeaaaaaaaaaam iiiiiiiiiiin Iiiiiiiiiiiiceeeeeeeeeeeeelaaaaaaaaaaaaaand")`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def repeat_vowels(s): + + return s +``` + +# --solutions-- + +```py +def repeat_vowels(s): + vowels = "aeiouAEIOU" + count = 0 + result = [] + + for char in s: + result.append(char) + if char in vowels: + result.append(char.lower() * count) + count += 1 + + return "".join(result) +``` diff --git a/curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a902959.md b/curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a902959.md new file mode 100644 index 00000000000..352a4d77b6c --- /dev/null +++ b/curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a902959.md @@ -0,0 +1,112 @@ +--- +id: 68adce01c0e1144d0a902959 +title: "Python Challenge 26: IPv4 Validator" +challengeType: 29 +dashedName: python-challenge-26 +--- + +# --description-- + +Given a string, determine if it is a valid IPv4 Address. A valid IPv4 address consists of four integer numbers separated by dots (`.`). Each number must satisfy the following conditions: + +- It is between 0 and 255 inclusive. +- It does not have leading zeros (e.g. 0 is allowed, 01 is not). +- Only numeric characters are allowed. + +# --hints-- + +`is_valid_ipv4("192.168.1.1")` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_valid_ipv4("192.168.1.1"))`) +}}) +``` + +`is_valid_ipv4("0.0.0.0")` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_valid_ipv4("0.0.0.0"))`) +}}) +``` + +`is_valid_ipv4("255.01.50.111")` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_valid_ipv4("255.01.50.111"))`) +}}) +``` + +`is_valid_ipv4("255.00.50.111")` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_valid_ipv4("255.00.50.111"))`) +}}) +``` + +`is_valid_ipv4("256.101.50.115")` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_valid_ipv4("256.101.50.115"))`) +}}) +``` + +`is_valid_ipv4("192.168.101.")` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_valid_ipv4("192.168.101."))`) +}}) +``` + +`is_valid_ipv4("192168145213")` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_valid_ipv4("192168145213"))`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def is_valid_ipv4(ipv4): + + return ipv4 +``` + +# --solutions-- + +```py +def is_valid_ipv4(ipv4): + parts = ipv4.split(".") + + if len(parts) != 4: + return False + + for part in parts: + if not part.isdigit(): + return False + + num = int(part) + if num < 0 or num > 255: + return False + + if len(part) > 1 and part.startswith("0"): + return False + + return True +``` diff --git a/curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a90295b.md b/curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a90295b.md new file mode 100644 index 00000000000..55b87b64910 --- /dev/null +++ b/curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a90295b.md @@ -0,0 +1,82 @@ +--- +id: 68adce01c0e1144d0a90295b +title: "Python Challenge 27: Matrix Rotate" +challengeType: 29 +dashedName: python-challenge-27 +--- + +# --description-- + +Given a matrix (an array of arrays), rotate the matrix 90 degrees clockwise and return it. For instance, given `[[1, 2], [3, 4]]`, which looks like this: + +| 1 | 2 | +|---|---| +| 3 | 4 | + +You should return `[[3, 1], [4, 2]]`, which looks like this: + +| 3 | 1 | +|---|---| +| 4 | 2 | + +# --hints-- + +`rotate([[1]])` should return `[[1]]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(rotate([[1]]), [[1]])`) +}}) +``` + +`rotate([[1, 2], [3, 4]])` should return `[[3, 1], [4, 2]]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(rotate([[1, 2], [3, 4]]), [[3, 1], [4, 2]])`) +}}) +``` + +`rotate([[1, 2, 3], [4, 5, 6], [7, 8, 9]])` should return `[[7, 4, 1], [8, 5, 2], [9, 6, 3]]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(rotate([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), [[7, 4, 1], [8, 5, 2], [9, 6, 3]])`) +}}) +``` + +`rotate([[0, 1, 0], [1, 0, 1], [0, 0, 0]])` should return `[[0, 1, 0], [0, 0, 1], [0, 1, 0]]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(rotate([[0, 1, 0], [1, 0, 1], [0, 0, 0]]), [[0, 1, 0], [0, 0, 1], [0, 1, 0]])`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def rotate(matrix): + + return matrix +``` + +# --solutions-- + +```py +def rotate(matrix): + n = len(matrix) + result = [[0] * n for _ in range(n)] + + for i in range(n): + for j in range(n): + result[j][n - 1 - i] = matrix[i][j] + + return result +``` diff --git a/curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a90295d.md b/curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a90295d.md new file mode 100644 index 00000000000..f9e865546d3 --- /dev/null +++ b/curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a90295d.md @@ -0,0 +1,126 @@ +--- +id: 68adce01c0e1144d0a90295d +title: "Python Challenge 28: Roman Numeral Parser" +challengeType: 29 +dashedName: python-challenge-28 +--- + +# --description-- + +Given a string representing a Roman numeral, return its integer value. + +Roman numerals consist of the following symbols and values: + +| Symbol | Value | +|--------|-------| +| I | 1 | +| V | 5 | +| X | 10 | +| L | 50 | +| C | 100 | +| D | 500 | +| M | 1000 | + +- Numerals are read left to right. If a smaller numeral appears before a larger one, the value is subtracted. Otherwise, values are added. + +# --hints-- + +`parse_roman_numeral("III")` should return `3`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(parse_roman_numeral("III"), 3)`) +}}) +``` + +`parse_roman_numeral("IV")` should return `4`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(parse_roman_numeral("IV"), 4)`) +}}) +``` + +`parse_roman_numeral("XXVI")` should return `26`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(parse_roman_numeral("XXVI"), 26)`) +}}) +``` + +`parse_roman_numeral("XCIX")` should return `99`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(parse_roman_numeral("XCIX"), 99)`) +}}) +``` + +`parse_roman_numeral("CDLX")` should return `460`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(parse_roman_numeral("CDLX"), 460)`) +}}) +``` + +`parse_roman_numeral("DIV")` should return `504`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(parse_roman_numeral("DIV"), 504)`) +}}) +``` + +`parse_roman_numeral("MMXXV")` should return `2025`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(parse_roman_numeral("MMXXV"), 2025)`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def parse_roman_numeral(numeral): + + return numeral +``` + +# --solutions-- + +```py +def parse_roman_numeral(numeral): + roman_map = { + "I": 1, + "V": 5, + "X": 10, + "L": 50, + "C": 100, + "D": 500, + "M": 1000 + } + + total = 0 + for i in range(len(numeral)): + current = roman_map[numeral[i]] + next_val = roman_map[numeral[i + 1]] if i + 1 < len(numeral) else 0 + + if current < next_val: + total -= current + else: + total += current + + return total +``` diff --git a/curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a90295f.md b/curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a90295f.md new file mode 100644 index 00000000000..f19398e6a41 --- /dev/null +++ b/curriculum/challenges/english/blocks/daily-coding-challenges-python/68adce01c0e1144d0a90295f.md @@ -0,0 +1,105 @@ +--- +id: 68adce01c0e1144d0a90295f +title: "Python Challenge 29: Acronym Builder" +challengeType: 29 +dashedName: python-challenge-29 +--- + +# --description-- + +Given a string containing one or more words, return an acronym of the words using the following constraints: + +- The acronym should consist of the first letter of each word, capitalized. +- The acronym should ignore the first letter of these words unless they are the first word of the given string: `a`, `for`, `an`, `and`, `by`, and `of`. +- The acronym letters should be returned in order they are given. +- The acronym should not contain any spaces. + +# --hints-- + +`build_acronym("Search Engine Optimization")` should return `"SEO"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(build_acronym("Search Engine Optimization"), "SEO")`) +}}) +``` + +`build_acronym("Frequently Asked Questions")` should return `"FAQ"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(build_acronym("Frequently Asked Questions"), "FAQ")`) +}}) +``` + +`build_acronym("National Aeronautics and Space Administration")` should return `"NASA"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(build_acronym("National Aeronautics and Space Administration"), "NASA")`) +}}) +``` + +`build_acronym("Federal Bureau of Investigation")` should return `"FBI"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(build_acronym("Federal Bureau of Investigation"), "FBI")`) +}}) +``` + +`build_acronym("For your information")` should return `"FYI"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(build_acronym("For your information"), "FYI")`) +}}) +``` + +`build_acronym("By the way")` should return `"BTW"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(build_acronym("By the way"), "BTW")`) +}}) +``` + +`build_acronym("An unstoppable herd of waddling penguins overtakes the icy mountains and sings happily")` should return `"AUHWPOTIMSH"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(build_acronym("An unstoppable herd of waddling penguins overtakes the icy mountains and sings happily"), "AUHWPOTIMSH")`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def build_acronym(s): + + return s +``` + +# --solutions-- + +```py +def build_acronym(s): + small_words = {"a", "for", "an", "and", "by", "of"} + words = s.split() + acronym = "" + + for i, word in enumerate(words): + if i == 0 or word.lower() not in small_words: + acronym += word[0].upper() + + return acronym +``` diff --git a/curriculum/structure/blocks/daily-coding-challenges-javascript.json b/curriculum/structure/blocks/daily-coding-challenges-javascript.json index 8527f843fcb..286f4e5dabc 100644 --- a/curriculum/structure/blocks/daily-coding-challenges-javascript.json +++ b/curriculum/structure/blocks/daily-coding-challenges-javascript.json @@ -102,6 +102,26 @@ { "id": "6821ec02237de8297eaee79a", "title": "JavaScript Challenge 24" + }, + { + "id": "68adce01c0e1144d0a902956", + "title": "JavaScript Challenge 25" + }, + { + "id": "68adce01c0e1144d0a902958", + "title": "JavaScript Challenge 26" + }, + { + "id": "68adce01c0e1144d0a90295a", + "title": "JavaScript Challenge 27" + }, + { + "id": "68adce01c0e1144d0a90295c", + "title": "JavaScript Challenge 28" + }, + { + "id": "68adce01c0e1144d0a90295e", + "title": "JavaScript Challenge 29" } ] } diff --git a/curriculum/structure/blocks/daily-coding-challenges-python.json b/curriculum/structure/blocks/daily-coding-challenges-python.json index ca9d0e51b71..5e93d711752 100644 --- a/curriculum/structure/blocks/daily-coding-challenges-python.json +++ b/curriculum/structure/blocks/daily-coding-challenges-python.json @@ -101,6 +101,26 @@ { "id": "6821eccb237de8297eaee7a6", "title": "Python Challenge 24" + }, + { + "id": "68adce01c0e1144d0a902957", + "title": "Python Challenge 25" + }, + { + "id": "68adce01c0e1144d0a902959", + "title": "Python Challenge 26" + }, + { + "id": "68adce01c0e1144d0a90295b", + "title": "Python Challenge 27" + }, + { + "id": "68adce01c0e1144d0a90295d", + "title": "Python Challenge 28" + }, + { + "id": "68adce01c0e1144d0a90295f", + "title": "Python Challenge 29" } ] }