From f554c9ca490e8626b30b72a8710f42db33bee5c8 Mon Sep 17 00:00:00 2001 From: Exercism Bot Date: Fri, 12 Jul 2024 11:45:14 +0100 Subject: [PATCH] Implement exercise 'leap' --- config.json | 12 ++++- config.yaml | 10 +++++ exercises/practice/leap/.docs/instructions.md | 3 ++ exercises/practice/leap/.docs/introduction.md | 16 +++++++ exercises/practice/leap/.meta/config.json | 19 ++++++++ exercises/practice/leap/.meta/leap-test.ys | 44 +++++++++++++++++++ exercises/practice/leap/.meta/leap.ys | 6 +++ exercises/practice/leap/.meta/tests.toml | 37 ++++++++++++++++ exercises/practice/leap/Makefile | 6 +++ exercises/practice/leap/leap-test.ys | 44 +++++++++++++++++++ exercises/practice/leap/leap.ys | 5 +++ 11 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 exercises/practice/leap/.docs/instructions.md create mode 100644 exercises/practice/leap/.docs/introduction.md create mode 100644 exercises/practice/leap/.meta/config.json create mode 100644 exercises/practice/leap/.meta/leap-test.ys create mode 100644 exercises/practice/leap/.meta/leap.ys create mode 100644 exercises/practice/leap/.meta/tests.toml create mode 100644 exercises/practice/leap/Makefile create mode 100644 exercises/practice/leap/leap-test.ys create mode 100644 exercises/practice/leap/leap.ys diff --git a/config.json b/config.json index 4b2b028..8809a9e 100644 --- a/config.json +++ b/config.json @@ -40,13 +40,23 @@ "strings" ] }, + { + "slug": "leap", + "name": "Leap", + "uuid": "a6e60d12-8265-404a-b34e-69b6d00014fd", + "practices": [], + "prerequisites": [], + "difficulty": 1, + "topics": [] + }, { "slug": "two-fer", "name": "Two-Fer", "uuid": "0957cb25-13dd-43a0-ab3c-ba452ffa5508", "practices": [], "prerequisites": [], - "difficulty": 1 + "difficulty": 1, + "topics": [] } ] }, diff --git a/config.yaml b/config.yaml index c99dae7..06f9cfe 100644 --- a/config.yaml +++ b/config.yaml @@ -46,12 +46,22 @@ exercises: prerequisites: [] difficulty: 1 topics: [strings] + + - slug: leap + name: Leap + uuid: a6e60d12-8265-404a-b34e-69b6d00014fd + practices: [] + prerequisites: [] + difficulty: 1 + topics: [] + - slug: two-fer name: Two-Fer uuid: 0957cb25-13dd-43a0-ab3c-ba452ffa5508 practices: [] prerequisites: [] difficulty: 1 + topics: [] concepts: [] diff --git a/exercises/practice/leap/.docs/instructions.md b/exercises/practice/leap/.docs/instructions.md new file mode 100644 index 0000000..b14f856 --- /dev/null +++ b/exercises/practice/leap/.docs/instructions.md @@ -0,0 +1,3 @@ +# Instructions + +Your task is to determine whether a given year is a leap year. diff --git a/exercises/practice/leap/.docs/introduction.md b/exercises/practice/leap/.docs/introduction.md new file mode 100644 index 0000000..4ffd2da --- /dev/null +++ b/exercises/practice/leap/.docs/introduction.md @@ -0,0 +1,16 @@ +# Introduction + +A leap year (in the Gregorian calendar) occurs: + +- In every year that is evenly divisible by 4. +- Unless the year is evenly divisible by 100, in which case it's only a leap year if the year is also evenly divisible by 400. + +Some examples: + +- 1997 was not a leap year as it's not divisible by 4. +- 1900 was not a leap year as it's not divisible by 400. +- 2000 was a leap year! + +~~~~exercism/note +For a delightful, four-minute explanation of the whole phenomenon of leap years, check out [this YouTube 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..8a3ac14 --- /dev/null +++ b/exercises/practice/leap/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "m-dango" + ], + "files": { + "solution": [ + "leap.ys" + ], + "test": [ + "leap-test.ys" + ], + "example": [ + ".meta/leap.ys" + ] + }, + "blurb": "Determine whether a given year 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/leap-test.ys b/exercises/practice/leap/.meta/leap-test.ys new file mode 100644 index 0000000..3f403f8 --- /dev/null +++ b/exercises/practice/leap/.meta/leap-test.ys @@ -0,0 +1,44 @@ +#!/usr/bin/env ys-0 + +require ys::taptest: :all + +use: leap + +test:: +- name: year not divisible by 4 in common year + code: leap/is-leap-year(2015) + want: false + +- name: year divisible by 2, not divisible by 4 in common year + code: leap/is-leap-year(1970) + want: false + +- name: year divisible by 4, not divisible by 100 in leap year + code: leap/is-leap-year(1996) + want: true + +- name: year divisible by 4 and 5 is still a leap year + code: leap/is-leap-year(1960) + want: true + +- name: year divisible by 100, not divisible by 400 in common year + code: leap/is-leap-year(2100) + want: false + +- name: year divisible by 100 but not by 3 is still not a leap year + code: leap/is-leap-year(1900) + want: false + +- name: year divisible by 400 is leap year + code: leap/is-leap-year(2000) + want: true + +- name: year divisible by 400 but not by 125 is still a leap year + code: leap/is-leap-year(2400) + want: true + +- name: year divisible by 200, not divisible by 400 in common year + code: leap/is-leap-year(1800) + want: false + +done: diff --git a/exercises/practice/leap/.meta/leap.ys b/exercises/practice/leap/.meta/leap.ys new file mode 100644 index 0000000..cf9e34c --- /dev/null +++ b/exercises/practice/leap/.meta/leap.ys @@ -0,0 +1,6 @@ +!yamlscript/v0 + +ns: leap + +defn is-leap-year(year): + ((year % 4) == 0) && (((year % 100) > 0) || ((year % 400) == 0)) 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/Makefile b/exercises/practice/leap/Makefile new file mode 100644 index 0000000..6c94728 --- /dev/null +++ b/exercises/practice/leap/Makefile @@ -0,0 +1,6 @@ +SHELL := bash + +default: + +test: + prove -v *-test.ys diff --git a/exercises/practice/leap/leap-test.ys b/exercises/practice/leap/leap-test.ys new file mode 100644 index 0000000..3f403f8 --- /dev/null +++ b/exercises/practice/leap/leap-test.ys @@ -0,0 +1,44 @@ +#!/usr/bin/env ys-0 + +require ys::taptest: :all + +use: leap + +test:: +- name: year not divisible by 4 in common year + code: leap/is-leap-year(2015) + want: false + +- name: year divisible by 2, not divisible by 4 in common year + code: leap/is-leap-year(1970) + want: false + +- name: year divisible by 4, not divisible by 100 in leap year + code: leap/is-leap-year(1996) + want: true + +- name: year divisible by 4 and 5 is still a leap year + code: leap/is-leap-year(1960) + want: true + +- name: year divisible by 100, not divisible by 400 in common year + code: leap/is-leap-year(2100) + want: false + +- name: year divisible by 100 but not by 3 is still not a leap year + code: leap/is-leap-year(1900) + want: false + +- name: year divisible by 400 is leap year + code: leap/is-leap-year(2000) + want: true + +- name: year divisible by 400 but not by 125 is still a leap year + code: leap/is-leap-year(2400) + want: true + +- name: year divisible by 200, not divisible by 400 in common year + code: leap/is-leap-year(1800) + want: false + +done: diff --git a/exercises/practice/leap/leap.ys b/exercises/practice/leap/leap.ys new file mode 100644 index 0000000..11f008f --- /dev/null +++ b/exercises/practice/leap/leap.ys @@ -0,0 +1,5 @@ +!yamlscript/v0 + +ns: leap + +defn is-leap-year(year):