Created
February 28, 2020 14:29
-
-
Save jaypowley/9b563b715e97ec143f33297dd3f5e637 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Rules - https://techcommunity.microsoft.com/t5/azure-developer-community-blog/it-s-2020-is-your-code-ready-for-leap-day/ba-p/1157279 | |
… Is the year evenly divisible by 4? Then it is a leap year. (Examples: 2012, 2016, 2020, 2024) | |
… Unless it is also evenly divisible by 100. Those are not leap years. (Examples: 1800, 1900, 2100) | |
… Except that year that are evenly divisible by 400 are leap years. (Examples: 1600, 2000, 2400) | |
*) | |
let fmod (x:int) (y:int) : bool = x % y = 0 | |
let isEvenlyDivisibleByFour (year:int) : bool = fmod year 4 | |
let isEvenlyDivisibleByOneHundred (year:int) : bool = fmod year 100 | |
let isEvenlyDivisibleByFourHundred (year:int) : bool = fmod year 400 | |
let isLeapYear year = | |
let divisibleByFour = isEvenlyDivisibleByFour year | |
let divisibleByOneHundred = isEvenlyDivisibleByOneHundred year | |
let divisibleByFourHundred = isEvenlyDivisibleByFourHundred year | |
divisibleByFour && (not divisibleByOneHundred || divisibleByFourHundred) | |
isLeapYear 2016;; | |
isLeapYear 2020;; | |
isLeapYear 2021;; | |
isLeapYear 2024;; | |
isLeapYear 1800;; | |
isLeapYear 1900;; | |
isLeapYear 2100;; | |
isLeapYear 1600;; | |
isLeapYear 2000;; | |
isLeapYear 2400;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment