Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
"prerequisites": [],
"difficulty": 2
},
{
"slug": "leap",
"name": "Leap",
"uuid": "473f85b9-c74e-4c6f-91a0-003b370bff5c",
"practices": [],
"prerequisites": [],
"difficulty": 2
},
{
"slug": "two-fer",
"name": "Two-Fer",
Expand Down
3 changes: 3 additions & 0 deletions exercises/practice/leap/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Instructions

Your task is to determine whether a given year is a leap year.
16 changes: 16 additions & 0 deletions exercises/practice/leap/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -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).
~~~~
2 changes: 2 additions & 0 deletions exercises/practice/leap/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
**/*.res.js
1 change: 1 addition & 0 deletions exercises/practice/leap/.meta/Leap.res
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let isLeapYear = year => year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)
1 change: 1 addition & 0 deletions exercises/practice/leap/.meta/Leap.resi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let isLeapYear: int => bool
23 changes: 23 additions & 0 deletions exercises/practice/leap/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"authors": [
"therealowenrees"
],
"files": {
"solution": [
"src/Leap.res"
],
"test": [
"tests/Leap_test.res"
],
"example": [
".meta/Leap.res",
".meta/Leap.resi"
],
"editor": [
"src/Leap.resi"
]
},
"blurb": "Determine whether a given year is a leap year.",
"source": "CodeRanch Cattle Drive, Assignment 3",
"source_url": "https://web.archive.org/web/20240907033714/https://coderanch.com/t/718816/Leap"
}
19 changes: 19 additions & 0 deletions exercises/practice/leap/.meta/testTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { assertEqual } from "../../../../test_generator/assertions.js";
import { generateTests } from '../../../../test_generator/testGenerator.js';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const slug = path.basename(path.resolve(__dirname, '..'))

// EDIT THIS WITH YOUR ASSERTIONS
export const assertionFunctions = [ assertEqual ]

// EDIT THIS WITH YOUR TEST TEMPLATES
export const template = (c) => {
const { year } = c.input

return `assertEqual(~message="${c.description}", isLeapYear(${year}), ${c.expected})`
}

generateTests(__dirname, slug, assertionFunctions, template)
37 changes: 37 additions & 0 deletions exercises/practice/leap/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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"
21 changes: 21 additions & 0 deletions exercises/practice/leap/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Exercism

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading
Loading