diff --git a/client/i18n/locales/english/intro.json b/client/i18n/locales/english/intro.json index 4f785f6e17f..2194e0c3fba 100644 --- a/client/i18n/locales/english/intro.json +++ b/client/i18n/locales/english/intro.json @@ -4264,6 +4264,20 @@ } } }, + "dev-playground": { + "title": "Dev Playground", + "intro": ["Playground for creating and testing challenges"], + "blocks": { + "daily-coding-challenges-javascript": { + "title": "Daily Coding Challenges JavaScript", + "intro": ["Place to create JavaScript daily coding challenges."] + }, + "daily-coding-challenges-python": { + "title": "Daily Coding Challenges Python", + "intro": ["Place to create Python daily coding challenges."] + } + } + }, "misc-text": { "browse-other": "Browse our other free certifications", "courses": "Courses", diff --git a/client/src/assets/superblock-icon.tsx b/client/src/assets/superblock-icon.tsx index 7c94f572674..89e7e0790f2 100644 --- a/client/src/assets/superblock-icon.tsx +++ b/client/src/assets/superblock-icon.tsx @@ -45,7 +45,8 @@ const iconMap = { [SuperBlocks.B1English]: B1EnglishIcon, [SuperBlocks.A2Spanish]: A2EnglishIcon, [SuperBlocks.RosettaCode]: RosettaCodeIcon, - [SuperBlocks.PythonForEverybody]: PythonIcon + [SuperBlocks.PythonForEverybody]: PythonIcon, + [SuperBlocks.DevPlayground]: Code }; type SuperBlockIconProps = { diff --git a/client/src/pages/learn/dev-playground/daily-coding-challenges-javascript/index.md b/client/src/pages/learn/dev-playground/daily-coding-challenges-javascript/index.md new file mode 100644 index 00000000000..a86127b7483 --- /dev/null +++ b/client/src/pages/learn/dev-playground/daily-coding-challenges-javascript/index.md @@ -0,0 +1,9 @@ +--- +title: Introduction to the Daily Coding Challenges JavaScript +block: daily-coding-challenges-javascript +superBlock: dev-playground +--- + +## Introduction to the Daily Coding Challenges JavaScript + +JavaScript daily coding challenges. diff --git a/client/src/pages/learn/dev-playground/daily-coding-challenges-python/index.md b/client/src/pages/learn/dev-playground/daily-coding-challenges-python/index.md new file mode 100644 index 00000000000..02aea38d504 --- /dev/null +++ b/client/src/pages/learn/dev-playground/daily-coding-challenges-python/index.md @@ -0,0 +1,9 @@ +--- +title: Introduction to the Daily Coding Challenges Python +block: daily-coding-challenges-python +superBlock: dev-playground +--- + +## Introduction to the Daily Coding Challenges Python + +Python daily coding challenges. diff --git a/client/src/pages/learn/dev-playground/index.md b/client/src/pages/learn/dev-playground/index.md new file mode 100644 index 00000000000..d1b8793806a --- /dev/null +++ b/client/src/pages/learn/dev-playground/index.md @@ -0,0 +1,9 @@ +--- +title: Dev Playground +superBlock: dev-playground +certification: dev-playground +--- + +## Introduction to the Dev Playground + +Playground for creating and testing new challenges diff --git a/client/src/templates/Challenges/classic/desktop-layout.tsx b/client/src/templates/Challenges/classic/desktop-layout.tsx index b3e5f05a635..43f2105a6b7 100644 --- a/client/src/templates/Challenges/classic/desktop-layout.tsx +++ b/client/src/templates/Challenges/classic/desktop-layout.tsx @@ -232,7 +232,9 @@ const DesktopLayout = (props: DesktopLayoutProps): JSX.Element => { challengeType === challengeTypes.multifilePythonCertProject || challengeType === challengeTypes.lab || challengeType === challengeTypes.jsLab || - challengeType === challengeTypes.pyLab; + challengeType === challengeTypes.pyLab || + challengeType === challengeTypes.dailyChallengeJs || + challengeType === challengeTypes.dailyChallengePy; const isProjectStyle = projectBasedChallenge || isMultifileProject; const displayPreviewPane = hasPreview && showPreviewPane; const displayPreviewPortal = hasPreview && showPreviewPortal; diff --git a/client/src/templates/Challenges/classic/editor.tsx b/client/src/templates/Challenges/classic/editor.tsx index 8a6b38ed32b..e98fab27ed7 100644 --- a/client/src/templates/Challenges/classic/editor.tsx +++ b/client/src/templates/Challenges/classic/editor.tsx @@ -286,7 +286,8 @@ const Editor = (props: EditorProps): JSX.Element => { highlightActiveIndentation: props.challengeType === challengeTypes.python || props.challengeType === challengeTypes.multifilePythonCertProject || - props.challengeType === challengeTypes.pyLab + props.challengeType === challengeTypes.pyLab || + props.challengeType === challengeTypes.dailyChallengePy }, minimap: { enabled: false @@ -309,7 +310,8 @@ const Editor = (props: EditorProps): JSX.Element => { tabSize: props.challengeType !== challengeTypes.python && props.challengeType !== challengeTypes.multifilePythonCertProject && - props.challengeType !== challengeTypes.pyLab + props.challengeType !== challengeTypes.pyLab && + props.challengeType !== challengeTypes.dailyChallengePy ? 2 : 4, dragAndDrop: true, diff --git a/client/src/templates/Challenges/classic/show.tsx b/client/src/templates/Challenges/classic/show.tsx index 47f2835ffdb..670053898db 100644 --- a/client/src/templates/Challenges/classic/show.tsx +++ b/client/src/templates/Challenges/classic/show.tsx @@ -173,7 +173,8 @@ const StepPreview = ({ }) => { return challengeType === challengeTypes.python || challengeType === challengeTypes.multifilePythonCertProject || - challengeType === challengeTypes.pyLab ? ( + challengeType === challengeTypes.pyLab || + challengeType === challengeTypes.dailyChallengePy ? ( ) : ( diff --git a/client/src/templates/Challenges/redux/execute-challenge-saga.js b/client/src/templates/Challenges/redux/execute-challenge-saga.js index 9e74b00d910..a7079a83b14 100644 --- a/client/src/templates/Challenges/redux/execute-challenge-saga.js +++ b/client/src/templates/Challenges/redux/execute-challenge-saga.js @@ -292,7 +292,8 @@ export function* previewChallengeSaga(action) { challengeData.challengeType === challengeTypes.python || challengeData.challengeType === challengeTypes.multifilePythonCertProject || - challengeData.challengeType === challengeTypes.pyLab + challengeData.challengeType === challengeTypes.pyLab || + challengeData.challengeType === challengeTypes.dailyChallengePy ) { yield updatePython(challengeData); } else { @@ -326,7 +327,8 @@ function* updatePreviewSaga(action) { if ( challengeData.challengeType === challengeTypes.python || challengeData.challengeType === challengeTypes.multifilePythonCertProject || - challengeData.challengeType === challengeTypes.pyLab + challengeData.challengeType === challengeTypes.pyLab || + challengeData.challengeType === challengeTypes.dailyChallengePy ) { yield updatePython(challengeData); } else { diff --git a/client/src/templates/Challenges/redux/selectors.js b/client/src/templates/Challenges/redux/selectors.js index 9d97d9a619a..87dd40912df 100644 --- a/client/src/templates/Challenges/redux/selectors.js +++ b/client/src/templates/Challenges/redux/selectors.js @@ -97,7 +97,9 @@ export const challengeDataSelector = state => { challengeType === challengeTypes.js || challengeType === challengeTypes.jsProject || challengeType === challengeTypes.jsLab || - challengeType === challengeTypes.pyLab + challengeType === challengeTypes.pyLab || + challengeType === challengeTypes.dailyChallengeJs || + challengeType === challengeTypes.dailyChallengePy ) { const { required = [], template = '' } = challengeMetaSelector(state); challengeData = { diff --git a/client/src/templates/Challenges/utils/build.ts b/client/src/templates/Challenges/utils/build.ts index df87100701c..2dcab5945c3 100644 --- a/client/src/templates/Challenges/utils/build.ts +++ b/client/src/templates/Challenges/utils/build.ts @@ -105,7 +105,9 @@ export const buildFunctions = { [challengeTypes.multifilePythonCertProject]: buildPythonChallenge, [challengeTypes.lab]: buildDOMChallenge, [challengeTypes.jsLab]: buildJSChallenge, - [challengeTypes.pyLab]: buildPythonChallenge + [challengeTypes.pyLab]: buildPythonChallenge, + [challengeTypes.dailyChallengeJs]: buildJSChallenge, + [challengeTypes.dailyChallengePy]: buildPythonChallenge }; export function canBuildChallenge(challengeData: BuildChallengeData): boolean { @@ -134,7 +136,9 @@ const testRunners = { [challengeTypes.multifileCertProject]: getDOMTestRunner, [challengeTypes.multifilePythonCertProject]: getPyTestRunner, [challengeTypes.lab]: getDOMTestRunner, - [challengeTypes.pyLab]: getPyTestRunner + [challengeTypes.pyLab]: getPyTestRunner, + [challengeTypes.dailyChallengeJs]: getJSTestRunner, + [challengeTypes.dailyChallengePy]: getPyTestRunner }; export function getTestRunner( @@ -403,7 +407,8 @@ export function challengeHasPreview({ challengeType === challengeTypes.multifilePythonCertProject || challengeType === challengeTypes.python || challengeType === challengeTypes.lab || - challengeType === challengeTypes.pyLab + challengeType === challengeTypes.pyLab || + challengeType === challengeTypes.dailyChallengePy ); } @@ -415,6 +420,7 @@ export function isJavaScriptChallenge({ return ( challengeType === challengeTypes.js || challengeType === challengeTypes.jsProject || - challengeType === challengeTypes.jsLab + challengeType === challengeTypes.jsLab || + challengeType === challengeTypes.dailyChallengeJs ); } diff --git a/client/src/utils/curriculum-layout.ts b/client/src/utils/curriculum-layout.ts index c034416f9ba..1ad52852362 100644 --- a/client/src/utils/curriculum-layout.ts +++ b/client/src/utils/curriculum-layout.ts @@ -14,7 +14,9 @@ const projectBasedChallengeTypes = [ challengeTypes.multifilePythonCertProject, challengeTypes.lab, challengeTypes.jsLab, - challengeTypes.pyLab + challengeTypes.pyLab, + challengeTypes.dailyChallengeJs, + challengeTypes.dailyChallengePy ]; export const isProjectBased = ( diff --git a/curriculum/challenges/_meta/daily-coding-challenges-javascript/meta.json b/curriculum/challenges/_meta/daily-coding-challenges-javascript/meta.json new file mode 100644 index 00000000000..7e2f4dcc803 --- /dev/null +++ b/curriculum/challenges/_meta/daily-coding-challenges-javascript/meta.json @@ -0,0 +1,109 @@ +{ + "name": "Daily Coding Challenges JavaScript", + "isUpcomingChange": true, + "dashedName": "daily-coding-challenges-javascript", + "usesMultifileEditor": true, + "helpCategory": "JavaScript", + "order": 0, + "disableLoopProtectTests": true, + "superBlock": "dev-playground", + "blockLayout": "legacy-challenge-list", + "challengeOrder": [ + { + "id": "6814d8e1516e86b171929de4", + "title": "JavaScript Challenge 1" + }, + { + "id": "681cb05adab50c87ddb2e513", + "title": "JavaScript Challenge 2" + }, + { + "id": "681cb1a2dab50c87ddb2e514", + "title": "JavaScript Challenge 3" + }, + { + "id": "681cb1afdab50c87ddb2e515", + "title": "JavaScript Challenge 4" + }, + { + "id": "681cb1afdab50c87ddb2e516", + "title": "JavaScript Challenge 5" + }, + { + "id": "681cb1afdab50c87ddb2e517", + "title": "JavaScript Challenge 6" + }, + { + "id": "681cb1b0dab50c87ddb2e518", + "title": "JavaScript Challenge 7" + }, + { + "id": "681cb1b0dab50c87ddb2e519", + "title": "JavaScript Challenge 8" + }, + { + "id": "681cb1b0dab50c87ddb2e51a", + "title": "JavaScript Challenge 9" + }, + { + "id": "681cb1b0dab50c87ddb2e51b", + "title": "JavaScript Challenge 10" + }, + { + "id": "68216eb60f957572e7c340c4", + "title": "JavaScript Challenge 11" + }, + { + "id": "68216ef80f957572e7c340c5", + "title": "JavaScript Challenge 12" + }, + { + "id": "6821ebc9237de8297eaee78f", + "title": "JavaScript Challenge 13" + }, + { + "id": "6821ebce237de8297eaee790", + "title": "JavaScript Challenge 14" + }, + { + "id": "6821ebd4237de8297eaee791", + "title": "JavaScript Challenge 15" + }, + { + "id": "6821ebda237de8297eaee792", + "title": "JavaScript Challenge 16" + }, + { + "id": "6821ebdf237de8297eaee793", + "title": "JavaScript Challenge 17" + }, + { + "id": "6821ebe4237de8297eaee794", + "title": "JavaScript Challenge 18" + }, + { + "id": "6821ebea237de8297eaee795", + "title": "JavaScript Challenge 19" + }, + { + "id": "6821ebee237de8297eaee796", + "title": "JavaScript Challenge 20" + }, + { + "id": "6821ebf3237de8297eaee797", + "title": "JavaScript Challenge 21" + }, + { + "id": "6821ebf8237de8297eaee798", + "title": "JavaScript Challenge 22" + }, + { + "id": "6821ebfd237de8297eaee799", + "title": "JavaScript Challenge 23" + }, + { + "id": "6821ec02237de8297eaee79a", + "title": "JavaScript Challenge 24" + } + ] +} \ No newline at end of file diff --git a/curriculum/challenges/_meta/daily-coding-challenges-python/meta.json b/curriculum/challenges/_meta/daily-coding-challenges-python/meta.json new file mode 100644 index 00000000000..d72022e8a26 --- /dev/null +++ b/curriculum/challenges/_meta/daily-coding-challenges-python/meta.json @@ -0,0 +1,108 @@ +{ + "name": "Daily Coding Challenges Python", + "isUpcomingChange": true, + "dashedName": "daily-coding-challenges-python", + "usesMultifileEditor": true, + "helpCategory": "Python", + "order": 1, + "superBlock": "dev-playground", + "blockLayout": "legacy-challenge-list", + "challengeOrder": [ + { + "id": "6814d93d516e86b171929de5", + "title": "Python Challenge 1" + }, + { + "id": "681cb1b1dab50c87ddb2e51c", + "title": "Python Challenge 2" + }, + { + "id": "681cb1b1dab50c87ddb2e51d", + "title": "Python Challenge 3" + }, + { + "id": "681cb1b1dab50c87ddb2e51e", + "title": "Python Challenge 4" + }, + { + "id": "681cb1b1dab50c87ddb2e51f", + "title": "Python Challenge 5" + }, + { + "id": "681cb1b2dab50c87ddb2e520", + "title": "Python Challenge 6" + }, + { + "id": "681cb1b2dab50c87ddb2e521", + "title": "Python Challenge 7" + }, + { + "id": "681cb1b2dab50c87ddb2e522", + "title": "Python Challenge 8" + }, + { + "id": "681cb1b2dab50c87ddb2e523", + "title": "Python Challenge 9" + }, + { + "id": "681cb1b3dab50c87ddb2e524", + "title": "Python Challenge 10" + }, + { + "id": "68216eff0f957572e7c340c6", + "title": "Python Challenge 11" + }, + { + "id": "68216f040f957572e7c340c7", + "title": "Python Challenge 12" + }, + { + "id": "6821ec92237de8297eaee79b", + "title": "Python Challenge 13" + }, + { + "id": "6821ec98237de8297eaee79c", + "title": "Python Challenge 14" + }, + { + "id": "6821ec9d237de8297eaee79d", + "title": "Python Challenge 15" + }, + { + "id": "6821eca2237de8297eaee79e", + "title": "Python Challenge 16" + }, + { + "id": "6821eca7237de8297eaee79f", + "title": "Python Challenge 17" + }, + { + "id": "6821ecab237de8297eaee7a0", + "title": "Python Challenge 18" + }, + { + "id": "6821ecb1237de8297eaee7a1", + "title": "Python Challenge 19" + }, + { + "id": "6821ecb5237de8297eaee7a2", + "title": "Python Challenge 20" + }, + { + "id": "6821ecb9237de8297eaee7a3", + "title": "Python Challenge 21" + }, + { + "id": "6821ecbf237de8297eaee7a4", + "title": "Python Challenge 22" + }, + { + "id": "6821ecc5237de8297eaee7a5", + "title": "Python Challenge 23" + }, + { + "id": "6821eccb237de8297eaee7a6", + "title": "Python Challenge 24" + } + ] +} \ No newline at end of file diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-1.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-1.md new file mode 100644 index 00000000000..0ffca1839a6 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-1.md @@ -0,0 +1,90 @@ +--- +id: 6814d8e1516e86b171929de4 +title: "JavaScript Challenge 1: Vowel Balance" +challengeType: 28 +dashedName: javascript-challenge-1 +--- + +# --description-- + +Given a string, determine whether the number of vowels in the first half of the string is equal to the number of vowels in the second half. + +- The string can contain any characters. +- The letters `a`, `e`, `i`, `o`, and `u`, in either uppercase or lowercase, are considered vowels. +- If there's an odd number of characters in the string, ignore the center character. + +# --hints-- + +`isBalanced("racecar")` should return `true`. + +```js +assert.isTrue(isBalanced("racecar")); +``` + +`isBalanced("Lorem Ipsum")` should return `true`. + +```js +assert.isTrue(isBalanced("Lorem Ipsum")); +``` + +`isBalanced("Kitty Ipsum")` should return `false`. + +```js +assert.isFalse(isBalanced("Kitty Ipsum")); +``` + +`isBalanced("string")` should return `false`. + +```js +assert.isFalse(isBalanced("string")); +``` + +`isBalanced(" ")` should return `true`. + +```js +assert.isTrue(isBalanced(" ")); +``` + +`isBalanced("abcdefghijklmnopqrstuvwxyz")` should return `false`. + +```js +assert.isFalse(isBalanced("abcdefghijklmnopqrstuvwxyz")); +``` + +`isBalanced("123A#b!E&*456-o.U")` should return `true`. + +```js +assert.isTrue(isBalanced("123A#b!E&*456-o.U")); +``` + +# --seed-- + +## --seed-contents-- + +```js +function isBalanced(s) { + + return s; +} +``` + +# --solutions-- + +```js +function isBalanced(s) { + const vowels = 'aeiou'; + const half = Math.floor(s.length / 2); + + let firstHalf = s.slice(0, half); + let secondHalf = s.length % 2 === 0 ? s.slice(half) : s.slice(half + 1); + + const countVowels = str => + str + .toLowerCase() + .split('') + .filter(c => vowels.includes(c)) + .length; + + return countVowels(firstHalf) === countVowels(secondHalf); +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-10.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-10.md new file mode 100644 index 00000000000..5e732e79291 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-10.md @@ -0,0 +1,70 @@ +--- +id: 681cb1b0dab50c87ddb2e51b +title: "JavaScript Challenge 10: 3 Strikes" +challengeType: 28 +dashedName: javascript-challenge-10 +--- + +# --description-- + +Given an integer between 1 and 10,000, return a count of how many numbers from 1 up to that integer whose square contains at least one digit 3. + +# --hints-- + +`squaresWithThree(1)` should return `0`. + +```js +assert.equal(squaresWithThree(1), 0); +``` + +`squaresWithThree(10)` should return `1`. + +```js +assert.equal(squaresWithThree(10), 1); +``` + +`squaresWithThree(100)` should return `19`. + +```js +assert.equal(squaresWithThree(100), 19); +``` + +`squaresWithThree(1000)` should return `326`. + +```js +assert.equal(squaresWithThree(1000), 326); +``` + +`squaresWithThree(10000)` should return `4531`. + +```js +assert.equal(squaresWithThree(10000), 4531); +``` + +# --seed-- + +## --seed-contents-- + +```js +function squaresWithThree(n) { + + return n; +} +``` + +# --solutions-- + +```js +function squaresWithThree(n) { + let count = 0; + + for (let i = 1; i <= n; i++) { + const square = i * i; + if (square.toString().includes('3')) { + count++; + } + } + + return count; +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-11.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-11.md new file mode 100644 index 00000000000..f815d1c5091 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-11.md @@ -0,0 +1,67 @@ +--- +id: 68216eb60f957572e7c340c4 +title: "JavaScript Challenge 11: Mile Pace" +challengeType: 28 +dashedName: javascript-challenge-11 +--- + +# --description-- + +Given a number of miles ran, and a time in `"MM:SS"` (minutes:seconds) it took to run those miles, return a string for the average time it took to run each mile in the format `"MM:SS"`. + +- Add leading zeros when needed. + +# --hints-- + +`milePace(3, "24:00")` should return `"08:00"`. + +```js +assert.equal(milePace(3, "24:00"), "08:00"); +``` + +`milePace(1, "06:45")` should return `"06:45"`. + +```js +assert.equal(milePace(1, "06:45"), "06:45"); +``` + +`milePace(2, "07:00")` should return `"03:30"`. + +```js +assert.equal(milePace(2, "07:00"), "03:30"); +``` + +`milePace(26.2, "120:35")` should return `"04:36"`. + +```js +assert.equal(milePace(26.2, "120:35"), "04:36"); +``` + +# --seed-- + +## --seed-contents-- + +```js +function milePace(miles, duration) { + + return miles; +} +``` + +# --solutions-- + +```js +function milePace(miles, duration) { + const [minutes, seconds] = duration.split(':').map(Number); + const totalSeconds = minutes * 60 + seconds; + const avgSecondsPerMile = totalSeconds / miles; + + const avgMinutes = Math.floor(avgSecondsPerMile / 60); + const avgSeconds = Math.round(avgSecondsPerMile % 60); + + const paddedMinutes = avgMinutes.toString().padStart(2, '0'); + const paddedSeconds = avgSeconds.toString().padStart(2, '0'); + + return `${paddedMinutes}:${paddedSeconds}`; +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-12.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-12.md new file mode 100644 index 00000000000..2bdf29ce61c --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-12.md @@ -0,0 +1,69 @@ +--- +id: 68216ef80f957572e7c340c5 +title: "JavaScript Challenge 12: Message Decoder" +challengeType: 28 +dashedName: javascript-challenge-12 +--- + +# --description-- + +Given a secret message string, and an integer representing the number of letters that were used to shift the message to encode it, return the decoded string. + +- A positive number means the message was shifted forward in the alphabet. +- A negative number means the message was shifted backward in the alphabet. +- Case matters, decoded characters should retain the case of their encoded counterparts. +- Non-alphabetical characters should not get decoded. + +# --hints-- + +`decode("Xlmw mw e wigvix qiwweki.", 4)` should return `"This is a secret message."` + +```js +assert.equal(decode("Xlmw mw e wigvix qiwweki.", 4), "This is a secret message."); +``` + +`decode("Byffi Qilfx!", 20)` should return `"Hello World!"` + +```js +assert.equal(decode("Byffi Qilfx!", 20), "Hello World!"); +``` + +`decode("Zqd xnt njzx?", -1)` should return `"Are you okay?"` + +```js +assert.equal(decode("Zqd xnt njzx?", -1), "Are you okay?"); +``` + +`decode("oannLxmnLjvy", 9)` should return `"freeCodeCamp"` + +```js +assert.equal(decode("oannLxmnLjvy", 9), "freeCodeCamp"); +``` + +# --seed-- + +## --seed-contents-- + +```js +function decode(message, shift) { + + return message; +} +``` + +# --solutions-- + +```js +function decode(message, shift) { + return message.split('').map(char => { + if (/[a-zA-Z]/.test(char)) { + const base = char === char.toLowerCase() ? 'a'.charCodeAt(0) : 'A'.charCodeAt(0); + const charCode = char.charCodeAt(0); + const offset = (charCode - base - shift + 26) % 26; + return String.fromCharCode(base + offset); + } else { + return char; + } + }).join(''); +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-13.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-13.md new file mode 100644 index 00000000000..06436453657 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-13.md @@ -0,0 +1,97 @@ +--- +id: 6821ebc9237de8297eaee78f +title: "JavaScript Challenge 13: Unnatural Prime" +challengeType: 28 +dashedName: javascript-challenge-13 +--- + +# --description-- + +Given an integer, determine if that number is a prime number or a negative prime number. + +- A prime number is a positive integer greater than 1 that is only divisible by 1 and itself. +- A negative prime number is the negative version of a positive prime number. +- `1` and `0` are not considered prime numbers. + +# --hints-- + +`isUnnaturalPrime(1)` should return `false`. + +```js +assert.isFalse(isUnnaturalPrime(1)); +``` + +`isUnnaturalPrime(-1)` should return `false`. + +```js +assert.isFalse(isUnnaturalPrime(-1)); +``` + +`isUnnaturalPrime(19)` should return `true`. + +```js +assert.isTrue(isUnnaturalPrime(19)); +``` + +`isUnnaturalPrime(-23)` should return `true`. + +```js +assert.isTrue(isUnnaturalPrime(-23)); +``` + +`isUnnaturalPrime(0)` should return `false`. + +```js +assert.isFalse(isUnnaturalPrime(0)); +``` + +`isUnnaturalPrime(97)` should return `true`. + +```js +assert.isTrue(isUnnaturalPrime(97)); +``` + +`isUnnaturalPrime(-61)` should return `true`. + +```js +assert.isTrue(isUnnaturalPrime(-61)); +``` + +`isUnnaturalPrime(99)` should return `false`. + +```js +assert.isFalse(isUnnaturalPrime(99)); +``` + +`isUnnaturalPrime(-44)` should return `false`. + +```js +assert.isFalse(isUnnaturalPrime(-44)); +``` + +# --seed-- + +## --seed-contents-- + +```js +function isUnnaturalPrime(n) { + + return n; +} +``` + +# --solutions-- + +```js +function isUnnaturalPrime(n) { + const abs = Math.abs(n); + + if (abs <= 1) return false; + + for (let i = 2; i <= Math.sqrt(abs); i++) { + if (abs % i === 0) return false; + } + + return true; +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-14.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-14.md new file mode 100644 index 00000000000..aa2d33fb40e --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-14.md @@ -0,0 +1,117 @@ +--- +id: 6821ebce237de8297eaee790 +title: "JavaScript Challenge 14: Character Battle" +challengeType: 28 +dashedName: javascript-challenge-14 +--- + +# --description-- + +Given two strings representing your army and an opposing army, each character from your army battles the character at the same position from the opposing army using the following rules: + +- Characters `a-z` have a strength of `1-26`, respectively. +- Characters `A-Z` have a strength of `27-52`, respectively. +- Digits `0-9` have a strength of their face value. +- All other characters have a value of zero. +- Each character can only fight one battle. + +For each battle, the stronger character wins. The army with more victories, wins the war. Return the following values: + +- `"Opponent retreated"` if your army has more characters than the opposing army. +- `"We retreated"` if the opposing army has more characters than yours. +- `"We won"` if your army won more battles. +- `"We lost"` if the opposing army won more battles. +- `"It was a tie"` if both armies won the same number of battles. + +# --hints-- + +`battle("Hello", "World")` should return `"We lost"`. + +```js +assert.equal(battle("Hello", "World"), "We lost"); +``` + +`battle("pizza", "salad")` should return `"We won"`. + +```js +assert.equal(battle("pizza", "salad"), "We won"); +``` + +`battle("C@T5", "D0G$")` should return `"We won"`. + +```js +assert.equal(battle("C@T5", "D0G$"), "We won"); +``` + +`battle("kn!ght", "orc")` should return `"Opponent retreated"`. + +```js +assert.equal(battle("kn!ght", "orc"), "Opponent retreated"); +``` + +`battle("PC", "Mac")` should return `"We retreated"`. + +```js +assert.equal(battle("PC", "Mac"), "We retreated"); +``` + +`battle("Wizards", "Dragons")` should return `"It was a tie"`. + +```js +assert.equal(battle("Wizards", "Dragons"), "It was a tie"); +``` + +`battle("Mr. Smith", "Dr. Jones")` should return `"It was a tie"`. + +```js +assert.equal(battle("Mr. Smith", "Dr. Jones"), "It was a tie"); +``` + +# --seed-- + +## --seed-contents-- + +```js +function battle(myArmy, opposingArmy) { + + return myArmy; +} +``` + +# --solutions-- + +```js +function getStrength(soldier) { + const soldiers = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + let strength = 0; + + if (/\d/.test(soldier)) { + strength = parseInt(soldier); + } else if (soldiers.includes(soldier)) { + strength = soldiers.indexOf(soldier) + 1; + } + + return strength; +} + +function battle(myArmy, opposingArmy) { + if (myArmy.length > opposingArmy.length) return 'Opponent retreated'; + if (opposingArmy.length > myArmy.length) return 'We retreated'; + + let myWins = 0; + let theirWins = 0; + + for (let i = 0; i < myArmy.length; i++) { + const mySoldier = myArmy[i]; + const theirSoldier = opposingArmy[i]; + + const myStrength = getStrength(mySoldier); + const theirStrength = getStrength(theirSoldier); + + if (myStrength > theirStrength) myWins++; + if (theirStrength > myStrength) theirWins++; + } + + return myWins > theirWins ? 'We won' : theirWins > myWins ? 'We lost' : 'It was a tie'; +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-15.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-15.md new file mode 100644 index 00000000000..31c136b3de1 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-15.md @@ -0,0 +1,75 @@ +--- +id: 6821ebd4237de8297eaee791 +title: "JavaScript Challenge 15: camelCase" +challengeType: 28 +dashedName: javascript-challenge-15 +--- + +# --description-- + +Given a string, return its camel case version using the following rules: + +- Words in the string argument are separated by one or more characters from the following set: space (` `), dash (`-`), or underscore (`_`). Treat any sequence of these as a word break. +- The first word should be all lowercase. +- Each subsequent word should start with an uppercase letter, with the rest of it lowercase. +- All spaces and separators should be removed. + +# --hints-- + +`toCamelCase("hello world")` should return `"helloWorld"`. + +```js +assert.equal(toCamelCase("hello world"), "helloWorld"); +``` + +`toCamelCase("HELLO WORLD")` should return `"helloWorld"`. + +```js +assert.equal(toCamelCase("HELLO WORLD"), "helloWorld"); +``` + +`toCamelCase("secret agent-X")` should return `"secretAgentX"`. + +```js +assert.equal(toCamelCase("secret agent-X"), "secretAgentX"); +``` + +`toCamelCase("FREE cODE cAMP")` should return `"freeCodeCamp"`. + +```js +assert.equal(toCamelCase("FREE cODE cAMP"), "freeCodeCamp"); +``` + +`toCamelCase("ye old-_-sea faring_buccaneer_-_with a - peg__leg----and a_parrot_ _named- _squawk")` should return `"yeOldSeaFaringBuccaneerWithAPegLegAndAParrotNamedSquawk"`. + +```js +assert.equal(toCamelCase("ye old-_-sea faring_buccaneer_-_with a - peg__leg----and a_parrot_ _named- _squawk"), "yeOldSeaFaringBuccaneerWithAPegLegAndAParrotNamedSquawk"); +``` + +# --seed-- + +## --seed-contents-- + +```js +function toCamelCase(s) { + + return s; +} +``` + +# --solutions-- + +```js +function toCamelCase(s) { + const words = s.replace(/[_\- ]+/g, ' ').split(' '); + + return words.map((word, i) => { + if (i === 0) { + return word.toLowerCase(); + } else { + const tempWord = word.split(''); + return tempWord.shift().toUpperCase() + tempWord.join('').toLowerCase(); + } + }).join('') +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-16.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-16.md new file mode 100644 index 00000000000..2110f219d6b --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-16.md @@ -0,0 +1,63 @@ +--- +id: 6821ebda237de8297eaee792 +title: "JavaScript Challenge 16: Reverse Parenthesis" +challengeType: 28 +dashedName: javascript-challenge-16 +--- + +# --description-- + +Given a string that contains properly nested parentheses, return the decoded version of the string using the following rules: + +- All characters inside each pair of parentheses should be reversed. +- Parentheses should be removed from the final result. +- If parentheses are nested, the innermost pair should be reversed first, and then its result should be included in the reversal of the outer pair. +- Assume all parentheses are evenly balanced and correctly nested. + +# --hints-- + +`decode("(f(b(dc)e)a)")` should return `"abcdef"`. + +```js +assert.equal(decode("(f(b(dc)e)a)"), "abcdef"); +``` + +`decode("((is?)(a(t d)h)e(n y( uo)r)aC)")` should return `"Can you read this?"`. + +```js +assert.equal(decode("((is?)(a(t d)h)e(n y( uo)r)aC)"), "Can you read this?"); +``` + +`decode("f(Ce(re))o((e(aC)m)d)p")` should return `"freeCodeCamp"`. + +```js +assert.equal(decode("f(Ce(re))o((e(aC)m)d)p"), "freeCodeCamp"); +``` + +# --seed-- + +## --seed-contents-- + +```js +function decode(s) { + + return s; +} +``` + +# --solutions-- + +```js +function decode(s) { + while (s.includes(')')) { + const closeIndex = s.indexOf(')'); + const openIndex = s.lastIndexOf('(', closeIndex); + const before = s.slice(0, openIndex); + const group = s.slice(openIndex + 1, closeIndex).split('').reverse().join(''); + const after = s.slice(closeIndex + 1); + s = before + group + after; + } + + return s; +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-17.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-17.md new file mode 100644 index 00000000000..abdfb2c4f52 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-17.md @@ -0,0 +1,87 @@ +--- +id: 6821ebdf237de8297eaee793 +title: "JavaScript Challenge 17: Unorder of Operations" +challengeType: 28 +dashedName: javascript-challenge-17 +--- + +# --description-- + +Given an array of integers and an array of string operators, apply the operations to the numbers sequentially from left-to-right. Repeat the operations as needed until all numbers are used. Return the final result. + +For example, given `[1, 2, 3, 4, 5]` and `['+', '*']`, return the result of evaluating `1 + 2 * 3 + 4 * 5` from left-to-right ignoring standard order of operations. + +- Valid operators are `+`, `-`, `*`, `/`, and `%`. + +# --hints-- + +`evaluate([5, 6, 7, 8, 9], ['+', '-'])` should return `3` + +```js +assert.equal(evaluate([5, 6, 7, 8, 9], ['+', '-']), 3); +``` + +`evaluate([17, 61, 40, 24, 38, 14], ['+', '%'])` should return `38` + +```js +assert.equal(evaluate([17, 61, 40, 24, 38, 14], ['+', '%']), 38); +``` + +`evaluate([20, 2, 4, 24, 12, 3], ['*', '/'])` should return `60` + +```js +assert.equal(evaluate([20, 2, 4, 24, 12, 3], ['*', '/']), 60); +``` + +`evaluate([11, 4, 10, 17, 2], ['*', '*', '%'])` should return `30` + +```js +assert.equal(evaluate([11, 4, 10, 17, 2], ['*', '*', '%']), 30); +``` + +`evaluate([33, 11, 29, 13], ['/', '-'])` should return `-2` + +```js +assert.equal(evaluate([33, 11, 29, 13], ['/', '-']), -2); +``` + +# --seed-- + +## --seed-contents-- + +```js +function evaluate(numbers, operators) { + + return numbers; +} +``` + +# --solutions-- + +```js +function doMath(a, b, operator) { + switch (operator) { + case "+": + return a + b; + case "-": + return a - b; + case "*": + return a * b; + case "/": + return a / b; + default: + return a % b; + } +} + +function evaluate(numbers, operators) { + let total = numbers[0]; + + for (let i = 1; i < numbers.length; i++) { + const operator = operators[(i - 1) % operators.length]; + total = doMath(total, numbers[i], operator); + } + + return total; +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-18.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-18.md new file mode 100644 index 00000000000..7a140622727 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-18.md @@ -0,0 +1,74 @@ +--- +id: 6821ebe4237de8297eaee794 +title: "JavaScript Challenge 18: Second Best" +challengeType: 28 +dashedName: javascript-challenge-18 +--- + +# --description-- + +Given an array of integers representing the price of different laptops, and an integer representing your budget, return: + +1. The second most expensive laptop if it is within your budget, or +2. The most expensive laptop that is within your budget, or +3. `0` if no laptops are within your budget. + +- Duplicate prices should be ignored. + +# --hints-- + +`getLaptopCost([1500, 2000, 1800, 1400], 1900)` should return `1800` + +```js +assert.equal(getLaptopCost([1500, 2000, 1800, 1400], 1900), 1800); +``` + +`getLaptopCost([1500, 2000, 2000, 1800, 1400], 1900)` should return `1800` + +```js +assert.equal(getLaptopCost([1500, 2000, 2000, 1800, 1400], 1900), 1800); +``` + +`getLaptopCost([2099, 1599, 1899, 1499], 2200)` should return `1899` + +```js +assert.equal(getLaptopCost([2099, 1599, 1899, 1499], 2200), 1899); +``` + +`getLaptopCost([2099, 1599, 1899, 1499], 1000)` should return `0` + +```js +assert.equal(getLaptopCost([2099, 1599, 1899, 1499], 1000), 0); +``` + +`getLaptopCost([1200, 1500, 1600, 1800, 1400, 2000], 1450)` should return `1400` + +```js +assert.equal(getLaptopCost([1200, 1500, 1600, 1800, 1400, 2000], 1450), 1400); +``` + +# --seed-- + +## --seed-contents-- + +```js +function getLaptopCost(laptops, budget) { + + return laptops; +} +``` + +# --solutions-- + +```js +function getLaptopCost(laptops, budget) { + laptops = [...new Set(laptops)].sort((a, b) => b - a); + + if (budget >= laptops[1]) return laptops[1]; + if (budget < laptops[laptops.length - 1]) return 0; + + for (let i = 2; i < laptops.length; i++) { + if (budget >= laptops[i]) return laptops[i]; + } +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-19.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-19.md new file mode 100644 index 00000000000..98b8c25a46a --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-19.md @@ -0,0 +1,83 @@ +--- +id: 6821ebea237de8297eaee795 +title: "JavaScript Challenge 19: Candlelight" +challengeType: 28 +dashedName: javascript-challenge-19 +--- + +# --description-- + +Given an integer representing the number of candles you start with, and an integer representing how many burned candles it takes to create a new one, return the number of candles you will have used after creating and burning as many as you can. + +For example, if given 7 candles and it takes 2 burned candles to make a new one: + +1. Burn 7 candles to get 7 leftovers, +2. Recycle 6 leftovers into 3 new candles (1 leftover remains), +3. Burn 3 candles to get 3 more leftovers (4 total), +4. Recycle 4 leftovers into 2 new candles, +5. Burn 2 candles to get 2 leftovers, +6. Recycle 2 leftovers into 1 new candle, +7. Burn 1 candle. + +You will have burned 13 total candles in the example. + +# --hints-- + +`burnCandles(7, 2)` should return `13` + +```js +assert.equal(burnCandles(7, 2), 13); +``` + +`burnCandles(10, 5)` should return `12` + +```js +assert.equal(burnCandles(10, 5), 12); +``` + +`burnCandles(20, 3)` should return `29` + +```js +assert.equal(burnCandles(20, 3), 29); +``` + +`burnCandles(17, 4)` should return `22` + +```js +assert.equal(burnCandles(17, 4), 22); +``` + +`burnCandles(2345, 3)` should return `3517` + +```js +assert.equal(burnCandles(2345, 3), 3517); +``` + +# --seed-- + +## --seed-contents-- + +```js +function burnCandles(candles, leftoversNeeded) { + + return candles; +} +``` + +# --solutions-- + +```js +function burnCandles(candles, leftoversNeeded) { + let totalBurned = 0; + let unusedLeftovers = 0; + + while (candles > 0) { + totalBurned += candles; + const leftovers = candles + unusedLeftovers; + candles = Math.floor(leftovers / leftoversNeeded); + unusedLeftovers = leftovers % leftoversNeeded; + } + + return totalBurned; +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-2.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-2.md new file mode 100644 index 00000000000..a3818958bc5 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-2.md @@ -0,0 +1,138 @@ +--- +id: 681cb05adab50c87ddb2e513 +title: "JavaScript Challenge 2: Base Check" +challengeType: 28 +dashedName: javascript-challenge-2 +--- + +# --description-- + +Given a string representing a number, and an integer base from 2 to 36, determine whether the number is valid in that base. + +- The string may contain integers, and uppercase or lowercase characters. +- The check should be case-insensitive. +- The base can be any number 2-36. +- A number is valid if every character is a valid digit in the given base. +- Example of valid digits for bases: + - Base 2: 0-1 + - Base 8: 0-7 + - Base 10: 0-9 + - Base 16: 0-9 and A-F + - Base 36: 0-9 and A-Z + +# --hints-- + +`isValidNumber("10101", 2)` should return `true`. + +```js +assert.isTrue(isValidNumber("10101", 2)) +``` + +`isValidNumber("10201", 2)` should return `false`. + +```js +assert.isFalse(isValidNumber("10201", 2)) +``` + +`isValidNumber("76543210", 8)` should return `true`. + +```js +assert.isTrue(isValidNumber("76543210", 8)) +``` + +`isValidCode("9876543210", 8)` should return `false`. + +```js +assert.isFalse(isValidNumber("9876543210", 8)) +``` + +`isValidNumber("9876543210", 10)` should return `true`. + +```js +assert.isTrue(isValidNumber("9876543210", 10)) +``` + +`isValidNumber("ABC", 10)` should return `false`. + +```js +assert.isFalse(isValidNumber("ABC", 10)) +``` + +`isValidNumber("ABC", 16)` should return `true`. + +```js +assert.isTrue(isValidNumber("ABC", 16)) +``` + +`isValidNumber("Z", 36)` should return `true`. + +```js +assert.isTrue(isValidNumber("Z", 36)) +``` + +`isValidNumber("ABC", 20)` should return `true`. + +```js +assert.isTrue(isValidNumber("ABC", 20)) +``` + +`isValidNumber("4B4BA9", 16)` should return `true`. + +```js +assert.isTrue(isValidNumber("4B4BA9", 16)) +``` + +`isValidNumber("5G3F8F", 16)` should return `false`. + +```js +assert.isFalse(isValidNumber("5G3F8F", 16)) +``` + +`isValidNumber("5G3F8F", 17)` should return `true`. + +```js +assert.isTrue(isValidNumber("5G3F8F", 17)) +``` + +`isValidNumber("abc", 10)` should return `false`. + +```js +assert.isFalse(isValidNumber("abc", 10)) +``` + +`isValidNumber("abc", 16)` should return `true`. + +```js +assert.isTrue(isValidNumber("abc", 16)) +``` + +`isValidNumber("AbC", 16)` should return `true`. + +```js +assert.isTrue(isValidNumber("AbC", 16)) +``` + +`isValidNumber("z", 36)` should return `true`. + +```js +assert.isTrue(isValidNumber("z", 36)) +``` + +# --seed-- + +## --seed-contents-- + +```js +function isValidNumber(n, base) { + + return n; +} +``` + +# --solutions-- + +```js +function isValidNumber(n, base) { + return new RegExp(`^[${'0123456789abcdefghijklmnopqrstuvwxyz'.substring(0, base)}]+\$`, "i").test(n); +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-20.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-20.md new file mode 100644 index 00000000000..2eda9e83f0c --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-20.md @@ -0,0 +1,61 @@ +--- +id: 6821ebee237de8297eaee796 +title: "JavaScript Challenge 20: Array Duplicates" +challengeType: 28 +dashedName: javascript-challenge-20 +--- + +# --description-- + +Given an array of integers, return an array of integers that appear more than once in the initial array, sorted in ascending order. If no values appear more than once, return an empty array. + +- Only include one instance of each value in the returned array. + +# --hints-- + +`findDuplicates([1, 2, 3, 4, 5])` should return `[]`. + +```js +assert.deepEqual(findDuplicates([1, 2, 3, 4, 5]), []); +``` + +`findDuplicates([1, 2, 3, 4, 1, 2])` should return `[1, 2]`. + +```js +assert.deepEqual(findDuplicates([1, 2, 3, 4, 1, 2]), [1, 2]); +``` + +`findDuplicates([2, 34, 0, 1, -6, 23, 5, 3, 2, 5, 67, -6, 23, 2, 43, 2, 12, 0, 2, 4, 4])` should return `[-6, 0, 2, 4, 5, 23]`. + +```js +assert.deepEqual(findDuplicates([2, 34, 0, 1, -6, 23, 5, 3, 2, 5, 67, -6, 23, 2, 43, 2, 12, 0, 2, 4, 4]), [-6, 0, 2, 4, 5, 23]); +``` + +# --seed-- + +## --seed-contents-- + +```js +function findDuplicates(arr) { + + return arr; +} +``` + +# --solutions-- + +```js +function findDuplicates(arr) { + const duplicates = []; + + for (let i = 0; i < arr.length - 1; i++) { + for (let j = i + 1; j < arr.length; j++) { + if (arr[i] === arr[j] && !duplicates.includes(arr[i])) { + duplicates.push(arr[i]); + } + } + } + + return duplicates.sort((a, b) => a - b); +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-21.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-21.md new file mode 100644 index 00000000000..c61b06fb20b --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-21.md @@ -0,0 +1,186 @@ +--- +id: 6821ebf3237de8297eaee797 +title: "JavaScript Challenge 21: Hex Generator" +challengeType: 28 +dashedName: javascript-challenge-21 +--- + +# --description-- + +Given a named CSS color string, generate a random hexadecimal (hex) color code that is dominant in the given color. + +- The function should handle `"red"`, `"green"`, or `"blue"` as an input argument. +- If the input is not one of those, the function should return `"Invalid color"`. +- The function should return a random six-character hex color code where the input color value is greater than any of the others. +- Example of valid outputs for a given input: + +| Input | Output | +|---------|----------| +| `"red"` | `"FF0000"` | +| `"green"` | `"00FF00"` | +| `"blue"` | `"0000FF"` | + +# --hints-- + +`generateHex("yellow")` should return `"Invalid color"`. + +```js +assert.equal(generateHex("yellow"), "Invalid color"); +``` + +`generateHex("red")` should return a six-character string. + +```js +assert.lengthOf(generateHex("red"), 6); +``` + +`generateHex("red")` should return a valid six-character hex color code. + +```js +const hex = generateHex("red").toUpperCase(); +const isValidHex = /^[0-9A-F]{6}$/.test(hex); +assert.isTrue(isValidHex); +``` + +`generateHex("red")` should return a valid hex color with a higher red value than other colors. + +```js +const hex = generateHex("red").toUpperCase(); +const isValidHex = /^[0-9A-F]{6}$/.test(hex); +assert.isTrue(isValidHex); + +const r = parseInt(hex.slice(0, 2), 16); +const g = parseInt(hex.slice(2, 4), 16); +const b = parseInt(hex.slice(4, 6), 16); + +assert.isAbove(r, g); +assert.isAbove(r, b); +``` + +Calling `generateHex("red")` twice should return two different hex color values where red is dominant. + +```js +const hex1 = generateHex("red").toUpperCase(); +const isValidHex1 = /^[0-9A-F]{6}$/.test(hex1) +assert.isTrue(isValidHex1); + +const r1 = parseInt(hex1.slice(0, 2), 16); +const g1 = parseInt(hex1.slice(2, 4), 16); +const b1 = parseInt(hex1.slice(4, 6), 16); + +assert.isAbove(r1, g1); +assert.isAbove(r1, b1); + +const hex2 = generateHex("red").toUpperCase(); +const isValidHex2 = /^[0-9A-F]{6}$/.test(hex2); +assert.isTrue(isValidHex2); + +const r2 = parseInt(hex2.slice(0, 2), 16); +const g2 = parseInt(hex2.slice(2, 4), 16); +const b2 = parseInt(hex2.slice(4, 6), 16); + +assert.isAbove(r2, g2); +assert.isAbove(r2, b2); +assert.notEqual(hex1, hex2); +``` + +Calling `generateHex("green")` twice should return two different hex color values where green is dominant. + +```js +const hex1 = generateHex("green").toUpperCase(); +const isValidHex1 = /^[0-9A-F]{6}$/.test(hex1) +assert.isTrue(isValidHex1); + +const r1 = parseInt(hex1.slice(0, 2), 16); +const g1 = parseInt(hex1.slice(2, 4), 16); +const b1 = parseInt(hex1.slice(4, 6), 16); + +assert.isAbove(g1, r1); +assert.isAbove(g1, b1); + +const hex2 = generateHex("green").toUpperCase(); +const isValidHex2 = /^[0-9A-F]{6}$/.test(hex2); +assert.isTrue(isValidHex2); + +const r2 = parseInt(hex2.slice(0, 2), 16); +const g2 = parseInt(hex2.slice(2, 4), 16); +const b2 = parseInt(hex2.slice(4, 6), 16); + +assert.isAbove(g2, r2); +assert.isAbove(g2, b2); +assert.notEqual(hex1, hex2); +``` + +Calling `generateHex("blue")` twice should return two different hex color values where blue is dominant. + +```js +const hex1 = generateHex("blue").toUpperCase(); +const isValidHex1 = /^[0-9A-F]{6}$/.test(hex1) +assert.isTrue(isValidHex1); + +const r1 = parseInt(hex1.slice(0, 2), 16); +const g1 = parseInt(hex1.slice(2, 4), 16); +const b1 = parseInt(hex1.slice(4, 6), 16); + +assert.isAbove(b1, r1); +assert.isAbove(b1, g1); + +const hex2 = generateHex("blue").toUpperCase(); +const isValidHex2 = /^[0-9A-F]{6}$/.test(hex2); +assert.isTrue(isValidHex2); + +const r2 = parseInt(hex2.slice(0, 2), 16); +const g2 = parseInt(hex2.slice(2, 4), 16); +const b2 = parseInt(hex2.slice(4, 6), 16); + +assert.isAbove(b2, r2); +assert.isAbove(b2, g2); +assert.notEqual(hex1, hex2); +``` + +# --seed-- + +## --seed-contents-- + +```js +function generateHex(color) { + + return color; +} +``` + +# --solutions-- + +```js +function generateHex(color) { + const toHex = n => n.toString(16).padStart(2, "0").toUpperCase(); + + const dominant = Math.floor(Math.random() * 86) + 170; + const weak1 = Math.floor(Math.random() * 170); + const weak2 = Math.floor(Math.random() * 170); + + let r, g, b; + + switch (color) { + case "red": + r = dominant; + g = weak1; + b = weak2; + break; + case "green": + r = weak1; + g = dominant; + b = weak2; + break; + case "blue": + r = weak1; + g = weak2; + b = dominant; + break; + default: + return "Invalid color"; + } + + return `${toHex(r)}${toHex(g)}${toHex(b)}`; +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-22.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-22.md new file mode 100644 index 00000000000..6e6d10aec77 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-22.md @@ -0,0 +1,84 @@ +--- +id: 6821ebf8237de8297eaee798 +title: "JavaScript Challenge 22: Tribonacci Sequence" +challengeType: 28 +dashedName: javascript-challenge-22 +--- + +# --description-- + +The Tribonacci sequence is a series of numbers where each number is the sum of the three preceding ones. When starting with `0`, `0` and `1`, the first 10 numbers in the sequence are `0`, `0`, `1`, `1`, `2`, `4`, `7`, `13`, `24`, `44`. + +Given an array containing the first three numbers of a Tribonacci sequence, and an integer representing the length of the sequence, return an array containing the sequence of the given length. + +- Your function should handle sequences of any length greater than or equal to zero. +- If the length is zero, return an empty array. +- Note that the starting numbers are part of the sequence. + +# --hints-- + +`tribonacciSequence([0, 0, 1], 20)` should return `[0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, 3136, 5768, 10609, 19513]`. + +```js +assert.deepEqual(tribonacciSequence([0, 0, 1], 20), [0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, 3136, 5768, 10609, 19513]); +``` + +`tribonacciSequence([21, 32, 43], 1)` should return `[21]`. + + +```js +assert.deepEqual(tribonacciSequence([21, 32, 43], 1), [21]); +``` + +`tribonacciSequence([0, 0, 1], 0)` should return `[]`. + +```js +assert.deepEqual(tribonacciSequence([0, 0, 1], 0), []); +``` + +`tribonacciSequence([10, 20, 30], 2)` should return `[10, 20]`. + +```js +assert.deepEqual(tribonacciSequence([10, 20, 30], 2), [10, 20]); +``` + +`tribonacciSequence([10, 20, 30], 3)` should return `[10, 20, 30]`. + +```js +assert.deepEqual(tribonacciSequence([10, 20, 30], 3), [10, 20, 30]); +``` + +`tribonacciSequence([123, 456, 789], 8)` should return `[123, 456, 789, 1368, 2613, 4770, 8751, 16134]`. + +```js +assert.deepEqual(tribonacciSequence([123, 456, 789], 8), [123, 456, 789, 1368, 2613, 4770, 8751, 16134]); +``` + +# --seed-- + +## --seed-contents-- + +```js +function tribonacciSequence(startSequence, length) { + + return length; +} +``` + +# --solutions-- + +```js +function tribonacciSequence(startSequence, length) { + if (length === 0) return []; + if (length === 1) return [startSequence[0]]; + if (length === 2) return [startSequence[0], startSequence[1]]; + if (length === 3) return [...startSequence]; + + const sequence = [...startSequence]; + while (sequence.length < length) { + const nextValue = sequence[sequence.length - 1] + sequence[sequence.length - 2] + + sequence[sequence.length - 3]; + sequence.push(nextValue); + } + return sequence; +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-23.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-23.md new file mode 100644 index 00000000000..d31feac636c --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-23.md @@ -0,0 +1,72 @@ +--- +id: 6821ebfd237de8297eaee799 +title: "JavaScript Challenge 23: RGB to Hex" +challengeType: 28 +dashedName: javascript-challenge-23 +--- + +# --description-- + +Given a CSS `rgb(r, g, b)` color string, return its hexadecimal equivalent. + +Here are some example outputs for a given input: + +| Input | Output | +|---------|----------| +| `"rgb(255, 255, 255)"`| `"#ffffff"` | +| `"rgb(1, 2, 3)"` | `"#010203"` | + +- Make any letters lowercase. +- Return a `#` followed by six characters. Don't use any shorthand values. + +# --hints-- + +`rgbToHex("rgb(255, 255, 255)")` should return `"#ffffff"`. + +```js +assert.equal(rgbToHex("rgb(255, 255, 255)"), "#ffffff"); +``` + +`rgbToHex("rgb(1, 11, 111)")` should return `"#010b6f"`. + +```js +assert.equal(rgbToHex("rgb(1, 11, 111)"), "#010b6f"); +``` + +`rgbToHex("rgb(173, 216, 230)")` should return `"#add8e6"`. + +```js +assert.equal(rgbToHex("rgb(173, 216, 230)"), "#add8e6"); +``` + +`rgbToHex("rgb(79, 123, 201)")` should return `"#4f7bc9"`. + +```js +assert.equal(rgbToHex("rgb(79, 123, 201)"), "#4f7bc9"); +``` + +# --seed-- + +## --seed-contents-- + +```js +function rgbToHex(rgb) { + + return rgb; +} +``` + +# --solutions-- + +```js +function rgbToHex(rgb) { + const match = rgb.match(/\d+/g); + const [r, g, b] = match.map(num => + Math.max(0, Math.min(255, parseInt(num))) + .toString(16) + .padStart(2, '0') + ); + + return `#${r}${g}${b}`; +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-24.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-24.md new file mode 100644 index 00000000000..6c4d75854f1 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-24.md @@ -0,0 +1,93 @@ +--- +id: 6821ec02237de8297eaee79a +title: "JavaScript Challenge 24: Pangram" +challengeType: 28 +dashedName: javascript-challenge-24 +--- + +# --description-- + +Given a word or sentence and a string of lowercase letters, determine if the word or sentence uses all the letters from the given set at least once and no other letters. + +- Ignore non-alphabetical characters in the word or sentence. +- Ignore letter casing in the word or sentence. + +# --hints-- + +`isPangram("hello", "helo")` should return `true` + +```js +assert.isTrue(isPangram("hello", "helo")); +``` + +`isPangram("hello", "hel")` should return `false` + +```js +assert.isFalse(isPangram("hello", "hel")); +``` + +`isPangram("hello", "helow")` should return `false` + +```js +assert.isFalse(isPangram("hello", "helow")); +``` + +`isPangram("hello world", "helowrd")` should return `true` + +```js +assert.isTrue(isPangram("hello world", "helowrd")); +``` + +`isPangram("Hello World!", "helowrd")` should return `true` + +```js +assert.isTrue(isPangram("Hello World!", "helowrd")); +``` + +`isPangram("Hello World!", "heliowrd")` should return `false` + +```js +assert.isFalse(isPangram("Hello World!", "heliowrd")); +``` + +`isPangram("freeCodeCamp", "frcdmp")` should return `false` + +```js +assert.isFalse(isPangram("freeCodeCamp", "frcdmp")); +``` + +`isPangram("The quick brown fox jumps over the lazy dog.", "abcdefghijklmnopqrstuvwxyz")` should return `true` + +```js +assert.isTrue(isPangram("The quick brown fox jumps over the lazy dog.", "abcdefghijklmnopqrstuvwxyz")); +``` + +# --seed-- + +## --seed-contents-- + +```js +function isPangram(sentence, letters) { + + return sentence; +} +``` + +# --solutions-- + +```js +function isPangram(sentence, letters) { + const usedLetters = []; + for (let i = 0; i < sentence.length; i++) { + const letter = sentence[i].toLowerCase(); + if (!usedLetters.includes(letter) && /[a-z]/.test(letter)) { + usedLetters.push(letter); + } + } + + const sortedLetters = letters.split('').sort().join(''); + const sortedUsedLetters = usedLetters.sort().join(''); + + return sortedLetters === sortedUsedLetters; +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-3.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-3.md new file mode 100644 index 00000000000..85bc036252d --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-3.md @@ -0,0 +1,76 @@ +--- +id: 681cb1a2dab50c87ddb2e514 +title: "JavaScript Challenge 3: Fibonacci Sequence" +challengeType: 28 +dashedName: javascript-challenge-3 +--- + +# --description-- + +The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. When starting with `0` and `1`, the first 10 numbers in the sequence are `0`, `1`, `1`, `2`, `3`, `5`, `8`, `13`, `21`, `34`. + +Given an array containing the first two numbers of a Fibonacci sequence, and an integer representing the length of the sequence, return an array containing the sequence of the given length. + +- Your function should handle sequences of any length greater than or equal to zero. +- If the length is zero, return an empty array. +- Note that the starting numbers are part of the sequence. + +# --hints-- + +`fibonacciSequence([0, 1], 20)` should return `[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181]`. + +```js +assert.deepEqual(fibonacciSequence([0, 1], 20), [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181]); +``` + +`fibonacciSequence([21, 32], 1)` should return `[21]`. + +```js +assert.deepEqual(fibonacciSequence([21, 32], 1), [21]); +``` + +`fibonacciSequence([0, 1], 0)` should return `[]`. + +```js +assert.deepEqual(fibonacciSequence([0, 1], 0), []); +``` + +`fibonacciSequence([10, 20], 2)` should return `[10, 20]`. + +```js +assert.deepEqual(fibonacciSequence([10, 20], 2), [10, 20]); +``` + +`fibonacciSequence([123456789, 987654321], 5)` should return `[123456789, 987654321, 1111111110, 2098765431, 3209876541]`. + +```js +assert.deepEqual(fibonacciSequence([123456789, 987654321], 5), [123456789, 987654321, 1111111110, 2098765431, 3209876541]); +``` + +# --seed-- + +## --seed-contents-- + +```js +function fibonacciSequence(startSequence, length) { + + return length; +} +``` + +# --solutions-- + +```js +function fibonacciSequence(startSequence, length) { + if (length === 0) return []; + if (length === 1) return [startSequence[0]]; + if (length === 2) return [...startSequence]; + + const sequence = [...startSequence]; + while (sequence.length < length) { + const nextValue = sequence[sequence.length - 1] + sequence[sequence.length - 2]; + sequence.push(nextValue); + } + return sequence; +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-4.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-4.md new file mode 100644 index 00000000000..93b0aee72f9 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-4.md @@ -0,0 +1,63 @@ +--- +id: 681cb1afdab50c87ddb2e515 +title: "JavaScript Challenge 4: S P A C E J A M" +challengeType: 28 +dashedName: javascript-challenge-4 +--- + +# --description-- + +Given a string, remove all spaces from the string, insert two spaces between every character, convert all alphabetical letters to uppercase, and return the result. + +- Non-alphabetical characters should remain unchanged (except for spaces). + +# --hints-- + +`spaceJam("freeCodeCamp")` should return `"F R E E C O D E C A M P"`. + +```js +assert.equal(spaceJam("freeCodeCamp"), "F R E E C O D E C A M P"); +``` + +`spaceJam(" free Code Camp ")` should return `"F R E E C O D E C A M P"`. + +```js +assert.equal(spaceJam(" free Code Camp "), "F R E E C O D E C A M P"); +``` + +`spaceJam("Hello World?!")` should return `"H E L L O W O R L D ? !"`. + +```js +assert.equal(spaceJam("Hello World?!"), "H E L L O W O R L D ? !"); +``` + +`spaceJam("C@t$ & D0g$")` should return `"C @ T $ & D 0 G $"`. + +```js +assert.equal(spaceJam("C@t$ & D0g$"), "C @ T $ & D 0 G $"); +``` + +`spaceJam("allyourbase")` should return `"A L L Y O U R B A S E"`. + +```js +assert.equal(spaceJam("all your base"), "A L L Y O U R B A S E"); +``` + +# --seed-- + +## --seed-contents-- + +```js +function spaceJam(s) { + + return s; +} +``` + +# --solutions-- + +```js +function spaceJam(s) { + return s.toUpperCase().replace(/\s+/g, '').split('').join(' '); +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-5.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-5.md new file mode 100644 index 00000000000..161416741ac --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-5.md @@ -0,0 +1,72 @@ +--- +id: 681cb1afdab50c87ddb2e516 +title: "JavaScript Challenge 5: Jbelmud Text" +challengeType: 28 +dashedName: javascript-challenge-5 +--- + +# --description-- + +Given a string, return a jumbled version of that string where each word is transformed using the following constraints: + +- The first and last letters of the words remain in place +- All letters between the first and last letter are sorted alphabetically. +- The input strings will contain no punctuation, and will be entirely lowercase. + +# --hints-- + +`jbelmu("hello world")` should return `"hello wlord"`. + +```js +assert.equal(jbelmu("hello world"), "hello wlord"); +``` + +`jbelmu("i love jumbled text")` should return `"i love jbelmud text"`. + +```js +assert.equal(jbelmu("i love jumbled text"), "i love jbelmud text"); +``` + +`jbelmu("freecodecamp is my favorite place to learn to code")` should return `"faccdeeemorp is my faiortve pacle to laern to cdoe"`. + +```js +assert.equal(jbelmu("freecodecamp is my favorite place to learn to code"), "faccdeeemorp is my faiortve pacle to laern to cdoe"); +``` + +`jbelmu("the quick brown fox jumps over the lazy dog")` should return `"the qciuk borwn fox jmpus oevr the lazy dog"`. + +```js +assert.equal(jbelmu("the quick brown fox jumps over the lazy dog"), "the qciuk borwn fox jmpus oevr the lazy dog"); +``` + +# --seed-- + +## --seed-contents-- + +```js +function jbelmu(text) { + + return text; +} +``` + +# --solutions-- + +```js +function jbelmu(text) { + return text + .split(' ') + .map((word) => { + if (word.length <= 3) return word; + const first = word[0]; + const last = word[word.length - 1]; + const middle = word + .slice(1, -1) + .split('') + .sort() + .join(''); + return first + middle + last; + }) + .join(' '); +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-6.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-6.md new file mode 100644 index 00000000000..1d0930e3f56 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-6.md @@ -0,0 +1,72 @@ +--- +id: 681cb1afdab50c87ddb2e517 +title: "JavaScript Challenge 6: Anagram Checker" +challengeType: 28 +dashedName: javascript-challenge-6 +--- + +# --description-- + +Given two strings, determine if they are anagrams of each other (contain the same characters in any order). + +- Ignore casing and white space. + +# --hints-- + +`areAnagrams("listen", "silent")` should return `true`. + +```js +assert.isTrue(areAnagrams("listen", "silent")); +``` + +`areAnagrams("School master", "The classroom")` should return `true`. + +```js +assert.isTrue(areAnagrams("School master", "The classroom")); +``` + +`areAnagrams("A gentleman", "Elegant man")` should return `true`. + +```js +assert.isTrue(areAnagrams("A gentleman", "Elegant man")); +``` + +`areAnagrams("Hello", "World")` should return `false`. + +```js +assert.isFalse(areAnagrams("Hello", "World")); +``` + +`areAnagrams("apple", "banana")` should return `false`. + +```js +assert.isFalse(areAnagrams("apple", "banana")); +``` + +`areAnagrams("cat", "dog")` should return `false`. + +```js +assert.isFalse(areAnagrams("cat", "dog")); +``` + +# --seed-- + +## --seed-contents-- + +```js +function areAnagrams(str1, str2) { + + return str1; +} +``` + +# --solutions-- + +```js +function areAnagrams(str1, str2) { + const clean = (str) => + str.replace(/\s+/g, '').toLowerCase().split('').sort().join(''); + + return clean(str1) === clean(str2); +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-7.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-7.md new file mode 100644 index 00000000000..3b6708ca71b --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-7.md @@ -0,0 +1,64 @@ +--- +id: 681cb1b0dab50c87ddb2e518 +title: "JavaScript Challenge 7: Targeted Sum" +challengeType: 28 +dashedName: javascript-challenge-7 +--- + +# --description-- + +Given an array of numbers and an integer target, find two unique numbers in the array that add up to the target value. Return an array with the indices of those two numbers, or `"Target not found"` if no two numbers sum up to the target. + +- The returned array should have the indices in ascending order. + +# --hints-- + +`findTarget([2, 7, 11, 15], 9)` should return `[0, 1]`. + +```js +assert.deepEqual(findTarget([2, 7, 11, 15], 9), [0, 1]); +``` + +`findTarget([3, 2, 4, 5], 6)` should return `[1, 2]`. + +```js +assert.deepEqual(findTarget([3, 2, 4, 5], 6), [1, 2]); +``` + +`findTarget([1, 3, 5, 6, 7, 8], 15)` should return `[4, 5]`. + +```js +assert.deepEqual(findTarget([1, 3, 5, 6, 7, 8], 15), [4, 5]); +``` + +`findTarget([1, 3, 5, 7], 14)` should return `"Target not found"`. + +```js +assert.equal(findTarget([1, 3, 5, 7], 14), "Target not found"); +``` + +# --seed-- + +## --seed-contents-- + +```js +function findTarget(arr, target) { + + return arr; +} +``` + +# --solutions-- + +```js +function findTarget(arr, target) { + for (let i = 0; i < arr.length; i++) { + for (let j = i + 1; j < arr.length; j++) { + if (arr[i] + arr[j] === target) { + return [i, j]; + } + } + } + return 'Target not found' +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-8.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-8.md new file mode 100644 index 00000000000..8fc59750211 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-8.md @@ -0,0 +1,51 @@ +--- +id: 681cb1b0dab50c87ddb2e519 +title: "JavaScript Challenge 8: Factorializer" +challengeType: 28 +dashedName: javascript-challenge-8 +--- + +# --description-- + +Given an integer from zero to 20, return the factorial of that number. The factorial of a number is the product of all the numbers between 1 and the given number. + +- The factorial of zero is 1. + +# --hints-- + +`factorial(0)` should return `1`. + +```js +assert.equal(factorial(0), 1); +``` + +`factorial(5)` should return `120`. + +```js +assert.equal(factorial(5), 120); +``` + +`factorial(20)` should return `2432902008176640000`. + +```js +assert.equal(factorial(20), 2432902008176640000); +``` + +# --seed-- + +## --seed-contents-- + +```js +function factorial(n) { + + return n; +} +``` + +# --solutions-- + +```js +function factorial(n) { + return n == 0 ? 1 : n * factorial(n - 1); +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-9.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-9.md new file mode 100644 index 00000000000..abc436c6e0a --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-javascript/javascript-challenge-9.md @@ -0,0 +1,65 @@ +--- +id: 681cb1b0dab50c87ddb2e51a +title: "JavaScript Challenge 9: Sum of Squares" +challengeType: 28 +dashedName: javascript-challenge-9 +--- + +# --description-- + +Given a positive integer up to 1,000, return the sum of all the integers squared from 1 up to the number. + +# --hints-- + +`sumOfSquares(5)` should return `55`. + +```js +assert.equal(sumOfSquares(5), 55); +``` + +`sumOfSquares(10)` should return `385`. + +```js +assert.equal(sumOfSquares(10), 385); +``` + +`sumOfSquares(25)` should return `5525`. + +```js +assert.equal(sumOfSquares(25), 5525); +``` + +`sumOfSquares(500)` should return `41791750`. + +```js +assert.equal(sumOfSquares(500), 41791750); +``` + +`sumOfSquares(1000)` should return `333833500`. + +```js +assert.equal(sumOfSquares(1000), 333833500); +``` + +# --seed-- + +## --seed-contents-- + +```js +function sumOfSquares(n) { + + return n; +} +``` + +# --solutions-- + +```js +function sumOfSquares(n) { + let total = 1; + for(let i = 2; i <= n; i++) { + total += i * i; + } + return total; +} +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-1.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-1.md new file mode 100644 index 00000000000..b6475c926ce --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-1.md @@ -0,0 +1,106 @@ +--- +id: 6814d93d516e86b171929de5 +title: "Python Challenge 1: Vowel Balance" +challengeType: 29 +dashedName: python-challenge-1 +--- + +# --description-- + +Given a string, determine whether the number of vowels in the first half of the string is equal to the number of vowels in the second half. + +- The string can contain any characters. +- The letters `a`, `e`, `i`, `o`, and `u`, in either uppercase or lowercase, are considered vowels. +- If there's an odd number of characters in the string, ignore the center character. + +# --hints-- + +`is_balanced("racecar")` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_balanced("racecar"))`) +}}) +``` + +`is_balanced("Lorem Ipsum")` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_balanced("Lorem Ipsum"))`) +}}) +``` + +`is_balanced("Kitty Ipsum")` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_balanced("Kitty Ipsum"))`) +}}) +``` + +`is_balanced("string")` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_balanced("string"))`) +}}) +``` + +`is_balanced(" ")` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_balanced(" "))`) +}}) +``` + +`is_balanced("abcdefghijklmnopqrstuvwxyz")` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_balanced("abcdefghijklmnopqrstuvwxyz"))`) +}}) +``` + +`is_balanced("123A#b!E&*456-o.U")` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_balanced("123A#b!E&*456-o.U"))`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def is_balanced(s): + + return s +``` + +# --solutions-- + +```py +def is_balanced(s): + vowels = set("aeiouAEIOU") + n = len(s) + half = n // 2 + + first_half = s[:half] + second_half = s[-half:] + + def count_vowels(sub): + return sum(1 for char in sub if char in vowels) + + return count_vowels(first_half) == count_vowels(second_half) +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-10.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-10.md new file mode 100644 index 00000000000..e203d16e252 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-10.md @@ -0,0 +1,79 @@ +--- +id: 681cb1b3dab50c87ddb2e524 +title: "Python Challenge 10: 3 Strikes" +challengeType: 29 +dashedName: python-challenge-10 +--- + +# --description-- + +Given an integer between 1 and 10,000, return a count of how many numbers from 1 up to that integer whose square contains at least one digit 3. + +# --hints-- + +`squares_with_three(1)` should return `0`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(squares_with_three(1), 0)`) +}}) +``` + +`squares_with_three(10)` should return `1`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(squares_with_three(10), 1)`) +}}) +``` + +`squares_with_three(100)` should return `19`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(squares_with_three(100), 19)`) +}}) +``` + +`squares_with_three(1000)` should return `326`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(squares_with_three(1000), 326)`) +}}) +``` + +`squares_with_three(10000)` should return `4531`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(squares_with_three(10000), 4531)`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def squares_with_three(n): + + return n +``` + +# --solutions-- + +```py +def squares_with_three(n): + count = 0 + for i in range(1, n + 1): + square = i * i + if '3' in str(square): + count += 1 + return count +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-11.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-11.md new file mode 100644 index 00000000000..01691104918 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-11.md @@ -0,0 +1,74 @@ +--- +id: 68216eff0f957572e7c340c6 +title: "Python Challenge 11: Mile Pace" +challengeType: 29 +dashedName: python-challenge-11 +--- + +# --description-- + +Given a number of miles ran, and a time in `"MM:SS"` (minutes:seconds) it took to run those miles, return a string for the average time it took to run each mile in the format `"MM:SS"`. + +- Add leading zeros when needed. + +# --hints-- + +`mile_pace(3, "24:00")` should return `"08:00"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(mile_pace(3, "24:00"), "08:00")`) +}}) +``` + +`mile_pace(1, "06:45")` should return `"06:45"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(mile_pace(1, "06:45"), "06:45")`) +}}) +``` + +`mile_pace(2, "07:00")` should return `"03:30"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(mile_pace(2, "07:00"), "03:30")`) +}}) +``` + +`mile_pace(26.2, "120:35")` should return `"04:36"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(mile_pace(26.2, "120:35"), "04:36")`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def mile_pace(miles, duration): + + return miles +``` + +# --solutions-- + +```py +def mile_pace(miles, duration): + minutes, seconds = map(int, duration.split(":")) + total_seconds = minutes * 60 + seconds + avg_seconds_per_mile = total_seconds / miles + + avg_minutes = int(avg_seconds_per_mile // 60) + avg_seconds = round(avg_seconds_per_mile % 60) + + return f"{avg_minutes:02d}:{avg_seconds:02d}" +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-12.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-12.md new file mode 100644 index 00000000000..fc462c9bb56 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-12.md @@ -0,0 +1,78 @@ +--- +id: 68216f040f957572e7c340c7 +title: "Python Challenge 12: Message Decoder" +challengeType: 29 +dashedName: python-challenge-12 +--- + +# --description-- + +Given a secret message string, and an integer representing the number of letters that were used to shift the message to encode it, return the decoded string. + +- A positive number means the message was shifted forward in the alphabet. +- A negative number means the message was shifted backward in the alphabet. +- Case matters, decoded characters should retain the case of their encoded counterparts. +- Non-alphabetical characters should not get decoded. + +# --hints-- + +`decode("Xlmw mw e wigvix qiwweki.", 4)` should return `"This is a secret message."` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(decode("Xlmw mw e wigvix qiwweki.", 4), "This is a secret message.")`) +}}) +``` + +`decode("Byffi Qilfx!", 20)` should return `"Hello World!"` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(decode("Byffi Qilfx!", 20), "Hello World!")`) +}}) +``` + +`decode("Zqd xnt njzx?", -1)` should return `"Are you okay?"` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(decode("Zqd xnt njzx?", -1), "Are you okay?")`) +}}) +``` + +`decode("oannLxmnLjvy", 9)` should return `"freeCodeCamp"` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(decode("oannLxmnLjvy", 9), "freeCodeCamp")`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def decode(message, shift): + + return message +``` + +# --solutions-- + +```py +def decode(message, shift): + decoded_message = [] + for char in message: + if char.isalpha(): + base = ord('a') if char.islower() else ord('A') + new_char = chr((ord(char) - base - shift) % 26 + base) + decoded_message.append(new_char) + else: + decoded_message.append(char) + return ''.join(decoded_message) +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-13.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-13.md new file mode 100644 index 00000000000..73d79bbe3a7 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-13.md @@ -0,0 +1,123 @@ +--- +id: 6821ec92237de8297eaee79b +title: "Python Challenge 13: Unnatural Prime" +challengeType: 29 +dashedName: python-challenge-13 +--- + +# --description-- + +Given an integer, determine if that number is a prime number or a negative prime number. + +- A prime number is a positive integer greater than 1 that is only divisible by 1 and itself. +- A negative prime number is the negative version of a positive prime number. +- `1` and `0` are not considered prime numbers. + +# --hints-- + +`is_unnatural_prime(1)` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_unnatural_prime(1))`) +}}) +``` + +`is_unnatural_prime(-1)` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_unnatural_prime(-1))`) +}}) +``` + +`is_unnatural_prime(19)` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_unnatural_prime(19))`) +}}) +``` + +`is_unnatural_prime(-23)` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_unnatural_prime(-23))`) +}}) +``` + +`is_unnatural_prime(0)` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_unnatural_prime(0))`) +}}) +``` + +`is_unnatural_prime(97)` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_unnatural_prime(97))`) +}}) +``` + +`is_unnatural_prime(-61)` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_unnatural_prime(-61))`) +}}) +``` + +`is_unnatural_prime(99)` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_unnatural_prime(99))`) +}}) +``` + +`is_unnatural_prime(-44)` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_unnatural_prime(-44))`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def is_unnatural_prime(n): + + return n +``` + +# --solutions-- + +```py +def is_unnatural_prime(n): + abs_n = abs(n) + + if abs_n <= 1: + return False + + for i in range(2, int(abs_n ** 0.5) + 1): + if abs_n % i == 0: + return False + + return True +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-14.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-14.md new file mode 100644 index 00000000000..a0beb935243 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-14.md @@ -0,0 +1,138 @@ +--- +id: 6821ec98237de8297eaee79c +title: "Python Challenge 14: Character Battle" +challengeType: 29 +dashedName: python-challenge-14 +--- + +# --description-- + +Given two strings representing your army and an opposing army, each character from your army battles the character at the same position from the opposing army using the following rules: + +- Characters `a-z` have a strength of `1-26`, respectively. +- Characters `A-Z` have a strength of `27-52`, respectively. +- Digits `0-9` have a strength of their face value. +- All other characters have a value of zero. +- Each character can only fight one battle. + +For each battle, the stronger character wins. The army with more victories, wins the war. Return the following values: + +- `"Opponent retreated"` if your army has more characters than the opposing army. +- `"We retreated"` if the opposing army has more characters than yours. +- `"We won"` if your army won more battles. +- `"We lost"` if the opposing army won more battles. +- `"It was a tie"` if both armies won the same number of battles. + +# --hints-- + +`battle("Hello", "World")` should return `"We lost"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(battle("Hello", "World"), "We lost")`) +}}) +``` + +`battle("pizza", "salad")` should return `"We won"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(battle("pizza", "salad"), "We won")`) +}}) +``` + +`battle("C@T5", "D0G$")` should return `"We won"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(battle("C@T5", "D0G$"), "We won")`) +}}) +``` + +`battle("kn!ght", "orc")` should return `"Opponent retreated"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(battle("kn!ght", "orc"), "Opponent retreated")`) +}}) +``` + +`battle("PC", "Mac")` should return `"We retreated"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(battle("PC", "Mac"), "We retreated")`) +}}) +``` + +`battle("Wizards", "Dragons")` should return `"It was a tie"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(battle("Wizards", "Dragons"), "It was a tie")`) +}}) +``` + +`battle("Mr. Smith", "Dr. Jones")` should return `"It was a tie"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(battle("Mr. Smith", "Dr. Jones"), "It was a tie")`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def battle(my_army, oppoising_army): + + return my_army +``` + +# --solutions-- + +```py +def get_strength(soldier): + letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + + if soldier.isdigit(): + return int(soldier) + elif soldier in letters: + return letters.index(soldier) + 1 + else: + return 0 + +def battle(my_army, opposing_army): + if len(my_army) > len(opposing_army): + return 'Opponent retreated' + if len(opposing_army) > len(my_army): + return 'We retreated' + + my_wins = 0 + their_wins = 0 + + for my_soldier, their_soldier in zip(my_army, opposing_army): + my_strength = get_strength(my_soldier) + their_strength = get_strength(their_soldier) + + if my_strength > their_strength: + my_wins += 1 + elif their_strength > my_strength: + their_wins += 1 + + if my_wins > their_wins: + return 'We won' + elif their_wins > my_wins: + return 'We lost' + else: + return 'It was a tie' +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-15.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-15.md new file mode 100644 index 00000000000..642badb1950 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-15.md @@ -0,0 +1,88 @@ +--- +id: 6821ec9d237de8297eaee79d +title: "Python Challenge 15: camelCase" +challengeType: 29 +dashedName: python-challenge-15 +--- + +# --description-- + +Given a string, return its camel case version using the following rules: + +- Words in the string argument are separated by one or more characters from the following set: space (` `), dash (`-`), or underscore (`_`). Treat any sequence of these as a word break. +- The first word should be all lowercase. +- Each subsequent word should start with an uppercase letter, with the rest of it lowercase. +- All spaces and separators should be removed. + +# --hints-- + +`to_camel_case("hello world")` should return `"helloWorld"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(to_camel_case("hello world"), "helloWorld")`) +}}) +``` + +`to_camel_case("HELLO WORLD")` should return `"helloWorld"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(to_camel_case("HELLO WORLD"), "helloWorld")`) +}}) +``` + +`to_camel_case("secret agent-X")` should return `"secretAgentX"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(to_camel_case("secret agent-X"), "secretAgentX")`) +}}) +``` + +`to_camel_case("FREE cODE cAMP")` should return `"freeCodeCamp"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(to_camel_case("FREE cODE cAMP"), "freeCodeCamp")`) +}}) +``` + +`to_camel_case("ye old-_-sea faring_buccaneer_-_with a - peg__leg----and a_parrot_ _named- _squawk")` should return `"yeOldSeaFaringBuccaneerWithAPegLegAndAParrotNamedSquawk"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(to_camel_case("ye old-_-sea faring_buccaneer_-_with a - peg__leg----and a_parrot_ _named- _squawk"), "yeOldSeaFaringBuccaneerWithAPegLegAndAParrotNamedSquawk")`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def to_camel_case(s): + + return s +``` + +# --solutions-- + +```py +import re +def to_camel_case(s): + words = re.split(r'[_\- ]+', s) + + camel = [ + words[0].lower() if words else '' + ] + [ + word.capitalize() for word in words[1:] + ] + + return ''.join(camel) +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-16.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-16.md new file mode 100644 index 00000000000..8f9050ea15c --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-16.md @@ -0,0 +1,66 @@ +--- +id: 6821eca2237de8297eaee79e +title: "Python Challenge 16: Reverse Parenthesis" +challengeType: 29 +dashedName: python-challenge-16 +--- + +# --description-- + +Given a string that contains properly nested parentheses, return the decoded version of the string using the following rules: + +- All characters inside each pair of parentheses should be reversed. +- Parentheses should be removed from the final result. +- If parentheses are nested, the innermost pair should be reversed first, and then its result should be included in the reversal of the outer pair. +- Assume all parentheses are evenly balanced and correctly nested. + +# --hints-- + +`decode("(f(b(dc)e)a)")` should return `"abcdef"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(decode("(f(b(dc)e)a)"), "abcdef")`) +}}) +``` + +`decode("((is?)(a(t d)h)e(n y( uo)r)aC)")` should return `"Can you read this?"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(decode("((is?)(a(t d)h)e(n y( uo)r)aC)"), "Can you read this?")`) +}}) +``` + +`decode("f(Ce(re))o((e(aC)m)d)p")` should return `"freeCodeCamp"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(decode("f(Ce(re))o((e(aC)m)d)p"), "freeCodeCamp")`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def decode(s): + + return s +``` + +# --solutions-- + +```py +def decode(s): + while ')' in s: + close_index = s.index(')') + open_index = s.rindex('(', 0, close_index) + inner = s[open_index + 1:close_index][::-1] + s = s[:open_index] + inner + s[close_index + 1:] + return s +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-17.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-17.md new file mode 100644 index 00000000000..b008f80e6bf --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-17.md @@ -0,0 +1,96 @@ +--- +id: 6821eca7237de8297eaee79f +title: "Python Challenge 17: Unorder of Operations" +challengeType: 29 +dashedName: python-challenge-17 +--- + +# --description-- + +Given an array of integers and an array of string operators, apply the operations to the numbers sequentially from left-to-right. Repeat the operations as needed until all numbers are used. Return the final result. + +For example, given `[1, 2, 3, 4, 5]` and `['+', '*']`, return the result of evaluating `1 + 2 * 3 + 4 * 5` from left-to-right ignoring standard order of operations. + +- Valid operators are `+`, `-`, `*`, `/`, and `%`. + +# --hints-- + +`evaluate([5, 6, 7, 8, 9], ['+', '-'])` should return `3` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(evaluate([5, 6, 7, 8, 9], ['+', '-']), 3)`) +}}) +``` + +`evaluate([17, 61, 40, 24, 38, 14], ['+', '%'])` should return `38` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(evaluate([17, 61, 40, 24, 38, 14], ['+', '%']), 38)`) +}}) +``` + +`evaluate([20, 2, 4, 24, 12, 3], ['*', '/'])` should return `60` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(evaluate([20, 2, 4, 24, 12, 3], ['*', '/']), 60)`) +}}) +``` + +`evaluate([11, 4, 10, 17, 2], ['*', '*', '%'])` should return `30` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(evaluate([11, 4, 10, 17, 2], ['*', '*', '%']), 30)`) +}}) +``` + +`evaluate([33, 11, 29, 13], ['/', '-'])` should return `-2` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(evaluate([33, 11, 29, 13], ['/', '-']), -2)`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def evaluate(numbers, operators): + + return numbers +``` + +# --solutions-- + +```py +def do_math(a, b, operator): + if operator == '+': + return a + b + elif operator == '-': + return a - b + elif operator == '*': + return a * b + elif operator == '/': + return a / b + else: + return a % b + +def evaluate(numbers, operators): + total = numbers[0] + + for i in range(1, len(numbers)): + operator = operators[(i - 1) % len(operators)] + total = do_math(total, numbers[i], operator) + + return total +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-18.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-18.md new file mode 100644 index 00000000000..590ef6ae4f9 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-18.md @@ -0,0 +1,91 @@ +--- +id: 6821ecab237de8297eaee7a0 +title: "Python Challenge 18: Second Best" +challengeType: 29 +dashedName: python-challenge-18 +--- + +# --description-- + +Given an array of integers representing the price of different laptops, and an integer representing your budget, return: + +1. The second most expensive laptop if it is within your budget, or +2. The most expensive laptop that is within your budget, or +3. `0` if no laptops are within your budget. + +- Duplicate prices should be ignored. + +# --hints-- + +`get_laptop_cost([1500, 2000, 1800, 1400], 1900)` should return `1800` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(get_laptop_cost([1500, 2000, 1800, 1400], 1900), 1800)`) +}}) +``` + +`get_laptop_cost([1500, 2000, 2000, 1800, 1400], 1900)` should return `1800` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(get_laptop_cost([1500, 2000, 2000, 1800, 1400], 1900), 1800)`) +}}) +``` + +`get_laptop_cost([2099, 1599, 1899, 1499], 2200)` should return `1899` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(get_laptop_cost([2099, 1599, 1899, 1499], 2200), 1899)`) +}}) +``` + +`get_laptop_cost([2099, 1599, 1899, 1499], 1000)` should return `0` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(get_laptop_cost([2099, 1599, 1899, 1499], 1000), 0)`) +}}) +``` + +`get_laptop_cost([1200, 1500, 1600, 1800, 1400, 2000], 1450)` should return `1400` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(get_laptop_cost([1200, 1500, 1600, 1800, 1400, 2000], 1450), 1400)`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def get_laptop_cost(laptops, budget): + + return laptops +``` + +# --solutions-- + +```py +def get_laptop_cost(laptops, budget): + laptops = sorted(set(laptops), reverse=True) + + if len(laptops) >= 2 and budget >= laptops[1]: + return laptops[1] + if not laptops or budget < laptops[-1]: + return 0 + + for price in laptops[2:]: + if budget >= price: + return price + + return 0 +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-19.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-19.md new file mode 100644 index 00000000000..3c5f667838e --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-19.md @@ -0,0 +1,95 @@ +--- +id: 6821ecb1237de8297eaee7a1 +title: "Python Challenge 19: Candlelight" +challengeType: 29 +dashedName: python-challenge-19 +--- + +# --description-- + +Given an integer representing the number of candles you start with, and an integer representing how many burned candles it takes to create a new one, return the number of candles you will have used after creating and burning as many as you can. + +For example, if given 7 candles and it takes 2 burned candles to make a new one: + +1. Burn 7 candles to get 7 leftovers, +2. Recycle 6 leftovers into 3 new candles (1 leftover remains), +3. Burn 3 candles to get 3 more leftovers (4 total), +4. Recycle 4 leftovers into 2 new candles, +5. Burn 2 candles to get 2 leftovers, +6. Recycle 2 leftovers into 1 new candle, +7. Burn 1 candle. + +You will have burned 13 total candles in the example. + +# --hints-- + +`burn_candles(7, 2)` should return `13` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(burn_candles(7, 2), 13)`) +}}) +``` + +`burn_candles(10, 5)` should return `12` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(burn_candles(10, 5), 12)`) +}}) +``` + +`burn_candles(20, 3)` should return `29` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(burn_candles(20, 3), 29)`) +}}) +``` + +`burn_candles(17, 4)` should return `22` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(burn_candles(17, 4), 22)`) +}}) +``` + +`burn_candles(2345, 3)` should return `3517` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(burn_candles(2345, 3), 3517)`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def burn_candles(candles, leftovers_needed): + + return candles +``` + +# --solutions-- + +```py +def burn_candles(candles, leftovers_needed): + total_burned = 0 + unused_leftovers = 0 + + while candles > 0: + total_burned += candles + leftovers = candles + unused_leftovers + candles = leftovers // leftovers_needed + unused_leftovers = leftovers % leftovers_needed + + return total_burned +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-2.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-2.md new file mode 100644 index 00000000000..077f080335a --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-2.md @@ -0,0 +1,193 @@ +--- +id: 681cb1b1dab50c87ddb2e51c +title: "Python Challenge 2: Base Check" +challengeType: 29 +dashedName: python-challenge-2 +--- + +# --description-- + +Given a string representing a number, and an integer base from 2 to 36, determine whether the number is valid in that base. + +- The string may contain integers, and uppercase or lowercase characters. +- The check should be case-insensitive. +- The base can be any number 2-36. +- A number is valid if every character is a valid digit in the given base. +- Example of valid digits for bases: + - Base 2: 0-1 + - Base 8: 0-7 + - Base 10: 0-9 + - Base 16: 0-9 and A-F + - Base 36: 0-9 and A-Z + +# --hints-- + +`is_valid_number("10101", 2)` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_valid_number("10101", 2))`); +}}) +``` + +`is_valid_number("10201", 2)` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_valid_number("10201", 2))`) +}}) +``` + +`is_valid_number("76543210", 8)` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_valid_number("76543210", 8))`) +}}) +``` + +`is_valid_number("9876543210", 8)` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_valid_number("9876543210", 8))`) +}}) +``` + +`is_valid_number("9876543210", 10)` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_valid_number("9876543210", 10))`) +}}) +``` + +`is_valid_number("ABC", 10)` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_valid_number("ABC", 10))`) +}}) +``` + +`is_valid_number("ABC", 16)` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_valid_number("ABC", 16))`) +}}) +``` + +`is_valid_number("Z", 36)` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_valid_number("Z", 36))`) +}}) +``` + +`is_valid_number("ABC", 20)` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_valid_number("ABC", 20))`) +}}) +``` + +`is_valid_number("4B4BA9", 16)` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_valid_number("4B4BA9", 16))`) +}}) +``` + +`is_valid_number("5G3F8F", 16)` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_valid_number("5G3F8F", 16))`) +}}) +``` + +`is_valid_number("5G3F8F", 17)` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_valid_number("5G3F8F", 17))`) +}}) +``` + +`is_valid_number("abc", 10)` should return `False`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_valid_number("abc", 10))`) +}}) +``` + +`is_valid_number("abc", 16)` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_valid_number("abc", 16))`) +}}) +``` + +`is_valid_number("AbC", 16)` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_valid_number("AbC", 16))`) +}}) +``` + +`is_valid_number("z", 36)` should return `True`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_valid_number("z", 36))`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def is_valid_number(n, base): + + return n +``` + +# --solutions-- + +```py +def is_valid_number(n, base): + allChars = "0123456789abcdefghijklmnopqrstuvwxyz" + newN = n.lower() + + availableChars = allChars[0:base] + + for char in newN: + if char not in availableChars: + return False + + return True +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-20.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-20.md new file mode 100644 index 00000000000..919273ade4d --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-20.md @@ -0,0 +1,65 @@ +--- +id: 6821ecb5237de8297eaee7a2 +title: "Python Challenge 20: Array Duplicates" +challengeType: 29 +dashedName: python-challenge-20 +--- + +# --description-- + +Given an array of integers, return an array of integers that appear more than once in the initial array, in the same order that they appear in the initial array. If no values appear more than once, return an empty array. + +# --hints-- + +`find_duplicates([1, 2, 3, 4, 5])` should return `[]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(find_duplicates([1, 2, 3, 4, 5]), [])`) +}}) +``` + +`find_duplicates([1, 2, 3, 4, 1, 2])` should return `[1, 2]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(find_duplicates([1, 2, 3, 4, 1, 2]), [1, 2])`) +}}) +``` + +`find_duplicates([2, 34, 0, 1, -6, 23, 5, 3, 2, 5, 67, -6, 23, 2, 43, 2, 12, 0, 2, 4, 4])` should return `[-6, 0, 2, 4, 5, 23]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(find_duplicates([2, 34, 0, 1, -6, 23, 5, 3, 2, 5, 67, -6, 23, 2, 43, 2, 12, 0, 2, 4, 4]), [-6, 0, 2, 4, 5, 23])`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def find_duplicates(arr): + + return arr +``` + +# --solutions-- + +```py +def find_duplicates(arr): + seen = set() + duplicates = set() + + for num in arr: + if num in seen: + duplicates.add(num) + else: + seen.add(num) + + return sorted(duplicates) +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-21.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-21.md new file mode 100644 index 00000000000..3847f2fc0ce --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-21.md @@ -0,0 +1,205 @@ +--- +id: 6821ecb9237de8297eaee7a3 +title: "Python Challenge 21: Hex Generator" +challengeType: 29 +dashedName: python-challenge-21 +--- + +# --description-- + +Given a named CSS color string, generate a random hexadecimal (hex) color code that is dominant in the given color. + +- The function should handle `"red"`, `"green"`, or `"blue"` as an input argument. +- If the input is not one of those, the function should return `"Invalid color"`. +- The function should return a random six-character hex color code where the input color value is greater than any of the others. +- Example of valid outputs for a given input: + +| Input | Output | +|---------|----------| +| `"red"` | `"FF0000"` | +| `"green"` | `"00FF00"` | +| `"blue"` | `"0000FF"` | + +# --hints-- + +`generate_hex("yellow")` should return `"Invalid color"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(generate_hex("yellow"), "Invalid color")`); +}}) +``` + +`generate_hex("red")` should return a six-character string. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(len(generate_hex("red")), 6)`); +}}) +``` + +`generate_hex("red")` should return a valid six-character hex color code. + +```js +({test: () => { runPython(` +from unittest import TestCase + +hex = generate_hex("red").upper() +is_valid_hex = len(hex) == 6 and all(c in "0123456789ABCDEF" for c in hex) +TestCase().assertTrue(is_valid_hex)`) +}}) +``` + +`generate_hex("red")` should return a valid hex color with a higher red value than other colors. + +```js +({test: () => { runPython(` +from unittest import TestCase + +hex = generate_hex("red").upper() +is_valid_hex = len(hex) == 6 and all(c in "0123456789ABCDEF" for c in hex) +TestCase().assertTrue(is_valid_hex) + +r = int(hex[:2], 16) +g = int(hex[2:4], 16) +b = int(hex[4:], 16) + +TestCase().assertGreater(r, g) +TestCase().assertGreater(r, b)`) +}}) +``` + +Calling `generate_hex("red")` twice should return two different hex color values where red is dominant. + +```js +({test: () => { runPython(` +from unittest import TestCase + +hex1 = generate_hex("red").upper() +is_valid_hex1 = len(hex1) == 6 and all(c in "0123456789ABCDEF" for c in hex1) +TestCase().assertTrue(is_valid_hex1) + +r1 = int(hex1[:2], 16) +g1 = int(hex1[2:4], 16) +b1 = int(hex1[4:], 16) + +TestCase().assertGreater(r1, g1) +TestCase().assertGreater(r1, b1) + +hex2 = generate_hex("red").upper() +is_valid_hex2 = len(hex2) == 6 and all(c in "0123456789ABCDEF" for c in hex2) +TestCase().assertTrue(is_valid_hex2) + +r2 = int(hex2[:2], 16) +g2 = int(hex2[2:4], 16) +b2 = int(hex2[4:], 16) + +TestCase().assertGreater(r2, g2) +TestCase().assertGreater(r2, b2) +TestCase().assertNotEqual(hex1, hex2)`); +}}) +``` + +Calling `generate_hex("green")` twice should return two different hex color values where green is dominant. + +```js +({test: () => { runPython(` +from unittest import TestCase + +hex1 = generate_hex("green").upper() +is_valid_hex1 = len(hex1) == 6 and all(c in "0123456789ABCDEF" for c in hex1) +TestCase().assertTrue(is_valid_hex1) + +r1 = int(hex1[:2], 16) +g1 = int(hex1[2:4], 16) +b1 = int(hex1[4:], 16) + +TestCase().assertGreater(g1, r1) +TestCase().assertGreater(g1, b1) + +hex2 = generate_hex("green").upper() +is_valid_hex2 = len(hex2) == 6 and all(c in "0123456789ABCDEF" for c in hex2) +TestCase().assertTrue(is_valid_hex2) + +r2 = int(hex2[:2], 16) +g2 = int(hex2[2:4], 16) +b2 = int(hex2[4:], 16) + +TestCase().assertGreater(g2, r2) +TestCase().assertGreater(g2, b2) +TestCase().assertNotEqual(hex1, hex2)`); +}}) +``` + +Calling `generate_hex("blue")` twice should return two different hex color values where blue is dominant. + +```js +({test: () => { runPython(` +from unittest import TestCase + +hex1 = generate_hex("blue").upper() +is_valid_hex1 = len(hex1) == 6 and all(c in "0123456789ABCDEF" for c in hex1) +TestCase().assertTrue(is_valid_hex1) + +r1 = int(hex1[:2], 16) +g1 = int(hex1[2:4], 16) +b1 = int(hex1[4:], 16) + +TestCase().assertGreater(b1, r1) +TestCase().assertGreater(b1, g1) + +hex2 = generate_hex("blue").upper() +is_valid_hex2 = len(hex2) == 6 and all(c in "0123456789ABCDEF" for c in hex2) +TestCase().assertTrue(is_valid_hex2) + +r2 = int(hex2[:2], 16) +g2 = int(hex2[2:4], 16) +b2 = int(hex2[4:], 16) + +TestCase().assertGreater(b2, r2) +TestCase().assertGreater(b2, g2) +TestCase().assertNotEqual(hex1, hex2)`); +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def generate_hex(color): + + return color +``` + +# --solutions-- + +```py +import random +def generate_hex(color): + def to_hex(n): + return hex(n)[2:].upper().zfill(2) + + dominant = random.randint(170, 255) + weak1 = random.randint(0, 169) + weak2 = random.randint(0, 169) + + if color.lower() == "red": + r = dominant + g = weak1 + b = weak2 + elif color.lower() == "green": + r = weak1 + g = dominant + b = weak2 + elif color.lower() == "blue": + r = weak1 + g = weak2 + b = dominant + else: + return "Invalid color" + + return f'{to_hex(r)}{to_hex(g)}{to_hex(b)}' +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-22.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-22.md new file mode 100644 index 00000000000..4e875c21758 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-22.md @@ -0,0 +1,103 @@ +--- +id: 6821ecbf237de8297eaee7a4 +title: "Python Challenge 22: Tribonacci Sequence" +challengeType: 29 +dashedName: python-challenge-22 +--- + +# --description-- + +The Tribonacci sequence is a series of numbers where each number is the sum of the three preceding ones. When starting with `0`, `0` and `1`, the first 10 numbers in the sequence are `0`, `0`, `1`, `1`, `2`, `4`, `7`, `13`, `24`, `44`. + +Given an array containing the first three numbers of a Tribonacci sequence, and an integer representing the length of the sequence, return an array containing the sequence of the given length. + +- Your function should handle sequences of any length greater than or equal to zero. +- If the length is zero, return an empty array. +- Note that the starting numbers are part of the sequence. + +# --hints-- + +`tribonacci_sequence([0, 0, 1], 20)` should return `[0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, 3136, 5768, 10609, 19513]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(tribonacci_sequence([0, 0, 1], 20), [0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, 3136, 5768, 10609, 19513])`) +}}) +``` + +`tribonacci_sequence([21, 32, 43], 1)` should return `[21]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(tribonacci_sequence([21, 32, 43], 1), [21])`) +}}) +``` + +`tribonacci_sequence([0, 0, 1], 0)` should return `[]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(tribonacci_sequence([0, 0, 1], 0), [])`) +}}) +``` + +`tribonacci_sequence([10, 20, 30], 2)` should return `[10, 20]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(tribonacci_sequence([10, 20, 30], 2), [10, 20])`) +}}) +``` + +`tribonacci_sequence([10, 20, 30], 3)` should return `[10, 20, 30]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(tribonacci_sequence([10, 20, 30], 3), [10, 20, 30])`) +}}) +``` + +`tribonacci_sequence([123, 456, 789], 8)` should return `[123, 456, 789, 1368, 2613, 4770, 8751, 16134]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(tribonacci_sequence([123, 456, 789], 8), [123, 456, 789, 1368, 2613, 4770, 8751, 16134])`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def tribonacci_sequence(start_sequence, length): + + return length +``` + +# --solutions-- + +```py +def tribonacci_sequence(start_sequence, length): + if length == 0: + return [] + if length == 1: + return [start_sequence[0]] + if length == 2: + return [start_sequence[0], start_sequence[1]] + if length == 3: + return start_sequence[:] + + sequence = start_sequence[:] + while len(sequence) < length: + next_value = sequence[-1] + sequence[-2] + sequence[-3] + sequence.append(next_value) + + return sequence +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-23.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-23.md new file mode 100644 index 00000000000..4e3256db38e --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-23.md @@ -0,0 +1,78 @@ +--- +id: 6821ecc5237de8297eaee7a5 +title: "Python Challenge 23: RGB to Hex" +challengeType: 29 +dashedName: python-challenge-23 +--- + +# --description-- + +Given a CSS `rgb(r, g, b)` color string, return its hexadecimal equivalent. + +Here are some example outputs for a given input: + +| Input | Output | +|---------|----------| +| `"rgb(255, 255, 255)"`| `"#ffffff"` | +| `"rgb(1, 2, 3)"` | `"#010203"` | + +- Make any letters lowercase. +- Return a `#` followed by six characters. Don't use any shorthand values. + +# --hints-- + +`rgb_to_hex("rgb(255, 255, 255)")` should return `"#ffffff"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(rgb_to_hex("rgb(255, 255, 255)"), "#ffffff")`) +}}) +``` + +`rgb_to_hex("rgb(1, 11, 111)")` should return `"#010b6f"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(rgb_to_hex("rgb(1, 11, 111)"), "#010b6f")`) +}}) +``` + +`rgb_to_hex("rgb(173, 216, 230)")` should return `"#add8e6"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(rgb_to_hex("rgb(173, 216, 230)"), "#add8e6")`) +}}) +``` + +`rgb_to_hex("rgb(79, 123, 201)")` should return `"#4f7bc9"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(rgb_to_hex("rgb(79, 123, 201)"), "#4f7bc9")`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def rgb_to_hex(rgb): + + return rgb +``` + +# --solutions-- + +```py +def rgb_to_hex(rgb): + import re + match = re.findall(r'\d+', rgb) + r, g, b = [max(0, min(255, int(x))) for x in match[:3]] + return f'#{r:02x}{g:02x}{b:02x}' +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-24.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-24.md new file mode 100644 index 00000000000..3f6024ae9b1 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-24.md @@ -0,0 +1,113 @@ +--- +id: 6821eccb237de8297eaee7a6 +title: "Python Challenge 24: Pangram" +challengeType: 29 +dashedName: python-challenge-24 +--- + +# --description-- + +Given a word or sentence and a string of lowercase letters, determine if the word or sentence uses all the letters from the given set at least once and no other letters. + +- Ignore non-alphabetical characters in the word or sentence. +- Ignore letter casing in the word or sentence. + +# --hints-- + +`is_pangram("hello", "helo")` should return `True` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_pangram("hello", "helo"))`) +}}) +``` + +`is_pangram("hello", "hel")` should return `False` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_pangram("hello", "hel"))`) +}}) +``` + +`is_pangram("hello", "helow")` should return `False` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_pangram("hello", "helow"))`) +}}) +``` + +`is_pangram("hello world", "helowrd")` should return `True` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_pangram("hello world", "helowrd"))`) +}}) +``` + +`is_pangram("Hello World!", "helowrd")` should return `True` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_pangram("Hello World!", "helowrd"))`) +}}) +``` + +`is_pangram("Hello World!", "heliowrd")` should return `False` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_pangram("Hello World!", "heliowrd"))`) +}}) +``` + +`is_pangram("freeCodeCamp", "frcdmp")` should return `False` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(is_pangram("freeCodeCamp", "frcdmp"))`) +}}) +``` + +`is_pangram("The quick brown fox jumps over the lazy dog.", "abcdefghijklmnopqrstuvwxyz")` should return `True` + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(is_pangram("The quick brown fox jumps over the lazy dog.", "abcdefghijklmnopqrstuvwxyz"))`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def is_pangram(sentence, letters): + + return sentence +``` + +# --solutions-- + +```py +import re +def is_pangram(sentence, letters): + used_letters = [] + for char in sentence.lower(): + if re.match(r'[a-z]', char) and char not in used_letters: + used_letters.append(char) + + sorted_letters = ''.join(sorted(letters.lower())) + sorted_used_letters = ''.join(sorted(used_letters)) + + return sorted_letters == sorted_used_letters +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-3.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-3.md new file mode 100644 index 00000000000..a74ee770e99 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-3.md @@ -0,0 +1,93 @@ +--- +id: 681cb1b1dab50c87ddb2e51d +title: "Python Challenge 3: Fibonacci Sequence" +challengeType: 29 +dashedName: python-challenge-3 +--- + +# --description-- + +The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. When starting with `0` and `1`, the first 10 numbers in the sequence are `0`, `1`, `1`, `2`, `3`, `5`, `8`, `13`, `21`, `34`. + +Given an array containing the first two numbers of a Fibonacci sequence, and an integer representing the length of the sequence, return an array containing the sequence of the given length. + +- Your function should handle sequences of any length greater than or equal to zero. +- If the length is zero, return an empty array. +- Note that the starting numbers are part of the sequence. + +# --hints-- + + +`fibonacci_sequence([0, 1], 20)` should return `[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(fibonacci_sequence([0, 1], 20), [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181])`) +}}) +``` + +`fibonacci_sequence([21, 32], 1)` should return `[21]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(fibonacci_sequence([21, 32], 1), [21])`) +}}) +``` + +`fibonacci_sequence([0, 1], 0)` should return `[]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(fibonacci_sequence([0, 1], 0), [])`) +}}) +``` + +`fibonacci_sequence([10, 20], 2)` should return `[10, 20]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(fibonacci_sequence([10, 20], 2), [10, 20])`) +}}) +``` + +`fibonacci_sequence([123456789, 987654321], 5)` should return `[123456789, 987654321, 1111111110, 2098765431, 3209876541]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(fibonacci_sequence([123456789, 987654321], 5), [123456789, 987654321, 1111111110, 2098765431, 3209876541])`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def fibonacci_sequence(start_sequence, length): + + return length +``` + +# --solutions-- + +```py +def fibonacci_sequence(start_sequence, length): + if length == 0: + return [] + if length == 1: + return [start_sequence[0]] + if length == 2: + return start_sequence[:] + + sequence = start_sequence[:] + while len(sequence) < length: + next_value = sequence[-1] + sequence[-2] + sequence.append(next_value) + + return sequence +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-4.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-4.md new file mode 100644 index 00000000000..ad4704d45bd --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-4.md @@ -0,0 +1,78 @@ +--- +id: 681cb1b1dab50c87ddb2e51e +title: "Python Challenge 4: S P A C E J A M" +challengeType: 29 +dashedName: python-challenge-4 +--- + +# --description-- + +Given a string, remove all spaces from the string, insert two spaces between every character, convert all alphabetical letters to uppercase, and return the result. + +- Non-alphabetical characters should remain unchanged (except for spaces). + +# --hints-- + +`space_jam("freeCodeCamp")` should return `"F R E E C O D E C A M P"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(space_jam("freeCodeCamp"), "F R E E C O D E C A M P")`) +}}) +``` + +`space_jam(" free Code Camp ")` should return `"F R E E C O D E C A M P"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(space_jam(" free Code Camp "), "F R E E C O D E C A M P")`) +}}) +``` + +`space_jam("Hello World?!")` should return `"H E L L O W O R L D ? !"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(space_jam("Hello World?!"), "H E L L O W O R L D ? !")`) +}}) +``` + +`space_jam("C@t$ & D0g$")` should return `"C @ T $ & D 0 G $"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(space_jam("C@t$ & D0g$"), "C @ T $ & D 0 G $")`) +}}) +``` + +`space_jam("allyourbase")` should return `"A L L Y O U R B A S E"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(space_jam("all your base"), "A L L Y O U R B A S E")`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def space_jam(s): + + return s +``` + +# --solutions-- + +```py +def space_jam(s): + s = s.replace(" ", "") + s = " ".join(s) + return s.upper() +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-5.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-5.md new file mode 100644 index 00000000000..a8dd04bdaaa --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-5.md @@ -0,0 +1,81 @@ +--- +id: 681cb1b1dab50c87ddb2e51f +title: "Python Challenge 5: Jbelmud Text" +challengeType: 29 +dashedName: python-challenge-5 +--- + +# --description-- + +Given a string, return a jumbled version of that string where each word is transformed using the following constraints: + +- The first and last letters of the words remain in place +- All letters between the first and last letter are sorted alphabetically. +- The input strings will contain no punctuation, and will be entirely lowercase. + +# --hints-- + +`jbelmu("hello world")` should return `"hello wlord"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(jbelmu("hello world"), "hello wlord")`) +}}) +``` + +`jbelmu("i love jumbled text")` should return `"i love jbelmud text"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(jbelmu("i love jumbled text"), "i love jbelmud text")`) +}}) +``` + +`jbelmu("freecodecamp is my favorite place to learn to code")` should return `"faccdeeemorp is my faiortve pacle to laern to cdoe"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(jbelmu("freecodecamp is my favorite place to learn to code"), "faccdeeemorp is my faiortve pacle to laern to cdoe")`) +}}) +``` + +`jbelmu("the quick brown fox jumps over the lazy dog")` should return `"the qciuk borwn fox jmpus oevr the lazy dog"`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(jbelmu("the quick brown fox jumps over the lazy dog"), "the qciuk borwn fox jmpus oevr the lazy dog")`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def jbelmu(text): + + return text +``` + +# --solutions-- + +```py +def jbelmu(text): + words = text.split() + jumbled = [] + + for word in words: + if len(word) <= 3: + jumbled.append(word) + else: + first = word[0] + last = word[-1] + middle = ''.join(sorted(word[1:-1])) + jumbled.append(first + middle + last) + + return ' '.join(jumbled) +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-6.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-6.md new file mode 100644 index 00000000000..cc25fa6a306 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-6.md @@ -0,0 +1,88 @@ +--- +id: 681cb1b2dab50c87ddb2e520 +title: "Python Challenge 6: Anagram Checker" +challengeType: 29 +dashedName: python-challenge-6 +--- + +# --description-- + +Given two strings, determine if they are anagrams of each other (contain the same characters in any order). + +- Ignore casing and white space. + +# --hints-- + +`are_anagrams("listen", "silent")` should return `true`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(are_anagrams("listen", "silent"))`) +}}) +``` + +`are_anagrams("School master", "The classroom")` should return `true`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(are_anagrams("School master", "The classroom"))`) +}}) +``` + +`are_anagrams("A gentleman", "Elegant man")` should return `true`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertTrue(are_anagrams("A gentleman", "Elegant man"))`) +}}) +``` + +`are_anagrams("Hello", "World")` should return `false`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(are_anagrams("Hello", "World"))`) +}}) +``` + +`are_anagrams("apple", "banana")` should return `false`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(are_anagrams("apple", "banana"))`) +}}) +``` + +`are_anagrams("cat", "dog")` should return `false`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertFalse(are_anagrams("cat", "dog"))`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def are_anagrams(str1, str2): + + return str1 +``` + +# --solutions-- + +```py +def are_anagrams(str1, str2): + def clean(s): + return sorted(s.replace(" ", "").lower()) + + return clean(str1) == clean(str2) +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-7.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-7.md new file mode 100644 index 00000000000..aab65df9193 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-7.md @@ -0,0 +1,72 @@ +--- +id: 681cb1b2dab50c87ddb2e521 +title: "Python Challenge 7: Targeted Sum" +challengeType: 29 +dashedName: python-challenge-7 +--- + +# --description-- + +Given an array of numbers and an integer target, find two unique numbers in the array that add up to the target value. Return an array with the indices of those two numbers, or `"Target not found"` if no two numbers sum up to the target. + +- The returned array should have the indices in ascending order. + +# --hints-- + +`find_target([2, 7, 11, 15], 9)` should return `[0, 1]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(find_target([2, 7, 11, 15], 9), [0, 1])`) +}}) +``` + +`find_target([3, 2, 4, 5], 6)` should return `[1, 2]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(find_target([3, 2, 4, 5], 6), [1, 2])`) +}}) +``` + +`find_target([1, 3, 5, 6, 7, 8], 15)` should return `[4, 5]`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(find_target([1, 3, 5, 6, 7, 8], 15), [4, 5])`) +}}) +``` + +`find_target([1, 3, 5, 7], 14)` should return `'Target not found'`. + +```js + +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(find_target([1, 3, 5, 7], 14), "Target not found")`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def find_target(arr, target): + + return arr +``` + +# --solutions-- + +```py +def find_target(arr, target): + for i in range(len(arr)): + for j in range(i + 1, len(arr)): + if arr[i] + arr[j] == target: + return [i, j] + return 'Target not found' +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-8.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-8.md new file mode 100644 index 00000000000..49c7f35b8a4 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-8.md @@ -0,0 +1,61 @@ +--- +id: 681cb1b2dab50c87ddb2e522 +title: "Python Challenge 8: Factorializer" +challengeType: 29 +dashedName: python-challenge-8 +--- + +# --description-- + +Given an integer from zero to 20, return the factorial of that number. The factorial of a number is the product of all the numbers between 1 and the given number. + +- The factorial of zero is 1. + +# --hints-- + +`factorial(0)` should return `1`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(factorial(0), 1)`) +}}) +``` + +`factorial(5)` should return `120`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(factorial(5), 120)`) +}}) +``` + +`factorial(20)` should return `2432902008176640000`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(factorial(20), 2432902008176640000)`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def factorial(n): + + return n +``` + +# --solutions-- + +```py +def factorial(n): + result = 1 + for i in range(1, n + 1): + result *= i + return result +``` diff --git a/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-9.md b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-9.md new file mode 100644 index 00000000000..d258ddefbc9 --- /dev/null +++ b/curriculum/challenges/english/99-dev-playground/daily-coding-challenges-python/python-challenge-9.md @@ -0,0 +1,75 @@ +--- +id: 681cb1b2dab50c87ddb2e523 +title: "Python Challenge 9: Sum of Squares" +challengeType: 29 +dashedName: python-challenge-9 +--- + +# --description-- + +Given a positive integer up to 1,000, return the sum of all the integers squared from 1 up to the number. + +# --hints-- + +`sum_of_squares(5)` should return `55`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(sum_of_squares(5), 55)`) +}}) +``` + +`sum_of_squares(10)` should return `385`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(sum_of_squares(10), 385)`) +}}) +``` + +`sum_of_squares(25)` should return `5525`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(sum_of_squares(25), 5525)`) +}}) +``` + +`sum_of_squares(500)` should return `41791750`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(sum_of_squares(500), 41791750)`) +}}) +``` + +`sum_of_squares(1000)` should return `333833500`. + +```js +({test: () => { runPython(` +from unittest import TestCase +TestCase().assertEqual(sum_of_squares(1000), 333833500)`) +}}) +``` + +# --seed-- + +## --seed-contents-- + +```py +def sum_of_squares(n): + + return n +``` + +# --solutions-- + +```py +def sum_of_squares(n): + sum = ((n)*(n+1)*(2*n+1))//6 + return sum +``` diff --git a/curriculum/schema/challenge-schema.js b/curriculum/schema/challenge-schema.js index 97413c4156d..7dcd81689cd 100644 --- a/curriculum/schema/challenge-schema.js +++ b/curriculum/schema/challenge-schema.js @@ -156,7 +156,7 @@ const schema = Joi.object() otherwise: Joi.optional() }), certification: Joi.string().regex(slugWithSlashRE), - challengeType: Joi.number().min(0).max(27).required(), + challengeType: Joi.number().min(0).max(29).required(), checksum: Joi.number(), // TODO: require this only for normal challenges, not certs dashedName: Joi.string().regex(slugRE), diff --git a/curriculum/utils.js b/curriculum/utils.js index e67c2fff511..1e6558fa72e 100644 --- a/curriculum/utils.js +++ b/curriculum/utils.js @@ -85,7 +85,8 @@ const directoryToSuperblock = { '23-python-for-everybody': 'python-for-everybody', '24-b1-english-for-developers': 'b1-english-for-developers', '25-front-end-development': 'full-stack-developer', - '26-a2-professional-spanish': 'a2-professional-spanish' + '26-a2-professional-spanish': 'a2-professional-spanish', + '99-dev-playground': 'dev-playground' }; function getSuperBlockFromDir(dir) { diff --git a/curriculum/utils.test.ts b/curriculum/utils.test.ts index c71567d3bf5..31c7f552dba 100644 --- a/curriculum/utils.test.ts +++ b/curriculum/utils.test.ts @@ -178,7 +178,7 @@ describe('getSuperBlockFromPath', () => { .filter(item => fs.lstatSync(path.join(englishFolder, item)).isDirectory()); it('handles all the directories in ./challenges/english', () => { - expect.assertions(25); + expect.assertions(26); for (const directory of directories) { expect(() => getSuperBlockFromDir(directory)).not.toThrow(); @@ -186,7 +186,7 @@ describe('getSuperBlockFromPath', () => { }); it("returns valid superblocks (or 'certifications') for all valid arguments", () => { - expect.assertions(25); + expect.assertions(26); const superBlockPaths = directories.filter(x => x !== '00-certifications'); diff --git a/shared/config/certification-settings.ts b/shared/config/certification-settings.ts index 7a377157479..cbf6e9a9db5 100644 --- a/shared/config/certification-settings.ts +++ b/shared/config/certification-settings.ts @@ -277,7 +277,8 @@ export const superBlockToCertMap: { [SuperBlocks.CodingInterviewPrep]: null, [SuperBlocks.ProjectEuler]: null, [SuperBlocks.TheOdinProject]: null, - [SuperBlocks.RosettaCode]: null + [SuperBlocks.RosettaCode]: null, + [SuperBlocks.DevPlayground]: null }; export type CertSlug = (typeof Certification)[keyof typeof Certification]; diff --git a/shared/config/challenge-types.ts b/shared/config/challenge-types.ts index 5f195ce0ab3..32492c9256f 100644 --- a/shared/config/challenge-types.ts +++ b/shared/config/challenge-types.ts @@ -27,6 +27,8 @@ const generic = 24; const lab = 25; const jsLab = 26; const pyLab = 27; +const dailyChallengeJs = 28; +const dailyChallengePy = 29; export const challengeTypes = { html, @@ -57,7 +59,9 @@ export const challengeTypes = { generic, lab, jsLab, - pyLab + pyLab, + dailyChallengeJs, + dailyChallengePy }; export const hasNoSolution = (challengeType: number): boolean => { @@ -114,7 +118,9 @@ export const viewTypes = { [generic]: 'generic', [lab]: 'classic', [jsLab]: 'classic', - [pyLab]: 'classic' + [pyLab]: 'classic', + [dailyChallengeJs]: 'classic', + [dailyChallengePy]: 'classic' }; // determine the type of submit function to use for the challenge on completion @@ -149,9 +155,28 @@ export const submitTypes = { [generic]: 'tests', [lab]: 'tests', [jsLab]: 'tests', - [pyLab]: 'tests' + [pyLab]: 'tests', + [dailyChallengeJs]: 'tests', + [dailyChallengePy]: 'tests' }; export const canSaveToDB = (challengeType: number): boolean => challengeType === challengeTypes.multifileCertProject || challengeType === challengeTypes.multifilePythonCertProject; + +export const dailyCodingChallengeTypes = [ + challengeTypes.dailyChallengeJs, + challengeTypes.dailyChallengePy +]; + +export const getIsDailyCodingChallenge = (challengeType: number): boolean => + dailyCodingChallengeTypes.includes(challengeType); + +export const dailyCodingChallengeLanguages = { + [challengeTypes.dailyChallengeJs]: 'javascript', + [challengeTypes.dailyChallengePy]: 'python' +}; + +export const getDailyCodingChallengeLanguage = ( + challengeType: number +): string | undefined => dailyCodingChallengeLanguages[challengeType]; diff --git a/shared/config/curriculum.ts b/shared/config/curriculum.ts index 3cc052199e8..1e83b0cea8e 100644 --- a/shared/config/curriculum.ts +++ b/shared/config/curriculum.ts @@ -27,7 +27,8 @@ export enum SuperBlocks { B1English = 'b1-english-for-developers', A2Spanish = 'a2-professional-spanish', RosettaCode = 'rosetta-code', - PythonForEverybody = 'python-for-everybody' + PythonForEverybody = 'python-for-everybody', + DevPlayground = 'dev-playground' } /* @@ -100,7 +101,7 @@ export const superBlockStages: StageMap = { SuperBlocks.PythonForEverybody ], [SuperBlockStage.Next]: [], - [SuperBlockStage.Upcoming]: [SuperBlocks.A2Spanish] + [SuperBlockStage.Upcoming]: [SuperBlocks.A2Spanish, SuperBlocks.DevPlayground] }; Object.freeze(superBlockStages); diff --git a/tools/challenge-auditor/index.ts b/tools/challenge-auditor/index.ts index 07360c729fc..7caf89b89ed 100644 --- a/tools/challenge-auditor/index.ts +++ b/tools/challenge-auditor/index.ts @@ -55,7 +55,8 @@ const superBlockFolderMap = { 'python-for-everybody': '23-python-for-everybody', 'b1-english-for-developers': '24-b1-english-for-developers', 'full-stack-developer': '25-front-end-development', - 'a2-professional-spanish': '26-a2-professional-spanish' + 'a2-professional-spanish': '26-a2-professional-spanish', + 'dev-playground': '99-dev-playground' }; // Adding types for getChallengesForLang is possible, but not worth the effort diff --git a/tools/challenge-helper-scripts/fs-utils.ts b/tools/challenge-helper-scripts/fs-utils.ts index 09197f0c211..12d40265954 100644 --- a/tools/challenge-helper-scripts/fs-utils.ts +++ b/tools/challenge-helper-scripts/fs-utils.ts @@ -27,7 +27,8 @@ export function getSuperBlockSubPath(superBlock: SuperBlocks): string { [SuperBlocks.PythonForEverybody]: '23-python-for-everybody', [SuperBlocks.B1English]: '24-b1-english-for-developers', [SuperBlocks.FullStackDeveloper]: '25-front-end-development', - [SuperBlocks.A2Spanish]: '26-a2-professional-spanish' + [SuperBlocks.A2Spanish]: '26-a2-professional-spanish', + [SuperBlocks.DevPlayground]: '99-dev-playground' }; return pathMap[superBlock]; }