Project Euler again, problem 19. How many Sundays fell on the first of the month in the twentieth century?

Brute force solution in R but it let me play around with the way R handles dates. Seems more straight forward than in many languages (looking at you Java).

1
2
3
4
5
6
7
8
9
10
11
12
a.date <- as.Date("1901/01/01")
end.date <- as.Date("2000/12/31")
count <- 0
while (a.date <= end.date) {
  if (format(a.date, "%d") == "01") {
    if (format(a.date, "%A") == "Sunday") {
      count = count + 1
    }
  }
  a.date = a.date + 1
}
print(count)

Used a for loop initially but found that it wouldn’t iterate Date types. Could probably look into that in the future.