Skip to content

Commit 3e6ffc4

Browse files
authored
Merge pull request ashutosh97#80 from luminousbeam/master
Added Leap Year
2 parents 7f608fa + 86c057e commit 3e6ffc4

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Leap Year/instructions.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Leap
2+
Given a year, report if it is a leap year.
3+
4+
The tricky thing here is that a leap year in the Gregorian calendar occurs:
5+
6+
on every year that is evenly divisible by 4
7+
except every year that is evenly divisible by 100
8+
unless the year is also evenly divisible by 400
9+
For example, 1997 is not a leap year, but 1996 is. 1900 is not a leap year, but 2000 is.
10+
11+
If your language provides a method in the standard library that does this look-up, pretend it doesn't exist and implement it yourself.

Leap Year/ruby_solution.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def leap(year)
2+
puts year %400 == 0 || year %4 == 0 && !(year %100 == 0)
3+
end
4+
5+
leap(1996) #expect true
6+
leap(2000) #expect true
7+
leap(2015) #expect false
8+
leap(1800) #expect false

0 commit comments

Comments
 (0)