File tree Expand file tree Collapse file tree 8 files changed +143
-0
lines changed
exercises/practice/eliuds-eggs Expand file tree Collapse file tree 8 files changed +143
-0
lines changed Original file line number Diff line number Diff line change 335
335
],
336
336
"difficulty" : 3
337
337
},
338
+ {
339
+ "slug" : " eliuds-eggs" ,
340
+ "name" : " Eliud's Eggs" ,
341
+ "uuid" : " d9e488a6-c232-47cf-91c2-06249fa3f0b5" ,
342
+ "practices" : [
343
+ " numbers" ,
344
+ " enumeration"
345
+ ],
346
+ "prerequisites" : [],
347
+ "difficulty" : 3
348
+ },
338
349
{
339
350
"slug" : " hamming" ,
340
351
"name" : " Hamming" ,
Original file line number Diff line number Diff line change
1
+ # Instructions
2
+
3
+ Your task is to count the number of 1 bits in the binary representation of a number.
4
+
5
+ ## Restrictions
6
+
7
+ Keep your hands off that bit-count functionality provided by your standard library!
8
+ Solve this one yourself using other basic tools instead.
Original file line number Diff line number Diff line change
1
+ # Introduction
2
+
3
+ Your friend Eliud inherited a farm from her grandma Tigist.
4
+ Her granny was an inventor and had a tendency to build things in an overly complicated manner.
5
+ The chicken coop has a digital display showing an encoded number representing the positions of all eggs that could be picked up.
6
+
7
+ Eliud is asking you to write a program that shows the actual number of eggs in the coop.
8
+
9
+ The position information encoding is calculated as follows:
10
+
11
+ 1 . Scan the potential egg-laying spots and mark down a ` 1 ` for an existing egg or a ` 0 ` for an empty spot.
12
+ 2 . Convert the number from binary to decimal.
13
+ 3 . Show the result on the display.
14
+
15
+ Example 1:
16
+
17
+ ``` text
18
+ Chicken Coop:
19
+ _ _ _ _ _ _ _
20
+ |E| |E|E| | |E|
21
+
22
+ Resulting Binary:
23
+ 1 0 1 1 0 0 1
24
+
25
+ Decimal number on the display:
26
+ 89
27
+
28
+ Actual eggs in the coop:
29
+ 4
30
+ ```
31
+
32
+ Example 2:
33
+
34
+ ``` text
35
+ Chicken Coop:
36
+ _ _ _ _ _ _ _ _
37
+ | | | |E| | | | |
38
+
39
+ Resulting Binary:
40
+ 0 0 0 1 0 0 0 0
41
+
42
+ Decimal number on the display:
43
+ 16
44
+
45
+ Actual eggs in the coop:
46
+ 1
47
+ ```
Original file line number Diff line number Diff line change
1
+ {
2
+ "authors" : [
3
+ " ellnix"
4
+ ],
5
+ "files" : {
6
+ "solution" : [
7
+ " eliuds_eggs.rb"
8
+ ],
9
+ "test" : [
10
+ " eliuds_eggs_test.rb"
11
+ ],
12
+ "example" : [
13
+ " .meta/example.rb"
14
+ ]
15
+ },
16
+ "blurb" : " Help Eliud count the number of eggs in her chicken coop by counting the number of 1 bits in a binary representation." ,
17
+ "source" : " Christian Willner, Eric Willigers" ,
18
+ "source_url" : " https://forum.exercism.org/t/new-exercise-suggestion-pop-count/7632/5"
19
+ }
Original file line number Diff line number Diff line change
1
+ module EliudsEggs
2
+ def self . egg_count ( display_number )
3
+ display_number . to_s ( 2 ) . count ( '1' )
4
+ end
5
+ end
Original file line number Diff line number Diff line change
1
+ # This is an auto-generated file.
2
+ #
3
+ # Regenerating this file via `configlet sync` will:
4
+ # - Recreate every `description` key/value pair
5
+ # - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6
+ # - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7
+ # - Preserve any other key/value pair
8
+ #
9
+ # As user-added comments (using the # character) will be removed when this file
10
+ # is regenerated, comments can be added via a `comment` key.
11
+
12
+ [559e789d-07d1-4422-9004-3b699f83bca3 ]
13
+ description = " 0 eggs"
14
+
15
+ [97223282-f71e-490c-92f0-b3ec9e275aba ]
16
+ description = " 1 egg"
17
+
18
+ [1f8fd18f-26e9-4144-9a0e-57cdfc4f4ff5 ]
19
+ description = " 4 eggs"
20
+
21
+ [0c18be92-a498-4ef2-bcbb-28ac4b06cb81 ]
22
+ description = " 13 eggs"
Original file line number Diff line number Diff line change
1
+ =begin
2
+ Write your code for the 'Eliuds Eggs' exercise in this file. Make the tests in
3
+ `eliuds_eggs_test.rb` pass.
4
+
5
+ To get started with TDD, see the `README.md` file in your
6
+ `ruby/eliuds-eggs` directory.
7
+ =end
Original file line number Diff line number Diff line change
1
+ require 'minitest/autorun'
2
+ require_relative 'eliuds_eggs'
3
+
4
+ class EliudsEggsTest < Minitest ::Test
5
+ def test_0_eggs
6
+ # skip
7
+ assert_equal 0 , EliudsEggs . egg_count ( 0 )
8
+ end
9
+
10
+ def test_1_egg
11
+ skip
12
+ assert_equal 1 , EliudsEggs . egg_count ( 16 )
13
+ end
14
+
15
+ def test_4_eggs
16
+ skip
17
+ assert_equal 4 , EliudsEggs . egg_count ( 89 )
18
+ end
19
+
20
+ def test_13_eggs
21
+ skip
22
+ assert_equal 13 , EliudsEggs . egg_count ( 2_000_000_000 )
23
+ end
24
+ end
You can’t perform that action at this time.
0 commit comments