Julio Biason
3 years ago
8 changed files with 217 additions and 0 deletions
@ -0,0 +1,28 @@
|
||||
{ |
||||
"blurb": "Given a year, report if it is a leap year.", |
||||
"authors": [ |
||||
"tmcgilchrist" |
||||
], |
||||
"contributors": [ |
||||
"ErikSchierboom", |
||||
"iHiD", |
||||
"JordanAdams", |
||||
"juhlig", |
||||
"kytrinyx", |
||||
"NobbZ", |
||||
"xymbol" |
||||
], |
||||
"files": { |
||||
"solution": [ |
||||
"src/leap.erl" |
||||
], |
||||
"test": [ |
||||
"test/leap_tests.erl" |
||||
], |
||||
"example": [ |
||||
".meta/example.erl" |
||||
] |
||||
}, |
||||
"source": "JavaRanch Cattle Drive, exercise 3", |
||||
"source_url": "http://www.javaranch.com/leap.jsp" |
||||
} |
@ -0,0 +1 @@
|
||||
{"track":"erlang","exercise":"leap","id":"a86123e823824d97855ac299e3fb2b10","url":"https://exercism.org/tracks/erlang/exercises/leap","handle":"JBiason","is_requester":true,"auto_approve":false} |
@ -0,0 +1,36 @@
|
||||
# Help |
||||
|
||||
## Running the tests |
||||
|
||||
You can run the tests by running the following command from the exercise directory. |
||||
|
||||
```bash |
||||
$ rebar3 eunit |
||||
``` |
||||
|
||||
## Submitting your solution |
||||
|
||||
You can submit your solution using the `exercism submit src/leap.erl` 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 [Erlang track's documentation](https://exercism.org/docs/tracks/erlang) |
||||
- [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: |
||||
|
||||
- [Exercism related BEAM support channel on gitter](https://gitter.im/exercism/xerlang) |
||||
- [Erlang Documentation](http://www.erlang.org/doc.html) |
||||
- [Learn You Some Erlang for Great Good](http://learnyousomeerlang.com) |
||||
- [StackOverflow](http://stackoverflow.com/) |
@ -0,0 +1,49 @@
|
||||
# Leap |
||||
|
||||
Welcome to Leap on Exercism's Erlang 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 |
||||
|
||||
- @tmcgilchrist |
||||
|
||||
### Contributed to by |
||||
|
||||
- @ErikSchierboom |
||||
- @iHiD |
||||
- @JordanAdams |
||||
- @juhlig |
||||
- @kytrinyx |
||||
- @NobbZ |
||||
- @xymbol |
||||
|
||||
### Based on |
||||
|
||||
JavaRanch Cattle Drive, exercise 3 - http://www.javaranch.com/leap.jsp |
@ -0,0 +1,30 @@
|
||||
%% Erlang compiler options |
||||
{erl_opts, [debug_info, warnings_as_errors]}. |
||||
|
||||
{deps, [{erl_exercism, "0.1.2"}]}. |
||||
|
||||
{dialyzer, [ |
||||
{warnings, [underspecs, no_return]}, |
||||
{get_warnings, true}, |
||||
{plt_apps, top_level_deps}, % top_level_deps | all_deps |
||||
{plt_extra_apps, []}, |
||||
{plt_location, local}, % local | "/my/file/name" |
||||
{plt_prefix, "rebar3"}, |
||||
{base_plt_apps, [stdlib, kernel, crypto]}, |
||||
{base_plt_location, global}, % global | "/my/file/name" |
||||
{base_plt_prefix, "rebar3"} |
||||
]}. |
||||
|
||||
%% eunit:test(Tests) |
||||
{eunit_tests, []}. |
||||
%% Options for eunit:test(Tests, Opts) |
||||
{eunit_opts, [verbose]}. |
||||
|
||||
%% == xref == |
||||
|
||||
{xref_warnings, true}. |
||||
|
||||
%% xref checks to run |
||||
{xref_checks, [undefined_function_calls, undefined_functions, |
||||
locals_not_used, exports_not_used, |
||||
deprecated_function_calls, deprecated_functions]}. |
@ -0,0 +1,9 @@
|
||||
{application, leap, |
||||
[{description, "exercism.io - leap"}, |
||||
{vsn, "0.0.1"}, |
||||
{modules, []}, |
||||
{registered, []}, |
||||
{applications, [kernel, |
||||
stdlib]}, |
||||
{env, []} |
||||
]}. |
@ -0,0 +1,9 @@
|
||||
-module(leap). |
||||
|
||||
-export([leap_year/1]). |
||||
|
||||
|
||||
leap_year(Year) -> |
||||
(Year rem 4 == 0) |
||||
and ((Year rem 100 /= 0) |
||||
or (Year rem 400 == 0)). |
@ -0,0 +1,55 @@
|
||||
%% Generated with 'testgen v0.2.0' |
||||
%% Revision 1 of the exercises generator was used |
||||
%% https://github.com/exercism/problem-specifications/raw/a2c75d2e71c6a2efa1ce3d756292cc89d811136c/exercises/leap/canonical-data.json |
||||
%% This file is automatically generated from the exercises canonical data. |
||||
|
||||
-module(leap_tests). |
||||
|
||||
-include_lib("erl_exercism/include/exercism.hrl"). |
||||
-include_lib("eunit/include/eunit.hrl"). |
||||
|
||||
|
||||
|
||||
|
||||
'1_year_not_divisible_by_4_in_common_year_test_'() -> |
||||
{"year not divisible by 4 in common year", |
||||
?_assertNot(leap:leap_year(2015))}. |
||||
|
||||
'2_year_divisible_by_2_not_divisible_by_4_in_common_year_test_'() -> |
||||
{"year divisible by 2, not divisible by " |
||||
"4 in common year", |
||||
?_assertNot(leap:leap_year(1970))}. |
||||
|
||||
'3_year_divisible_by_4_not_divisible_by_100_in_leap_year_test_'() -> |
||||
{"year divisible by 4, not divisible by " |
||||
"100 in leap year", |
||||
?_assert(leap:leap_year(1996))}. |
||||
|
||||
'4_year_divisible_by_4_and_5_is_still_a_leap_year_test_'() -> |
||||
{"year divisible by 4 and 5 is still a " |
||||
"leap year", |
||||
?_assert(leap:leap_year(1960))}. |
||||
|
||||
'5_year_divisible_by_100_not_divisible_by_400_in_common_year_test_'() -> |
||||
{"year divisible by 100, not divisible " |
||||
"by 400 in common year", |
||||
?_assertNot(leap:leap_year(2100))}. |
||||
|
||||
'6_year_divisible_by_100_but_not_by_3_is_still_not_a_leap_year_test_'() -> |
||||
{"year divisible by 100 but not by 3 is " |
||||
"still not a leap year", |
||||
?_assertNot(leap:leap_year(1900))}. |
||||
|
||||
'7_year_divisible_by_400_is_leap_year_test_'() -> |
||||
{"year divisible by 400 is leap year", |
||||
?_assert(leap:leap_year(2000))}. |
||||
|
||||
'8_year_divisible_by_400_but_not_by_125_is_still_a_leap_year_test_'() -> |
||||
{"year divisible by 400 but not by 125 " |
||||
"is still a leap year", |
||||
?_assert(leap:leap_year(2400))}. |
||||
|
||||
'9_year_divisible_by_200_not_divisible_by_400_in_common_year_test_'() -> |
||||
{"year divisible by 200, not divisible " |
||||
"by 400 in common year", |
||||
?_assertNot(leap:leap_year(1800))}. |
Loading…
Reference in new issue