feat(curriculum): daily challenges 100-109 (#63406)

This commit is contained in:
Tom
2025-11-05 14:58:25 -06:00
committed by GitHub
parent 4043c6e1ff
commit 4c07a4e219
23 changed files with 1734 additions and 1 deletions
@@ -0,0 +1,65 @@
---
id: 68ffb91507a5b645769328c3
title: "Challenge 100: 100 Characters"
challengeType: 28
dashedName: challenge-100
---
# --description--
Welcome to the 100th Daily Coding Challenge!
Given a string, repeat its characters until the result is exactly 100 characters long. If your repetitions go over 100 characters, trim the extra so it's exactly 100.
# --hints--
`oneHundred("One hundred ")` should return `"One hundred One hundred One hundred One hundred One hundred One hundred One hundred One hundred One "`.
```js
assert.equal(oneHundred("One hundred "), "One hundred One hundred One hundred One hundred One hundred One hundred One hundred One hundred One ");
```
`oneHundred("freeCodeCamp ")` should return `"freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeC"`.
```js
assert.equal(oneHundred("freeCodeCamp "), "freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeC");
```
`oneHundred("daily challenges ")` should return `"daily challenges daily challenges daily challenges daily challenges daily challenges daily challenge"`.
```js
assert.equal(oneHundred("daily challenges "), "daily challenges daily challenges daily challenges daily challenges daily challenges daily challenge");
```
`oneHundred("!")` should return `"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"`.
```js
assert.equal(oneHundred("!"), "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
```
# --seed--
## --seed-contents--
```js
function oneHundred(chars) {
return chars;
}
```
# --solutions--
```js
function oneHundred(chars) {
let result = "";
let i = 0;
while (result.length < 100) {
result += chars[i % chars.length];
i++;
}
return result.slice(0, 100);
}
```
@@ -0,0 +1,95 @@
---
id: 68ffb91507a5b645769328c4
title: "Challenge 101: Markdown Heading Converter"
challengeType: 28
dashedName: challenge-101
---
# --description--
Given a string representing a Markdown heading, return the equivalent HTML heading.
A valid Markdown heading must:
- Start with zero or more spaces, followed by
- 1 to 6 hash characters (`#`) in a row, then
- At least one space. And finally,
- The heading text.
The number of hash symbols determines the heading level. For example, one hash symbol corresponds to an `h1` tag, and six hash symbols correspond to an `h6` tag.
If the given string doesn't have the exact format above, return `"Invalid format"`.
For example, given `"# My level 1 heading"`, return `"<h1>My level 1 heading</h1>"`.
Note: The console may not display HTML tags in strings when logging messages. Check the browser console to see logs with tags included.
# --hints--
`convert("# My level 1 heading")` should return `"<h1>My level 1 heading</h1>"`.
```js
assert.equal(convert("# My level 1 heading"), "<h1>My level 1 heading</h1>");
```
`convert("My heading")` should return `"Invalid format"`.
```js
assert.equal(convert("My heading"), "Invalid format");
```
`convert("##### My level 5 heading")` should return `"<h5>My level 5 heading</h5>"`.
```js
assert.equal(convert("##### My level 5 heading"), "<h5>My level 5 heading</h5>");
```
`convert("#My heading")` should return `"Invalid format"`.
```js
assert.equal(convert("#My heading"), "Invalid format");
```
`convert(" ### My level 3 heading")` should return `"<h3>My level 3 heading</h3>"`.
```js
assert.equal(convert(" ### My level 3 heading"), "<h3>My level 3 heading</h3>");
```
`convert("####### My level 7 heading")` should return `"Invalid format"`.
```js
assert.equal(convert("####### My level 7 heading"), "Invalid format");
```
`convert("## My #2 heading")` should return `"<h2>My #2 heading</h2>"`.
```js
assert.equal(convert("## My #2 heading"), "<h2>My #2 heading</h2>");
```
# --seed--
## --seed-contents--
```js
function convert(heading) {
return heading;
}
```
# --solutions--
```js
function convert(heading) {
const trimmed = heading.trim()
if (!/^#{1,6}\s+\S+/.test(trimmed)) return "Invalid format"
const hashCount = trimmed.indexOf(' ');
const text = trimmed.slice(hashCount).trimStart();
return `<h${hashCount}>${text}</h${hashCount}>`;
}
```
@@ -0,0 +1,82 @@
---
id: 68ffb91507a5b645769328c5
title: "Challenge 102: Longest Word"
challengeType: 28
dashedName: challenge-102
---
# --description--
Given a sentence string, return the longest word in the sentence.
- Words are separated by a single space.
- Only letters (`a-z`, case-insensitive) count toward the word's length.
- If there are multiple words with the same length, return the first one that appears.
- Return the word as it appears in the given string, with punctuation removed.
# --hints--
`longestWord("The quick red fox")` should return `"quick"`.
```js
assert.equal(longestWord("The quick red fox"), "quick");
```
`longestWord("Hello coding challenge.")` should return `"challenge"`.
```js
assert.equal(longestWord("Hello coding challenge."), "challenge");
```
`longestWord("Do Try This At Home.")` should return `"This"`.
```js
assert.equal(longestWord("Do Try This At Home."), "This");
```
`longestWord("This sentence... has commas, ellipses, and an exlamation point!")` should return `"exlamation"`.
```js
assert.equal(longestWord("This sentence... has commas, ellipses, and an exlamation point!"), "exlamation");
```
`longestWord("A tie? No way!")` should return `"tie"`.
```js
assert.equal(longestWord("A tie? No way!"), "tie");
```
`longestWord("Wouldn't you like to know.")` should return `"Wouldnt"`.
```js
assert.equal(longestWord("Wouldn't you like to know."), "Wouldnt");
```
# --seed--
## --seed-contents--
```js
function longestWord(sentence) {
return sentence;
}
```
# --solutions--
```js
function longestWord(sentence) {
const words = sentence.split(" ");
let longest = "";
for (let word of words) {
const cleaned = word.replace(/[^a-z]/gi, "");
if (cleaned.length > longest.length) {
longest = cleaned;
}
}
return longest;
}
```
@@ -0,0 +1,71 @@
---
id: 68ffb91507a5b645769328c6
title: "Challenge 103: LCM"
challengeType: 28
dashedName: challenge-103
---
# --description--
Given two integers, return the least common multiple (LCM) of the two numbers.
The LCM of two numbers is the smallest positive integer that is a multiple of both numbers. For example, given `4` and `6`, return `12` because:
- Multiples of `4` are `4`, `8`, `12` and so on.
- Multplies of `6` are `6`, `12`, `18` and so on.
- `12` is the smallest number that is a multiple of both.
# --hints--
`lcm(4, 6)` should return `12`.
```js
assert.equal(lcm(4, 6), 12);
```
`lcm(9, 6)` should return `18`.
```js
assert.equal(lcm(9, 6), 18);
```
`lcm(10, 100)` should return `100`.
```js
assert.equal(lcm(10, 100), 100);
```
`lcm(13, 17)` should return `221`.
```js
assert.equal(lcm(13, 17), 221);
```
`lcm(45, 70)` should return `630`.
```js
assert.equal(lcm(45, 70), 630);
```
# --seed--
## --seed-contents--
```js
function lcm(a, b) {
return a;
}
```
# --solutions--
```js
function lcm(a, b) {
function gcd(x, y) {
return y === 0 ? x : gcd(y, x % y);
}
return Math.abs(a * b) / gcd(a, b);
}
```
@@ -0,0 +1,66 @@
---
id: 68ffb91507a5b645769328c7
title: "Challenge 104: Recipe Scaler"
challengeType: 28
dashedName: challenge-104
---
# --description--
Given an array of recipe ingredients and a number to scale the recipe, return a an array with the quantities scaled accordingly.
- Each item in the given array will be a string in the format: `"quantity unit ingredient"`. For example `"2 C Flour"`.
- Scale the quantity by the given number. Do not include any trailing zeros and do not convert any units.
- Return the scaled items in the same order they are given.
# --hints--
`scaleRecipe(["2 C Flour", "1.5 T Sugar"], 2)` should return `["4 C Flour", "3 T Sugar"]`.
```js
assert.deepEqual(scaleRecipe(["2 C Flour", "1.5 T Sugar"], 2), ["4 C Flour", "3 T Sugar"]);
```
`scaleRecipe(["4 T Flour", "1 C Milk", "2 T Oil"], 1.5)` should return `["6 T Flour", "1.5 C Milk", "3 T Oil"]`.
```js
assert.deepEqual(scaleRecipe(["4 T Flour", "1 C Milk", "2 T Oil"], 1.5), ["6 T Flour", "1.5 C Milk", "3 T Oil"]);
```
`scaleRecipe(["3 C Milk", "2 C Oats"], 0.5)` should return `["1.5 C Milk", "1 C Oats"]`.
```js
assert.deepEqual(scaleRecipe(["3 C Milk", "2 C Oats"], 0.5), ["1.5 C Milk", "1 C Oats"]);
```
`scaleRecipe(["2 C All-purpose Flour", "1 t Baking Soda", "1 t Salt", "1 C Butter", "0.5 C Sugar", "0.5 C Brown Sugar", "1 t Vanilla Extract", "2 C Chocolate Chips"], 2.5)` should return `["5 C All-purpose Flour", "2.5 t Baking Soda", "2.5 t Salt", "2.5 C Butter", "1.25 C Sugar", "1.25 C Brown Sugar", "2.5 t Vanilla Extract", "5 C Chocolate Chips"]`.
```js
assert.deepEqual(scaleRecipe(["2 C All-purpose Flour", "1 t Baking Soda", "1 t Salt", "1 C Butter", "0.5 C Sugar", "0.5 C Brown Sugar", "1 t Vanilla Extract", "2 C Chocolate Chips"], 2.5), ["5 C All-purpose Flour", "2.5 t Baking Soda", "2.5 t Salt", "2.5 C Butter", "1.25 C Sugar", "1.25 C Brown Sugar", "2.5 t Vanilla Extract", "5 C Chocolate Chips"]);
```
# --seed--
## --seed-contents--
```js
function scaleRecipe(ingredients, scale) {
return ingredients;
}
```
# --solutions--
```js
function scaleRecipe(ingredients, scale) {
return ingredients.map(item => {
const [quantityStr, unit, ...rest] = item.split(" ");
const ingredientName = rest.join(" ");
const quantity = parseFloat(quantityStr) * scale;
return `${quantity} ${unit} ${ingredientName}`;
});
}
```
@@ -0,0 +1,65 @@
---
id: 68ffb91507a5b645769328c8
title: "Challenge 105: Character Count"
challengeType: 28
dashedName: challenge-105
---
# --description--
Given a sentence string, return an array with a count of each character in alphabetical order.
- Treat upper and lowercase letters as the same letter when counting.
- Ignore numbers, spaces, punctuation, etc.
- Return the count and letter in the format `"letter count"`. For instance, `"a 3"`.
- All returned letters should be lowercase.
- Do not return a count of letters that are not in the given string.
# --hints--
`countCharacters("hello world")` should return `["d 1", "e 1", "h 1", "l 3", "o 2", "r 1", "w 1"]`.
```js
assert.deepEqual(countCharacters("hello world"), ["d 1", "e 1", "h 1", "l 3", "o 2", "r 1", "w 1"]);
```
`countCharacters("I love coding challenges!")` should return `["a 1", "c 2", "d 1", "e 3", "g 2", "h 1", "i 2", "l 3", "n 2", "o 2", "s 1", "v 1"]`.
```js
assert.deepEqual(countCharacters("I love coding challenges!"), ["a 1", "c 2", "d 1", "e 3", "g 2", "h 1", "i 2", "l 3", "n 2", "o 2", "s 1", "v 1"]);
```
`countCharacters("// TODO: Complete this challenge ASAP!")` should return `["a 3", "c 2", "d 1", "e 4", "g 1", "h 2", "i 1", "l 3", "m 1", "n 1", "o 3", "p 2", "s 2", "t 3"]`.
```js
assert.deepEqual(countCharacters("// TODO: Complete this challenge ASAP!"), ["a 3", "c 2", "d 1", "e 4", "g 1", "h 2", "i 1", "l 3", "m 1", "n 1", "o 3", "p 2", "s 2", "t 3"]);
```
# --seed--
## --seed-contents--
```js
function countCharacters(sentence) {
return sentence;
}
```
# --solutions--
```js
function countCharacters(sentence) {
const counts = {};
for (let char of sentence.toLowerCase()) {
if (char >= "a" && char <= "z") {
counts[char] = (counts[char] || 0) + 1;
}
}
return Object.keys(counts)
.sort()
.map(letter => `${letter} ${counts[letter]}`);
}
```
@@ -0,0 +1,75 @@
---
id: 68ffb91507a5b645769328c9
title: "Challenge 106: Message Validator"
challengeType: 28
dashedName: challenge-106
---
# --description--
Given a message string and a validation string, determine if the message is valid.
- A message is valid if each word in the message starts with the corresponding letter in the validation string, in order.
- Letters are case-insensitive.
- Words in the message are separated by single spaces.
# --hints--
`isValidMessage("hello world", "hw")` should return `true`.
```js
assert.isTrue(isValidMessage("hello world", "hw"));
```
`isValidMessage("ALL CAPITAL LETTERS", "acl")` should return `true`.
```js
assert.isTrue(isValidMessage("ALL CAPITAL LETTERS", "acl"));
```
`isValidMessage("Coding challenge are boring.", "cca")` should return `false`.
```js
assert.isFalse(isValidMessage("Coding challenge are boring.", "cca"));
```
`isValidMessage("The quick brown fox jumps over the lazy dog.", "TQBFJOTLD")` should return `true`.
```js
assert.isTrue(isValidMessage("The quick brown fox jumps over the lazy dog.", "TQBFJOTLD"));
```
`isValidMessage("The quick brown fox jumps over the lazy dog.", "TQBFJOTLDT")` should return `false`.
```js
assert.isFalse(isValidMessage("The quick brown fox jumps over the lazy dog.", "TQBFJOTLDT"));
```
# --seed--
## --seed-contents--
```js
function isValidMessage(message, validator) {
return message;
}
```
# --solutions--
```js
function isValidMessage(message, validation) {
const words = message.split(" ");
if (words.length !== validation.length) return false;
for (let i = 0; i < words.length; i++) {
if (words[i][0].toLowerCase() !== validation[i].toLowerCase()) {
return false;
}
}
return true;
}
```
@@ -0,0 +1,77 @@
---
id: 68ffb91507a5b645769328ca
title: "Challenge 107: FizzBuzz"
challengeType: 28
dashedName: challenge-107
---
# --description--
Given an integer (`n`), return an array of integers from `1` to `n` (inclusive), replacing numbers that a multiple of:
- 3 with `"Fizz"`.
- 5 with `"Buzz"`.
- 3 and 5 with `"FizzBuzz"`.
# --hints--
`fizzBuzz(2)` should return `[1, 2]`.
```js
assert.deepEqual(fizzBuzz(2), [1, 2]);
```
`fizzBuzz(4)` should return `[1, 2, "Fizz", 4]`.
```js
assert.deepEqual(fizzBuzz(4), [1, 2, "Fizz", 4]);
```
`fizzBuzz(8)` should return `[1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8]`.
```js
assert.deepEqual(fizzBuzz(8), [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8]);
```
`fizzBuzz(20)` should return `[1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz"]`.
```js
assert.deepEqual(fizzBuzz(20), [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz"]);
```
`fizzBuzz(50)` should return `[1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26, "Fizz", 28, 29, "FizzBuzz", 31, 32, "Fizz", 34, "Buzz", "Fizz", 37, 38, "Fizz", "Buzz", 41, "Fizz", 43, 44, "FizzBuzz", 46, 47, "Fizz", 49, "Buzz"]`.
```js
assert.deepEqual(fizzBuzz(50), [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26, "Fizz", 28, 29, "FizzBuzz", 31, 32, "Fizz", 34, "Buzz", "Fizz", 37, 38, "Fizz", "Buzz", 41, "Fizz", 43, 44, "FizzBuzz", 46, 47, "Fizz", 49, "Buzz"]);
```
# --seed--
## --seed-contents--
```js
function fizzBuzz(n) {
return n;
}
```
# --solutions--
```js
function fizzBuzz(n) {
const result = [];
for (let i = 1; i <= n; i++) {
if (i % 15 === 0) {
result.push("FizzBuzz");
} else if (i % 3 === 0) {
result.push("Fizz");
} else if (i % 5 === 0) {
result.push("Buzz");
} else {
result.push(i);
}
}
return result;
}
```
@@ -0,0 +1,86 @@
---
id: 68ffb91507a5b645769328cb
title: "Challenge 108: BuzzFizz"
challengeType: 28
dashedName: challenge-108
---
# --description--
Given an array, determine if it is a correct FizzBuzz sequence from 1 to the last item in the array. A sequence is correct if:
- Numbers that are multiples of 3 are replaced with "Fizz"
- Numbers that are multiples of 5 are replaced with "Buzz"
- Numbers that are multiples of both 3 and 5 are replaced with "FizzBuzz"
- All other numbers remain as integers in ascending order, starting from 1.
- The array must start at 1 and have no missing or extra elements.
# --hints--
`isFizzBuzz([1, 2, "Fizz", 4])` should return `true`.
```js
assert.isTrue(isFizzBuzz([1, 2, "Fizz", 4]));
```
`isFizzBuzz([1, 2, 3, 4])` should return `false`.
```js
assert.isFalse(isFizzBuzz([1, 2, 3, 4]));
```
`isFizzBuzz([1, 2, "Fizz", 4, "Buzz", 7])` should return `false`.
```js
assert.isFalse(isFizzBuzz([1, 2, "Fizz", 4, "Buzz", 7]));
```
`isFizzBuzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, "FizzBuzz"])` should return `false`.
```js
assert.isFalse(isFizzBuzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, "FizzBuzz"]));
```
`isFizzBuzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, "Fizz"])` should return `false`.
```js
assert.isFalse(isFizzBuzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, "Fizz"]));
```
`isFizzBuzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, "Buzz"])` should return `false`.
```js
assert.isFalse(isFizzBuzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, "Buzz"]));
```
`isFizzBuzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26, "Fizz", 28, 29, "FizzBuzz", 31, 32, "Fizz", 34, "Buzz", "Fizz", 37, 38, "Fizz", "Buzz", 41, "Fizz", 43, 44, "FizzBuzz", 46, 47, "Fizz", 49, "Buzz"])` should return `true`.
```js
assert.isTrue(isFizzBuzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26, "Fizz", 28, 29, "FizzBuzz", 31, 32, "Fizz", 34, "Buzz", "Fizz", 37, 38, "Fizz", "Buzz", 41, "Fizz", 43, 44, "FizzBuzz", 46, 47, "Fizz", 49, "Buzz"]));
```
# --seed--
## --seed-contents--
```js
function isFizzBuzz(sequence) {
return sequence;
}
```
# --solutions--
```js
function isFizzBuzz(sequence) {
for (let i = 0; i < sequence.length; i++) {
const n = i + 1;
if (n % 15 === 0 && sequence[i] !== "FizzBuzz") return false;
if (n % 3 === 0 && n % 5 !== 0 && sequence[i] !== "Fizz") return false;
if (n % 5 === 0 && n % 3 !== 0 && sequence[i] !== "Buzz") return false;
if (n % 3 !== 0 && n % 5 !== 0 && sequence[i] !== n) return false;
}
return true;
}
```
@@ -0,0 +1,78 @@
---
id: 68ffb91507a5b645769328cc
title: "Challenge 109: What's My Age Again?"
challengeType: 28
dashedName: challenge-109
---
# --description--
Given the date of someone's birthday in the format `YYYY-MM-DD`, return the person's age as of November 27th, 2025.
- Assume all birthdays are valid dates before November 27th, 2025.
- Return the age as an integer.
- Be sure to account for whether the person has already had their birthday in 2025.
# --hints--
`calculateAge("2000-11-20")` should return `25`.
```js
assert.equal(calculateAge("2000-11-20"), 25);
```
`calculateAge("2000-12-01")` should return `24`.
```js
assert.equal(calculateAge("2000-12-01"), 24);
```
`calculateAge("2014-10-25")` should return `11`.
```js
assert.equal(calculateAge("2014-10-25"), 11);
```
`calculateAge("1994-01-06")` should return `31`.
```js
assert.equal(calculateAge("1994-01-06"), 31);
```
`calculateAge("1994-12-14")` should return `30`.
```js
assert.equal(calculateAge("1994-12-14"), 30);
```
# --seed--
## --seed-contents--
```js
function calculateAge(birthday) {
return birthday;
}
```
# --solutions--
```js
function calculateAge(birthday) {
const today = new Date("2025-11-27");
const [year, month, day] = birthday.split("-").map(Number);
const birthDate = new Date(year, month - 1, day);
let age = today.getFullYear() - birthDate.getFullYear();
if (
today.getMonth() < birthDate.getMonth() ||
(today.getMonth() === birthDate.getMonth() && today.getDate() < birthDate.getDate())
) {
age--;
}
return age;
}
```
@@ -0,0 +1,76 @@
---
id: 68ffb91507a5b645769328c3
title: "Challenge 100: 100 Characters"
challengeType: 29
dashedName: challenge-100
---
# --description--
Welcome to the 100th Daily Coding Challenge!
Given a string, repeat its characters until the result is exactly 100 characters long. If your repetitions go over 100 characters, trim the extra so it's exactly 100.
# --hints--
`one_hundred("One hundred ")` should return `"One hundred One hundred One hundred One hundred One hundred One hundred One hundred One hundred One "`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(one_hundred("One hundred "), "One hundred One hundred One hundred One hundred One hundred One hundred One hundred One hundred One ")`)
}})
```
`one_hundred("freeCodeCamp ")` should return `"freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeC"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(one_hundred("freeCodeCamp "), "freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeC")`)
}})
```
`one_hundred("daily challenges ")` should return `"daily challenges daily challenges daily challenges daily challenges daily challenges daily challenge"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(one_hundred("daily challenges "), "daily challenges daily challenges daily challenges daily challenges daily challenges daily challenge")`)
}})
```
`one_hundred("!")` should return `"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(one_hundred("!"), "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")`)
}})
```
# --seed--
## --seed-contents--
```py
def one_hundred(chars):
return chars
```
# --solutions--
```py
def one_hundred(chars):
result = ""
i = 0
while len(result) < 100:
result += chars[i % len(chars)]
i += 1
return result[:100]
```
@@ -0,0 +1,116 @@
---
id: 68ffb91507a5b645769328c4
title: "Challenge 101: Markdown Heading Converter"
challengeType: 29
dashedName: challenge-101
---
# --description--
Given a string representing a Markdown heading, return the equivalent HTML heading.
A valid Markdown heading must:
- Start with zero or more spaces, followed by
- 1 to 6 hash characters (`#`) in a row, then
- At least one space. And finally,
- The heading text.
The number of hash symbols determines the heading level. For example, one hash symbol corresponds to an `h1` tag, and six hash symbols correspond to an `h6` tag.
If the given string doesn't have the exact format above, return `"Invalid format"`.
For example, given `"# My level 1 heading"`, return `"<h1>My level 1 heading</h1>"`.
Note: The console may not display HTML tags in strings when logging messages. Check the browser console to see logs with tags included.
# --hints--
`convert("# My level 1 heading")` should return `"<h1>My level 1 heading</h1>"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert("# My level 1 heading"), "<h1>My level 1 heading</h1>")`)
}})
```
`convert("My heading")` should return `"Invalid format"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert("My heading"), "Invalid format")`)
}})
```
`convert("##### My level 5 heading")` should return `"<h5>My level 5 heading</h5>"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert("##### My level 5 heading"), "<h5>My level 5 heading</h5>")`)
}})
```
`convert("#My heading")` should return `"Invalid format"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert("#My heading"), "Invalid format")`)
}})
```
`convert(" ### My level 3 heading")` should return `"<h3>My level 3 heading</h3>"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert(" ### My level 3 heading"), "<h3>My level 3 heading</h3>")`)
}})
```
`convert("####### My level 7 heading")` should return `"Invalid format"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert("####### My level 7 heading"), "Invalid format")`)
}})
```
`convert("## My #2 heading")` should return `"<h2>My #2 heading</h2>"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert("## My #2 heading"), "<h2>My #2 heading</h2>")`)
}})
```
# --seed--
## --seed-contents--
```py
def convert(heading):
return heading
```
# --solutions--
```py
import re
def convert(heading):
trimmed = heading.strip()
if not re.match(r'^#{1,6}\s+\S+', trimmed):
return "Invalid format"
hash_count = trimmed.find(' ')
text = trimmed[hash_count:].lstrip()
return f"<h{hash_count}>{text}</h{hash_count}>"
```
@@ -0,0 +1,97 @@
---
id: 68ffb91507a5b645769328c5
title: "Challenge 102: Longest Word"
challengeType: 29
dashedName: challenge-102
---
# --description--
Given a sentence string, return the longest word in the sentence.
- Words are separated by a single space.
- Only letters (`a-z`, case-insensitive) count toward the word's length.
- If there are multiple words with the same length, return the first one that appears.
- Return the word as it appears in the given string, with punctuation removed.
# --hints--
`longest_word("The quick red fox")` should return `"quick"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(longest_word("The quick red fox"), "quick")`)
}})
```
`longest_word("Hello coding challenge.")` should return `"challenge"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(longest_word("Hello coding challenge."), "challenge")`)
}})
```
`longest_word("Do Try This At Home.")` should return `"This"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(longest_word("Do Try This At Home."), "This")`)
}})
```
`longest_word("This sentence... has commas, ellipses, and an exlamation point!")` should return `"exlamation"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(longest_word("This sentence... has commas, ellipses, and an exlamation point!"), "exlamation")`)
}})
```
`longest_word("A tie? No way!")` should return `"tie"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(longest_word("A tie? No way!"), "tie")`)
}})
```
`longest_word("Wouldn't you like to know.")` should return `"Wouldnt"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(longest_word("Wouldn't you like to know."), "Wouldnt")`)
}})
```
# --seed--
## --seed-contents--
```py
def longest_word(sentence):
return sentence
```
# --solutions--
```py
import re
def longest_word(sentence):
words = sentence.split(" ")
longest = ""
for word in words:
cleaned = re.sub(r'[^a-zA-Z]', '', word)
if len(cleaned) > len(longest):
longest = cleaned
return longest
```
@@ -0,0 +1,83 @@
---
id: 68ffb91507a5b645769328c6
title: "Challenge 103: LCM"
challengeType: 29
dashedName: challenge-103
---
# --description--
Given two integers, return the least common multiple (LCM) of the two numbers.
The LCM of two numbers is the smallest positive integer that is a multiple of both numbers. For example, given `4` and `6`, return `12` because:
- Multiples of `4` are `4`, `8`, `12` and so on.
- Multplies of `6` are `6`, `12`, `18` and so on.
- `12` is the smallest number that is a multiple of both.
# --hints--
`lcm(4, 6)` should return `12`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(lcm(4, 6), 12)`)
}})
```
`lcm(9, 6)` should return `18`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(lcm(9, 6), 18)`)
}})
```
`lcm(10, 100)` should return `100`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(lcm(10, 100), 100)`)
}})
```
`lcm(13, 17)` should return `221`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(lcm(13, 17), 221)`)
}})
```
`lcm(45, 70)` should return `630`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(lcm(45, 70), 630)`)
}})
```
# --seed--
## --seed-contents--
```py
def lcm(a, b):
return a
```
# --solutions--
```py
def lcm(a, b):
def gcd(x, y):
return x if y == 0 else gcd(y, x % y)
return abs(a * b) // gcd(a, b)
```
@@ -0,0 +1,84 @@
---
id: 68ffb91507a5b645769328c7
title: "Challenge 104: Recipe Scaler"
challengeType: 29
dashedName: challenge-104
---
# --description--
Given an array of recipe ingredients and a number to scale the recipe, return a an array with the quantities scaled accordingly.
- Each item in the given array will be a string in the format: `"quantity unit ingredient"`. For example `"2 C Flour"`.
- Scale the quantity by the given number. Do not include any trailing zeros and do not convert any units.
- Return the scaled items in the same order they are given.
# --hints--
`scale_recipe(["2 C Flour", "1.5 T Sugar"], 2)` should return `["4 C Flour", "3 T Sugar"]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(scale_recipe(["2 C Flour", "1.5 T Sugar"], 2), ["4 C Flour", "3 T Sugar"])`)
}})
```
`scale_recipe(["4 T Flour", "1 C Milk", "2 T Oil"], 1.5)` should return `["6 T Flour", "1.5 C Milk", "3 T Oil"]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(scale_recipe(["4 T Flour", "1 C Milk", "2 T Oil"], 1.5), ["6 T Flour", "1.5 C Milk", "3 T Oil"])`)
}})
```
`scale_recipe(["3 C Milk", "2 C Oats"], 0.5)` should return `["1.5 C Milk", "1 C Oats"]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(scale_recipe(["3 C Milk", "2 C Oats"], 0.5), ["1.5 C Milk", "1 C Oats"])`)
}})
```
`scale_recipe(["2 C All-purpose Flour", "1 t Baking Soda", "1 t Salt", "1 C Butter", "0.5 C Sugar", "0.5 C Brown Sugar", "1 t Vanilla Extract", "2 C Chocolate Chips"], 2.5)` should return `["5 C All-purpose Flour", "2.5 t Baking Soda", "2.5 t Salt", "2.5 C Butter", "1.25 C Sugar", "1.25 C Brown Sugar", "2.5 t Vanilla Extract", "5 C Chocolate Chips"]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(scale_recipe(["2 C All-purpose Flour", "1 t Baking Soda", "1 t Salt", "1 C Butter", "0.5 C Sugar", "0.5 C Brown Sugar", "1 t Vanilla Extract", "2 C Chocolate Chips"], 2.5), ["5 C All-purpose Flour", "2.5 t Baking Soda", "2.5 t Salt", "2.5 C Butter", "1.25 C Sugar", "1.25 C Brown Sugar", "2.5 t Vanilla Extract", "5 C Chocolate Chips"])`)
}})
```
# --seed--
## --seed-contents--
```py
def scale_recipe(ingredients, scale):
return ingredients
```
# --solutions--
```py
def scale_recipe(ingredients, scale):
scaled = []
for item in ingredients:
parts = item.split(" ")
quantity = float(parts[0]) * scale
unit = parts[1]
ingredient_name = " ".join(parts[2:])
if quantity.is_integer():
quantity_str = str(int(quantity))
else:
quantity_str = str(quantity)
scaled.append(f"{quantity_str} {unit} {ingredient_name}")
return scaled
```
@@ -0,0 +1,67 @@
---
id: 68ffb91507a5b645769328c8
title: "Challenge 105: Character Count"
challengeType: 29
dashedName: challenge-105
---
# --description--
Given a sentence string, return an array with a count of each character in alphabetical order.
- Treat upper and lowercase letters as the same letter when counting.
- Ignore numbers, spaces, punctuation, etc.
- Return the count and letter in the format `"letter count"`. For instance, `"a 3"`.
- All returned letters should be lowercase.
- Do not return a count of letters that are not in the given string.
# --hints--
`count_characters("hello world")` should return `["d 1", "e 1", "h 1", "l 3", "o 2", "r 1", "w 1"]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(count_characters("hello world"), ["d 1", "e 1", "h 1", "l 3", "o 2", "r 1", "w 1"])`)
}})
```
`count_characters("I love coding challenges!")` should return `["a 1", "c 2", "d 1", "e 3", "g 2", "h 1", "i 2", "l 3", "n 2", "o 2", "s 1", "v 1"]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(count_characters("I love coding challenges!"), ["a 1", "c 2", "d 1", "e 3", "g 2", "h 1", "i 2", "l 3", "n 2", "o 2", "s 1", "v 1"])`)
}})
```
`count_characters("// TODO: Complete this challenge ASAP!")` should return `["a 3", "c 2", "d 1", "e 4", "g 1", "h 2", "i 1", "l 3", "m 1", "n 1", "o 3", "p 2", "s 2", "t 3"]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(count_characters("// TODO: Complete this challenge ASAP!"), ["a 3", "c 2", "d 1", "e 4", "g 1", "h 2", "i 1", "l 3", "m 1", "n 1", "o 3", "p 2", "s 2", "t 3"])`)
}})
```
# --seed--
## --seed-contents--
```py
def count_characters(sentence):
return sentence
```
# --solutions--
```py
def count_characters(sentence):
from collections import Counter
letters = [c.lower() for c in sentence if c.isalpha()]
counts = Counter(letters)
return [f"{letter} {counts[letter]}" for letter in sorted(counts)]
```
@@ -0,0 +1,87 @@
---
id: 68ffb91507a5b645769328c9
title: "Challenge 106: Message Validator"
challengeType: 29
dashedName: challenge-106
---
# --description--
Given a message string and a validation string, determine if the message is valid.
- A message is valid if each word in the message starts with the corresponding letter in the validation string, in order.
- Letters are case-insensitive.
- Words in the message are separated by single spaces.
# --hints--
`is_valid_message("hello world", "hw")` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_message("hello world", "hw"), True)`)
}})
```
`is_valid_message("ALL CAPITAL LETTERS", "acl")` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_message("ALL CAPITAL LETTERS", "acl"), True)`)
}})
```
`is_valid_message("Coding challenge are boring.", "cca")` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_message("Coding challenge are boring.", "cca"), False)`)
}})
```
`is_valid_message("The quick brown fox jumps over the lazy dog.", "TQBFJOTLD")` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_message("The quick brown fox jumps over the lazy dog.", "TQBFJOTLD"), True)`)
}})
```
`is_valid_message("The quick brown fox jumps over the lazy dog.", "TQBFJOTLDT")` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_message("The quick brown fox jumps over the lazy dog.", "TQBFJOTLDT"), False)`)
}})
```
# --seed--
## --seed-contents--
```py
def is_valid_message(message, validation):
return message
```
# --solutions--
```py
def is_valid_message(message, validation):
words = message.split()
if len(words) != len(validation):
return False
for word, val_letter in zip(words, validation):
if word[0].lower() != val_letter.lower():
return False
return True
```
@@ -0,0 +1,88 @@
---
id: 68ffb91507a5b645769328ca
title: "Challenge 107: FizzBuzz"
challengeType: 29
dashedName: challenge-107
---
# --description--
Given an integer (`n`), return an array of integers from `1` to `n` (inclusive), replacing numbers that a multiple of:
- 3 with `"Fizz"`.
- 5 with `"Buzz"`.
- 3 and 5 with `"FizzBuzz"`.
# --hints--
`fizz_buzz(2)` should return `[1, 2]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(fizz_buzz(2), [1, 2])`)
}})
```
`fizz_buzz(4)` should return `[1, 2, "Fizz", 4]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(fizz_buzz(4), [1, 2, "Fizz", 4])`)
}})
```
`fizz_buzz(8)` should return `[1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(fizz_buzz(8), [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8])`)
}})
```
`fizz_buzz(20)` should return `[1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz"]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(fizz_buzz(20), [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz"])`)
}})
```
`fizz_buzz(50)` should return `[1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26, "Fizz", 28, 29, "FizzBuzz", 31, 32, "Fizz", 34, "Buzz", "Fizz", 37, 38, "Fizz", "Buzz", 41, "Fizz", 43, 44, "FizzBuzz", 46, 47, "Fizz", 49, "Buzz"]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(fizz_buzz(50), [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26, "Fizz", 28, 29, "FizzBuzz", 31, 32, "Fizz", 34, "Buzz", "Fizz", 37, 38, "Fizz", "Buzz", 41, "Fizz", 43, 44, "FizzBuzz", 46, 47, "Fizz", 49, "Buzz"])`)
}})
```
# --seed--
## --seed-contents--
```py
def fizz_buzz(n):
return n
```
# --solutions--
```py
def fizz_buzz(n):
result = []
for i in range(1, n+1):
if i % 15 == 0:
result.append("FizzBuzz")
elif i % 3 == 0:
result.append("Fizz")
elif i % 5 == 0:
result.append("Buzz")
else:
result.append(i)
return result
```
@@ -0,0 +1,108 @@
---
id: 68ffb91507a5b645769328cb
title: "Challenge 108: BuzzFizz"
challengeType: 29
dashedName: challenge-108
---
# --description--
Given an array, determine if it is a correct FizzBuzz sequence from 1 to the last item in the array. A sequence is correct if:
- Numbers that are multiples of 3 are replaced with "Fizz"
- Numbers that are multiples of 5 are replaced with "Buzz"
- Numbers that are multiples of both 3 and 5 are replaced with "FizzBuzz"
- All other numbers remain as integers in ascending order, starting from 1.
- The array must start at 1 and have no missing or extra elements.
# --hints--
`is_fizz_buzz([1, 2, "Fizz", 4])` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_fizz_buzz([1, 2, "Fizz", 4]), True)`)
}})
```
`is_fizz_buzz([1, 2, 3, 4])` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_fizz_buzz([1, 2, 3, 4]), False)`)
}})
```
`is_fizz_buzz([1, 2, "Fizz", 4, "Buzz", 7])` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_fizz_buzz([1, 2, "Fizz", 4, "Buzz", 7]), False)`)
}})
```
`is_fizz_buzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, "FizzBuzz"])` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_fizz_buzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, "FizzBuzz"]), False)`)
}})
```
`is_fizz_buzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, "Fizz"])` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_fizz_buzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, "Fizz"]), False)`)
}})
```
`is_fizz_buzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, "Buzz"])` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_fizz_buzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, "Buzz"]), False)`)
}})
```
`is_fizz_buzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26, "Fizz", 28, 29, "FizzBuzz", 31, 32, "Fizz", 34, "Buzz", "Fizz", 37, 38, "Fizz", "Buzz", 41, "Fizz", 43, 44, "FizzBuzz", 46, 47, "Fizz", 49, "Buzz"])` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_fizz_buzz([1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26, "Fizz", 28, 29, "FizzBuzz", 31, 32, "Fizz", 34, "Buzz", "Fizz", 37, 38, "Fizz", "Buzz", 41, "Fizz", 43, 44, "FizzBuzz", 46, 47, "Fizz", 49, "Buzz"]), True)`)
}})
```
# --seed--
## --seed-contents--
```py
def is_fizz_buzz(sequence):
return sequence
```
# --solutions--
```py
def is_fizz_buzz(sequence):
for i, val in enumerate(sequence):
n = i + 1
if n % 15 == 0 and val != "FizzBuzz":
return False
if n % 3 == 0 and n % 5 != 0 and val != "Fizz":
return False
if n % 5 == 0 and n % 3 != 0 and val != "Buzz":
return False
if n % 3 != 0 and n % 5 != 0 and val != n:
return False
return True
```
@@ -0,0 +1,87 @@
---
id: 68ffb91507a5b645769328cc
title: "Challenge 109: What's My Age Again?"
challengeType: 29
dashedName: challenge-109
---
# --description--
Given the date of someone's birthday in the format `YYYY-MM-DD`, return the person's age as of November 27th, 2025.
- Assume all birthdays are valid dates before November 27th, 2025.
- Return the age as an integer.
- Be sure to account for whether the person has already had their birthday in 2025.
# --hints--
`calculate_age("2000-11-20")` should return `25`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(calculate_age("2000-11-20"), 25)`)
}})
```
`calculate_age("2000-12-01")` should return `24`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(calculate_age("2000-12-01"), 24)`)
}})
```
`calculate_age("2014-10-25")` should return `11`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(calculate_age("2014-10-25"), 11)`)
}})
```
`calculate_age("1994-01-06")` should return `31`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(calculate_age("1994-01-06"), 31)`)
}})
```
`calculate_age("1994-12-14")` should return `30`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(calculate_age("1994-12-14"), 30)`)
}})
```
# --seed--
## --seed-contents--
```py
def calculate_age(birthday):
return birthday
```
# --solutions--
```py
from datetime import datetime
def calculate_age(birthday):
today = datetime(2025, 11, 27)
birth_date = datetime.strptime(birthday, "%Y-%m-%d")
age = today.year - birth_date.year
if (today.month, today.day) < (birth_date.month, birth_date.day):
age -= 1
return age
```
@@ -402,6 +402,46 @@
{
"id": "68f6587287ad1f4ad39b0c85",
"title": "Challenge 99: Fingerprint Test"
},
{
"id": "68ffb91507a5b645769328c3",
"title": "Challenge 100: 100 Characters"
},
{
"id": "68ffb91507a5b645769328c4",
"title": "Challenge 101: Markdown Heading Converter"
},
{
"id": "68ffb91507a5b645769328c5",
"title": "Challenge 102: Longest Word"
},
{
"id": "68ffb91507a5b645769328c6",
"title": "Challenge 103: LCM"
},
{
"id": "68ffb91507a5b645769328c7",
"title": "Challenge 104: Recipe Scaler"
},
{
"id": "68ffb91507a5b645769328c8",
"title": "Challenge 105: Character Count"
},
{
"id": "68ffb91507a5b645769328c9",
"title": "Challenge 106: Message Validator"
},
{
"id": "68ffb91507a5b645769328ca",
"title": "Challenge 107: FizzBuzz"
},
{
"id": "68ffb91507a5b645769328cb",
"title": "Challenge 108: BuzzFizz"
},
{
"id": "68ffb91507a5b645769328cc",
"title": "Challenge 109: What's My Age Again?"
}
]
}
@@ -401,6 +401,46 @@
{
"id": "68f6587287ad1f4ad39b0c85",
"title": "Challenge 99: Fingerprint Test"
},
{
"id": "68ffb91507a5b645769328c3",
"title": "Challenge 100: 100 Characters"
},
{
"id": "68ffb91507a5b645769328c4",
"title": "Challenge 101: Markdown Heading Converter"
},
{
"id": "68ffb91507a5b645769328c5",
"title": "Challenge 102: Longest Word"
},
{
"id": "68ffb91507a5b645769328c6",
"title": "Challenge 103: LCM"
},
{
"id": "68ffb91507a5b645769328c7",
"title": "Challenge 104: Recipe Scaler"
},
{
"id": "68ffb91507a5b645769328c8",
"title": "Challenge 105: Character Count"
},
{
"id": "68ffb91507a5b645769328c9",
"title": "Challenge 106: Message Validator"
},
{
"id": "68ffb91507a5b645769328ca",
"title": "Challenge 107: FizzBuzz"
},
{
"id": "68ffb91507a5b645769328cb",
"title": "Challenge 108: BuzzFizz"
},
{
"id": "68ffb91507a5b645769328cc",
"title": "Challenge 109: What's My Age Again?"
}
]
}
@@ -13,7 +13,7 @@ const { MONGOHQ_URL } = process.env;
// Number challenges in the dev-playground blocks
// Update this if the number of challenges changes
const EXPECTED_CHALLENGE_COUNT = 99;
const EXPECTED_CHALLENGE_COUNT = 109;
// Date to set for the first challenge, second challenge will be one day later, etc...
// **DO NOT CHANGE THIS AFTER RELEASE (if seeding production - okay for local dev)**