Skip to content

Commit bc32b76

Browse files
Sync collatz-conjecture (#559)
[no important files changed]
1 parent 4dfa49b commit bc32b76

File tree

5 files changed

+26
-35
lines changed

5 files changed

+26
-35
lines changed
Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
11
# Instructions
22

3-
The Collatz Conjecture or 3x+1 problem can be summarized as follows:
4-
5-
Take any positive integer n.
6-
If n is even, divide n by 2 to get n / 2.
7-
If n is odd, multiply n by 3 and add 1 to get 3n + 1.
8-
Repeat the process indefinitely.
9-
The conjecture states that no matter which number you start with, you will always reach 1 eventually.
10-
11-
Given a number n, return the number of steps required to reach 1.
12-
13-
## Examples
14-
15-
Starting with n = 12, the steps would be as follows:
16-
17-
0. 12
18-
1. 6
19-
2. 3
20-
3. 10
21-
4. 5
22-
5. 16
23-
6. 8
24-
7. 4
25-
8. 2
26-
9. 1
27-
28-
Resulting in 9 steps.
29-
So for input n = 12, the return value would be 9.
3+
Given a positive integer, return the number of steps it takes to reach 1 according to the rules of the Collatz Conjecture.

exercises/practice/collatz-conjecture/.meta/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
]
1515
},
1616
"blurb": "Calculate the number of steps to reach 1 using the Collatz conjecture.",
17-
"source": "An unsolved problem in mathematics named after mathematician Lothar Collatz",
18-
"source_url": "https://en.wikipedia.org/wiki/3x_%2B_1_problem"
17+
"source": "Wikipedia",
18+
"source_url": "https://en.wikipedia.org/wiki/Collatz_conjecture"
1919
}

exercises/practice/collatz-conjecture/.meta/example.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
return function(n)
2-
assert(n > 0, 'Only positive numbers are allowed')
2+
assert(n > 0, 'Only positive integers are allowed')
33

44
local steps = 0
55

exercises/practice/collatz-conjecture/.meta/tests.toml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
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.
411

512
[540a3d51-e7a6-47a5-92a3-4ad1838f0bfd]
613
description = "zero steps for one"
@@ -16,6 +23,16 @@ description = "large number of even and odd steps"
1623

1724
[7d4750e6-def9-4b86-aec7-9f7eb44f95a3]
1825
description = "zero is an error"
26+
include = false
27+
28+
[2187673d-77d6-4543-975e-66df6c50e2da]
29+
description = "zero is an error"
30+
reimplements = "7d4750e6-def9-4b86-aec7-9f7eb44f95a3"
1931

2032
[c6c795bf-a288-45e9-86a1-841359ad426d]
2133
description = "negative value is an error"
34+
include = false
35+
36+
[ec11f479-56bc-47fd-a434-bcd7a31a7a2e]
37+
description = "negative value is an error"
38+
reimplements = "c6c795bf-a288-45e9-86a1-841359ad426d"

exercises/practice/collatz-conjecture/collatz-conjecture_spec.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ describe('collatz-conjecture', function()
2020
it('zero is an error', function()
2121
assert.has_error(function()
2222
conjecture(0)
23-
end, 'Only positive numbers are allowed')
23+
end)
2424
end)
2525

2626
it('negative value is an error', function()
2727
assert.has_error(function()
2828
conjecture(-15)
29-
end, 'Only positive numbers are allowed')
29+
end)
3030
end)
3131
end)

0 commit comments

Comments
 (0)