Some solutions for the julia path
This commit is contained in:
19
julia/eliuds-eggs/.exercism/config.json
Normal file
19
julia/eliuds-eggs/.exercism/config.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"authors": [
|
||||
"BNAndras"
|
||||
],
|
||||
"files": {
|
||||
"solution": [
|
||||
"eliuds-eggs.jl"
|
||||
],
|
||||
"test": [
|
||||
"runtests.jl"
|
||||
],
|
||||
"example": [
|
||||
".meta/example.jl"
|
||||
]
|
||||
},
|
||||
"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"
|
||||
}
|
||||
1
julia/eliuds-eggs/.exercism/metadata.json
Normal file
1
julia/eliuds-eggs/.exercism/metadata.json
Normal file
@@ -0,0 +1 @@
|
||||
{"track":"julia","exercise":"eliuds-eggs","id":"52e0e72667584ac59823a6b0a8e8671e","url":"https://exercism.org/tracks/julia/exercises/eliuds-eggs","handle":"Kimawari","is_requester":true,"auto_approve":false}
|
||||
34
julia/eliuds-eggs/HELP.md
Normal file
34
julia/eliuds-eggs/HELP.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# Help
|
||||
|
||||
## Running the tests
|
||||
|
||||
To run the tests, run this command from within the exercise directory:
|
||||
|
||||
```bash
|
||||
$ julia runtests.jl
|
||||
```
|
||||
|
||||
## Submitting your solution
|
||||
|
||||
You can submit your solution using the `exercism submit eliuds-eggs.jl` 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 [Julia track's documentation](https://exercism.org/docs/tracks/julia)
|
||||
- The [Julia track's programming category on the forum](https://forum.exercism.org/c/programming/julia)
|
||||
- [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, we recommend that you submit your code and request mentoring :)
|
||||
|
||||
If you don't want to do that for whatever reason, then you can find the wider Julia community channels [here](https://julialang.org/community/).
|
||||
89
julia/eliuds-eggs/README.md
Normal file
89
julia/eliuds-eggs/README.md
Normal file
@@ -0,0 +1,89 @@
|
||||
# Eliud's Eggs
|
||||
|
||||
Welcome to Eliud's Eggs on Exercism's Julia 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
|
||||
_ _ _ _ _ _ _
|
||||
|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
|
||||
|
||||
## 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.
|
||||
|
||||
## Source
|
||||
|
||||
### Created by
|
||||
|
||||
- @BNAndras
|
||||
|
||||
### Based on
|
||||
|
||||
Christian Willner, Eric Willigers - https://forum.exercism.org/t/new-exercise-suggestion-pop-count/7632/5
|
||||
3
julia/eliuds-eggs/eliuds-eggs.jl
Normal file
3
julia/eliuds-eggs/eliuds-eggs.jl
Normal file
@@ -0,0 +1,3 @@
|
||||
function eggcount(number)
|
||||
return count_ones(number)
|
||||
end
|
||||
21
julia/eliuds-eggs/runtests.jl
Normal file
21
julia/eliuds-eggs/runtests.jl
Normal file
@@ -0,0 +1,21 @@
|
||||
using Test
|
||||
|
||||
include("eliuds-eggs.jl")
|
||||
|
||||
@testset verbose = true "tests" begin
|
||||
@testset "0 eggs" begin
|
||||
@test eggcount(0) == 0
|
||||
end
|
||||
|
||||
@testset "1 egg" begin
|
||||
@test eggcount(16) == 1
|
||||
end
|
||||
|
||||
@testset "4 eggs" begin
|
||||
@test eggcount(89) == 4
|
||||
end
|
||||
|
||||
@testset "13 eggs" begin
|
||||
@test eggcount(2000000000) == 13
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user