Compare commits

...

112 Commits

Author SHA1 Message Date
sagarishere a83bdeee1a
Merge 36f1c07317 into bf0e6e8876 2024-08-12 11:44:50 +03:00
zanninso bf0e6e8876 docs: rename linked list exercises folders to fix naming unconsistency 2024-08-12 09:33:30 +01:00
miguel 96a01b4677 fix(itoabase): adding missing main file for the code editor 2024-08-02 10:49:56 +01:00
nprimo d70fd80095 docs(printif): update subject to be inline with tests 2024-07-29 14:43:14 +01:00
Toussaint Louis e5633da44f Tests(DPxAI): Rename test file for Quest00 Ex05 2024-07-29 08:58:38 +01:00
oumaimafisaoui f2615fe541 Docs(DPxAI): Fixed subject for Quest00/Ex05 2024-07-29 08:58:38 +01:00
Louis TOUSSAINT 4942f82ae9 Tests(DPxAI): Add test for Quest00 Ex05 2024-07-29 08:58:38 +01:00
oumaimafisaoui dd513813c8 Docs(DPxAI): Add subject for Quest00 Ex05 2024-07-29 08:58:38 +01:00
oumaimafisaoui bca1a985b7 Chore(DPxAI): removed the link check 2024-07-29 08:57:38 +01:00
oumaimafisaoui 2a8d5dcac9 Chore(DPxAI): change the name of the test 2024-07-29 08:57:38 +01:00
oumaimafisaoui 214a873fae Chore(DPxAI): change the name of the test 2024-07-29 08:57:38 +01:00
oumaimafisaoui ec4e7aad95 Docs(DPxAI): replaced Quest00 with Shape Crafting 2024-07-29 08:57:38 +01:00
oumaimafisaoui f4f036d758 Docs(DPxAI): Fix formatting issue in Ex06 2024-07-29 08:57:38 +01:00
oumaimafisaoui edfa1a2215 Docs(DPxAI): Fix the subject of Quest00 / Ex06 2024-07-29 08:57:38 +01:00
oumaimafisaoui 071d868dd9 Docs(DPxAI): Apply prettier to Quest00/Ex06 2024-07-29 08:57:38 +01:00
oumaimafisaoui a6386b64c7 Docs(DPxAI): Apply prettier to Quest00/Ex06 2024-07-29 08:57:38 +01:00
oumaimafisaoui 9b09d150dd Test(DPxAI): Add test to Quest00/Ex06 2024-07-29 08:57:38 +01:00
oumaimafisaoui 06da451352 Docs(DPxAI): Add subject for Quest00/Ex06 2024-07-29 08:57:38 +01:00
nprimo bd5041d8ea chore(sudoku): remove extra `"` from audit instructions 2024-07-26 10:14:14 +01:00
miguel 701ddd5a70 docs(rgb-match) fix subject of rgb-match 2024-07-24 11:21:22 +01:00
miguel 4778a0b693 docs(hiddenp) fix subject of hiddenp 2024-07-24 10:45:55 +01:00
nprimo d945335743 fix(printif + printifnot): make example coherent with subject 2024-07-24 09:54:07 +01:00
oumaimafisaoui 1fa3587092 Test(DPxAI): Test for Quest00/Ex04 2024-07-23 11:41:29 +01:00
oumaimafisaoui 14c996ee45 Docs(DPxAI): Add Subject class-it 2024-07-23 11:41:29 +01:00
oumaimafisaoui 6358e1b972 Docs(DPxAI): Add Subject class-it 2024-07-23 11:41:29 +01:00
oumaimafisaoui 113176f6c7 tests(DPxAI): duplicated the test for embedded organs 2024-07-23 10:34:26 +01:00
oumaimafisaoui 1ef4ca4fe0 docs(DPxAI): Adding subject of Quest00 Ex03 2024-07-23 10:34:09 +01:00
oumaimafisaoui e9b0dcaa31 Chore(DPxAI): Fixed file naming in subject 2024-07-23 10:22:20 +01:00
oumaimafisaoui acf4417523 docs(): Add subject for Quest00 Ex02 2024-07-23 10:22:20 +01:00
oumaimafisaoui 152f8427c5 Chore(DPxAI): fixed the test for select-then-style 2024-07-23 10:22:12 +01:00
oumaimafisaoui dc7a5c69c3 test(DPxAI): Added a test for Quest00/Ex02 2024-07-23 10:22:12 +01:00
oumaimafisaoui f9949d37d9 Chore(DPxAI): Deleted call_it folder 2024-07-23 10:16:38 +01:00
Oumaimafisaoui 39bcca4ace test(DPxAI:Quest00/Ex01): Duplicating the tests instead of overriding the existing ones: the-skelton and call-it 2024-07-23 10:16:38 +01:00
Oumaimafisaoui ed9afe7f20 test(DPxAI:Quest00/Ex01): Fixing the naming in test to be snake_case and changing the folders names to be in kebab-case 2024-07-23 10:16:38 +01:00
Oumaimafisaoui dc204f05d7 test(DPxAI:Quest00/Ex01): Fixing the naming in test to be snake_case 2024-07-23 10:16:38 +01:00
Oumaimafisaoui a4195e4fc5 feat/test(DPxAI): Added the subject and modified naming for the test of Quest00/Ex01 and modified the .gitignore file 2024-07-23 10:16:38 +01:00
zanninso 4c8ce4f9b4 docs: fix examples input 2024-07-22 16:13:43 +01:00
zanninso cb7db108de docs: fix typos 2024-07-22 16:13:43 +01:00
zanninso 9287509880 docs: fix formatting 2024-07-22 16:13:43 +01:00
zanninso 8408c85d2f docs: adding more details 2024-07-22 16:13:43 +01:00
zanninso 6895ee71a0 docs: fix typo and messing imports 2024-07-22 16:13:43 +01:00
amin a9ca2c3d08 docs: adding subject and main 2024-07-22 16:13:43 +01:00
zanninso 786b7b55ee docs: adding messing imports 2024-07-22 11:41:52 +01:00
zanninso 5335dcc417 docs: fix formatting 2024-07-22 11:41:52 +01:00
zanninso 511d44b7c3 docs: fix typos 2024-07-22 11:41:52 +01:00
amin 812ce57850 docs:fix formatting 2024-07-22 11:41:52 +01:00
amin d2d9e09f06 docs: adding subject and main 2024-07-22 11:41:52 +01:00
nprimo 6a28cbea5a fix(has-city): remove backslash that causes unexpected markdown render behaviour 2024-07-22 09:07:28 +01:00
zanninso 87b526be74 docs: fix typos and adding more details 2024-07-19 16:51:49 +01:00
amin 42768b456b docs: fix formating 2024-07-19 16:51:49 +01:00
amin b0692b6052 docs: fix typo and adding more details 2024-07-19 16:51:49 +01:00
zanninso be3fac7ddf docs: adding more details in the description 2024-07-19 16:51:49 +01:00
zanninso 277b6b34d5 docs: fix formatting 2024-07-19 16:51:49 +01:00
amin 6e23e38d9b docs: adding subject and main 2024-07-19 16:51:49 +01:00
amin caaa46afe6 test: adding subject and main 2024-07-19 16:50:38 +01:00
zanninso a89a441036 docs: adding more details 2024-07-18 15:56:59 +01:00
amin a4e4dcc580 docs: adding subject and main 2024-07-18 15:56:59 +01:00
amin 5a5658c839 docs: adding subject and main 2024-07-18 15:56:59 +01:00
zanninso 2a1642e7fe docs: adding edge case test 2024-07-18 15:43:12 +01:00
zanninso 42cf862d11 docs: adding example for singular period 2024-07-18 15:43:12 +01:00
amin 9a21ca8dbe docs: adding subject and main 2024-07-18 15:43:12 +01:00
zanninso d789bcd666 docs: fix formatting 2024-07-18 15:42:59 +01:00
amin 868e5821e6 docs: adding subject and main 2024-07-18 15:42:59 +01:00
amin 6f4f10e010 docs: change the main file to be aling with the subject 2024-07-18 11:50:34 +01:00
amin a9a53977e9 docs: adding more test examples 2024-07-18 11:50:34 +01:00
amin 347089d53c docs: adding more test examples 2024-07-18 11:50:34 +01:00
zanninso 514423cb67 docs: fix typo and adding more details. 2024-07-18 11:50:34 +01:00
zanninso 51a5af45f7 docs: fix formatting 2024-07-18 11:50:34 +01:00
amin e514c70648 docs: adding subject and main 2024-07-18 11:50:34 +01:00
zanninso a611b6704d docs: specify timezone for the formatting 2024-07-18 11:50:20 +01:00
amin 47bbfdf7d5 docs: fix typos 2024-07-18 11:50:20 +01:00
amin 351c4bc3bd docs: adding more details and fix typos 2024-07-18 11:50:20 +01:00
amin a7e7a03e7a docs: adding more details and fix formatting 2024-07-18 11:50:20 +01:00
amin b48006ef88 docs: formatting 2024-07-18 11:50:20 +01:00
amin 6fd1b11727 docs: fix typo 2024-07-18 11:50:20 +01:00
amin f1e8174e3b docs: adding subject and main 2024-07-18 11:50:20 +01:00
Harry 641dd957d3
fix(check-prettier): don't check removed files 2024-07-18 10:07:36 +01:00
Harry 5706499491
fix(check-links): don't check removed files 2024-07-18 10:06:52 +01:00
amin d98cd96e99 docs: adding more details about the edge case out of bound 2024-07-16 19:54:57 +01:00
amin 7fbf8702cc docs: adding more details in the description 2024-07-16 19:54:57 +01:00
amin 073746f135 docs: adding subject and main 2024-07-16 19:54:57 +01:00
amin 33854c08cc docs: fix inconsistency between subject and test 2024-07-11 02:24:42 +01:00
zanninso e5222a2296 docs: fix formatting and adding more details 2024-07-11 02:24:42 +01:00
amin 47aab4bd1b docs: formatting 2024-07-11 02:24:42 +01:00
amin 3a4f1c5d1f docs: adding subject and main 2024-07-11 02:24:42 +01:00
amin 0b0d423689 test: adding subject and main 2024-07-10 17:52:20 +01:00
amin 4f383a346f docs: remove uncessary comments 2024-07-10 17:49:43 +01:00
amin f3ba14efb0 test: adding subject and main 2024-07-10 17:49:43 +01:00
amin 94a379bb6f docs: apply change to make it clearler 2024-07-10 16:16:16 +01:00
zanninso 9c74903146 docs: adding more details 2024-07-10 16:16:16 +01:00
amin 3ceb7322eb docs: adding subject and main 2024-07-10 16:16:16 +01:00
amin 78f53f650e docs: formatting 2024-07-10 15:05:36 +01:00
amin f63261a432 docs: adding subject and main 2024-07-10 15:05:36 +01:00
amin ae40b4e64d test: formatting 2024-07-10 15:04:42 +01:00
amin bfe7898011 docs: adding subject and main 2024-07-10 15:04:42 +01:00
amin 94b510cdc3 docs: formatting 2024-07-10 12:34:22 +01:00
amin 2bee3d2db4 docs: adding subject and main 2024-07-10 12:34:22 +01:00
oumaimafisaoui 4e44aeb373 Fix: renamed skelton to the skeleton 2024-07-10 11:10:38 +01:00
oumaimafisaoui 0f76115885 Fix: deleted undesired files, modified instructions, modified tests 2024-07-10 11:10:38 +01:00
oumaimafisaoui d4635b3f6a docs:Formatting the subject skeleton 2024-07-10 11:10:38 +01:00
oumaimafisaoui 4fa98a738c docs:Adding a folder for the DPxAI and adding the first exercice skeleton 2024-07-10 11:10:38 +01:00
zanninso c7b5f9b6a0 docs: fix formatting 2024-07-10 02:13:42 +01:00
zanninso c145bddcc3 docs: adding more details 2024-07-10 02:13:42 +01:00
amin eed0e21332 docs: adding subject and main 2024-07-10 02:13:42 +01:00
zanninso 5adf2191a3 docs: adding more details 2024-07-10 02:08:45 +01:00
amin 68a93e668f docs: adding subject and main 2024-07-10 02:08:45 +01:00
amin 2ebeb4145a docs: adding detail for negative index edge case. 2024-07-09 17:17:03 +01:00
zanninso cfc77d160f docs: add more details and fix formatting 2024-07-09 17:17:03 +01:00
amin 122391b887 docs: adding subject and main 2024-07-09 17:17:03 +01:00
amin c9f01f665d docs: adding subject and main 2024-07-09 17:17:03 +01:00
Harry dd8ac5fe39
feat(readme): update content 2024-07-09 16:30:19 +01:00
sagarishere 36f1c07317
Improved checking for import, moved removeComments
Improved checking of imports and moved removeComments to separate function, clearly explaining that it's limited to javascript type of comments.
2023-01-24 22:11:51 +02:00
71 changed files with 2724 additions and 27 deletions

