diff --git a/config.json b/config.json index 8689ac6..2d4269c 100644 --- a/config.json +++ b/config.json @@ -234,6 +234,14 @@ "transforming" ] }, + { + "slug": "leap", + "name": "Leap", + "uuid": "fed8614b-fa32-465e-8699-dbcf0cfc0798", + "practices": [], + "prerequisites": [], + "difficulty": 2 + }, { "slug": "linked-list", "name": "Linked List", diff --git a/exercises/practice/leap/.docs/instructions.md b/exercises/practice/leap/.docs/instructions.md new file mode 100644 index 0000000..a83826b --- /dev/null +++ b/exercises/practice/leap/.docs/instructions.md @@ -0,0 +1,22 @@ +# Instructions + +Given a year, report if it is a leap year. + +The tricky thing here is that a leap year in the Gregorian calendar occurs: + +```text +on every year that is evenly divisible by 4 + except every year that is evenly divisible by 100 + unless the year is also evenly divisible by 400 +``` + +For example, 1997 is not a leap year, but 1996 is. +1900 is not a leap year, but 2000 is. + +## Notes + +Though our exercise adopts some very simple rules, there is more to learn! + +For a delightful, four minute explanation of the whole leap year phenomenon, go watch [this youtube video][video]. + +[video]: https://www.youtube.com/watch?v=xX96xng7sAE diff --git a/exercises/practice/leap/.meta/config.json b/exercises/practice/leap/.meta/config.json new file mode 100644 index 0000000..e68a613 --- /dev/null +++ b/exercises/practice/leap/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "leap.coffee" + ], + "test": [ + "leap.spec.coffee" + ], + "example": [ + ".meta/example.coffee" + ] + }, + "blurb": "Given a year, report if it is a leap year.", + "source": "CodeRanch Cattle Drive, Assignment 3", + "source_url": "https://coderanch.com/t/718816/Leap" +} diff --git a/exercises/practice/leap/.meta/example.coffee b/exercises/practice/leap/.meta/example.coffee new file mode 100644 index 0000000..5600aee --- /dev/null +++ b/exercises/practice/leap/.meta/example.coffee @@ -0,0 +1,4 @@ +class Leap + leapYear: (year) -> + year % 4 == 0 && (!(year % 100 == 0) || year % 400 == 0) +module.exports = Leap diff --git a/exercises/practice/leap/.meta/tests.toml b/exercises/practice/leap/.meta/tests.toml new file mode 100644 index 0000000..ce6ba32 --- /dev/null +++ b/exercises/practice/leap/.meta/tests.toml @@ -0,0 +1,37 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[6466b30d-519c-438e-935d-388224ab5223] +description = "year not divisible by 4 in common year" + +[ac227e82-ee82-4a09-9eb6-4f84331ffdb0] +description = "year divisible by 2, not divisible by 4 in common year" + +[4fe9b84c-8e65-489e-970b-856d60b8b78e] +description = "year divisible by 4, not divisible by 100 in leap year" + +[7fc6aed7-e63c-48f5-ae05-5fe182f60a5d] +description = "year divisible by 4 and 5 is still a leap year" + +[78a7848f-9667-4192-ae53-87b30c9a02dd] +description = "year divisible by 100, not divisible by 400 in common year" + +[9d70f938-537c-40a6-ba19-f50739ce8bac] +description = "year divisible by 100 but not by 3 is still not a leap year" + +[42ee56ad-d3e6-48f1-8e3f-c84078d916fc] +description = "year divisible by 400 is leap year" + +[57902c77-6fe9-40de-8302-587b5c27121e] +description = "year divisible by 400 but not by 125 is still a leap year" + +[c30331f6-f9f6-4881-ad38-8ca8c12520c1] +description = "year divisible by 200, not divisible by 400 in common year" diff --git a/exercises/practice/leap/leap.coffee b/exercises/practice/leap/leap.coffee new file mode 100644 index 0000000..e8e63fc --- /dev/null +++ b/exercises/practice/leap/leap.coffee @@ -0,0 +1,4 @@ +class Leap + leapYear: (year) -> + +module.exports = Leap diff --git a/exercises/practice/leap/leap.spec.coffee b/exercises/practice/leap/leap.spec.coffee new file mode 100644 index 0000000..2c5c507 --- /dev/null +++ b/exercises/practice/leap/leap.spec.coffee @@ -0,0 +1,39 @@ +Leap = require './leap' + +describe 'Leap', -> + leap = new Leap() + it 'year not divisible by 4 is common year', -> + result = leap.leapYear(2015) + expect(result).toEqual false + + it 'year divisible by 2, not divisible by 4 is common year', -> + result = leap.leapYear(1970) + expect(result).toEqual false + + it 'year divisible by 4, not divisible by 100 is leap year', -> + result = leap.leapYear(1996) + expect(result).toEqual true + + it 'year divisible by 4 and 5 is still a leap year', -> + result = leap.leapYear(1960) + expect(result).toEqual true + + it 'year divisible by 100, not divisible by 400 is common year', -> + result = leap.leapYear(2100) + expect(result).toEqual false + + it 'year divisible by 100 but not by 3 is still not a leap year', -> + result = leap.leapYear 1900 + expect(result).toEqual false + + it 'year divisible by 400 is leap year', -> + result = leap.leapYear 2000 + expect(result).toEqual true + + it 'year divisible by 400 but not by 125 is still a leap year', -> + result = leap.leapYear(2400) + expect(result).toEqual true + + it 'year divisible by 200, not divisible by 400 is common year', -> + result = leap.leapYear(1800) + expect(result).toEqual false