Leap

Leap

Easy

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!
Note

For a delightful, four-minute explanation of the whole phenomenon of leap years, check out this YouTube video.

Instructions

Your task is to determine whether a given year is a leap year.

You will see a cases_test.go file in this exercise. This holds the test cases used in the leap_test.go. You can mostly ignore this file.

However, if you are interested... we sometimes generate the test data from a cross language repository. In that repo exercises may have a .json file that contains common test data. Some of our local exercises have an intermediary program that takes the problem specification JSON and turns in into Go structs that are fed into the <exercise>_test.go file. The Go specific transformation of that data lives in the cases_test.go file.

Edit via GitHub The link opens in a new window or tab
Go Exercism

Ready to start Leap?

Sign up to Exercism to learn and master Go with 34 concepts, 140 exercises, and real human mentoring, all for free.

Deep Dive into Leap!

Deep dive into the different algorithms and approaches you can use to solve Leap, as Jeremy and Erik explore interesting Community Solutions across 10 different languages on Exercism.