View File

@ -23,7 +23,7 @@ jobs:
- name: 🔍 Get all changed *.md file(s)
id: changed-md
run: |
echo "changed_files=$(git diff --name-only --merge-base origin/master | grep "\.md$" | xargs)" >> "$GITHUB_OUTPUT"
echo "changed_files=$(git diff --name-only --diff-filter=ACMRT --merge-base origin/master | grep "\.md$" | xargs)" >> "$GITHUB_OUTPUT"
- name: 🔗 Run Check Links
if: steps.changed-md.outputs.changed_files != ''

View File

@ -20,7 +20,7 @@ jobs:
- name: 🔍 Get all changed *.md file(s)
id: changed-md
run: |
echo "changed_files=$(git diff --name-only --merge-base origin/master | grep "\.md$" | xargs)" >> $GITHUB_OUTPUT
echo "changed_files=$(git diff --name-only --diff-filter=ACMRT --merge-base origin/master | grep "\.md$" | xargs)" >> $GITHUB_OUTPUT
- name: Run step if any *.md file(s) changed
if: steps.changed-md.outputs.changed_files != ''

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
node_modules
rust/**/target/
js/soluss
**/.DS_Store

View File

@ -1,4 +1,4 @@
# Welcome to the [Public Repository](https://github.com/01-edu/public) of the [01 Edu System](https://github.com/01-edu) 👋
# Welcome to the [Public](https://github.com/01-edu/public) Repository of the [01 Edu System](https://github.com/01-edu) 👋
![01 Edu System](https://github.com/01-edu/public/assets/14015057/35560fed-34e6-42c8-a71b-71b0534b7ad7)
@ -8,11 +8,11 @@ All of our courses are meticulously crafted to offer challenging yet enjoyable,
### 🎭 **Our Philosophy**
Some of our subjects are **intentionally designed** to be **ambiguous** or **less specific**, reflecting our unique pedagogical approach. Please keep this in mind before reporting any issues or support requests.
Some of our subjects are **intentionally designed** to be **ambiguous** or **less specific**, reflecting our unique pedagogical approach. Please keep this in mind before reporting any [**⁉️ issues**](https://github.com/01-edu/public/issues) or support requests.
### 🫶 **Contribute**
We welcome contributions! Feel free to submit a pull request. Due to the high volume of tasks, there may be a delay in reviewing your submission.
We welcome contributions! Feel free to submit a [**🪢 pull request**](https://github.com/01-edu/public/pulls). Due to the high volume of tasks, there may be a delay in reviewing your submission.
Thank you!<br>
**📚 The Content Team**

19
dom/call-it_test.js Normal file
View File

@ -0,0 +1,19 @@
export const tests = []
tests.push(async ({ page, eq }) => {
// check the face
return eq.$('section#face', { textContent: '' })
})
tests.push(async ({ page, eq }) => {
// check the upper-body
return eq.$('section#upper-body', { textContent: '' })
})
tests.push(async ({ page, eq }) => {
// check the lower-body, my favorite part
return eq.$('section#lower-body', { textContent: '' })
})

36
dom/class-it_test.js Normal file
View File

@ -0,0 +1,36 @@
export const tests = []
tests.push(async ({ page, eq }) => {
// check the class 'eye' has been declared properly in the CSS
eq.css('.eye', {
width: '60px',
height: '60px',
backgroundColor: 'red',
borderRadius: '50%',
})
})
tests.push(async ({ page, eq }) => {
// check the class 'arm' has been declared properly in the CSS
eq.css('.arm', { backgroundColor: 'aquamarine' })
})
tests.push(async ({ page, eq }) => {
// check the class 'leg' has been declared properly in the CSS
eq.css('.leg', { backgroundColor: 'dodgerblue' })
})
tests.push(async ({ page, eq }) => {
// check the class 'body-member' has been declared properly in the CSS
eq.css('.body-member', { width: '50px', margin: '30px' })
})
tests.push(async ({ page, eq }) => {
// check that the targetted elements have the correct class names
await eq.$('p#eye-left', { className: 'eye' })
await eq.$('p#eye-right', { className: 'eye' })
await eq.$('div#arm-left', { className: 'arm body-member' })
await eq.$('div#arm-right', { className: 'arm body-member' })
await eq.$('div#leg-left', { className: 'leg body-member' })
await eq.$('div#leg-right', { className: 'leg body-member' })
})

View File

@ -0,0 +1,90 @@
export const tests = []
tests.push(async ({ page, eq }) => {
// check that the HTML structure is correct & elements are nested properly
const elements = await page.$$eval('body', (nodes) => {
const toNode = (el) => {
const node = {}
node.tag = el.tagName.toLowerCase()
node.id = el.id
if (el.children.length) {
node.children = [...el.children].map(toNode)
}
return node
}
return [...nodes[0].children].map(toNode)
})
eq(expectedStructure, elements)
})
tests.push(async ({ page, eq }) => {
// check the section selector style has been updated properly
eq.css('section', {
display: 'flex',
justifyContent: 'center',
})
})
tests.push(async ({ page, eq }) => {
// check if the provided CSS has been correctly copy pasted
eq.css('div, p', {
border: '1px solid black',
padding: '10px',
margin: '0px',
borderRadius: '30px',
})
eq.css('#face', { alignItems: 'center' })
eq.css('#eyes', {
display: 'flex',
backgroundColor: 'yellow',
justifyContent: 'space-between',
alignItems: 'center',
borderRadius: '50px',
width: '200px',
})
eq.css('#torso', {
width: '200px',
backgroundColor: 'violet',
})
})
const expectedStructure = [
{
tag: 'section',
id: 'face',
children: [
{
tag: 'div',
id: 'eyes',
children: [
{ tag: 'p', id: 'eye-left' },
{ tag: 'p', id: 'eye-right' },
],
},
],
},
{
tag: 'section',
id: 'upper-body',
children: [
{ tag: 'div', id: 'arm-left' },
{ tag: 'div', id: 'torso' },
{ tag: 'div', id: 'arm-right' },
],
},
{
tag: 'section',
id: 'lower-body',
children: [
{ tag: 'div', id: 'leg-left' },
{ tag: 'div', id: 'leg-right' },
],
},
]

40
dom/first-move_test.js Normal file
View File

@ -0,0 +1,40 @@
export const tests = []
tests.push(async ({ eq, page }) => {
// check the JS script has a valid src
const source = await page.$eval(
'script',
(node) => node.src.includes('.js') && node.src,
)
if (!source.length) throw Error('missing script src')
})
tests.push(async ({ eq, page }) => {
// check the class 'eye-closed' has been added in the CSS
eq.css('.eye-closed', {
height: '4px',
padding: '0px 5px',
borderRadius: '10px',
})
})
tests.push(async ({ eq, page }) => {
// check the class of left eye before the JS is loaded
await page.setJavaScriptEnabled(false)
await page.reload()
await eq.$('p#eye-left', { className: 'eye' })
})
tests.push(async ({ eq, page }) => {
// check the class of left eye has been updated after the JS is loaded
await page.setJavaScriptEnabled(true)
await page.reload()
await eq.$('p#eye-left', { className: 'eye eye-closed' })
// check the background color of left eye has changed after the JS is loaded
const eyeLeftBg = await page.$eval(
'#eye-left',
(node) => node.style.backgroundColor,
)
eq(eyeLeftBg, 'black')
})

View File

@ -0,0 +1,49 @@
export const tests = []
tests.push(async ({ eq }) => {
// check the CSS stylesheet is linked in the head tag
await eq.$('head link', {
rel: 'stylesheet',
href: 'http://localhost:9898/select-then-style/select-then-style.css',
})
})
tests.push(async ({ eq }) => {
// check the universal selector has been declared properly
await eq.css('*', {
margin: '0px',
opacity: '0.85',
boxSizing: 'border-box',
})
})
tests.push(async ({ eq }) => {
// check that the body was styled
await eq.css('body', { height: '100vh' })
})
tests.push(async ({ eq }) => {
// check that sections elements are styled
await eq.css('section', {
padding: '20px',
width: '100%',
height: 'calc(33.3333%)',
})
})
tests.push(async ({ eq }) => {
// check that the individual sections are styled
await eq.css('#face', { backgroundColor: 'cyan' })
await eq.css('#upper-body', { backgroundColor: 'blueviolet' })
await eq.css('#lower-body', { backgroundColor: 'lightsalmon' })
})

38
dom/the-skeleton_test.js Normal file
View File

@ -0,0 +1,38 @@
export const tests = []
tests.push(async ({ page, eq }) => {
// check that the title tag is present & is set with some text
const title = await page.$eval('title', (node) => node.textContent)
if (!title.length) throw Error('missing title')
})
tests.push(async ({ page, eq }) => {
// check that the title tag is set with text from the given list
const title = await page.$eval('title', (node) => node.textContent)
if (title !== 'invisibility' && title !== 'light-speed' && title !== 'super-strength' && title !== 'advanced-healing' && title !== 'mind-link') {
throw Error('wrong title, pick one of the list')
}
// invisibility
// light-speed
// super-strength
// advanced-healing
// mind-link
})
tests.push(async ({ page, eq }) => {
// check the face
return eq.$('section:nth-child(1)', { textContent: 'face' })
})
tests.push(async ({ page, eq }) => {
// check the upper-body
return eq.$('section:nth-child(2)', { textContent: 'upper-body' })
})
tests.push(async ({ page, eq }) => {
// check the lower-body
return eq.$('section:nth-child(3)', { textContent: 'lower-body' })
})

View File

@ -0,0 +1,18 @@
[
{
"description": "Log a number in the console",
"code": "// If you see this code, it means that you failed the first tests.\n// each tests have it's own code to be tested that will appear if\n// your solution doesn't pass it, it is not here to help you.\n// While sometimes it may clarify the instructions\n// this specific test is complex and will most likely confuse you.\n\n// This is to save all the values that you console.log'd\nconst args = saveArguments(console, 'log')\n\n// This comment below will be replaced by your code\n// Your code\n\n// This is where we check that the value are expected.\n// It's pretty advanced code, you don't have to understand it\n// Do not try to use it for the solution, it will not help you.\nconst typeOfLoggedValues = args.flat().map((v) => typeof v)\nif (!typeOfLoggedValues.includes('number')) {\n // this is where we create the error message you see:\n throw Error('you must log a number')\n // that's what you should focus on trying to understand\n // the message, not `throw` or `Error` don't worry about\n // that, worry about showing a number in the console !\n}"
},
{
"description": "Log a boolean in the console",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nconst typeOfLoggedValues = args.flat().map((v) => typeof v)\nif (!typeOfLoggedValues.includes('boolean')) {\n throw Error('you must log a boolean')\n}"
},
{
"description": "Log a string in the console",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nconst typeOfLoggedValues = args.flat().map((v) => typeof v)\nif (!typeOfLoggedValues.includes('string')) {\n throw Error('you must log a string')\n}"
},
{
"description": "Log the string Hello There ! in the console",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nconst loggedValues = args.flat().join(' ')\nif (!loggedValues.includes('Hello There !')) {\n throw Error('you must log the text Hello There !')\n}"
}
]

View File

@ -149,17 +149,27 @@ ${tests.trim()};`.trim()
}
const loadAndSanitizeSolution = async () => {
const path = `${solutionPath}/${name}.js`
const rawCode = await read(path, "student solution")
try {
const path = `${solutionPath}/${name}.js`
const rawCode = await read(path, "student solution")
const sanitizedCode = removeComments(rawCode)
// this is a very crude and basic removal of comments
// since checking code is only use to prevent cheating
// it's not that important if it doesn't work 100% of the time.
const code = rawCode.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, "").trim()
if (code.includes("import")) fatal("import keyword not allowed")
return { code, rawCode, path }
if (sanitizedCode.includes("import ")) { // space is important as it prevents "imported" or "importance" or other words containing "import"
throw new Error("The use of the 'import' keyword is not allowed.")
}
return { code: sanitizedCode, rawCode, path }
} catch (error) {
console.error(error)
}
}
const removeComments = (code) => {
// removes JS single line and multi-line comments only. Not for bash files etc.
// for use with multiple file-types, I suggest writing a removeComments function with language-type as input and then handling accordingly
return code.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, "").trim()
}
const runTests = async ({ url, path, code }) => {
const { setup, tests } = await import(url).catch(err =>
fatal(`Unable to execute ${name}, error:\n${stackFmt(err, url)}`),

View File

@ -0,0 +1,41 @@
## Call it
> Brainpower mode
### Context
Congrats! You created the very first base for your entity and you witnessed its appearance in the Digital
World - your browser.. However, it is still a tiny seed of the marvelous thing it could become. Be patient;
there's still a bit of work to do.
### Directions
First of all, instead of writing down what things are _(you're not writing down on your hand the word 'hand',
are you?)_, we're going to identify them semantically with the very practical [id
attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attri butes/id). This `id` has to be a **unique**
identifier on your webpage, allowing you to target your element when needed. You can compare it to your name and
surname; this is what identifies you to other people, and if someone's calling you by your name, you answer.
### Instructions
So let's identify the 3 elements we have so far: in each section, remove the text content from inside the tag
and set it as the value of the `id` attribute of the corresponding `section` text.
**Run your code in the editor preview:** \
you don't see _anything_? Don't freak out! \
Inspect the HTML that has been created with your
[browser inspector tool](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools),
and if you done it correctly, you should see the 3 sections inside the `body` with the `id` attribute set in
your HTML structure.
### Code examples
To set the `id` of a `div` tag to `"my-lil-div"`:
```html
<div id="my-lil-div"></div>
```
### Notions
- [`id` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id)

View File

@ -0,0 +1,66 @@
## Class it!
> Brainpower Mode
### Context
Alright, your being is almost done; some elements still need a bit more shaping, and then we'll make it come to life!
### Resources
We provide you with some content to get started smoothly. Check it out!
- Video [CSS - Set & style with CSS class](https://www.youtube.com/watch?v=-U397k4VloU&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=6)
### Instructions
If you look at your page, you can observe that some elements come in pairs: the eyes, the arms, and the legs. They are the same organ, one on the left and one on the right; they have exactly the same shape. So for practicality and to avoid repeating the same style twice, we're not going to use their `id` to style them, but a [`class`](https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors). Unlike an `id`, a `class` can be attributed to several different elements with common rulesets, so the style defined for that class will apply to all the HTML elements that have it.
#### Task 1
Create the following three classes, set them with the given rulesets, and attribute them to the corresponding HTML elements:
- Class `eye`:
- `width` of 60 pixels
- `height` of 60 pixels
- `background-color` "red"
- `border-radius` of 50%
- Attributed to `eye-left` & `eye-right`
- Class `arm`:
- `background-color` "aquamarine"
- Attributed to `arm-left` & `arm-right`
- Class `leg`:
- `background-color` "dodgerblue"
- Attributed to `leg-left` & `leg-right`
Note that you can attribute several classes to the same element. Create the class `body-member`, which sets the `width` to 50 pixels and the `margin` to 30 pixels, and add it to the `class` attribute of these elements: `arm-left`, `arm-right`, `leg-left`, & `leg-right`.
### Code examples
Declare a class `my-first-class` and style it with a `color` to `"blue"` and a `background-color` to `"pink"`:
```css
.my-first-class {
color: blue;
background-color: pink;
}
```
Apply classes to HTML elements:
```html
<div class="my-first-class"></div>
<div class="another-class"></div>
<div class="my-first-class another-class"></div>
```
### Expected output
This is what you should see in the browser:
![](https://github.com/01-edu/public/raw/master/subjects/class-that/class-that.png)
> Need help? Ask your tablemate.
### Notions
- [CSS class](https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors)

View File

@ -0,0 +1,104 @@
## Embedded Organs
> Brainpower Mode
### Context
Bravo! You've outlined the global shape of your robot friend, but now it's time to bring it to life on Earth by adding essential parts. Let's equip your robot with its vital organs! To do this, we're going to introduce you to the concept of nesting elements inside others. This will allow you to build a fully functional robot, one piece at a time.
> Don't be afraid of the density of things you are asked to do. Just divide the work up step by step.
### Instructions
So far, you just have a unique layer in your `<body>`: `face`, `upper-body`, and `lower-body` are all at the same level.
But as you know, on a face, there are two eyes, a nose, and a mouth - and inside that mouth, a tongue, etc.; any element can potentially be a container for other elements.
#### Task 1
Let's add new elements and wrap them in different layers; convert this list of organs into an HTML structure with the corresponding given tags!
```html
<section id="face">
<div id="eyes">
<p id="eye-left"></p>
<p id="eye-right"></p>
</div>
</section>
<section id="upper-body">
<div id="arm-left"></div>
<div id="torso"></div>
<div id="arm-right"></div>
</section>
<section id="lower-body">
<div id="leg-left"></div>
<div id="leg-right"></div>
</section>
```
#### Task 2
Modify your CSS file to add rulesets to `section` tags: `display` at "flex" and `justify-content` at "center" (this is to turn the `section` tags into [`flex` containers](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox), so the elements inside will be centered)
#### Task 3
Add the following CSS to your CSS file to see the freshly-added nested elements:
```
div,
p {
border: solid 1px black;
padding: 10px;
margin: 0;
border-radius: 30px;
}
#face {
align-items: center;
}
#eyes {
display: flex;
background-color: yellow;
justify-content: space-between;
align-items: center;
border-radius: 50px;
width: 200px;
}
#torso {
width: 200px;
background-color: violet;
}
```
### Code examples
Nest several elements:
```html
<div id="first-element">
<span id="second-element"></span>
<div id="third-element">
<p id="fourth-element"></p>
</div>
</div>
```
### Expected output
This is what you should see in the browser:
![](https://github.com/01-edu/public/raw/master/subjects/nesting-organs/nesting-organs.png)
> From now on, you can customize the `background-color` of the three following background sections from the CSS code by choosing the colors that you think best suit your theme.
> \#face
> \#upper-body
> \#lower-body
> You don't know which color is configurable? [Internet will give you the list](https://letmegooglethat.com/?q=css+color+list)
### Notions
- [Anatomy of an HTML element](https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Getting_started#anatomy_of_an_html_element)
- [Nesting HTML elements](https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Getting_started#nesting_elements)
- [Flexbox layout](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox), you can train on [Flexbox froggy](https://flexboxfroggy.com/)

View File

@ -0,0 +1,108 @@
## First move
> Brainpower mode
### Context
Glad to see you here! It's impressive how far you've come today, and you are just one step away from seeing a simple yet impressive thing we can do with JavaScript. This will give you a glimpse of how JavaScript works with HTML and CSS to make your robot interesting! By using JavaScript, you will control and interact with your creation, adding dynamic abilities that make it come alive.
So far, you haven't learned much about JavaScript (but you will soon, don't worry!), but we want you to see an example of how powerful JavaScript can be in modifying the robot.
In these instructions, you will execute the steps to change your robot's eyes from open to closed using JavaScript! Does it seem simple? Yes, but you will later make your robot more dynamic by pushing a button to open and close that eye! Of course, that's for when you learn more about JavaScript (Again, a secret for you because you made it until here).
This is more of a puzzle to use your brain to follow hints and make things work, even if it seems complex (it is not!). Isn't that your brain's superpower?
> Follow the instructions, ask your peers if you are stuck and stay motivated because you are close to the Shape Crafting goal!
> Follow every hint you have in the subject!
### Instructions
- for the JavaScript (JS) files, when you have to link one, it's named like so: `name-of-the-exercise.js`
Still there? Well done! But hold on, here begins the serious part... In order to control your creation, you're going to plug its brain: JavaScript.
First, define this new class in `your CSS file`:
```css
.eye-closed {
height: 4px;
padding: 0 5px;
border-radius: 10px;
}
```
#### Task 1
Second, [`Link a JS script`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) to your HTML file.
#### Task 2
Then in your Javascript file, you're going to close the left eye of your entity. To do so, you have to target the `eye-left` HTML element by its `id` using the [`getElementById`](https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById) method.
#### Task 3
Then, [set the `style`](https://developer.mozilla.org/en-US/docs/Web/API/ElementCSSInlineStyle/style#setting_styles) of your `eye-left` to change its background color to "black". We also need to modify its shape; for that, we are going to add a new class to it.
### Code examples
#### Example 1
To target the `nose` HTML element by its `id` using getElementById:
In HTML file:
```html
<!-- HTML -->
<div id="nose"></div>
```
In the JS file:
```js
const nose = document.getElementById("nose");
```
#### Example 2
To change the color of the nose to red:
```css
.nose-red {
width: 20px;
height: 20px;
background-color: red;
border-radius: 50%;
}
```
```js
nose.classList.add("nose-red");
```
#### Example 3
To change the background color of nose to yellow:
```css
nose.style.backgroundColor = 'yellow'
```
### Expected output
> By the way, do you like your new background color chosen earlier? Me too.
> To personalize your robot even more, don't hesitate to change the inclination of its arms in a direction that reflects the personality you have chosen!
> I think [adding a rotation](https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/rotate) to the `arm class` is a good solution.
This is what you should see in the browser:
[![personalize-bring-it-to-life-dom-example.png](https://i.postimg.cc/Df5pcWN1/personalize-bring-it-to-life-dom-example.png)](https://postimg.cc/pyhBWdRd)
### Resources
We provide you with some content to get started smoothly, check it out!
- Video [Link a JS script to your HTML file](https://www.youtube.com/watch?v=jMvsQm-p1gM&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=7)
- Video [JS variables explained](https://www.youtube.com/watch?v=XNjhAMhyVJo&list=PLDa5D3mQAy7Sj0s4J6R5HT2xsEXkYuYFL&index=3)
- Video [DOM JS - getElementById](https://www.youtube.com/watch?v=34kAR8yBtDM&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=8)
- Video [DOM JS - Set an element's inline style](https://www.youtube.com/watch?v=pxlYKvju1z8&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=15)
- Video [DOM JS - classList: add & remove](https://www.youtube.com/watch?v=uQEM-3_4vPA&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=17)
- [Memo DOM JS](https://github.com/nan-academy/js-training/blob/gh-pages/examples/dom.js)

View File

@ -0,0 +1,81 @@
## Glance on Power
> Brainpower mode
### Context
Bravo! You've successfully brought the shape of your robot friend into existence. Now, it's time to take the next exciting step and start building the power to bring your robot to life. Yes, it's time to start thinking like a coder, builder! Using JavaScript, you'll be able to add dynamic abilities and interactions to your creation. Get ready to breathe life into your robot friend!
Ready to start collecting your power through learning to code? Let's go, time is against us!
### Concepts
#### Values
In the coding world, values are like the energy sources that power your robot. There are three types of values that can model the **WORLD**! _(In the end, it's all `1`s and `0`s for the computer)_, but for us, **humans**, we need an easier way of representing things.
> We can all agree that `11010001100101110110011011001101111` is not a very friendly way to say `'hello'`!
#### Numbers 🔢
Numbers are like the vital stats of your robot:
- Whole numbers: `1`, `23`, `232139283`
- Negative numbers are prefixed with `-`: `-1`, `-1231`
- Decimal numbers: `3.14`, `-2.53343`, etc.
Use them for _quantities_ like in daily life.
#### Booleans ✖️ / ✔️
Booleans are the simple true/false logic gates for your robot:
- Something is `true`
- or `false`
They represent a truth, an answer to a closed-ended question _(anything that can be answered with yes or no)_:
- Is the robot's battery full? `true`
- Is the robot currently charging? `false`
- Can the robot see an obstacle? `true` _(most likely)_
#### Strings 🆒
Strings are the commands and messages your robot can use:
- `'Activate'`
- `'Hello, human!'`
A string is a sequence of characters used to represent text. It needs **delimiters** to define its _beginning_ and _end_. Delimiters are matching quotes, either `` ` ``, `"`, or `'`.
### Using `console.log`
To display output from a script into a console, use the function `console.log`:
```js
console.log(); // <- will show an empty line
```
Add any value between the parentheses to see it appear when the script is executed.
It is very important to use this often to validate that our code is working correctly. The more it is tested, the easier it is to understand what's going on in the code!
In doubt, `console.log` everything, don't be shy, they are free.
### Instructions
To do this exercise, use the code editor on the right side of your window. In the `hello-there.js` file, code a program that displays:
- The exact text `Hello There!`
- Any `Number` (like the robot's serial number)
- And a `Boolean` (indicating if the robot's sensors are active)
Don't forget to test your code before submitting it, using the `Run` button.
### Recommendation
Videos designed to give **hints** are assigned to each quest. It is strongly suggested to watch them as you go.
### Ressources
- [Introduction to JavaScript](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps)

View File

@ -0,0 +1,82 @@
## Select then style
> Brainpower mode
### Context
To bring your robot friend to life, it's not enough to just build its skeleton with HTML. Your robot needs personality and style, and that's where CSS (Cascading Style Sheets) comes in. CSS is like the clothing and accessories that give your robot its unique look and feel. It helps you decorate and arrange the elements on your page, making everything look just right. Ready to start styling? Lets dive in and give your robot buddy the perfect look!
### Resources
We provide you with some content to get started smoothly, check it out!
- Video [Link a CSS stylesheet to your HTML file](https://www.youtube.com/watch?v=e7G-KhaqTjs&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=3)
- Video [CSS - Style with type selectors](https://www.youtube.com/watch?v=q0ur7YWBzhs&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=4)
- Video [HTML/CSS - Set & style with ID selector](https://www.youtube.com/watch?v=3b3MiY-MR-Y&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=5)
### Instructions
Now that you have created and properly identified the different sections of your being, it's time to make it look more lifelike! To achieve that, you're going to style it with [CSS][0]. Create a CSS file, [link it][1] to your `select-then-style.html`, and:
- Target all the elements with the [universal selector][2] and style them with:
- `margin` of `0`
- `box-sizing` set to `border-box`
- `opacity` of `0.85`
- Target the `body` tag and style it with a `height` of `100vh` so it takes the viewport height.
- Target all the `section` tags with the [type selector][3], and style them with:
- `padding` of `20px`
- `width` of `100%`
- `height` of `calc(100% / 3)` _(one third of the `body` height)_
- Target each of the following elements with the [`id` selector][4], using the `id` you defined earlier for each section, and style them:
- `face` with a "cyan" `background-color`
- `upper-body` with a "blueviolet" `background-color`
- `lower-body` with a "lightsalmon" `background-color`
### Code examples
To style an element, you systematically have to declare [rulesets][5], composed of a property and a value.
Set the color of `div` tags to `"red"`:
```css
div {
color: red;
}
```
Set the `background-color` of the HTML element with the `id` `"block-1"`:
```css
#block-1 {
color: red;
}
```
### Expected output
This is what you should see in the browser: ![screenshot][8]
### Notions
- [`link` a CSS file][1]
- [CSS basics][7]
- [ruleset][5]
- [List of different selectors][6]
- [universal selector][2]
- [type selector][3]
- [`id` selector][4]
[0]: https://developer.mozilla.org/en-US/docs/Web/CSS
[1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#including_a_stylesheet
[2]: https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors
[3]: https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors
[4]: https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors
[5]: https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics#anatomy_of_a_css_ruleset
[6]: https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics#different_types_of_selectors
[7]: https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics
[8]: https://github.com/01-edu/public/blob/master/subjects/select-and-style/select-and-style.png?raw=true

View File

@ -0,0 +1,75 @@
## The skeleton
> Brainpower mode
### Context
To craft your robot friend, you first need to build its skeleton, and that's where HTML comes in. HTML is the blueprint that sets up the structure of your robot, giving it shape and form. With HTML, you'll create the framework that holds all your amazing ideas together. Ready to start building? Lets dive in and create the foundation of your robot buddy!
> For the whole quest, the principle is to iterate over your code: when you finish an exercise, copy-paste your code to use it in the next one.
> Contrary to what you will see in the videos, you don't have to run a server on your machine to use the HTML, CSS and JavaScript thanks to the integrated code editor that takes care of all that.
> We've left the videos for the other educational content they provide.
### Files naming
- for the HTML files: `name-of-the-exercise.html`
- for the CSS files: when you have to link one, it's named like so: `name-of-the-exercise.css`
### Resources
We provide you with some content to get started smoothly, check it out!
- Video [Where to start](https://www.youtube.com/watch?v=i2PWvTERU-g&list=PLDa5D3mQAy7SKRLbYIEAcPrbQxrR_g1uM&index=1)
- Video [Basic set up of an HTML page](https://www.youtube.com/watch?v=QtKoO7tT-Gg&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=1)
- Video [Different HTML tags overview](https://www.youtube.com/watch?v=Al-Jzpib8VY&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=2)
Those videos are accompanying you step by step in each exercise, but if you want to check right away all the notions covered in the quest, you can watch the whole playlist throughout your next exercices[Web - HTML, CSS & DOM JavaScript](https://www.youtube.com/playlist?list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF).
> Your working environment may not be exactly the same as what you see in the videos or documentation, just try to adapt your work according to your research and discoveries.
> Don't be afraid to try!
### Instructions
Ready? Let's code!
> The first step to achieve in your quest is to craft the shape of your robot ; for that, 2 things needs to be done:
>
> - Customize the( [`<head>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head) tag)
> - Customize the ([`<title>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title) tag)
To create any project, some things need to be declared in the HTML file - those are not visible elements in your page, but things cannot work without them.
#### The `<head>` part:
Choose a power that you will give to your robot from the following list and put it as a `<title>`:
- invisibility
- light-speed
- super-strength
- advanced-healing
- mind-link
#### The `<body>` part:
This section contains the content of your webpage , in our case the lower body of your buddy. Define the skeleton of your robot by organizing it into three main sections: the face, the upper body, and the lower body. Inside the <body> tag of your HTML file, create three divisions using <section> tags, and place the following text content inside each one: face, upper-body, lower-body.
> Don't forget to press Render again to refresh the display page when you modify your code.
### Code examples
To create a `div` tag with `hello` as text content inside the `body`:
```html
<body>
<div>hello</div>
</body>
```
### Notions
- [`html` tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html)
- [`head` tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head)
- [`title` tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title)
- [`body` tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body)
- [`section` tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/section)

View File

@ -2,7 +2,7 @@
### Instructions
Create a function `hasCity` that takes a string called `country` and an array of strings, which are cities of that country, which returns a new function. \
Create a function `hasCity` that takes a string called `country` and an array of strings, which are cities of that country, which returns a new function.
The new function takes a string, called `city`, as a parameter and which determines
whether the array contains that string or not.

View File

@ -2,13 +2,13 @@
### Instructions
Write a program named `hiddenp` that takes two `string` and that, if the first `string` is hidden in the second one, displays `1` followed by a newline (`'\n'`), otherwise it displays `0` followed by a newline.
Write a program named `hiddenp` that takes two `strings` as arguments. The program should check if the first string `s1` is hidden in the second `s2`.
`s1` is considered hidden in `s2` if it is possible to find each character from `s1` in `s2`, in the same order as they appear in `s1`, but not necessarily consecutively.
Let s1 and s2 be `string`. It is considered that s1 is hidden in s2 if it is possible to find each character from s1 in s2, **in the same order as they appear in s1.**
If s1 is an empty `string`, it is considered hidden in any `string`.
If the number of arguments is different from 2, the program displays nothing.
- If `s1` is hidden in `s2`, the program should display `1` followed by a newline.
- If `s1` is not hidden in `s2`, the program should display `0` followed by a newline.
- If `s1` is an empty string, it is considered hidden in any string.
- If the number of arguments is different from 2, the program should display nothing.
### Usage

19
subjects/itoabase/main.go Normal file
View File

@ -0,0 +1,19 @@
package main
import (
"fmt"
"piscine"
)
func main() {
fmt.Println(piscine.ItoaBase(10, 2))
fmt.Println(piscine.ItoaBase(255, 16))
fmt.Println(piscine.ItoaBase(-42, 4))
fmt.Println(piscine.ItoaBase(123, 10))
fmt.Println(piscine.ItoaBase(0, 8))
fmt.Println(piscine.ItoaBase(255, 2))
fmt.Println(piscine.ItoaBase(-255, 16))
fmt.Println(piscine.ItoaBase(15, 16))
fmt.Println(piscine.ItoaBase(10, 4))
fmt.Println(piscine.ItoaBase(255, 10))
}

View File

@ -0,0 +1,17 @@
public class ExerciseRunner {
public static void main(String[] args) {
AgeFinder AgeFinder = new AgeFinder();
// Test case 1
String date1 = "2000-01-01";
System.out.println("Age: " + AgeFinder.calculateAge(date1));
// Test case 2
String date2 = "1990-06-15";
System.out.println("Age: " + AgeFinder.calculateAge(date2));
// Test case 3
String date3 = "2010-12-25";
System.out.println("Age: " + AgeFinder.calculateAge(date3));
}
}

View File

@ -0,0 +1,60 @@
## Age Finder
### Instructions
Create a class `AgeFinder` that provides a method to calculate the age from a given date. The date will be provided in the format `yyyy-MM-dd`.
In case of any error the method `calculateAge` should return `-1`
> 💡 Have you ever seen someone with a negative age???
### Expected Class
```java
import java.time.LocalDate;
import java.time.Period;
import java.time.format.DateTimeFormatter;
public class AgeFinder {
public int calculateAge(String date) {
// Implementation to calculate the age from the given date
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
public class ExerciseRunner {
public static void main(String[] args) {
AgeFinder AgeFinder = new AgeFinder();
// Test case 1
String date1 = "2000-01-01";
System.out.println("Age: " + AgeFinder.calculateAge(date1));
// Test case 2
String date2 = "1990-06-15";
System.out.println("Age: " + AgeFinder.calculateAge(date2));
// Test case 3
String date3 = "2010-12-25";
System.out.println("Age: " + AgeFinder.calculateAge(date3));
}
}
```
### Expected Output
```shell
$ date
Tue Jul 9 03:58:06 PM UTC 2024
$ javac *.java -d build
$ java -cp build ExerciseRunner
Age: 24
Age: 34
Age: 13
$
```

View File

@ -0,0 +1,17 @@
public class ExerciseRunner {
public static void main(String[] args) {
ArmstrongNumber armstrongNumber = new ArmstrongNumber();
// Test case 1
int number1 = 153;
System.out.println("Is " + number1 + " an Armstrong number? " + armstrongNumber.isArmstrong(number1)); // Expected output: true
// Test case 2
int number2 = 123;
System.out.println("Is " + number2 + " an Armstrong number? " + armstrongNumber.isArmstrong(number2)); // Expected output: false
// Test case 3
int number3 = 9474;
System.out.println("Is " + number3 + " an Armstrong number? " + armstrongNumber.isArmstrong(number3)); // Expected output: true
}
}

View File

@ -0,0 +1,52 @@
## Armstrong Number
### Instructions
Write a program to check if a given number is an Armstrong number. An Armstrong number of n digits is an integer such that the sum of its digits raised to the power n is equal to the number itself.
Example: 153 is an Armstrong number bacause `1^3 + 5^3 + 3^3 = 153`
### Expected Class
```java
public class ArmstrongNumber {
public boolean isArmstrong(int number) {
// Implementation to check if the given number is an Armstrong number
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
public class ExerciseRunner {
public static void main(String[] args) {
ArmstrongNumber armstrongNumber = new ArmstrongNumber();
// Test case 1
int number1 = 153;
System.out.println("Is " + number1 + " an Armstrong number? " + armstrongNumber.isArmstrong(number1)); // Expected output: true
// Test case 2
int number2 = 123;
System.out.println("Is " + number2 + " an Armstrong number? " + armstrongNumber.isArmstrong(number2)); // Expected output: false
// Test case 3
int number3 = 9474;
System.out.println("Is " + number3 + " an Armstrong number? " + armstrongNumber.isArmstrong(number3)); // Expected output: true
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Is 153 an Armstrong number? true
Is 123 an Armstrong number? false
Is 9474 an Armstrong number? true
$
```

View File

@ -0,0 +1,11 @@
public class ExerciseRunner {
public static void main(String[] args) {
RegexDirector director = new RegexDirector();
RegexBuilder builder = new ConcreteRegexBuilder();
director.setBuilder(builder);
Regex regex = director.construct();
System.out.println(regex);
}
}

View File

@ -0,0 +1,96 @@
## Builder Blueprint
### Instructions
You are given an incomplete Builder design pattern implementation with some incorrect parts. Complete and fix the classes to demonstrate your understanding of how the Builder design pattern works.
Regex component required:
- Any Character: `.`
- Digit: `\d`
- Whitespace : `\s`
- Word Character: `\w`
### Expected Classes
```java
// Regex class
public class Regex {
private StringBuilder pattern;
public Regex(List<String> component) {
...
}
public String getPattern() {
return pattern.toString();
}
}
// Builder interface
public ... RegexBuilder {
void buildLiteral(String literal);
void buildAnyCharacter();
void buildDigit();
void buildWhitespace();
void buildWordCharacter();
Regex getResult();
}
// ConcreteRegexBuilder class
public class ConcreteRegexBuilder {
private Regex regex = new Regex();
List<String> component;
...
@Override
public Regex getResult() {
// Missing return statement
}
}
// RegexDirector class
public class RegexDirector {
private RegexBuilder builder;
public void setBuilder(RegexBuilder builder) {
this.builder = builder;
}
public Regex construct() {
builder.buildLiteral("Hello");
builder.buildWhitespace();
builder.buildWordCharacter();
builder.buildAnyCharacter();
return builder.getResult();
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your classes:
```java
public class ExerciseRunner {
public static void main(String[] args) {
RegexDirector director = new RegexDirector();
RegexBuilder builder = new ConcreteRegexBuilder();
director.setBuilder(builder);
Regex regex = director.construct();
System.out.println(regex);
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Hello\s\w.
$
```

View File

@ -0,0 +1,19 @@
public class ExerciseRunner {
public static void main(String[] args) {
LinkedList list = new CircularLinkedList();
// Add elements to the list
list.add(1);
list.add(2);
list.add(3);
// Access elements by index
System.out.println("Element at index 0: " + list.at(0)); // Expected output: 1
System.out.println("Element at index 1: " + list.at(1)); // Expected output: 2
System.out.println("Element at index 2: " + list.at(2)); // Expected output: 3
// Remove an element by index
list.remove(1);
System.out.println("Element at index 1 after removal: " + list.at(1)); // Expected output: 3
}
}

View File

@ -0,0 +1,119 @@
## Circular Linked List
### Instructions
Create a circular single linked list data structure that implements the following methods:
- `at(int index)`: to access an element by its index. if the index is negative or if the list is empty return -1.
- `add(int value)`: to add an element at the end of the list.
- `remove(int index)`: to remove an element by its index.
- `size()`: to return the size of the list.
Define these methods in an interface called `LinkedList`, and implement this interface in a class called `CircularLinkedList`. Additionally, add a private method `next(Node node)` in this class to use it for travers the list in other methods. This method should print the message "Go to next node\n" each time it is called.
If the index is over the size then you have to keep going using `next` method to achieve the given index.
### Explanation
A circular linked list is a linear data structure where each element is a separate object called a node. Each node contains two fields:
- `value`: stores the data.
- `next`: stores a reference to the next node in the list.
The first node is called the head of the list and the last node in a circular linked list points back to the first node, forming a circle. The list allows for efficient insertion and deletion of elements. However, accessing an element by its index requires traversing the list from the head to the desired position.
### Expected Interface
````java
public interface LinkedList {
int at(int index);
void add(int value);
void remove(int index);
int size();
}
### Expected Class
```java
public class CircularLinkedList implements LinkedList {
private Node head;
private class Node {
int value;
Node next;
Node(int value) {
this.value = value;
this.next = null;
}
}
@Override
public int at(int index) {
// Implementation for accessing an element by its index
}
@Override
public void add(int value) {
// Implementation for adding an element at the end of the list
}
@Override
public void remove(int index) {
// Implementation for removing an element by its index
}
@Override
public int size() {
// Implementation getting the size of the list
}
private Node next(Node node) {
// Print the message "Go to next node"
}
}
````
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
public class ExerciseRunner {
public static void main(String[] args) {
LinkedList list = new CircularLinkedList();
// Add elements to the list
list.add(1);
list.add(2);
list.add(3);
// Access elements by index
System.out.println("Element at index 0: " + list.at(0)); // Expected output: 1
System.out.println("Element at index 1: " + list.at(1)); // Expected output: 2
System.out.println("Element at index 2: " + list.at(2)); // Expected output: 3
// Remove an element by index
list.remove(1);
System.out.println("Element at index 1 after removal: " + list.at(1)); // Expected output: 3
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Go to next node
Element at index 0: 1
Go to next node
Element at index 1: 2
Go to next node
Go to next node
Element at index 2: 3
Go to next node
Go to next node
Element at index 1 after removal: 3
$
```

View File

@ -0,0 +1,23 @@
import java.util.List;
import java.util.Arrays;
public class ExerciseRunner {
public static void main(String[] args) {
ConfigProtector protector = new ConfigProtector();
// Test case 1
String configFile1 = "username=admin\npassword=secret\nhost=localhost\n";
List<String> sensitiveKeys1 = Arrays.asList("password");
System.out.println("Protected Config 1:\n" + protector.hideSensitiveData(configFile1, sensitiveKeys1));
// Test case 2
String configFile2 = "apiKey=12345\napiSecret=abcdef\nendpoint=https://api.example.com\n";
List<String> sensitiveKeys2 = Arrays.asList("apiKey", "apiSecret");
System.out.println("Protected Config 2:\n" + protector.hideSensitiveData(configFile2, sensitiveKeys2));
// Test case 3
String configFile3 = "username=user\npassword=pass\n";
List<String> sensitiveKeys3 = Arrays.asList("username", "password");
System.out.println("Protected Config 3:\n" + protector.hideSensitiveData(configFile3, sensitiveKeys3));
}
}

View File

@ -0,0 +1,75 @@
## Config Protector
### Instructions
Create a class `ConfigProtector` that provides a method to hide sensitive data in a configuration file using `Regex`. The method should replace sensitive values with asterisks. The configuration file will be provided as a `String`, and the keys for the sensitive data will be given in a `List`.
The config file format will always be as follows:
```
username=admin
npassword=secret
...
```
### Expected Class
```java
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ConfigProtector {
public String hideSensitiveData(String configFile, List<String> sensitiveKeys) {
// Implementation to hide sensitive data in the configuration file using regex
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
import java.util.List;
import java.util.Arrays;
public class ExerciseRunner {
public static void main(String[] args) {
ConfigProtector protector = new ConfigProtector();
String configFile1 = "username=admin\npassword=secret\nhost=localhost\n";
List<String> sensitiveKeys1 = Arrays.asList("password");
System.out.println("Protected Config 1:\n" + protector.hideSensitiveData(configFile1, sensitiveKeys1));
String configFile2 = "apiKey=12345\napiSecret=abcdef\nendpoint=https://api.example.com\n";
List<String> sensitiveKeys2 = Arrays.asList("apiKey", "apiSecret");
System.out.println("Protected Config 2:\n" + protector.hideSensitiveData(configFile2, sensitiveKeys2));
String configFile3 = "username=user\npassword=pass\n";
List<String> sensitiveKeys3 = Arrays.asList("username", "password");
System.out.println("Protected Config 3:\n" + protector.hideSensitiveData(configFile3, sensitiveKeys3));
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Protected Config 1:
username=admin
password=******
host=localhost
Protected Config 2:
apiKey=*****
apiSecret=******
endpoint=https://api.example.com
Protected Config 3:
username=****
password=****
$
```

View File

@ -0,0 +1,15 @@
public class ExerciseRunner {
public static void main(String[] args) {
DateFormatter df = new DateFormatter(1656374400, "DD/MM/YYYY");
System.out.println(df.getFormattedDate());
df.setFormat("dd.MM.yyyy");
System.out.println(df.getFormattedDate());
df.setDate(1672531200);
System.out.println(df.getFormattedDate());
df.setFormat("DD month yyyy");
System.out.println(df.getFormattedDate());
}
}

View File

@ -0,0 +1,70 @@
## Date Formatter
### Instructions
Write a class `DateFormatter` that has three private attributes:
- `date`: the date to be formatted (as a UNIX time in seconds).
- `format`: the format to convert the date to.
- `formattedDate`: contains the date converted into the given format(in the "UTC" Timezone).
Create getters for all the attributes and setters for `date` and `format`. The conversion should happen when you set the `format` or the `date`. If the `format` is not correct, the conversion shouldn't happen. Additionally, create methods to output the date in the specified `format`, and constructors with only the `date`, with `date` and `format`, and a default constructor.
The default date is the current date, and the format as follows `DD/MM/YYYY`. The format is case insensitive
> Using standard library to convert UNIX time to date and to get date component is allowed.
#### The accepted date formats are:
- `DD/MM/YYYY`
- `DD Month YYYY`
- `DD.MM.YYYY`
### Expected Functions
```java
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateFormatter {
private long date;
private String formattedDate;
private String format;
...
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
public class ExerciseRunner {
public static void main(String[] args) {
DateFormatter df = new DateFormatter(1656374400, "DD/MM/YYYY");
System.out.println(df.getFormattedDate());
df.setFormat("dd.MM.yyyy");
System.out.println(df.getFormattedDate());
df.setDate(1672531200);
System.out.println(df.getFormattedDate());
df.setFormat("DD month yyyy");
System.out.println(df.getFormattedDate());
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
28/06/2022
28.06.2022
31.12.2022
31 December 2022
$
```

View File

@ -0,0 +1,30 @@
public class ExerciseRunner {
public static void main(String[] args) {
DayOfWeekFinder finder = new DayOfWeek();
// Test case 1
String startDate1 = "2023-06-22";
String dayOfWeek1 = "Monday";
System.out.println("Next " + dayOfWeek1 + " after " + startDate1 + ": " + finder.findNextDayOfWeek(startDate1, dayOfWeek1)); // Expected output: 2023-06-26
// Test case 2
String startDate2 = "2023-06-22";
String dayOfWeek2 = "Friday";
System.out.println("Next " + dayOfWeek2 + " after " + startDate2 + ": " + finder.findNextDayOfWeek(startDate2, dayOfWeek2)); // Expected output: 2023-06-23
// Test case 3
String startDate3 = "2023-06-22";
String dayOfWeek3 = "Sunday";
System.out.println("Next " + dayOfWeek3 + " after " + startDate3 + ": " + finder.findNextDayOfWeek(startDate3, dayOfWeek3)); // Expected output: 2023-06-25
// Error case: invalid date format
String startDate4 = "invalid-date";
String dayOfWeek4 = "Monday";
System.out.println("Next " + dayOfWeek4 + " after " + startDate4 + ": " + finder.findNextDayOfWeek(startDate4, dayOfWeek4)); // Expected output: Error
// Error case: invalid day of the week
String startDate5 = "2023-06-22";
String dayOfWeek5 = "Funday";
System.out.println("Next " + dayOfWeek5 + " after " + startDate5 + ": " + finder.findNextDayOfWeek(startDate5, dayOfWeek5)); // Expected output: Error
}
}

View File

@ -0,0 +1,72 @@
## Day Of Week
### Instructions
Create a class `DayOfWeekFinder` that provides a method to find the date of the next specified day of the week from a given date. The date will be provided in the format `yyyy-MM-dd`, and the day of the week will be provided as a string (e.g., "Monday", "Tuesday").
You should return 'Error' in case of any error.
### Expected Class
```java
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
public class DayOfWeekFinder {
public String findNextDayOfWeek(String startDate, String dayOfWeek) {
...
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
public class ExerciseRunner {
public static void main(String[] args) {
DayOfWeekFinder finder = new DayOfWeekFinder();
// Test case 1
String startDate1 = "2023-06-22";
String dayOfWeek1 = "Monday";
System.out.println("Next " + dayOfWeek1 + " after " + startDate1 + ": " + finder.findNextDayOfWeek(startDate1, dayOfWeek1));
// Test case 2
String startDate2 = "2023-06-22";
String dayOfWeek2 = "Friday";
System.out.println("Next " + dayOfWeek2 + " after " + startDate2 + ": " + finder.findNextDayOfWeek(startDate2, dayOfWeek2));
// Test case 3
String startDate3 = "2023-06-22";
String dayOfWeek3 = "Sunday";
System.out.println("Next " + dayOfWeek3 + " after " + startDate3 + ": " + finder.findNextDayOfWeek(startDate3, dayOfWeek3));
// Error case: invalid date format
String startDate4 = "invalid-date";
String dayOfWeek4 = "Monday";
System.out.println("Next " + dayOfWeek4 + " after " + startDate4 + ": " + finder.findNextDayOfWeek(startDate4, dayOfWeek4));
// Error case: invalid day of the week
String startDate5 = "2023-06-22";
String dayOfWeek5 = "Funday";
System.out.println("Next " + dayOfWeek5 + " after " + startDate5 + ": " + finder.findNextDayOfWeek(startDate5, dayOfWeek5));
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Next Monday after 2023-06-22: 2023-06-26
Next Friday after 2023-06-22: 2023-06-23
Next Sunday after 2023-06-22: 2023-06-25
Next Monday after invalid-date: Error
Next Funday after 2023-06-22: Error
$
```

View File

@ -0,0 +1,29 @@
public class ExerciseRunner {
public static void main(String[] args) {
LinkedList list = new DoubleLinkedList();
// Add elements to the list
list.add(1);
list.add(2);
list.add(3);
// Access elements by index
System.out.println("Element at index 0: " + list.at(0)); // Expected output: 1
System.out.println("Element at index 1: " + list.at(1)); // Expected output: 2
System.out.println("Element at index 2: " + list.at(2)); // Expected output: 3
list.add(4);
// Access elements by index
System.out.println("Element at index 0: " + list.at(0)); // Expected output: 1
System.out.println("Element at index 1: " + list.at(1)); // Expected output: 2
System.out.println("Element at index 2: " + list.at(2)); // Expected output: 3
System.out.println("Element at index 3: " + list.at(3)); // Expected output: 4
// Remove an element by index
list.remove(1);
list.remove(2);
System.out.println("List size : " + list.size()); // Expected output: 2
System.out.println("Element at index 1 after removal: " + list.at(1)); // Expected output: 3
}
}

View File

@ -0,0 +1,6 @@
public interface LinkedList {
int at(int index);
void add(int value);
void remove(int index);
int size();
}

View File

@ -0,0 +1,135 @@
## Double Linked List
### Instructions
Create a double linked list data structure that implements the following methods:
- `at(int index)`: to access an element by its index. If the index is out of bound return -1.
- `add(int value)`: to add an element at the end of the list.
- `remove(int index)`: to remove an element by its index. If the index is out of bound nothing happen.
- `size()`: to get the size of the list.
Define these methods in an interface called `LinkedList`, and implement this interface in a class that you will create. Additionally, add private methods `next(Node node)` and `prev(Node node)` in your class that will be used in the other methods. These methods should print the messages "Go to next node\n" and "Go to previous node\n" each time they are called, respectively.
### Explanation
A double linked list is a linear data structure where each element is a separate object called a node. Each node contains three fields:
- `value`: stores the data.
- `next`: stores a reference to the next node in the list.
- `prev`: stores a reference to the previous node in the list.
The first node is called the head of the list and the last node always has next pointing to null. The list allows for efficient insertion and deletion of elements. However, accessing an element by its index requires traversing the list from the head to the desired position.
### Given Interface
```java
public interface LinkedList {
int at(int index);
void add(int value);
void remove(int index);
int size();
}
```
### Expected Class
```java
public class DoubleLinkedList implements LinkedList {
private Node head;
private Node tail;
private class Node {
int value;
Node next;
Node prev;
...
}
@Override
public int at(int index) {
// Implementation for accessing an element by its index
}
@Override
public void add(int value) {
// Implementation for adding an element at the end of the list
}
@Override
public void remove(int index) {
// Implementation for removing an element by its index
}
@Override
public int size() {
// Implementation for getting the size of the list
}
private Node next(Node node) {
// Implementation for going to the next
}
private Node prev(Node node) {
// Implementation for going to the prev
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
public class ExerciseRunner {
public static void main(String[] args) {
LinkedList list = new DoubleLinkedList();
// Add elements to the list
list.add(1);
list.add(2);
list.add(3);
// Access elements by index
System.out.println("Element at index 0: " + list.at(0)); // Expected output: 1
System.out.println("Element at index 1: " + list.at(1)); // Expected output: 2
System.out.println("Element at index 2: " + list.at(2)); // Expected output: 3
list.add(4);
// Access elements by index
System.out.println("Element at index 0: " + list.at(0)); // Expected output: 1
System.out.println("Element at index 1: " + list.at(1)); // Expected output: 2
System.out.println("Element at index 2: " + list.at(2)); // Expected output: 3
System.out.println("Element at index 3: " + list.at(3)); // Expected output: 4
// Remove an element by index
list.remove(1);
list.remove(2);
System.out.println("List size : " + list.size()); // Expected output: 2
System.out.println("Element at index 1 after removal: " + list.at(1)); // Expected output: 3
}
}
```
### Expected Output
```java
$ javac *.java -d build
$ java -cp build ExerciseRunner
Element at index 0: 1
Go to next node
Element at index 1: 2
Element at index 2: 3
Element at index 0: 1
Go to next node
Element at index 1: 2
Go to previous node
Element at index 2: 3
Element at index 3: 4
Go to next node
List size : 2
Element at index 1 after removal: 3
$
```

View File

@ -0,0 +1,15 @@
public class ExerciseRunner {
public static void main(String[] args) {
Factorial iterativeFactorial = new IterativeFactorial();
Factorial recursiveFactorial = new RecursiveFactorial();
// Test iterative factorial
int number = 5;
long iterativeResult = iterativeFactorial.calculate(number);
System.out.println("Iterative Factorial of " + number + " is: " + iterativeResult); // Expected output: 120
// Test recursive factorial
long recursiveResult = recursiveFactorial.calculate(number);
System.out.println("Recursive Factorial of " + number + " is: " + recursiveResult); // Expected output: 120
}
}

View File

@ -0,0 +1,73 @@
## Factorial Master
### Instructions
Create an abstract class `Factorial` that will serve as the base class for calculating the factorial of a number. This class should have an abstract method `calculate` that will be implemented by its child classes.
Implement two child classes:
- `IterativeFactorial` which implements the factorial calculation using an iterative approach.
- `RecursiveFactorial` which implements the factorial calculation using a recursive approach.
> Note: The factorial of 0 is 1, according to the [convention](https://www.chilimath.com/lessons/intermediate-algebra/zero-factorial/)
#### Formula for factorial calculation:
n! = n × (n1) × (n2) ×× 1
And an example:
5! = 5 × 4 × 3 × 2 × 1 = 120
### Expected Abstract Class
```java
public abstract class Factorial {
public abstract long calculate(int n);
}
public class IterativeFactorial extends Factorial {
@Override
public long calculate(int n) {
// iterative factorial calculation
}
}
public class RecursiveFactorial extends Factorial {
@Override
public long calculate(int n) {
// recursive factorial calculation
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your classes:
```java
public class ExerciseRunner {
public static void main(String[] args) {
Factorial iterativeFactorial = new IterativeFactorial();
Factorial recursiveFactorial = new RecursiveFactorial();
// Test iterative factorial
int number = 5;
long iterativeResult = iterativeFactorial.calculate(number);
System.out.println("Iterative Factorial of " + number + " is: " + iterativeResult); // Expected output: 120
// Test recursive factorial
long recursiveResult = recursiveFactorial.calculate(number);
System.out.println("Recursive Factorial of " + number + " is: " + recursiveResult); // Expected output: 120
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Iterative Factorial of 5 is: 120
Recursive Factorial of 5 is: 120
$
```

View File

@ -0,0 +1,26 @@
public class ExerciseRunner {
public static void main(String[] args) {
Factory factory = new Factory();
ConcreteProductA productA = factory.createProduct("A");
if (productA != null) {
productA.showDetails();
} else {
System.out.println("Invalid product type");
}
ConcreteProductA productB = factory.createProduct("B");
if (productB != null) {
productB.showDetails();
} else {
System.out.println("Invalid product type");
}
Object invalidProduct = factory.createProduct("C");
if (invalidProduct != null) {
invalidProduct.showDetails();
} else {
System.out.println("Invalid product type");
}
}
}

View File

@ -0,0 +1,75 @@
## Factory Blueprint
### Instructions
You are given an incomplete Factory design pattern implementation with some incorrect parts. Complete and fix the class to demonstrate your understanding of how the Factory design pattern works.
### Expected Classes
```java
// Product interface
public interface Product {
void showDetails();
}
// ConcreteProductA class
public class ConcreteProductA {
...
}
// ConcreteProductB class
public class ConcreteProductB {
...
}
// Factory class
public class Factory {
public Product createProduct(String type) {
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your classes:
```java
public class ExerciseRunner {
public static void main(String[] args) {
Factory factory = new Factory();
ConcreteProductA productA = factory.createProduct("A");
if (productA != null) {
productA.showDetails();
} else {
System.out.println("Invalid product type");
}
ConcreteProductA productB = factory.createProduct("B");
if (productB != null) {
productB.showDetails();
} else {
System.out.println("Invalid product type");
}
Object invalidProduct = factory.createProduct("C");
if (invalidProduct != null) {
invalidProduct.showDetails();
} else {
System.out.println("Invalid product type");
}
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
This is ConcreteProductA.
This is ConcreteProductB.
Invalid product type
$
```

View File

@ -0,0 +1,19 @@
import java.util.Arrays;
public class ExerciseRunner {
public static void main(String[] args) {
HarmoniousFusion merger = new HarmoniousFusion();
// Test case 1
int[] arr1 = {1, 3, 5};
int[] arr2 = {2, 4, 6};
int[] mergedArray = merger.merge(arr1, arr2);
System.out.println(Arrays.toString(mergedArray)); // Expected output: [1, 2, 3, 4, 5, 6]
// Test case 2
int[] arr3 = {1, 3, 5, 7};
int[] arr4 = {2, 4, 6};
mergedArray = merger.merge(arr3, arr4);
System.out.println(Arrays.toString(mergedArray)); // Expected output: [1, 2, 3, 4, 5, 6, 7]
}
}

View File

@ -0,0 +1,51 @@
## Harmonious Fusion
### Instructions
Create a class `HarmoniousFusion` that provides a method to merge two sorted arrays into one sorted array. The merged array should also be sorted.
### Expected Class
```java
public class HarmoniousFusion {
public int[] merge(int[] arr1, int[] arr2) {
// Implementation to merge two sorted arrays into one sorted array
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
import java.util.Arrays;
public class ExerciseRunner {
public static void main(String[] args) {
HarmoniousFusion merger = new HarmoniousFusion();
// Test case 1
int[] arr1 = {1, 3, 5};
int[] arr2 = {2, 4, 6};
int[] mergedArray = merger.merge(arr1, arr2);
System.out.println(Arrays.toString(mergedArray)); // Expected output: [1, 2, 3, 4, 5, 6]
// Test case 2
int[] arr3 = {1, 3, 5, 7};
int[] arr4 = {2, 4, 6};
mergedArray = merger.merge(arr3, arr4);
System.out.println(Arrays.toString(mergedArray)); // Expected output: [1, 2, 3, 4, 5, 6, 7]
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6, 7]
$
```

View File

@ -0,0 +1,11 @@
public class ExerciseRunner {
public static void main(String[] args) {
AnagramChecker checker = new AnagramChecker();
// Test cases
System.out.println(checker.isAnagram("listen", "silent")); // Expected output: true
System.out.println(checker.isAnagram("triangle", "integral")); // Expected output: true
System.out.println(checker.isAnagram("apple", "pale")); // Expected output: false
System.out.println(checker.isAnagram("Astronomer", "Moon starer")); // Expected output: true
}
}

View File

@ -0,0 +1,45 @@
## Is Anagram
### Instructions
Create a class `AnagramChecker` that provides a method to check if two strings are anagrams. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.The comparison should be case insensitive.
### Expected Class
```java
public class AnagramChecker {
public boolean isAnagram(String str1, String str2) {
// Implementation to check if str1 and str2 are anagrams
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
public class ExerciseRunner {
public static void main(String[] args) {
AnagramChecker checker = new AnagramChecker();
// Test cases
System.out.println(checker.isAnagram("listen", "silent"));
System.out.println(checker.isAnagram("triangle", "integral"));
System.out.println(checker.isAnagram("apple", "pale"));
System.out.println(checker.isAnagram("Astronomer", "Moon starer"));
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
true
true
false
false
$
```

View File

@ -0,0 +1,27 @@
public class ExerciseRunner {
public static void main(String[] args) {
MaximalSquare finder = new MaximalSquare();
// Test case 1
char[][] matrix1 = {
{'1', '0', '1', '0', '0'},
{'1', '0', '1', '1', '1'},
{'1', '1', '1', '1', '1'},
{'1', '0', '0', '1', '0'}
};
System.out.println("Maximal square area: " + finder.maximalSquare(matrix1)); // Expected output: 4
// Test case 2
char[][] matrix2 = {
{'0', '1'},
{'1', '0'}
};
System.out.println("Maximal square area: " + finder.maximalSquare(matrix2)); // Expected output: 1
// Test case 3
char[][] matrix3 = {
{'0'}
};
System.out.println("Maximal square area: " + finder.maximalSquare(matrix3)); // Expected output: 0
}
}

View File

@ -0,0 +1,60 @@
## Maximal Square
### Instructions
Create a class `MaximalSquare` that provides a method to find the area of the largest square containing only 1's in a given 2D binary matrix.
### Expected Class
```java
public class MaximalSquare {
public int maximalSquare(char[][] matrix) {
// Implementation to find the area of the largest square containing only 1's
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
public class ExerciseRunner {
public static void main(String[] args) {
MaximalSquare finder = new MaximalSquare();
// Test case 1
char[][] matrix1 = {
{'1', '0', '1', '0', '0'},
{'1', '0', '1', '1', '1'},
{'1', '1', '1', '1', '1'},
{'1', '0', '0', '1', '0'}
};
System.out.println("Maximal square area: " + finder.maximalSquare(matrix1)); // Expected output: 4
// Test case 2
char[][] matrix2 = {
{'0', '1'},
{'1', '0'}
};
System.out.println("Maximal square area: " + finder.maximalSquare(matrix2)); // Expected output: 1
// Test case 3
char[][] matrix3 = {
{'0'}
};
System.out.println("Maximal square area: " + finder.maximalSquare(matrix3)); // Expected output: 0
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Maximal square area: 4
Maximal square area: 1
Maximal square area: 0
$
```

View File

@ -0,0 +1,25 @@
public class ExerciseRunner {
public static void main(String[] args) {
MonthlyPeriod MonthlyPeriod = new MonthlyPeriod();
String startDate1 = "2020-01-01";
String endDate1 = "2023-06-15";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate1, endDate1));
String startDate2 = "2015-05-20";
String endDate2 = "2015-10-19";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate2, endDate2));
String startDate3 = "2015-05-20";
String endDate3 = "2015-10-19";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate3, endDate3));
String startDate4 = "2018-12-25";
String endDate4 = "2021-12-25";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate4, endDate4));
String startDate5 = "2018-10-25";
String endDate5 = "2019-11-30";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate5, endDate5));
}
}

View File

@ -0,0 +1,68 @@
## Monthly Period
### Instructions
Create a class `MonthlyPeriod` that provides a method to calculate the period between two given dates in terms of months and years. The dates will be provided in the format `yyyy-MM-dd`.
In case of any error the method `calculatePeriod` should return `Error`
> 💡 Going to the past is possible!
### Expected Class
```java
import java.time.LocalDate;
import java.time.Period;
import java.time.format.DateTimeFormatter;
public class MonthlyPeriod {
public String calculatePeriod(String startDate, String endDate) {
// Implementation to calculate the period between two dates in months and years
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
public class ExerciseRunner {
public static void main(String[] args) {
MonthlyPeriod MonthlyPeriod = new MonthlyPeriod();
String startDate1 = "2020-01-01";
String endDate1 = "2023-06-15";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate1, endDate1));
String startDate2 = "2015-05-20";
String endDate2 = "2015-10-19";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate2, endDate2));
String startDate3 = "2015-05-20";
String endDate3 = "2015-10-19";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate3, endDate3));
String startDate4 = "2018-12-25";
String endDate4 = "2021-12-25";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate4, endDate4));
String startDate5 = "2018-10-25";
String endDate5 = "2019-11-30";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate5, endDate5));
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Period: 3 years and 5 months
Period: 4 months
Period: 5 months
Period: 3 years
Period: 1 year and 1 month
$
```

View File

@ -0,0 +1,14 @@
public class ExerciseRunner {
public static void main(String[] args) {
PerfectNumber perfectNumber = new PerfectNumber();
int number1 = 6;
System.out.println("Is " + number1 + " a perfect number? " + perfectNumber.isPerfectNumber(number1));
int number2 = 28;
System.out.println("Is " + number2 + " a perfect number? " + perfectNumber.isPerfectNumber(number2));
int number3 = 12;
System.out.println("Is " + number3 + " a perfect number? " + perfectNumber.isPerfectNumber(number3));
}
}

View File

@ -0,0 +1,47 @@
## Perfect Number
### Instructions
Write a program to check if a given number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper positive divisors, excluding itself.
### Expected Class
```java
public class PerfectNumber {
public boolean isPerfectNumber(int number) {
// Implementation to check if the given number is a perfect number
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
public class ExerciseRunner {
public static void main(String[] args) {
PerfectNumber perfectNumber = new PerfectNumber();
int number1 = 6;
System.out.println("Is " + number1 + " a perfect number? " + perfectNumber.isPerfectNumber(number1));
int number2 = 28;
System.out.println("Is " + number2 + " a perfect number? " + perfectNumber.isPerfectNumber(number2));
int number3 = 12;
System.out.println("Is " + number3 + " a perfect number? " + perfectNumber.isPerfectNumber(number3));
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Is 6 a perfect number? true
Is 28 a perfect number? true
Is 12 a perfect number? false
$
```

View File

@ -0,0 +1,6 @@
public interface LinkedList {
int at(int index);
void add(int value);
void remove(int index);
int size();
}

View File

@ -0,0 +1,5 @@
public class ExerciseRunner {
public static void main(String[] args) {
System.out.println(Singleton.get???().whoAreYou());
}
}

View File

@ -0,0 +1,44 @@
## Singleton Blueprint
### Instructions
You are given an incomplete `Singleton` class. Complete the class to demonstrate your understanding of how the `Singleton` design pattern works. The `Singleton` pattern ensures that a class has only one instance and provides a global point of access to that instance.
### Expected Class
```java
public class Singleton {
public Singleton instance;
private Singleton() {
}
public Singleton get???() {
}
public String whoAreYou() {
return "Hello, I am a singleton!"
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
public class ExerciseRunner {
public static void main(String[] args) {
System.out.println(Singleton.get???().whoAreYou());
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Hello, I am a singleton!
$
```

View File

@ -0,0 +1,23 @@
import java.util.Arrays;
public class ExerciseRunner {
public static void main(String[] args) {
SpiralMatrix spiralMatrix = new SpiralMatrix();
// Test case 1
int n1 = 3;
int[][] matrix1 = spiralMatrix.generateMatrix(n1);
System.out.println("Spiral matrix for n = " + n1 + ":");
for (int[] row : matrix1) {
System.out.println(Arrays.toString(row));
}
// Test case 2
int n2 = 4;
int[][] matrix2 = spiralMatrix.generateMatrix(n2);
System.out.println("Spiral matrix for n = " + n2 + ":");
for (int[] row : matrix2) {
System.out.println(Arrays.toString(row));
}
}
}

View File

@ -0,0 +1,63 @@
## Spiral Matrix
### Instructions
Create a class `SpiralMatrix` that provides a method to generate a matrix filled with elements from 1 to n\*n in spiral order, given an integer n where n > 0.
### Expected Class
```java
public class SpiralMatrix {
public int[][] generateMatrix(int n) {
// Implementation to generate a spiral matrix
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
import java.util.Arrays;
public class ExerciseRunner {
public static void main(String[] args) {
SpiralMatrix spiralMatrix = new SpiralMatrix();
// Test case 1
int n1 = 3;
int[][] matrix1 = spiralMatrix.generateMatrix(n1);
System.out.println("Spiral matrix for n = " + n1 + ":");
for (int[] row : matrix1) {
System.out.println(Arrays.toString(row));
}
// Test case 2
int n2 = 4;
int[][] matrix2 = spiralMatrix.generateMatrix(n2);
System.out.println("Spiral matrix for n = " + n2 + ":");
for (int[] row : matrix2) {
System.out.println(Arrays.toString(row));
}
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Spiral matrix for n = 3:
[1, 2, 3]
[8, 9, 4]
[7, 6, 5]
Spiral matrix for n = 4:
[1, 2, 3, 4]
[12, 13, 14, 5]
[11, 16, 15, 6]
[10, 9, 8, 7]
$
```

View File

@ -0,0 +1,19 @@
public class ExerciseRunner {
public static void main(String[] args) {
// Example of a very short project
ProjectTime shortProject = new ProjectTime("2023-05-14 09:00", "2023-05-14 09:30");
System.out.println("Short Project Total Logged Time: " + shortProject.getHoursLogged()); // Should be "30 m"
// Example of an overnight project
ProjectTime overnightProject = new ProjectTime("2023-05-14 20:00", "2023-05-15 08:00");
System.out.println("Overnight Project Total Logged Time: " + overnightProject.getHoursLogged()); // Should be "12 h"
// Example of a full day project
ProjectTime fullDayProject = new ProjectTime("2023-05-14 00:00", "2023-05-15 00:00");
System.out.println("Full Day Project Total Logged Time: " + fullDayProject.getHoursLogged()); // Should be "24 h"
// Example with incorrect format
ProjectTime errorProject = new ProjectTime("2023-05-14", "2023-05-15 08:00");
System.out.println("Error Project Total Logged Time: " + errorProject.getHoursLogged()); // Should handle error or indicate incorrect format
}
}

View File

@ -0,0 +1,73 @@
## TimeTracker
### Instructions
Write a `ProjectTime` class to track the duration of a project using start and end times. You will be asked to add getter and setter methods for the `startTime` and `endTime` attributes. When you set one of them, you must update the `hoursLogged` attribute. The `hoursLogged` getter should output the hours in the following format:
- Less than 120 minutes: `hoursLogged` m
- Less than 120 hours: `hoursLogged` h
- Less than 120 days: `hoursLogged` d
- More than 120 days: `hoursLogged` mo
If there is any error, the number of `hoursLogged` should be handled accordingly.
> 💡 The `hoursLogged` shouldn't be a negative number except -1 in case of errors.
### Expected Functions
```java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ProjectTime {
private String startTime;
private String endTime;
private float hoursLogged;
public ProjectTime(String start, String end);
public void setStartTime();
public void setEndTime();
public String getStartTime();
public String getEndTime();
public String getHoursLogged();
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your function :
```java
public class ExerciseRunner {
public static void main(String[] args) {
ProjectTime shortProject = new ProjectTime("2023-05-14 09:00", "2023-05-14 09:30");
System.out.println("Short Project Total Logged Time: " + shortProject.getHoursLogged());
ProjectTime overnightProject = new ProjectTime("2023-05-14 20:00", "2023-05-15 08:00");
System.out.println("Overnight Project Total Logged Time: " + overnightProject.getHoursLogged());
ProjectTime fullDayProject = new ProjectTime("2023-05-14 00:00", "2023-05-15 00:00");
System.out.println("Full Day Project Total Logged Time: " + fullDayProject.getHoursLogged());
ProjectTime errorProject = new ProjectTime("2023-05-14", "2023-05-15 08:00");
System.out.println("Error Project Total Logged Time: " + errorProject.getHoursLogged());
}
}
```
and its output :
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Short Project Total Logged Time: 30 m
Overnight Project Total Logged Time: 12 h
Full Day Project Total Logged Time: 24 h
Error Project Total Logged Time: -1
$
```

View File

@ -0,0 +1,10 @@
public class ExerciseRunner {
public static void main(String[] args) {
TodoList myList = new TodoList(3); // List can hold up to 3 tasks
myList.addTask("Go grocery shopping");
myList.addTask("Pay electricity bill");
myList.setStatus(0, TaskStatus.COMPLETED); // Mark the first task as completed
myList.setDescription(1, "Pay all utility bills"); // Update the description of the second task
myList.displayTasks(); // Display the list of tasks
}
}

View File

@ -0,0 +1,70 @@
## TodoList
### Instructions
Write a class `Task` that has two attributes: `description` and `status`, with the corresponding getters and setters.
Write a class called `TodoList` that represents a to-do list. The class should be able to hold a specified number of tasks, each with a description and a status. Include methods to add tasks, set a task's status, update task descriptions, and display all tasks in a neat format showing their descriptions and statuses.
If the index is out of bound nothing happens.
> The description length will be less or equal to 30 character. When the list is full nothing more will be added.
### Expected Functions
```java
enum TaskStatus {
NEW, IN_PROGRESS, COMPLETED
}
public class Task {
private String description;
private TaskStatus status;
public void setDescription(String description);
// Getters and Setters
// ...
}
public class TodoList {
private Task[] tasks;
private int capacity;
public TodoList(int capacity);
public void addTask(String description);
public void setStatus(int index, TaskStatus status);
public void setDescription(int index, String newDescription);
public void displayTasks();
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your `TodoList` class:
```java
public class ExerciseRunner {
public static void main(String[] args) {
TodoList myList = new TodoList(3); // List can hold up to 3 tasks
myList.addTask("Go grocery shopping");
myList.addTask("Pay electricity bill");
myList.setStatus(0, TaskStatus.COMPLETED); // Mark the first task as completed
myList.setDescription(1, "Pay all utility bills"); // Update the description of the second task
myList.displayTasks(); // Display the list of tasks
}
}
```
and its output:
```shell
$ javac TaskList.java ExerciseRunner.java
$ java ExerciseRunner.java
Tasks:
Go grocery shopping | COMPLETED
Pay all utility bills | NEW
```

View File

@ -0,0 +1,33 @@
public class ExerciseRunner {
public static void main(String[] args) {
ValidSudoku validSudoku = new ValidSudoku();
// Test case 1
char[][] board1 = {
{'5', '3', '.', '.', '7', '.', '.', '.', '.'},
{'6', '.', '.', '1', '9', '5', '.', '.', '.'},
{'.', '9', '8', '.', '.', '.', '.', '6', '.'},
{'8', '.', '.', '.', '6', '.', '.', '.', '3'},
{'4', '.', '.', '8', '.', '3', '.', '.', '1'},
{'7', '.', '.', '.', '2', '.', '.', '.', '6'},
{'.', '6', '.', '.', '.', '.', '2', '8', '.'},
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}
};
System.out.println("Is board1 valid? " + validSudoku.isValidSudoku(board1)); // Expected output: true
// Test case 2
char[][] board2 = {
{'8', '3', '.', '.', '7', '.', '.', '.', '.'},
{'6', '.', '.', '1', '9', '5', '.', '.', '.'},
{'.', '9', '8', '.', '.', '.', '.', '6', '.'},
{'8', '.', '.', '.', '6', '.', '.', '.', '3'},
{'4', '.', '.', '8', '.', '3', '.', '.', '1'},
{'7', '.', '.', '.', '2', '.', '.', '.', '6'},
{'.', '6', '.', '.', '.', '.', '2', '8', '.'},
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}
};
System.out.println("Is board2 valid? " + validSudoku.isValidSudoku(board2)); // Expected output: false
}
}

View File

@ -0,0 +1,71 @@
## Valid Sudoku
### Instructions
Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:
1. Each row must contain the digits 1-9 without repetition.
2. Each column must contain the digits 1-9 without repetition.
3. Each of the nine 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition.
The Sudoku board could be partially filled, where empty cells are filled with the character '.'.
### Expected Class
```java
public class ValidSudoku {
public boolean isValidSudoku(char[][] board) {
// Implementation to determine if the Sudoku board is valid
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
public class ExerciseRunner {
public static void main(String[] args) {
ValidSudoku validSudoku = new ValidSudoku();
// Test case 1
char[][] board1 = {
{'5', '3', '.', '.', '7', '.', '.', '.', '.'},
{'6', '.', '.', '1', '9', '5', '.', '.', '.'},
{'.', '9', '8', '.', '.', '.', '.', '6', '.'},
{'8', '.', '.', '.', '6', '.', '.', '.', '3'},
{'4', '.', '.', '8', '.', '3', '.', '.', '1'},
{'7', '.', '.', '.', '2', '.', '.', '.', '6'},
{'.', '6', '.', '.', '.', '.', '2', '8', '.'},
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}
};
System.out.println("Is board1 valid? " + validSudoku.isValidSudoku(board1)); // Expected output: true
// Test case 2
char[][] board2 = {
{'8', '3', '.', '.', '7', '.', '.', '.', '.'},
{'6', '.', '.', '1', '9', '5', '.', '.', '.'},
{'.', '9', '8', '.', '.', '.', '.', '6', '.'},
{'8', '.', '.', '.', '6', '.', '.', '.', '3'},
{'4', '.', '.', '8', '.', '3', '.', '.', '1'},
{'7', '.', '.', '.', '2', '.', '.', '.', '6'},
{'.', '6', '.', '.', '.', '.', '2', '8', '.'},
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}
};
System.out.println("Is board2 valid? " + validSudoku.isValidSudoku(board2)); // Expected output: false
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Is board1 valid? true
Is board2 valid? false
$
```

View File

@ -2,7 +2,7 @@
### Instructions
Write a function that takes a `string` as an argument and returns the letter `G` followed by a newline `\n` if the argument length is more than 3, otherwise returns `Invalid Input` followed by a newline `\n`.
Write a function that takes a `string` as an argument and returns the letter `G` followed by a newline `\n` if the argument length is more or equal than 3, otherwise returns `Invalid Input` followed by a newline `\n`.
- If it's an empty string return `G` followed by a newline `\n`.
@ -39,7 +39,7 @@ And its output:
```console
$ go run . | cat -e
G$
Invalid Output$
G$
Invalid Output$
G$
Invalid Input$
```

View File

@ -37,8 +37,8 @@ And its output:
```console
$ go run . | cat -e
Invalid Output$
Invalid Output$
Invalid Input$
Invalid Input$
G$
G$
```

View File

@ -7,6 +7,7 @@ Implement the struct `Color` with the associated function `swap`. This function
### Expected functions
```rust
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Color {
pub r: u8,
pub g: u8,

View File

@ -1,6 +1,6 @@
#### Sudoku
> ***NOTE: If you are an admin and you want to test this project, follow the instructions [in the this subject](https://github.com/01-edu/go-tests/blob/master/raid-testing.md) before you proceed to the questions.***
> **_NOTE: If you are an admin and you want to test this project, follow the instructions [in the this subject](https://github.com/01-edu/go-tests/blob/master/raid-testing.md) before you proceed to the questions._**
##### Open the repository of the project and check the submitted files
@ -38,7 +38,7 @@
###### Does the program returns the value above?
##### Try running the program with the arguments: `""..5.3..81" "9.285..6." "6....4.5." "..74.283." "34976...5" "..83..49." "15..87..2" ".9....6.." ".26.495.3""`
##### Try running the program with the arguments: `"..5.3..81" "9.285..6." "6....4.5." "..74.283." "34976...5" "..83..49." "15..87..2" ".9....6.." ".26.495.3"`
```
4 7 5 9 3 6 2 8 1