diff --git a/exercises/collatz-conjecture/description.md b/exercises/collatz-conjecture/description.md deleted file mode 100644 index 6dd679c12b..0000000000 --- a/exercises/collatz-conjecture/description.md +++ /dev/null @@ -1,29 +0,0 @@ -# Description - -The Collatz Conjecture or 3x+1 problem can be summarized as follows: - -Take any positive integer n. -If n is even, divide n by 2 to get n / 2. -If n is odd, multiply n by 3 and add 1 to get 3n + 1. -Repeat the process indefinitely. -The conjecture states that no matter which number you start with, you will always reach 1 eventually. - -Given a number n, return the number of steps required to reach 1. - -## Examples - -Starting with n = 12, the steps would be as follows: - -0. 12 -1. 6 -2. 3 -3. 10 -4. 5 -5. 16 -6. 8 -7. 4 -8. 2 -9. 1 - -Resulting in 9 steps. -So for input n = 12, the return value would be 9. diff --git a/exercises/collatz-conjecture/instructions.md b/exercises/collatz-conjecture/instructions.md new file mode 100644 index 0000000000..af332a810f --- /dev/null +++ b/exercises/collatz-conjecture/instructions.md @@ -0,0 +1,3 @@ +# Instructions + +Given a positive integer, return the number of steps it takes to reach 1 according to the rules of the Collatz Conjecture. diff --git a/exercises/collatz-conjecture/introduction.md b/exercises/collatz-conjecture/introduction.md new file mode 100644 index 0000000000..c35bdeb67d --- /dev/null +++ b/exercises/collatz-conjecture/introduction.md @@ -0,0 +1,28 @@ +# Introduction + +One evening, you stumbled upon an old notebook filled with cryptic scribbles, as though someone had been obsessively chasing an idea. +On one page, a single question stood out: **Can every number find its way to 1?** +It was tied to something called the **Collatz Conjecture**, a puzzle that has baffled thinkers for decades. + +The rules were deceptively simple. +Pick any positive integer. + +- If it's even, divide it by 2. +- If it's odd, multiply it by 3 and add 1. + +Then, repeat these steps with the result, continuing indefinitely. + +Curious, you picked number 12 to test and began the journey: + +12 ➜ 6 ➜ 3 ➜ 10 ➜ 5 ➜ 16 ➜ 8 ➜ 4 ➜ 2 ➜ 1 + +Counting from the second number (6), it took 9 steps to reach 1, and each time the rules repeated, the number kept changing. +At first, the sequence seemed unpredictable — jumping up, down, and all over. +Yet, the conjecture claims that no matter the starting number, we'll always end at 1. + +It was fascinating, but also puzzling. +Why does this always seem to work? +Could there be a number where the process breaks down, looping forever or escaping into infinity? +The notebook suggested solving this could reveal something profound — and with it, fame, [fortune][collatz-prize], and a place in history awaits whoever could unlock its secrets. + +[collatz-prize]: https://mathprize.net/posts/collatz-conjecture/ diff --git a/exercises/collatz-conjecture/metadata.toml b/exercises/collatz-conjecture/metadata.toml index 4c7aa1fedc..5956db24ec 100644 --- a/exercises/collatz-conjecture/metadata.toml +++ b/exercises/collatz-conjecture/metadata.toml @@ -1,4 +1,4 @@ title = "Collatz Conjecture" blurb = "Calculate the number of steps to reach 1 using the Collatz conjecture." -source = "An unsolved problem in mathematics named after mathematician Lothar Collatz" -source_url = "https://en.wikipedia.org/wiki/3x_%2B_1_problem" +source = "Wikipedia" +source_url = "https://en.wikipedia.org/wiki/Collatz_conjecture"