Solution to problem 19 in Julia

This commit is contained in:
David Doblas Jiménez 2021-08-02 21:13:05 +02:00
parent fdcb80da68
commit ca3038d291

45
src/Julia/Problem019.jl Normal file
View File

@ -0,0 +1,45 @@
#=
Created on 02 Aug 2021
@author: David Doblas Jiménez
@email: daviddoji@pm.me
Solution for Problem 19 of Project Euler
https://projecteuler.net/problem=19 =#
using Dates
function Problem19()
"""
You are given the following information, but you may prefer to do some
research for yourself.
1 Jan 1900 was a Monday.
Thirty days has September, April, June and November.
All the rest have thirty-one,
Saving February alone,
Which has twenty-eight, rain or shine.
And on leap years, twenty-nine.
A leap year occurs on any year evenly divisible by 4, but not on a century
unless it is divisible by 400.
How many Sundays fell on the first of the month during the twentieth
century (1 Jan 1901 to 31 Dec 2000)?
"""
sundays = 0
for y in 1901:2000
for m in 1:12
# t = Date(y, m, 1)
if Dates.dayofweek(Date(y, m, 1)) == Dates.Sunday
sundays += 1
end
end
end
return sundays
end
println("Time to evaluate Problem 19:")
@time Problem19()
println("")
println("Result for Problem 19: ", Problem19())