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.


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.

The tests for this exercise (and future exercises), are prefix numbered like 'test00_'. This is not a normal convention in Pharo, however to ease the study of the language it is useful to present tests in a deterministic order.

For this exercise, study the 'arithmetic' method category for class Number, as well as how boolean operators are also defined as messages. Notice how "and:" and "or:" are implented in the classes True and False. You can use the context menu item "senders of..." to view how other parts of Pharo use these operators.

You may also find something useful trying... World > Tools > Finder > Examples > 20 . 4 . true
which is asking Pharo which operations between the first and second elements result in the third.
View demo

Last updated 28 July 2022
Edit via GitHub The link opens in a new window or tab
Pharo Exercism

Ready to start Leap?

Sign up to Exercism to learn and master Pharo with 42 exercises, and real human mentoring, all for free.