From 6b76c9b1d57d0f929c382f4b691633c0901a2f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Nygaard=20=C3=85snes?= Date: Sat, 7 Oct 2017 18:36:25 +0200 Subject: [PATCH 1/5] Added CollatzConjecture --- .../collatz-conjecture/CollatzConjecture.elm | 1 + .../CollatzConjecture.example.elm | 19 +++++++++ exercises/collatz-conjecture/elm-package.json | 15 +++++++ exercises/collatz-conjecture/package.json | 14 +++++++ exercises/collatz-conjecture/tests/Tests.elm | 39 +++++++++++++++++++ .../collatz-conjecture/tests/elm-package.json | 16 ++++++++ 6 files changed, 104 insertions(+) create mode 100644 exercises/collatz-conjecture/CollatzConjecture.elm create mode 100644 exercises/collatz-conjecture/CollatzConjecture.example.elm create mode 100644 exercises/collatz-conjecture/elm-package.json create mode 100644 exercises/collatz-conjecture/package.json create mode 100644 exercises/collatz-conjecture/tests/Tests.elm create mode 100644 exercises/collatz-conjecture/tests/elm-package.json diff --git a/exercises/collatz-conjecture/CollatzConjecture.elm b/exercises/collatz-conjecture/CollatzConjecture.elm new file mode 100644 index 0000000..fba62aa --- /dev/null +++ b/exercises/collatz-conjecture/CollatzConjecture.elm @@ -0,0 +1 @@ +module CollatzConjecture exposing (..) diff --git a/exercises/collatz-conjecture/CollatzConjecture.example.elm b/exercises/collatz-conjecture/CollatzConjecture.example.elm new file mode 100644 index 0000000..5400aa1 --- /dev/null +++ b/exercises/collatz-conjecture/CollatzConjecture.example.elm @@ -0,0 +1,19 @@ +module CollatzConjecture exposing (collatz) + + +collatz : Int -> Result String Int +collatz start = + if start <= 0 then + Err "Only positive numbers are allowed" + else + Ok (collatzHelper 0 start) + + +collatzHelper : Int -> Int -> Int +collatzHelper steps start = + if start == 1 then + steps + else if start % 2 == 0 then + collatzHelper (1 + steps) (start // 2) + else + collatzHelper (1 + steps) (3 * start + 1) diff --git a/exercises/collatz-conjecture/elm-package.json b/exercises/collatz-conjecture/elm-package.json new file mode 100644 index 0000000..8f73600 --- /dev/null +++ b/exercises/collatz-conjecture/elm-package.json @@ -0,0 +1,15 @@ +{ + "version": "3.0.0", + "summary": "Exercism problems in Elm.", + "repository": "https://github.com/exercism/elm.git", + "license": "BSD3", + "source-directories": [ + "." + ], + "exposed-modules": [], + "dependencies": { + "elm-lang/core": "5.0.0 <= v < 6.0.0" + }, + "elm-version": "0.18.0 <= v < 0.19.0" +} + diff --git a/exercises/collatz-conjecture/package.json b/exercises/collatz-conjecture/package.json new file mode 100644 index 0000000..31d6fb3 --- /dev/null +++ b/exercises/collatz-conjecture/package.json @@ -0,0 +1,14 @@ +{ + "description": "Exercism/Elm", + "repository": "https://github.com/exercism/elm.git", + "license": "MIT", + "scripts": { + "postinstall": "elm-package install -y", + "watch": "elm-test --watch", + "test": "elm-test" + }, + "dependencies": { + "elm": "0.18.0", + "elm-test": "0.18.3" + } +} diff --git a/exercises/collatz-conjecture/tests/Tests.elm b/exercises/collatz-conjecture/tests/Tests.elm new file mode 100644 index 0000000..e1d1e0a --- /dev/null +++ b/exercises/collatz-conjecture/tests/Tests.elm @@ -0,0 +1,39 @@ +module Tests exposing (..) + +import Test exposing (..) +import Expect +import CollatzConjecture exposing (collatz) + + +tests : Test +tests = + describe "CollatzConjecture tests" + [ test "zero steps for one" <| + \() -> + Expect.equal (Ok 0) (collatz 1) + + -- Once you get the first test passing, remove the + -- `skip <|` (just leave the comma) on the next + -- lines to continue! + + , skip <| + test "divide if even" <| + \() -> + Expect.equal (Ok 4) (collatz 16) + , skip <| + test "even and odd step" <| + \() -> + Expect.equal (Ok 9) (collatz 12) + , skip <| + test "Large number of even and odd step" <| + \() -> + Expect.equal (Ok 152) (collatz 1000000) + , skip <| + test "zero is an error" <| + \() -> + Expect.equal (Err "Only positive numbers are allowed") (collatz 0) + , skip <| + test "negative values is an error" <| + \() -> + Expect.equal (Err "Only positive numbers are allowed") (collatz -15) + ] diff --git a/exercises/collatz-conjecture/tests/elm-package.json b/exercises/collatz-conjecture/tests/elm-package.json new file mode 100644 index 0000000..3e92515 --- /dev/null +++ b/exercises/collatz-conjecture/tests/elm-package.json @@ -0,0 +1,16 @@ +{ + "version": "3.0.0", + "summary": "Exercism problems in Elm.", + "repository": "https://github.com/exercism/elm.git", + "license": "BSD3", + "source-directories": [ + ".", + ".." + ], + "exposed-modules": [], + "dependencies": { + "elm-lang/core": "5.0.0 <= v < 6.0.0", + "elm-community/elm-test": "4.0.0 <= v < 5.0.0" + }, + "elm-version": "0.18.0 <= v < 0.19.0" +} From f40f8a1ac08de858811df896480021f9d9a7f0aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Nygaard=20=C3=85snes?= Date: Sun, 8 Oct 2017 11:30:04 +0200 Subject: [PATCH 2/5] Fixed elm-format --- exercises/collatz-conjecture/CollatzConjecture.elm | 1 + exercises/collatz-conjecture/CollatzConjecture.example.elm | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/collatz-conjecture/CollatzConjecture.elm b/exercises/collatz-conjecture/CollatzConjecture.elm index fba62aa..78ca90b 100644 --- a/exercises/collatz-conjecture/CollatzConjecture.elm +++ b/exercises/collatz-conjecture/CollatzConjecture.elm @@ -1 +1,2 @@ module CollatzConjecture exposing (..) + diff --git a/exercises/collatz-conjecture/CollatzConjecture.example.elm b/exercises/collatz-conjecture/CollatzConjecture.example.elm index 5400aa1..f325ab6 100644 --- a/exercises/collatz-conjecture/CollatzConjecture.example.elm +++ b/exercises/collatz-conjecture/CollatzConjecture.example.elm @@ -9,7 +9,7 @@ collatz start = Ok (collatzHelper 0 start) -collatzHelper : Int -> Int -> Int +collatzHelper : Int -> Int -> Int collatzHelper steps start = if start == 1 then steps From dfd20410a8c998e339e36cfcefed2f68d132584c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Nygaard=20=C3=85snes?= Date: Sun, 8 Oct 2017 11:40:05 +0200 Subject: [PATCH 3/5] Added Collatz Conjecture to config --- config.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/config.json b/config.json index 41e0e3a..e3a670d 100644 --- a/config.json +++ b/config.json @@ -320,6 +320,15 @@ "difficulty": 1, "topics": [ + ] + }, + { + "slug": "collatz-conjecture", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + ] } ], From 1b852aeeb460c6d06e010f6c401874bb495f9e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Nygaard=20=C3=85snes?= Date: Sun, 8 Oct 2017 17:45:28 +0200 Subject: [PATCH 4/5] Added uuid for collatz-conjecture to config.json --- config.json | 1 + 1 file changed, 1 insertion(+) diff --git a/config.json b/config.json index 8179930..b44963d 100644 --- a/config.json +++ b/config.json @@ -323,6 +323,7 @@ ] }, { + "uuid": "1f52ab74-02d5-db80-8f95-521aba04d183e704422", "slug": "collatz-conjecture", "core": false, "unlocked_by": null, From 8bc34db0f212156328c6f63d7d4769be0f67de9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Nygaard=20=C3=85snes?= Date: Sun, 8 Oct 2017 17:57:29 +0200 Subject: [PATCH 5/5] Correct formatting --- exercises/collatz-conjecture/tests/Tests.elm | 21 ++++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/exercises/collatz-conjecture/tests/Tests.elm b/exercises/collatz-conjecture/tests/Tests.elm index e1d1e0a..9534dca 100644 --- a/exercises/collatz-conjecture/tests/Tests.elm +++ b/exercises/collatz-conjecture/tests/Tests.elm @@ -15,25 +15,24 @@ tests = -- Once you get the first test passing, remove the -- `skip <|` (just leave the comma) on the next -- lines to continue! - , skip <| test "divide if even" <| - \() -> - Expect.equal (Ok 4) (collatz 16) + \() -> + Expect.equal (Ok 4) (collatz 16) , skip <| test "even and odd step" <| - \() -> - Expect.equal (Ok 9) (collatz 12) + \() -> + Expect.equal (Ok 9) (collatz 12) , skip <| test "Large number of even and odd step" <| - \() -> - Expect.equal (Ok 152) (collatz 1000000) + \() -> + Expect.equal (Ok 152) (collatz 1000000) , skip <| test "zero is an error" <| - \() -> - Expect.equal (Err "Only positive numbers are allowed") (collatz 0) + \() -> + Expect.equal (Err "Only positive numbers are allowed") (collatz 0) , skip <| test "negative values is an error" <| - \() -> - Expect.equal (Err "Only positive numbers are allowed") (collatz -15) + \() -> + Expect.equal (Err "Only positive numbers are allowed") (collatz -15) ]