From f4af7cc147a167202403bda4b403a041989ec7e3 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Thu, 14 Oct 2021 12:58:20 -0300 Subject: [PATCH] Leap year --- racket/leap/.exercism/config.json | 26 ++++++++++++++++ racket/leap/.exercism/metadata.json | 1 + racket/leap/HELP.md | 39 ++++++++++++++++++++++++ racket/leap/README.md | 47 +++++++++++++++++++++++++++++ racket/leap/leap-test.rkt | 19 ++++++++++++ racket/leap/leap.rkt | 22 ++++++++++++++ 6 files changed, 154 insertions(+) create mode 100644 racket/leap/.exercism/config.json create mode 100644 racket/leap/.exercism/metadata.json create mode 100644 racket/leap/HELP.md create mode 100644 racket/leap/README.md create mode 100644 racket/leap/leap-test.rkt create mode 100644 racket/leap/leap.rkt diff --git a/racket/leap/.exercism/config.json b/racket/leap/.exercism/config.json new file mode 100644 index 0000000..3325c49 --- /dev/null +++ b/racket/leap/.exercism/config.json @@ -0,0 +1,26 @@ +{ + "blurb": "Given a year, report if it is a leap year.", + "authors": [ + "arguello" + ], + "contributors": [ + "mbertheau", + "PurityControl", + "robertpostill", + "timotheosh", + "yurrriq" + ], + "files": { + "solution": [ + "leap.rkt" + ], + "test": [ + "leap-test.rkt" + ], + "example": [ + ".meta/example.rkt" + ] + }, + "source": "JavaRanch Cattle Drive, exercise 3", + "source_url": "http://www.javaranch.com/leap.jsp" +} diff --git a/racket/leap/.exercism/metadata.json b/racket/leap/.exercism/metadata.json new file mode 100644 index 0000000..11497fb --- /dev/null +++ b/racket/leap/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"racket","exercise":"leap","id":"282753f427d94beda313070ecdb17f3b","url":"https://exercism.org/tracks/racket/exercises/leap","handle":"JBiason","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/racket/leap/HELP.md b/racket/leap/HELP.md new file mode 100644 index 0000000..136fc45 --- /dev/null +++ b/racket/leap/HELP.md @@ -0,0 +1,39 @@ +# Help + +## Running the tests + +To run the test through DrRacket, simply open the test file and click the 'Run' button in the upper right. + +To run the test from the command line, run the test from the exercise directory with the following command: + +``` +raco test -test.rkt +``` + +where `` should be replaced with the exercise's slug. + +## Submitting your solution + +You can submit your solution using the `exercism submit leap.rkt` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Racket track's documentation](https://exercism.org/docs/tracks/racket) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [The Racket Reference](http://docs.racket-lang.org/reference/index.html) +- [/r/racket](https://www.reddit.com/r/racket) is the Racket subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/racket) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/racket/leap/README.md b/racket/leap/README.md new file mode 100644 index 0000000..293c6a5 --- /dev/null +++ b/racket/leap/README.md @@ -0,0 +1,47 @@ +# Leap + +Welcome to Leap on Exercism's Racket Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## 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]: http://www.youtube.com/watch?v=xX96xng7sAE + +## Source + +### Created by + +- @arguello + +### Contributed to by + +- @mbertheau +- @PurityControl +- @robertpostill +- @timotheosh +- @yurrriq + +### Based on + +JavaRanch Cattle Drive, exercise 3 - http://www.javaranch.com/leap.jsp \ No newline at end of file diff --git a/racket/leap/leap-test.rkt b/racket/leap/leap-test.rkt new file mode 100644 index 0000000..dab00d2 --- /dev/null +++ b/racket/leap/leap-test.rkt @@ -0,0 +1,19 @@ +#lang racket/base + +(require "leap.rkt") + +(module+ test + (require rackunit rackunit/text-ui) + + (define suite + (test-suite + "leap tests" + + (test-eqv? "vanilla-leap-year" (leap-year? 1996) #t) + (test-eqv? "any-old-year" (leap-year? 2015)#f) + (test-eqv? "non-leap-even-year" (leap-year? 1998) #f) + (test-eqv? "century" (leap-year? 2100)#f) + (test-eqv? "not an exceptional-century" (leap-year? 1800) #f) + (test-eqv? "exceptional-century" (leap-year? 2000) #t))) + + (run-tests suite)) diff --git a/racket/leap/leap.rkt b/racket/leap/leap.rkt new file mode 100644 index 0000000..20bff8a --- /dev/null +++ b/racket/leap/leap.rkt @@ -0,0 +1,22 @@ +#lang racket + +(provide leap-year?) + +(define (div-by-4 year) + (= 0 (remainder year 4)) + ) + +(define (not-div-by-100 year) + (not (= 0 (remainder year 100))) + ) + +(define (div-by-400 year) + (= 0 (remainder year 400)) + ) + +(define (leap-year? year) + (and (div-by-4 year) + (or (div-by-400 year) + (not-div-by-100 year)) + ) + )