Skip to content

Instantly share code, notes, and snippets.

View m-mujica's full-sized avatar

Manuel Mujica m-mujica

View GitHub Profile
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
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