Groovy web console

subscribe to the feed Subscribe
to this
site

Thanksgiving Birthday

Published 4 months ago by Anonymous
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.Month

def thanksgivingBirthdayYears = (1941..2023).findAll {    
    LocalDate.of(it, Month.NOVEMBER, 23).dayOfWeek == DayOfWeek.THURSDAY
}

int previousThanksgivingYear = thanksgivingBirthdayYears[0]
thanksgivingBirthdayYears.each { year ->
    int diff = year - previousThanksgivingYear
    println "${year} ($diff years since the last match)"
    previousThanksgivingYear = year
}