Skip to content

Instantly share code, notes, and snippets.

@alextercete
Last active May 10, 2019 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alextercete/f6a54d88852ec14ba7dc50944e0ac31c to your computer and use it in GitHub Desktop.
Save alextercete/f6a54d88852ec14ba7dc50944e0ac31c to your computer and use it in GitHub Desktop.

Leap years

Problem

  1. All years divisible by 400 ARE leap years (so, for example, 2000 was indeed a leap year)
  2. All years divisible by 100 but not by 400 are NOT leap years (so, for example, 1700, 1800, and 1900 were NOT leap years, NOR will 2100 be a leap year)
  3. All years divisible by 4 but not by 100 ARE leap years (e.g., 2008, 2012, 2016)
  4. All years not divisible by 4 are NOT leap years (e.g. 2017, 2018, 2019)

See: http://codingdojo.org/kata/LeapYears/

Solution

using System;
using System.Linq;

internal class Program
{
  public static void Main(string[] args)
  {
    var years = new[] {1700, 1800, 1900, 2000, 2008, 2012, 2016, 2017, 2018, 2019};

    Console.WriteLine($"Leap years: {string.Join(", ", years.Where(IsLeapYear))}");
    // Output: Leap years: 2000, 2008, 2012, 2016
  }

  private static bool IsLeapYear(int year)
  {
    // TODO: Implement this
    return true;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment