Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
34
Task/Five-weekends/F-Sharp/five-weekends.fs
Normal file
34
Task/Five-weekends/F-Sharp/five-weekends.fs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
open System
|
||||
|
||||
[<EntryPoint>]
|
||||
let main argv =
|
||||
let (yearFrom, yearTo) = (1900, 2100)
|
||||
|
||||
let monthsWith5We year =
|
||||
[1; 3; 5; 7; 8; 10; 12] |>
|
||||
List.filter (fun month -> DateTime(year, month, 1).DayOfWeek = DayOfWeek.Friday)
|
||||
|
||||
let ym5we =
|
||||
[yearFrom .. yearTo]
|
||||
|> List.map (fun year -> year, (monthsWith5We year))
|
||||
|
||||
let countMonthsWith5We =
|
||||
ym5we
|
||||
|> List.sumBy (snd >> List.length)
|
||||
|
||||
let countYearsWithout5WeMonths =
|
||||
ym5we
|
||||
|> List.sumBy (snd >> List.isEmpty >> (function|true->1|_->0))
|
||||
|
||||
let allMonthsWith5we =
|
||||
ym5we
|
||||
|> List.filter (snd >> List.isEmpty >> not)
|
||||
|
||||
printfn "%d months in the range of years from %d to %d have 5 weekends."
|
||||
countMonthsWith5We yearFrom yearTo
|
||||
printfn "%d years in the range of years from %d to %d have no month with 5 weekends."
|
||||
countYearsWithout5WeMonths yearFrom yearTo
|
||||
printfn "Months with 5 weekends: %A ... %A"
|
||||
(List.take 5 allMonthsWith5we)
|
||||
(List.take 5 (List.skip ((List.length allMonthsWith5we) - 5) allMonthsWith5we))
|
||||
0
|
||||
Loading…
Add table
Add a link
Reference in a new issue