Exercism v3 launches on Sept 1st 2021. Learn more! ๐Ÿš€๐Ÿš€๐Ÿš€
Avatar of angelikatyborska

angelikatyborska's solution

to Leap in the Erlang Track

Published at Apr 02 2019 · 0 comments
Test suite


This exercise has changed since this solution was written.

Given a year, report if it is a leap year.

The tricky thing here is that a leap year in the Gregorian calendar occurs:

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.

If your language provides a method in the standard library that does this look-up, pretend it doesn't exist and implement it yourself.


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.

Running tests

In order to run the tests, issue the following command from the exercise directory:

For running the tests provided, rebar3 is used as it is the official build and dependency management tool for erlang now. Please refer to the tracks installation instructions on how to do that.

In order to run the tests, you can issue the following command from the exercise directory.

$ rebar3 eunit


For detailed information about the Erlang track, please refer to the help page on the Exercism site. This covers the basic information on setting up the development environment expected by the exercises.


JavaRanch Cattle Drive, exercise 3 http://www.javaranch.com/leap.jsp

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


%% Based on canonical data version 1.4.0
%% https://github.com/exercism/problem-specifications/raw/master/exercises/leap/canonical-data.json
%% This file is automatically generated from the exercises canonical data.



'1_year_not_divisible_by_4_common_year_test'() ->

'2_year_divisible_by_4_not_divisible_by_100_leap_year_test'() ->

'3_year_divisible_by_100_not_divisible_by_400_common_year_test'() ->

'4_year_divisible_by_400_leap_year_test'() ->

'5_year_divisible_by_200_not_divisible_by_400_common_year_test'() ->


leap_year(Year) ->
  (Year rem 4 =:= 0) andalso ((Year rem 100 =/= 0) orelse (Year rem 400 =:= 0)).

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other peopleโ€™s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?