Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Five-weekends/Groovy/five-weekends-1.groovy
Normal file
17
Task/Five-weekends/Groovy/five-weekends-1.groovy
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
enum Day {
|
||||
Sun, Mon, Tue, Wed, Thu, Fri, Sat
|
||||
static Day valueOf(Date d) { Day.valueOf(d.format('EEE')) }
|
||||
}
|
||||
|
||||
def date = Date.&parse.curry('yyyy-M-dd')
|
||||
def isLongMonth = { firstDay -> (firstDay + 31).format('dd') == '01'}
|
||||
|
||||
def fiveWeekends = { years ->
|
||||
years.collect { year ->
|
||||
(1..12).collect { month ->
|
||||
date("${year}-${month}-01")
|
||||
}.findAll { firstDay ->
|
||||
isLongMonth(firstDay) && Day.valueOf(firstDay) == Day.Fri
|
||||
}
|
||||
}.flatten()
|
||||
}
|
||||
5
Task/Five-weekends/Groovy/five-weekends-2.groovy
Normal file
5
Task/Five-weekends/Groovy/five-weekends-2.groovy
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def ym = { it.format('yyyy-MM') }
|
||||
def years = 1900..2100
|
||||
def fiveWeekendMonths = fiveWeekends(years)
|
||||
println "Number of five weekend months: ${fiveWeekendMonths.size()}"
|
||||
fiveWeekendMonths.each { println (ym(it)) }
|
||||
4
Task/Five-weekends/Groovy/five-weekends-3.groovy
Normal file
4
Task/Five-weekends/Groovy/five-weekends-3.groovy
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
def yearsWith = fiveWeekendMonths.collect { it.format('yyyy') as int } as Set
|
||||
def yearsWithout = (years as Set) - yearsWith
|
||||
println "\nNumber of years without a five weekend month: ${yearsWithout.size()}"
|
||||
yearsWithout.each { println it }
|
||||
Loading…
Add table
Add a link
Reference in a new issue