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
require 'date' | |
def is_valid_date? year, month, day | |
return false if year < 2000 || year > 2999 | |
Date::valid_date?(year, month, day) | |
end | |
class Date | |
def is_valid_date_for_millenium? millenium |
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
A zero-indexed array A consisting of N integers is given. | |
An equilibrium index of this array is any integer P such that 0 ≤ P < N | |
and the sum of elements of lower indices is equal to the sum of elements of higher indices, | |
i.e. A[0] + A[1] + ... + A[P−1] = A[P+1] + ... + A[N−2] + A[N−1]. | |
Sum of zero elements is assumed to be equal to 0. This can happen if P = 0 or if P = N−1. | |
For example, consider the following array A consisting of N = 7 elements: | |
A[0] = -7 A[1] = 1 A[2] = 5 |
NewerOlder