Over at Judaism.SE, there was a discussion about a formula to determine leap years in the Jewish calendar. Basically, the calendar follows a 19-year cycle, and seven of those years -- 3, 6, 8, 11, 14, 17, and 19 -- are leap years. Someone reduced this to the simple equation: (7y+1) mod 19 < 7.
My question is whether there is any rhyme or reason as to why this works, and is there a method to go about determining such formulas -- or is it all simply trial and error?