-
-
Notifications
You must be signed in to change notification settings - Fork 6
Add eliuds eggs #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add eliuds eggs #79
Changes from all commits
083c4cd
e205d16
577d044
4644b76
aa44bd9
3d891d2
53cbe5e
1cbb68d
558baee
e1c2e2f
b7eb906
0e605c5
91f2ec9
8dfd6a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,6 +114,19 @@ | |
| ], | ||
| "difficulty": 1 | ||
| }, | ||
| { | ||
| "slug": "eliuds-eggs", | ||
| "name": "Eliuds Eggs", | ||
| "uuid": "0875c5f0-8336-494b-b32a-b9d789d32ea7", | ||
| "practices": [ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bitwise isn't so I removed it, but loops, numbers, and basics are, or so it seems |
||
| "loops", | ||
| "numbers" | ||
| ], | ||
| "prerequisites": [ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| "basics" | ||
| ], | ||
| "difficulty": 1 | ||
| }, | ||
| { | ||
| "slug": "darts", | ||
| "name": "Darts", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Instructions | ||
|
|
||
| Your task is to count the number of 1 bits in the binary representation of a number. | ||
|
|
||
| ## Restrictions | ||
|
|
||
| Keep your hands off that bit-count functionality provided by your standard library! | ||
| Solve this one yourself using other basic tools instead. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Introduction | ||
|
|
||
| Your friend Eliud inherited a farm from her grandma Tigist. | ||
| Her granny was an inventor and had a tendency to build things in an overly complicated manner. | ||
| The chicken coop has a digital display showing an encoded number representing the positions of all eggs that could be picked up. | ||
|
|
||
| Eliud is asking you to write a program that shows the actual number of eggs in the coop. | ||
|
|
||
| The position information encoding is calculated as follows: | ||
|
|
||
| 1. Scan the potential egg-laying spots and mark down a `1` for an existing egg or a `0` for an empty spot. | ||
| 2. Convert the number from binary to decimal. | ||
| 3. Show the result on the display. | ||
|
|
||
| ## Example 1 | ||
|
|
||
|  | ||
|
|
||
| ```text | ||
| _ _ _ _ _ _ _ | ||
| |E| |E|E| | |E| | ||
| ``` | ||
|
|
||
| ### Resulting Binary | ||
|
|
||
|  | ||
|
|
||
| ```text | ||
| _ _ _ _ _ _ _ | ||
| |1|0|1|1|0|0|1| | ||
| ``` | ||
|
|
||
| ### Decimal number on the display | ||
|
|
||
| 89 | ||
|
|
||
| ### Actual eggs in the coop | ||
|
|
||
| 4 | ||
|
|
||
| ## Example 2 | ||
|
|
||
|  | ||
|
|
||
| ```text | ||
| _ _ _ _ _ _ _ | ||
| | | | |E| | | | | ||
| ``` | ||
|
|
||
| ### Resulting Binary | ||
|
|
||
|  | ||
|
|
||
| ```text | ||
| _ _ _ _ _ _ _ | ||
| |0|0|0|1|0|0|0| | ||
| ``` | ||
|
|
||
| ### Decimal number on the display | ||
|
|
||
| 8 | ||
|
|
||
| ### Actual eggs in the coop | ||
|
|
||
| 1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| @echo off | ||
| setlocal enabledelayedexpansion | ||
|
|
||
| set /a n=%~1 | ||
| set /a count=0 | ||
|
|
||
| :loop | ||
| if %n% EQU 0 goto :done | ||
| set /a bit=n %% 2 | ||
| set /a count+=bit | ||
| set /a n=n/2 | ||
| goto :loop | ||
|
|
||
| :done | ||
| echo %count% |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "authors": [ | ||
| "nastamattina" | ||
| ], | ||
| "files": { | ||
| "solution": [ | ||
| "EliudsEggs.bat" | ||
| ], | ||
| "test": [ | ||
| "EliudsEggsTest.bat" | ||
| ], | ||
| "example": [ | ||
| ".meta/Example.bat" | ||
| ] | ||
| }, | ||
| "blurb": "Help Eliud count the number of eggs in her chicken coop by counting the number of 1 bits in a binary representation.", | ||
| "source": "Christian Willner, Eric Willigers", | ||
| "source_url": "https://forum.exercism.org/t/new-exercise-suggestion-pop-count/7632/5" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # This is an auto-generated file. | ||
| # | ||
| # Regenerating this file via `configlet sync` will: | ||
| # - Recreate every `description` key/value pair | ||
| # - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
| # - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
| # - Preserve any other key/value pair | ||
| # | ||
| # As user-added comments (using the # character) will be removed when this file | ||
| # is regenerated, comments can be added via a `comment` key. | ||
|
|
||
| [559e789d-07d1-4422-9004-3b699f83bca3] | ||
| description = "0 eggs" | ||
|
|
||
| [97223282-f71e-490c-92f0-b3ec9e275aba] | ||
| description = "1 egg" | ||
|
|
||
| [1f8fd18f-26e9-4144-9a0e-57cdfc4f4ff5] | ||
| description = "4 eggs" | ||
|
|
||
| [0c18be92-a498-4ef2-bcbb-28ac4b06cb81] | ||
| description = "13 eggs" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| @echo off | ||
| setlocal enabledelayedexpansion | ||
|
|
||
| set /a n=%~1 | ||
| set "result=" | ||
|
|
||
| REM Your code goes here | ||
|
|
||
|
|
||
| echo %result% |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| @echo off | ||
| setlocal enabledelayedexpansion | ||
| REM --------------------------------------------------- | ||
| REM EliudsEggs Unit Testing | ||
| REM | ||
| REM sUnit Testing Framework version: 0.3 | ||
| REM --------------------------------------------------- | ||
|
|
||
| set isTestRunner=false | ||
| if "%1" == "test-runner" ( | ||
| set isTestRunner=true | ||
| ) | ||
|
|
||
| set "successCount=0" | ||
| set "failCount=0" | ||
|
|
||
| :Main | ||
| REM Initalize result variable | ||
| set "slug=EliudsEggs" | ||
|
|
||
| REM -------------------- | ||
| REM Test Case Start \/\/ | ||
| REM Resource: https://github.com/exercism/problem-specifications/blob/main/exercises/eliuds-eggs/canonical-data.json | ||
| REM -------------------- | ||
|
|
||
| set "expected=0" | ||
| set "if_success=Test passed" | ||
| set "if_failed=Test failed: 0 eggs." | ||
| CALL :Assert "0" | ||
|
|
||
| set "expected=1" | ||
| set "if_success=Test passed" | ||
| set "if_failed=Test failed: 1 egg." | ||
| CALL :Assert "16" | ||
|
|
||
| set "expected=4" | ||
| set "if_success=Test passed" | ||
| set "if_failed=Test failed: 4 eggs." | ||
| CALL :Assert "89" | ||
|
|
||
| set "expected=13" | ||
| set "if_success=Test passed" | ||
| set "if_failed=Test failed: 13 eggs." | ||
| CALL :Assert "2000000000" | ||
|
|
||
| REM -------------------- | ||
| REM Test Case End /\/\/\ | ||
| REM -------------------- | ||
|
|
||
| CALL :ResolveStatus | ||
| exit /b %errorlevel% | ||
| REM End of Main | ||
|
|
||
| REM --------------------------------------------------- | ||
| REM Assert [..Parameters(up to 9)] | ||
| REM --------------------------------------------------- | ||
| GOTO :End REM Prevents the code below from being executed | ||
| :Assert | ||
| set "stdout=" | ||
|
|
||
| REM Run the program and capture the output then delete the file | ||
| set filePath=%slug%.bat | ||
| if "%isTestRunner%"=="true" ( | ||
| set filePath=.meta\Example.bat | ||
| ) | ||
| set batPath=%~dp0 | ||
| CALL %batPath%%filePath% %~1 %~2 %~3 %~4 %~5 %~6 %~7 %~8 %~9 > stdout.bin 2>&1 | ||
| for /f "delims=" %%A in (stdout.bin) do ( | ||
| set "line=%%A" | ||
| if defined stdout ( | ||
| set "stdout=!stdout!\n!line!" | ||
| ) else ( | ||
| set "stdout=!line!" | ||
| ) | ||
| ) | ||
| del stdout.bin | ||
|
|
||
| REM Check if the result is correct | ||
| if "%stdout%" == "%expected%" ( | ||
| if defined if_success ( | ||
| echo %if_success% | ||
|
|
||
| REM Reset the variable to avoid duplicating the message. | ||
| set "if_success=" | ||
| set "if_failed=" | ||
| ) | ||
|
|
||
| REM If the result is correct, exit with code 0 | ||
| set /a successCount+=1 | ||
| exit /b 0 | ||
| ) else ( | ||
| if defined if_failed ( | ||
| echo %if_failed% | ||
|
|
||
| REM Reset the variable to avoid duplicating the message. | ||
| set "if_success=" | ||
| set "if_failed=" | ||
| ) | ||
|
|
||
| REM If the result is incorrect, exit with code 1 | ||
| set /a failCount+=1 | ||
| exit /b 1 | ||
| ) | ||
| GOTO :EOF REM Go back to the line after the call to :Assert | ||
|
|
||
| :ResolveStatus | ||
| set "status=" | ||
| if %failCount% gtr 0 ( | ||
| REM status: Fail | ||
| REM message: The test failed. | ||
| exit /b 1 | ||
|
|
||
| ) else ( | ||
| REM status: Pass | ||
| exit /b 0 | ||
|
|
||
| ) | ||
| GOTO :EOF REM Go back to the line after the call to :ExportResultAsJson | ||
|
|
||
| :End |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The canonical exercise name is Eliud's Eggs. It looks like the CI uses the name rather than the slug, which is causing the original issue. The appropriate thing to do here is likely have the CI directly convert the slug to Pascal Case. There's at least one practice exercise where the slug and title won't match. You don't necessarily have to make the CI change here, but this is something for the maintainer to consider.