From ca1c340a15673dda107bc23b7d988b7490c62075 Mon Sep 17 00:00:00 2001 From: Average-user Date: Mon, 18 Sep 2017 20:56:25 -0300 Subject: [PATCH 01/16] New excercise. collatz-conjecture --- exercises/collatz-conjecture/README.md | 85 +++++++++++++++++++ .../examples/success-standard/package.yaml | 16 ++++ .../success-standard/src/CollatzConjecture.hs | 9 ++ exercises/collatz-conjecture/package.yaml | 21 +++++ .../src/CollatzConjectre.hs | 4 + exercises/collatz-conjecture/stack.yaml | 1 + exercises/collatz-conjecture/test/Tests.hs | 59 +++++++++++++ 7 files changed, 195 insertions(+) create mode 100644 exercises/collatz-conjecture/README.md create mode 100644 exercises/collatz-conjecture/examples/success-standard/package.yaml create mode 100644 exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs create mode 100644 exercises/collatz-conjecture/package.yaml create mode 100644 exercises/collatz-conjecture/src/CollatzConjectre.hs create mode 100644 exercises/collatz-conjecture/stack.yaml create mode 100644 exercises/collatz-conjecture/test/Tests.hs diff --git a/exercises/collatz-conjecture/README.md b/exercises/collatz-conjecture/README.md new file mode 100644 index 000000000..8ad146254 --- /dev/null +++ b/exercises/collatz-conjecture/README.md @@ -0,0 +1,85 @@ +## Collatz Conjecture. + +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. + +## Getting Started + +For installation and learning resources, refer to the +[exercism help page](http://exercism.io/languages/haskell). + +## Running the tests + +To run the test suite, execute the following command: + +```bash +stack test +``` + +#### If you get an error message like this... + +``` +No .cabal file found in directory +``` + +You are probably running an old stack version and need +to upgrade it. + +#### Otherwise, if you get an error message like this... + +``` +No compiler found, expected minor version match with... +Try running "stack setup" to install the correct GHC... +``` + +Just do as it says and it will download and install +the correct compiler version: + +```bash +stack setup +``` + +## Running *GHCi* + +If you want to play with your solution in GHCi, just run the command: + +```bash +stack ghci +``` + +## Feedback, Issues, Pull Requests + +The [exercism/haskell](https://github.com/exercism/haskell) repository on +GitHub is the home for all of the Haskell exercises. + +If you have feedback about an exercise, or want to help implementing a new +one, head over there and create an issue. We'll do our best to help you! + +## Source + +All of Computer Science [http://www.wolframalpha.com/input/?i=binary&a=*C.binary-_*MathWorld-](http://www.wolframalpha.com/input/?i=binary&a=*C.binary-_*MathWorld-) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/collatz-conjecture/examples/success-standard/package.yaml b/exercises/collatz-conjecture/examples/success-standard/package.yaml new file mode 100644 index 000000000..26631e8d5 --- /dev/null +++ b/exercises/collatz-conjecture/examples/success-standard/package.yaml @@ -0,0 +1,16 @@ +name: collatz-conjecture + +dependencies: + - base + +library: + exposed-modules: CollatzConjecture + source-dirs: src + +tests: + test: + main: Tests.hs + source-dirs: test + dependencies: + - collatz-conjecture + - hspec diff --git a/exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs b/exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs new file mode 100644 index 000000000..57288e268 --- /dev/null +++ b/exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs @@ -0,0 +1,9 @@ +module CollatzConjecture (collatz) where + +collatzHelper :: Integer -> Integer -> Integer +collatzHelper t x | x == 1 = t + | even x = collatzHelper (t+1) (x `div` 2) + | otherwise = collatzHelper (t+1) (x*3 + 1) + +collatz :: Integer -> Integer +collatz = collatzHelper 0 diff --git a/exercises/collatz-conjecture/package.yaml b/exercises/collatz-conjecture/package.yaml new file mode 100644 index 000000000..a7524b4c1 --- /dev/null +++ b/exercises/collatz-conjecture/package.yaml @@ -0,0 +1,21 @@ + +name: collatz-conjecture +version: 1.0.0.3 + +dependencies: + - base + +library: + exposed-modules: CollatzConjecture + source-dirs: src + dependencies: + # - foo # List here the packages you + # - bar # want to use in your solution. + +tests: + test: + main: Tests.hs + source-dirs: test + dependencies: + - collatz-conjecture + - hspec diff --git a/exercises/collatz-conjecture/src/CollatzConjectre.hs b/exercises/collatz-conjecture/src/CollatzConjectre.hs new file mode 100644 index 000000000..1494deb79 --- /dev/null +++ b/exercises/collatz-conjecture/src/CollatzConjectre.hs @@ -0,0 +1,4 @@ +module CollatzConjecture (collatz) where + +collatz :: Integer -> Integer +collatz = error "You need to implement this function." diff --git a/exercises/collatz-conjecture/stack.yaml b/exercises/collatz-conjecture/stack.yaml new file mode 100644 index 000000000..10da6ea9e --- /dev/null +++ b/exercises/collatz-conjecture/stack.yaml @@ -0,0 +1 @@ +resolver: lts-8.21 diff --git a/exercises/collatz-conjecture/test/Tests.hs b/exercises/collatz-conjecture/test/Tests.hs new file mode 100644 index 000000000..a4570fa44 --- /dev/null +++ b/exercises/collatz-conjecture/test/Tests.hs @@ -0,0 +1,59 @@ +{-# OPTIONS_GHC -fno-warn-type-defaults #-} +{-# LANGUAGE RecordWildCards #-} + +import Data.Foldable (for_) +import Test.Hspec (Spec, describe, it, shouldBe) +import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith) + +import CollatzConjecture (collatz) + +main :: IO () +main = hspecWith defaultConfig {configFastFail = True} specs + +specs :: Spec +specs = describe "collatz" $ for_ cases test + where + + test Case{..} = it description assertion + where + assertion = collatz number `shouldBe` fromIntegral expected + + +data Case = Case { description :: String + , number :: Integer + , expected :: Integer + } + +cases :: [Case] +cases = [ Case { description = "collatz 1 don't require any steps." + , binary = 1 + , expected = 0 + } + , Case { description = "collatz 2 require 1 step." + , binary = 2 + , expected = 1 + } + , Case { description = "collatz 3 require 7 steps." + , binary = 3 + , expected = 7 + } + , Case { description = "collatz 4 require 2 steps." + , binary = 4 + , expected = 2 + } + , Case { description = "collatz 5 require 5 steps." + , binary = 5 + , expected = 5 + } + , Case { description = "collatz 6 require 8 steps." + , binary = 6 + , expected = 8 + } + , Case { description = "collatz 7 require 16 steps." + , binary = 7 + , expected = 16 + } + , Case { description = "collatz 666 require 113 steps." + , binary = 666 + , expected = 113 + ] From 319fdfa5a45ee93306ab89ca0d53b5821a70e3a7 Mon Sep 17 00:00:00 2001 From: Average-user Date: Mon, 18 Sep 2017 21:35:08 -0300 Subject: [PATCH 02/16] collatz-conjecture added to config.json --- config.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/config.json b/config.json index 3b53b152d..deb31cfe3 100644 --- a/config.json +++ b/config.json @@ -58,6 +58,15 @@ "topics": [ ] }, + { + "uuid": "6eba4eac-8395-4ad6-ac21-3651a11ab4b4", + "slug": "collatz-conjecture", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + ] + }, { "uuid": "85d77b8e-9b87-4d02-9fba-81f843bd66f1", "slug": "rna-transcription", From b24814762a012b1c412b18baa83ba3028ca0c147 Mon Sep 17 00:00:00 2001 From: Average-user Date: Mon, 18 Sep 2017 21:50:46 -0300 Subject: [PATCH 03/16] adding collatz-conjecture --- exercises/collatz-conjecture/test/Tests.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/collatz-conjecture/test/Tests.hs b/exercises/collatz-conjecture/test/Tests.hs index a4570fa44..be8d8fcac 100644 --- a/exercises/collatz-conjecture/test/Tests.hs +++ b/exercises/collatz-conjecture/test/Tests.hs @@ -56,4 +56,5 @@ cases = [ Case { description = "collatz 1 don't require any steps." , Case { description = "collatz 666 require 113 steps." , binary = 666 , expected = 113 + } ] From d353964ff3e6457a8b0a743d2eb3e195148c06d9 Mon Sep 17 00:00:00 2001 From: Average-user Date: Mon, 18 Sep 2017 22:09:46 -0300 Subject: [PATCH 04/16] collatz conjecture --- exercises/collatz-conjecture/test/Tests.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/exercises/collatz-conjecture/test/Tests.hs b/exercises/collatz-conjecture/test/Tests.hs index be8d8fcac..0c1d2dbcf 100644 --- a/exercises/collatz-conjecture/test/Tests.hs +++ b/exercises/collatz-conjecture/test/Tests.hs @@ -26,35 +26,35 @@ data Case = Case { description :: String cases :: [Case] cases = [ Case { description = "collatz 1 don't require any steps." - , binary = 1 + , number = 1 , expected = 0 } , Case { description = "collatz 2 require 1 step." - , binary = 2 + , number = 2 , expected = 1 } , Case { description = "collatz 3 require 7 steps." - , binary = 3 + , number = 3 , expected = 7 } , Case { description = "collatz 4 require 2 steps." - , binary = 4 + , number = 4 , expected = 2 } , Case { description = "collatz 5 require 5 steps." - , binary = 5 + , number = 5 , expected = 5 } , Case { description = "collatz 6 require 8 steps." - , binary = 6 + , number = 6 , expected = 8 } , Case { description = "collatz 7 require 16 steps." - , binary = 7 + , number = 7 , expected = 16 } , Case { description = "collatz 666 require 113 steps." - , binary = 666 + , number = 666 , expected = 113 } ] From 8d850ca7e22a017e97af6ddeeeef564076c61918 Mon Sep 17 00:00:00 2001 From: Lucas Polymeris Date: Mon, 18 Sep 2017 22:25:29 -0300 Subject: [PATCH 05/16] Update README.md --- exercises/collatz-conjecture/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/collatz-conjecture/README.md b/exercises/collatz-conjecture/README.md index 8ad146254..e0c6b62c5 100644 --- a/exercises/collatz-conjecture/README.md +++ b/exercises/collatz-conjecture/README.md @@ -79,7 +79,8 @@ one, head over there and create an issue. We'll do our best to help you! ## Source -All of Computer Science [http://www.wolframalpha.com/input/?i=binary&a=*C.binary-_*MathWorld-](http://www.wolframalpha.com/input/?i=binary&a=*C.binary-_*MathWorld-) +An unsolved problem in mathematics named after mathematician Lothar Collatz +see more at [collatz conjecture wikipedia]("https://en.wikipedia.org/wiki/3x_%2B_1_problem") ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. From e99495fbabce719424b1e559084fb41e3af98272 Mon Sep 17 00:00:00 2001 From: Lucas Polymeris Date: Mon, 18 Sep 2017 22:25:58 -0300 Subject: [PATCH 06/16] Update package.yaml From 80f3376abbbb038404d476577906f2e7896b5767 Mon Sep 17 00:00:00 2001 From: Lucas Polymeris Date: Mon, 18 Sep 2017 22:27:10 -0300 Subject: [PATCH 07/16] Update package.yaml --- exercises/collatz-conjecture/package.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/collatz-conjecture/package.yaml b/exercises/collatz-conjecture/package.yaml index a7524b4c1..d786ca4fa 100644 --- a/exercises/collatz-conjecture/package.yaml +++ b/exercises/collatz-conjecture/package.yaml @@ -1,6 +1,6 @@ name: collatz-conjecture -version: 1.0.0.3 +version: 1.1.1 dependencies: - base From 4f97913201bf403e432b5f8ec874c6d314094d5f Mon Sep 17 00:00:00 2001 From: Lucas Polymeris Date: Mon, 18 Sep 2017 22:28:12 -0300 Subject: [PATCH 08/16] Update package.yaml --- exercises/collatz-conjecture/package.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/exercises/collatz-conjecture/package.yaml b/exercises/collatz-conjecture/package.yaml index d786ca4fa..955a30369 100644 --- a/exercises/collatz-conjecture/package.yaml +++ b/exercises/collatz-conjecture/package.yaml @@ -1,4 +1,3 @@ - name: collatz-conjecture version: 1.1.1 From c8cfb11c007ca85bf0c191143ad913aa4b8206f0 Mon Sep 17 00:00:00 2001 From: Lucas Polymeris Date: Mon, 18 Sep 2017 22:44:42 -0300 Subject: [PATCH 09/16] Update package.yaml --- exercises/collatz-conjecture/package.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/collatz-conjecture/package.yaml b/exercises/collatz-conjecture/package.yaml index 955a30369..8b73186a7 100644 --- a/exercises/collatz-conjecture/package.yaml +++ b/exercises/collatz-conjecture/package.yaml @@ -1,5 +1,5 @@ name: collatz-conjecture -version: 1.1.1 +version: 1.1.1.1 dependencies: - base From 611ed615e557a155ad1a3238b7b510f7e392db49 Mon Sep 17 00:00:00 2001 From: Lucas Polymeris Date: Mon, 18 Sep 2017 23:05:56 -0300 Subject: [PATCH 10/16] Update Tests.hs --- exercises/collatz-conjecture/test/Tests.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/collatz-conjecture/test/Tests.hs b/exercises/collatz-conjecture/test/Tests.hs index 0c1d2dbcf..a09447bfa 100644 --- a/exercises/collatz-conjecture/test/Tests.hs +++ b/exercises/collatz-conjecture/test/Tests.hs @@ -30,11 +30,11 @@ cases = [ Case { description = "collatz 1 don't require any steps." , expected = 0 } , Case { description = "collatz 2 require 1 step." - , number = 2 + , number = 2 , expected = 1 } , Case { description = "collatz 3 require 7 steps." - , number = 3 + , number = 3 , expected = 7 } , Case { description = "collatz 4 require 2 steps." From 492764c18ffcef6f248ac6affdbba1deaf579dd8 Mon Sep 17 00:00:00 2001 From: Average-user Date: Tue, 19 Sep 2017 13:05:54 -0300 Subject: [PATCH 11/16] name fixed --- .../src/{CollatzConjectre.hs => CollatzConjecture.hs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename exercises/collatz-conjecture/src/{CollatzConjectre.hs => CollatzConjecture.hs} (100%) diff --git a/exercises/collatz-conjecture/src/CollatzConjectre.hs b/exercises/collatz-conjecture/src/CollatzConjecture.hs similarity index 100% rename from exercises/collatz-conjecture/src/CollatzConjectre.hs rename to exercises/collatz-conjecture/src/CollatzConjecture.hs From d8c117076bdd94040dbae15bb1150687c18f7565 Mon Sep 17 00:00:00 2001 From: Average-user Date: Tue, 19 Sep 2017 15:02:02 -0300 Subject: [PATCH 12/16] new cases --- .../success-standard/src/CollatzConjecture.hs | 3 +- exercises/collatz-conjecture/test/Tests.hs | 55 +++++++++---------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs b/exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs index 57288e268..75377c76b 100644 --- a/exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs +++ b/exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs @@ -6,4 +6,5 @@ collatzHelper t x | x == 1 = t | otherwise = collatzHelper (t+1) (x*3 + 1) collatz :: Integer -> Integer -collatz = collatzHelper 0 +collatz x = if x <= 0 then error "Only positive numbers are allowed" + else collatzHelper 0 x diff --git a/exercises/collatz-conjecture/test/Tests.hs b/exercises/collatz-conjecture/test/Tests.hs index a09447bfa..9446ee70f 100644 --- a/exercises/collatz-conjecture/test/Tests.hs +++ b/exercises/collatz-conjecture/test/Tests.hs @@ -20,41 +20,40 @@ specs = describe "collatz" $ for_ cases test data Case = Case { description :: String + , property :: String , number :: Integer , expected :: Integer } cases :: [Case] -cases = [ Case { description = "collatz 1 don't require any steps." +cases = [ Case { description = "zero steps for one" + , property = "steps" , number = 1 , expected = 0 } - , Case { description = "collatz 2 require 1 step." - , number = 2 - , expected = 1 - } - , Case { description = "collatz 3 require 7 steps." - , number = 3 - , expected = 7 - } - , Case { description = "collatz 4 require 2 steps." - , number = 4 - , expected = 2 - } - , Case { description = "collatz 5 require 5 steps." - , number = 5 - , expected = 5 - } - , Case { description = "collatz 6 require 8 steps." - , number = 6 - , expected = 8 - } - , Case { description = "collatz 7 require 16 steps." - , number = 7 - , expected = 16 - } - , Case { description = "collatz 666 require 113 steps." - , number = 666 - , expected = 113 + , Case { description = "divide if even" + , property = "steps" + , number = 16 + , expected = 4 + } + , Case { description = "even and odd steps" + , property = "steps" + , number = 12 + , expected = 9 + } + , Case { description = "Large number of even and odd steps" + , property = "steps" + , number = 1000000 + , expected = 152 + } + , Case { description = "zero is an error" + , property = "steps" + , number = 0 + , expected = error "Only positive numbers are allowed" + } + , Case { description = "negative value is an error" + , property = "steps" + , number = -15 + , expected = error "Only positive numbers are allowed" } ] From 2ed3db67b14a1bf243f580e23ad1c36792d62bd1 Mon Sep 17 00:00:00 2001 From: Average-user Date: Tue, 19 Sep 2017 15:22:06 -0300 Subject: [PATCH 13/16] handling errors with Maybe --- .../success-standard/src/CollatzConjecture.hs | 9 ++++----- exercises/collatz-conjecture/test/Tests.hs | 16 ++++++++-------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs b/exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs index 75377c76b..1855e3495 100644 --- a/exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs +++ b/exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs @@ -1,10 +1,9 @@ module CollatzConjecture (collatz) where -collatzHelper :: Integer -> Integer -> Integer -collatzHelper t x | x == 1 = t +collatzHelper :: Integer -> Integer -> Maybe Integer +collatzHelper t x | x == 1 = Just t | even x = collatzHelper (t+1) (x `div` 2) | otherwise = collatzHelper (t+1) (x*3 + 1) -collatz :: Integer -> Integer -collatz x = if x <= 0 then error "Only positive numbers are allowed" - else collatzHelper 0 x +collatz :: Integer -> Maybe Integer +collatz x = if x <= 0 then Nothing else collatzHelper 0 x diff --git a/exercises/collatz-conjecture/test/Tests.hs b/exercises/collatz-conjecture/test/Tests.hs index 9446ee70f..22767bf64 100644 --- a/exercises/collatz-conjecture/test/Tests.hs +++ b/exercises/collatz-conjecture/test/Tests.hs @@ -16,44 +16,44 @@ specs = describe "collatz" $ for_ cases test test Case{..} = it description assertion where - assertion = collatz number `shouldBe` fromIntegral expected + assertion = collatz number `shouldBe` expected data Case = Case { description :: String , property :: String , number :: Integer - , expected :: Integer + , expected :: Maybe Integer } cases :: [Case] cases = [ Case { description = "zero steps for one" , property = "steps" , number = 1 - , expected = 0 + , expected = Just 0 } , Case { description = "divide if even" , property = "steps" , number = 16 - , expected = 4 + , expected = Just 4 } , Case { description = "even and odd steps" , property = "steps" , number = 12 - , expected = 9 + , expected =Just 9 } , Case { description = "Large number of even and odd steps" , property = "steps" , number = 1000000 - , expected = 152 + , expected = Just 152 } , Case { description = "zero is an error" , property = "steps" , number = 0 - , expected = error "Only positive numbers are allowed" + , expected = Nothing } , Case { description = "negative value is an error" , property = "steps" , number = -15 - , expected = error "Only positive numbers are allowed" + , expected = Nothing } ] From 9061aeb486f487282c82915478c52387aba9a798 Mon Sep 17 00:00:00 2001 From: Average-user Date: Tue, 19 Sep 2017 15:26:05 -0300 Subject: [PATCH 14/16] fix on src --- exercises/collatz-conjecture/src/CollatzConjecture.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/collatz-conjecture/src/CollatzConjecture.hs b/exercises/collatz-conjecture/src/CollatzConjecture.hs index 1494deb79..239dff653 100644 --- a/exercises/collatz-conjecture/src/CollatzConjecture.hs +++ b/exercises/collatz-conjecture/src/CollatzConjecture.hs @@ -1,4 +1,4 @@ module CollatzConjecture (collatz) where -collatz :: Integer -> Integer +collatz :: Integer -> Maybe Integer collatz = error "You need to implement this function." From 14dfaeb755ded3e2b1fd36c3ca0fbf2427380d3e Mon Sep 17 00:00:00 2001 From: Average-user Date: Tue, 19 Sep 2017 16:32:42 -0300 Subject: [PATCH 15/16] a few corrections --- config.json | 1 + .../examples/success-standard/src/CollatzConjecture.hs | 2 +- exercises/collatz-conjecture/test/Tests.hs | 9 +-------- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/config.json b/config.json index deb31cfe3..da7dc2736 100644 --- a/config.json +++ b/config.json @@ -65,6 +65,7 @@ "unlocked_by": null, "difficulty": 1, "topics": [ + "Maybe" ] }, { diff --git a/exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs b/exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs index 1855e3495..4a25404f9 100644 --- a/exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs +++ b/exercises/collatz-conjecture/examples/success-standard/src/CollatzConjecture.hs @@ -6,4 +6,4 @@ collatzHelper t x | x == 1 = Just t | otherwise = collatzHelper (t+1) (x*3 + 1) collatz :: Integer -> Maybe Integer -collatz x = if x <= 0 then Nothing else collatzHelper 0 x +collatz x = if x <= 0 then Nothing else collatzHelper 0 x diff --git a/exercises/collatz-conjecture/test/Tests.hs b/exercises/collatz-conjecture/test/Tests.hs index 22767bf64..ffeb293d2 100644 --- a/exercises/collatz-conjecture/test/Tests.hs +++ b/exercises/collatz-conjecture/test/Tests.hs @@ -20,39 +20,32 @@ specs = describe "collatz" $ for_ cases test data Case = Case { description :: String - , property :: String , number :: Integer , expected :: Maybe Integer } cases :: [Case] cases = [ Case { description = "zero steps for one" - , property = "steps" , number = 1 , expected = Just 0 } , Case { description = "divide if even" - , property = "steps" , number = 16 , expected = Just 4 } , Case { description = "even and odd steps" - , property = "steps" , number = 12 - , expected =Just 9 + , expected = Just 9 } , Case { description = "Large number of even and odd steps" - , property = "steps" , number = 1000000 , expected = Just 152 } , Case { description = "zero is an error" - , property = "steps" , number = 0 , expected = Nothing } , Case { description = "negative value is an error" - , property = "steps" , number = -15 , expected = Nothing } From 6c6484a2d11d48a6a30070860bb5f3c14757cfa3 Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Tue, 19 Sep 2017 21:42:01 -0700 Subject: [PATCH 16/16] collatz: regenerate readme --- exercises/collatz-conjecture/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/exercises/collatz-conjecture/README.md b/exercises/collatz-conjecture/README.md index e0c6b62c5..9e3533cd1 100644 --- a/exercises/collatz-conjecture/README.md +++ b/exercises/collatz-conjecture/README.md @@ -1,4 +1,4 @@ -## Collatz Conjecture. +# Collatz Conjecture The Collatz Conjecture or 3x+1 problem can be summarized as follows: @@ -25,6 +25,8 @@ Starting with n = 12, the steps would be as follows: Resulting in 9 steps. So for input n = 12, the return value would be 9. + + ## Getting Started For installation and learning resources, refer to the @@ -79,8 +81,7 @@ one, head over there and create an issue. We'll do our best to help you! ## Source -An unsolved problem in mathematics named after mathematician Lothar Collatz -see more at [collatz conjecture wikipedia]("https://en.wikipedia.org/wiki/3x_%2B_1_problem") +An unsolved problem in mathematics named after mathematician Lothar Collatz [https://en.wikipedia.org/wiki/3x_%2B_1_problem](https://en.wikipedia.org/wiki/3x_%2B_1_problem) ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise.