Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2535,6 +2535,14 @@
"strings"
],
"difficulty": 7
},
{
"slug": "pop-count",
"name": "Eliud's Eggs",
"uuid": "2a3ecf62-fb5d-4dac-8369-72e7976a8f57",
"practices": [],
"prerequisites": [],
"difficulty": 2
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/leap/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Some examples:
- 1900 was not a leap year as it's not divisible by 400.
- 2000 was a leap year!

~~~~exercism/note
```exercism/note
For a delightful, four-minute explanation of the whole phenomenon of leap years, check out [this YouTube video](https://www.youtube.com/watch?v=xX96xng7sAE).
~~~~
```
8 changes: 8 additions & 0 deletions exercises/practice/pop-count/.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.
47 changes: 47 additions & 0 deletions exercises/practice/pop-count/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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
Chicken Coop:
_ _ _ _ _ _ _
|E| |E|E| | |E|

Resulting Binary:
1 0 1 1 0 0 1

Decimal number on the display:
89

Actual eggs in the coop:
4
```

Example 2:

```text
Chicken Coop:
_ _ _ _ _ _ _ _
| | | |E| | | | |

Resulting Binary:
0 0 0 1 0 0 0 0

Decimal number on the display:
16

Actual eggs in the coop:
1
```
14 changes: 14 additions & 0 deletions exercises/practice/pop-count/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"root": true,
"extends": "@exercism/eslint-config-javascript",
"env": {
"jest": true
},
"overrides": [
{
"files": [".meta/proof.ci.js", ".meta/exemplar.js", "*.spec.js"],
"excludedFiles": ["custom.spec.js"],
"extends": "@exercism/eslint-config-javascript/maintainers"
}
]
}
5 changes: 5 additions & 0 deletions exercises/practice/pop-count/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/node_modules
/bin/configlet
Copy link
Member

Choose a reason for hiding this comment

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

Was this file auto-created? It looks ... wrong. These ought to be in the root ignore file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was an auto-generated file.

/bin/configlet.exe
/pnpm-lock.yaml
/yarn.lock
19 changes: 19 additions & 0 deletions exercises/practice/pop-count/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"Cool-Katt"
],
"files": {
"solution": [
"pop-count.js"
],
"test": [
"pop-count.spec.js"
],
"example": [
".meta/proof.ci.js"
]
},
"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"
}
5 changes: 5 additions & 0 deletions exercises/practice/pop-count/.meta/proof.ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const eggCount = (displayValue) =>
[...displayValue.toString(2)].reduce(
(acc, curr) => (curr === '1' ? (acc += 1) : acc),
0,
);
22 changes: 22 additions & 0 deletions exercises/practice/pop-count/.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"
1 change: 1 addition & 0 deletions exercises/practice/pop-count/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
audit=false
Copy link
Member

Choose a reason for hiding this comment

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

This is also defined in the root and I suspect isn't needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another auto-generated file.

21 changes: 21 additions & 0 deletions exercises/practice/pop-count/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License
Copy link
Member

Choose a reason for hiding this comment

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

Licensing is done on a repo level, not an exercise level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yet another auto-generated file.


Copyright (c) 2021 Exercism

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions exercises/practice/pop-count/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
presets: ['@exercism/babel-preset-javascript'],
plugins: [],
};
33 changes: 33 additions & 0 deletions exercises/practice/pop-count/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@exercism/javascript-pop-count",
"description": "Exercism practice exercise on pop-count",
"author": "Katrina Owen",
"contributors": [
"Derk-Jan Karrenbeld <derk-jan+git@karrenbeld.info> (https://derk-jan.com)",
"Tejas Bubane (https://tejasbubane.github.io/)"
],
Comment on lines +4 to +8
Copy link
Member

Choose a reason for hiding this comment

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

@Cool-Katt Do you want to update these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean to add myself as a contributor? I don't know if I properly understand what you mean.

Copy link
Member

Choose a reason for hiding this comment

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

Yup. Or as the author. The only person that worked on this exercise is you so I think it ought to be reflected in the author/contributors docs.

"private": true,
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/exercism/javascript",
"directory": "exercises/practice/pop-count"
},
"devDependencies": {
"@babel/core": "^7.23.0",
"@exercism/babel-preset-javascript": "^0.2.1",
"@exercism/eslint-config-javascript": "^0.6.0",
"@types/jest": "^29.5.4",
"@types/node": "^20.5.6",
"babel-jest": "^29.6.4",
"core-js": "~3.32.2",
"eslint": "^8.49.0",
"jest": "^29.7.0"
},
"dependencies": {},
"scripts": {
"test": "jest ./*",
"watch": "jest --watch ./*",
"lint": "eslint ."
}
}
8 changes: 8 additions & 0 deletions exercises/practice/pop-count/pop-count.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// This is only a SKELETON file for the 'Poker' exercise. It's been provided as a
// convenience to get you started writing code faster.
//

export const eggCount = (displayValue) => {
throw new Error('Remove this statement and implement this function');
};
27 changes: 27 additions & 0 deletions exercises/practice/pop-count/pop-count.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { eggCount } from './pop-count';

describe('PopCount', () => {
test('0 eggs', () => {
const expected = 0;
const actual = eggCount(0);
expect(actual).toEqual(expected);
});

xtest('1 egg', () => {
const expected = 1;
const actual = eggCount(16);
expect(actual).toEqual(expected);
});

xtest('4 eggs', () => {
const expected = 4;
const actual = eggCount(89);
expect(actual).toEqual(expected);
});

xtest('13 eggs', () => {
const expected = 13;
const actual = eggCount(2000000000);
expect(actual).toEqual(expected);
});
});