# When's the nearest special common year?

A common year is a year that is not a leap year and where the first and last day of the year are on the same day. A special common year is one that starts on a Monday and so ends on a Monday as well.

Your challenge is to create a program/function that when given a year as input finds the nearest special common year, outputting itself if it is a common year. If the year is as close to the one before it as the one next to it output the larger one.

Input

An integer representing the year to test against in the range 1600 <= x <= 2100.

Output

An integer representing the nearest special common year.

Test cases

2017 -> 2018
2018 -> 2018
1992 -> 1990
1600 -> 1601
2100 -> 2103
1728 -> 1731 (lies between 1725 and 1731)

Notes

All 54 years in the given range are already shown in the linked Wikipedia article. I will also provide them here for reference:

1601, 1607, 1618, 1629, 1635, 1646, 1657, 1663, 1674, 1685, 1691
1703, 1714, 1725, 1731, 1742, 1753, 1759, 1770, 1781, 1787, 1798
1810, 1821, 1827, 1838, 1849, 1855, 1866, 1877, 1883, 1894, 1900
1906, 1917, 1923, 1934, 1945, 1951, 1962, 1973, 1979, 1990
2001, 2007, 2018, 2029, 2035, 2046, 2057, 2063, 2074, 2085, 2091
2103 (Needed for 2097 to 2100)
• just for reference to help people out, the sequence appears to go 6, 11, 11. IE 6 years after the first is another, 11 years after that is another, 11 years after that is another, 6 years after that is another, etc. – Skidsdev May 24 '17 at 10:47
• @Mayube Not quite. The actual sequence is "6, 11, 11, 6, 11, 11, 6, 11, 11, 6, 12, 11, 11, 6, 11, 11, 6, 11, 11, 6, 11, 12, 11, 6, 11, 11, 6, 11, 11, 6, 11, 6, 6, 11, 6, 11, 11, 6, 11, 11, 6, 11, 11, 6, 11, 11, 6, 11, 11, 6, 11, 11, 6" (note the 12s and the 6, 11, 6, 6, 11, 6) – Martin Ender May 24 '17 at 10:49
• Since the calendar repeats every 400 years, the relevant (periodic) part of the sequence is "6, 11, 11, 6, 11, 11, 6, 11, 11, 6, 12, 11, 11, 6, 11, 11, 6, 11, 11, 6, 11, 12, 11, 6, 11, 11, 6, 11, 11, 6, 11, 6, 6, 11, 6, 11, 11, 6, 11, 11, 6, 11, 11". I'll be impressed if anyone can save bytes with this, due to the three irregularities. – Martin Ender May 24 '17 at 11:08
• Congrats on 2k for me! :P – TheLethalCoder May 24 '17 at 11:38
• a year that is not a leap year and where the first and last day of the year are on the same day The second part of that definition is redundant. All non-leap years start and end on the same day, being exactly 52 weeks and one day (365 days) long. – John Gordon May 24 '17 at 18:56

# Jelly, 30 bytes

Try it online! or see a test suite.

### How?

Much like other answers this builds the list of years required for the input domain from the increments, and finds the maximal year of minimal absolute difference from the input.

⁽£d         - augmented base 250 literal = 1601
“Þıİs|9ṗ[¿¶F’                  - base 250 literal = 20129386383114231907032071
“©€¿‘            - code page index list = [6,12,11]
ṃ                 - base decompression = [6,11,11,6,11,11,6,11,11,6,12,11,11,6,11,11,6,11,11,6,11,12,11,6,11,11,6,11,11,6,11,6,6,11,6,11,11,6,11,11,6,11,11,6,11,11,6,11,11,6,11,11,6,12]
;        - concatenate = [1601,6,11,11,6,11,11,6,11,11,6,12,11,11,6,11,11,6,11,11,6,11,12,11,6,11,11,6,11,11,6,11,6,6,11,6,11,11,6,11,11,6,11,11,6,11,11,6,11,11,6,11,11,6,12]
+\      - reduce with addition = [1601,1607,1618,1629,1635,1646,1657,1663,1674,1685,1691,1703,1714,1725,1731,1742,1753,1759,1770,1781,1787,1798,1810,1821,1827,1838,1849,1855,1866,1877,1883,1894,1900,1906,1917,1923,1934,1945,1951,1962,1973,1979,1990,2001,2007,2018,2029,2035,2046,2057,2063,2074,2085,2091,2103]
⁸  - link's left argument, y
ÐṂ   - filter keep if maximal:
ạ     -   absolute difference
Ṁ - maximum (alternatively tail, Ṫ, since increasing)

# PHP, 67 Bytes

for(;date(LN,mktime(0,0,0,1,1,$y=$argn+$i))>1;)$i=($i<1)-$i;echo$y; Try it online! or for(;date(LN,strtotime("1/1/".$y=$argn+$i))>1;)$i=($i<1)-$i;echo$y;

Try it online!

Expanded

for(;
date(LN,mktime(0,0,0,1,1,$y=$argn+$i)) # N is 1 for Monday and L is 0 for Non leap year >1;) # loop so long as expression is not 1$i=($i<1)-$i; # set $i 0,1,-1,2,-2 ... echo$y; # Output Year

date

}