first two easy exercises
This commit is contained in:
commit
8c221fed78
20 changed files with 562 additions and 0 deletions
36
leap/HELP.md
Normal file
36
leap/HELP.md
Normal file
|
@ -0,0 +1,36 @@
|
|||
# Help
|
||||
|
||||
## Running the tests
|
||||
|
||||
A `Makefile` is provided with a default target to compile your solution and run the tests. At the command line in your exercise's directory, type:
|
||||
|
||||
```bash
|
||||
make
|
||||
```
|
||||
|
||||
## Submitting your solution
|
||||
|
||||
You can submit your solution using the `exercism submit leap.ml` 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 [OCaml track's documentation](https://exercism.org/docs/tracks/ocaml)
|
||||
- The [OCaml track's programming category on the forum](https://forum.exercism.org/c/programming/ocaml)
|
||||
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||
- 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:
|
||||
|
||||
- [Documentation for the Standard Library](http://caml.inria.fr/pub/docs/manual-ocaml/libref/index.html)
|
||||
- [/r/ocaml](https://www.reddit.com/r/ocaml) is the OCaml subreddit.
|
||||
- [StackOverflow](http://stackoverflow.com/questions/tagged/ocaml) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
|
9
leap/Makefile
Normal file
9
leap/Makefile
Normal file
|
@ -0,0 +1,9 @@
|
|||
default: clean test
|
||||
|
||||
test:
|
||||
dune runtest
|
||||
|
||||
clean:
|
||||
dune clean
|
||||
|
||||
.PHONY: clean
|
51
leap/README.md
Normal file
51
leap/README.md
Normal file
|
@ -0,0 +1,51 @@
|
|||
# Leap
|
||||
|
||||
Welcome to Leap on Exercism's OCaml 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]: https://www.youtube.com/watch?v=xX96xng7sAE
|
||||
|
||||
## Source
|
||||
|
||||
### Created by
|
||||
|
||||
- @tmcgilchrist
|
||||
|
||||
### Contributed to by
|
||||
|
||||
- @daveyarwood
|
||||
- @dvberkel
|
||||
- @iHiD
|
||||
- @ismaelga
|
||||
- @kytrinyx
|
||||
- @marionebl
|
||||
- @Peaupote
|
||||
- @pminten
|
||||
- @sbl
|
||||
- @sshine
|
||||
- @stevejb71
|
||||
|
||||
### Based on
|
||||
|
||||
CodeRanch Cattle Drive, Assignment 3 - https://coderanch.com/t/718816/Leap
|
16
leap/dune
Normal file
16
leap/dune
Normal file
|
@ -0,0 +1,16 @@
|
|||
(executable
|
||||
(name test)
|
||||
(libraries base ounit2))
|
||||
|
||||
(alias
|
||||
(name runtest)
|
||||
(deps (:x test.exe))
|
||||
(action (run %{x})))
|
||||
|
||||
(alias
|
||||
(name buildtest)
|
||||
(deps (:x test.exe)))
|
||||
|
||||
(env
|
||||
(dev
|
||||
(flags (:standard -warn-error -A))))
|
1
leap/dune-project
Normal file
1
leap/dune-project
Normal file
|
@ -0,0 +1 @@
|
|||
(lang dune 1.1)
|
2
leap/leap.ml
Normal file
2
leap/leap.ml
Normal file
|
@ -0,0 +1,2 @@
|
|||
let leap_year year =
|
||||
(year mod 4 = 0 && year mod 100 <> 0) || year mod 400 = 0
|
1
leap/leap.mli
Normal file
1
leap/leap.mli
Normal file
|
@ -0,0 +1 @@
|
|||
val leap_year: int -> bool
|
28
leap/test.ml
Normal file
28
leap/test.ml
Normal file
|
@ -0,0 +1,28 @@
|
|||
open OUnit2
|
||||
open Leap
|
||||
|
||||
let ae exp got _test_ctxt = assert_equal exp got ~printer:string_of_bool
|
||||
|
||||
let tests = [
|
||||
"year not divisible by 4 in common year" >::
|
||||
ae false (leap_year 2015);
|
||||
"year divisible by 2, not divisible by 4 in common year" >::
|
||||
ae false (leap_year 1970);
|
||||
"year divisible by 4, not divisible by 100 in leap year" >::
|
||||
ae true (leap_year 1996);
|
||||
"year divisible by 4 and 5 is still a leap year" >::
|
||||
ae true (leap_year 1960);
|
||||
"year divisible by 100, not divisible by 400 in common year" >::
|
||||
ae false (leap_year 2100);
|
||||
"year divisible by 100 but not by 3 is still not a leap year" >::
|
||||
ae false (leap_year 1900);
|
||||
"year divisible by 400 is leap year" >::
|
||||
ae true (leap_year 2000);
|
||||
"year divisible by 400 but not by 125 is still a leap year" >::
|
||||
ae true (leap_year 2400);
|
||||
"year divisible by 200, not divisible by 400 in common year" >::
|
||||
ae false (leap_year 1800);
|
||||
]
|
||||
|
||||
let () =
|
||||
run_test_tt_main ("leap tests" >::: tests)
|
Loading…
Add table
Add a link
Reference in a new issue