Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
18
Task/Five-weekends/Elixir/five-weekends.elixir
Normal file
18
Task/Five-weekends/Elixir/five-weekends.elixir
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
defmodule Date do
|
||||
@months { "January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December" }
|
||||
|
||||
def five_weekends(year) do
|
||||
for m <-[1,3,5,7,8,10,12], :calendar.day_of_the_week(year, m, 31) == 7, do: elem(@months, m-1)
|
||||
end
|
||||
end
|
||||
|
||||
months = Enum.map(1900..2100, fn year -> {year, Date.five_weekends(year)} end)
|
||||
{none, months5} = Enum.partition(months, fn {_,m} -> Enum.empty?(m) end)
|
||||
count = Enum.reduce(months5, 0, fn {year, months}, acc ->
|
||||
IO.puts "#{year} : #{Enum.join(months, ", ")}"
|
||||
acc + length(months)
|
||||
end)
|
||||
IO.puts "Found #{count} month with 5 weekends."
|
||||
IO.puts "\nFound #{length(none)} years with no month having 5 weekends:"
|
||||
IO.puts "#{inspect Enum.map(none, fn {y,_}-> y end)}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue