Skip to content
13 changes: 13 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@
],
"difficulty": 1
},
{
"slug": "eliuds-eggs",
"name": "Eliuds Eggs",
Copy link
Member

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.

"uuid": "0875c5f0-8336-494b-b32a-b9d789d32ea7",
"practices": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

practices should be an array of existing concept slugs. I don't believe any of these three exist.

Copy link
Author

Choose a reason for hiding this comment

The 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": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prerequisites should be an array of existing concept slugs that need to be unlocked before you can do this exercise in learning mode. This track doesn't have a learning mode so this section doesn't really need to be populated.

"basics"
],
"difficulty": 1
},
{
"slug": "darts",
"name": "Darts",
Expand Down
8 changes: 8 additions & 0 deletions exercises/practice/eliuds-eggs/.docs/instructions.md
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.
65 changes: 65 additions & 0 deletions exercises/practice/eliuds-eggs/.docs/introduction.md
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

![Seven individual nest boxes arranged in a row whose first, third, fourth and seventh nests each have a single egg.](https://assets.exercism.org/images/exercises/eliuds-eggs/example-1-coop.svg)

```text
_ _ _ _ _ _ _
|E| |E|E| | |E|
```

### Resulting Binary

![1011001](https://assets.exercism.org/images/exercises/eliuds-eggs/example-1-binary.svg)

```text
_ _ _ _ _ _ _
|1|0|1|1|0|0|1|
```

### Decimal number on the display

89

### Actual eggs in the coop

4

## Example 2

![Seven individual nest boxes arranged in a row where only the fourth nest has an egg.](https://assets.exercism.org/images/exercises/eliuds-eggs/example-2-coop.svg)

```text
_ _ _ _ _ _ _
| | | |E| | | |
```

### Resulting Binary

![0001000](https://assets.exercism.org/images/exercises/eliuds-eggs/example-2-binary.svg)

```text
_ _ _ _ _ _ _
|0|0|0|1|0|0|0|
```

### Decimal number on the display

8

### Actual eggs in the coop

1
15 changes: 15 additions & 0 deletions exercises/practice/eliuds-eggs/.meta/Example.bat
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%
19 changes: 19 additions & 0 deletions exercises/practice/eliuds-eggs/.meta/config.json
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"
}
22 changes: 22 additions & 0 deletions exercises/practice/eliuds-eggs/.meta/tests.toml
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"
10 changes: 10 additions & 0 deletions exercises/practice/eliuds-eggs/EliudsEggs.bat
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%
120 changes: 120 additions & 0 deletions exercises/practice/eliuds-eggs/EliudsEggsTest.bat
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