Skip to content
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

Webassembly day07 #301

Merged
merged 2 commits into from
Nov 12, 2023
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Exercism Workspace
| August | Apps | Dart (5/5), Java (0/5), Kotlin (0/5) |
| September | Slimline | Awk (5/5), Bash\* (5/5), jq (0/5), Perl (0/5) |
| October | Object-Oriented | Ruby (5/5), Java (0/5) |
| November | Nibbly | WebAssembly (3/5), x86-64 Assembly (0/5) |
| November | Nibbly | WebAssembly (4/5), x86-64 Assembly (0/5) |
| December | Diversions | |

\* not completed in 2023
Expand Down
1 change: 1 addition & 0 deletions wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
- [grains](./grains/README.md)
- [resistor-color](./resistor-color/README.md)
- [nucleotide-count](./nucleotide-count/README.md)
- [pop-count](./pop-count/README.md)
18 changes: 18 additions & 0 deletions wasm/pop-count/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"root": true,
"extends": "@exercism/eslint-config-javascript",
"env": {
"jest": true
},
"overrides": [
{
"files": [
"*.spec.js"
],
"excludedFiles": [
"custom.spec.js"
],
"extends": "@exercism/eslint-config-javascript/maintainers"
}
]
}
25 changes: 25 additions & 0 deletions wasm/pop-count/.exercism/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"authors": [
"keiravillekode"
],
"files": {
"solution": [
"pop-count.wat"
],
"test": [
"pop-count.spec.js"
],
"example": [
".meta/proof.ci.wat"
]
},
"blurb": "Help Eluid 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",
"custom": {
"version.tests.compatibility": "jest-27",
"flag.tests.task-per-describe": false,
"flag.tests.may-run-long": false,
"flag.tests.includes-optional": false
}
}
1 change: 1 addition & 0 deletions wasm/pop-count/.exercism/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"track":"wasm","exercise":"pop-count","id":"c46f46bfa1224b0289f9d2ca0f7b1397","url":"https://exercism.org/tracks/wasm/exercises/pop-count","handle":"vpayno","is_requester":true,"auto_approve":false}
1 change: 1 addition & 0 deletions wasm/pop-count/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
audit=false
1 change: 1 addition & 0 deletions wasm/pop-count/.prettierignore
72 changes: 72 additions & 0 deletions wasm/pop-count/HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Help

## Running the tests

## Setup

Go through the setup [instructions for WebAssembly][docs-exercism-wasm] to install the necessary dependencies.

## Requirements

Install assignment dependencies:

```shell
# Using npm
npm install

# Alternatively using yarn
yarn
```

## Making the test suite pass

All exercises come with a test suite to help you validate your solution before submitting.
You can execute these tests by opening a command prompt in the exercise's directory, and then running:

```bash
# Using npm
npm test

# Alternatively using yarn
yarn test
```

In some test suites all tests but the first have been skipped.

Once you get a test passing, you can enable the next one by changing `xtest` to `test`.

## Writing custom tests

If you wish to write additional, custom, tests, create a new file `custom.spec.js`, and submit it with your solution together with the new file:

```shell
exercism submit numbers.wat custom.spec.js
```

[docs-exercism-wasm]: https://exercism.org/docs/tracks/wasm/installation

## Submitting your solution

You can submit your solution using the `exercism submit pop-count.wat` command.
This command will upload your solution to the Exercism website and print the solution page's URL.

It's possible to submit an incomplete solution which allows you to:

- See how others have completed the exercise
- Request help from a mentor

## Need to get help?

If you'd like help solving the exercise, check the following pages:

- The [WebAssembly track's documentation](https://exercism.org/docs/tracks/wasm)
- The [WebAssembly track's programming category on the forum](https://forum.exercism.org/c/programming/wasm)
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)

Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.

To get help if you're having trouble, you can use one of the following resources:

- [/r/WebAssembly](https://www.reddit.com/r/WebAssembly/) is the WebAssembly subreddit.
- [Github issue tracker](https://github.com/exercism/wasm/issues) is where we track our development and maintenance of Javascript exercises in exercism. But if none of the above links help you, feel free to post an issue here.
21 changes: 21 additions & 0 deletions wasm/pop-count/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

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.
80 changes: 80 additions & 0 deletions wasm/pop-count/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Eliud's Eggs

Welcome to Eliud's Eggs on Exercism's WebAssembly Track.
If you need help running the tests or submitting your code, check out `HELP.md`.

## 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
```

## 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.

## Reserved Addresses

No linear memory is required for this exercise.

## Source

### Created by

- @keiravillekode

### Based on

Christian Willner, Eric Willigers - https://forum.exercism.org/t/new-exercise-suggestion-pop-count/7632/5

### My Solution

- [my solution]()
- [run-tests](./run-tests-wasm.txt)
4 changes: 4 additions & 0 deletions wasm/pop-count/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
presets: ["@exercism/babel-preset-javascript"],
plugins: [],
};
6 changes: 6 additions & 0 deletions wasm/pop-count/coverage/clover.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1699750916957" clover="3.2.0">
<project timestamp="1699750916957" name="All files">
<metrics statements="0" coveredstatements="0" conditionals="0" coveredconditionals="0" methods="0" coveredmethods="0" elements="0" coveredelements="0" complexity="0" loc="0" ncloc="0" packages="0" files="0" classes="0"/>
</project>
</coverage>
1 change: 1 addition & 0 deletions wasm/pop-count/coverage/coverage-final.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading