Project Euler #19: Counting Sundays

  • + 0 comments

    I spent really enourmous time solving this one because of notorios test cases 3 and 4.

    TLDR: use following snippet to read input values if you are using golang:

      for t:=0; t <T ; t++ {
          var year1, year2 int64
          var month1, month2, day1, day2 int
    
            dates := make([]string, 6, 6)
            for i := range dates {
                fmt.Scan(&dates[i])
            }
            year1, _ = strconv.ParseInt(dates[0], 10, 64) 
            month1, _ = strconv.Atoi(dates[1])
            day1, _ = strconv.Atoi(dates[2])
            year2, _ = strconv.ParseInt(dates[3], 10, 64)
            month2, _ = strconv.Atoi(dates[4])
            day2, _ = strconv.Atoi(dates[5])
    

    I made several optimizations, my code worked within milliseconds for all year ranges between 1900 and 10^16, but could not understand why my testcases fails because of timelimit. Then I added checks for input data, and only got wrong answer result. Finally I started adding checks for every line, crashing app immediately if check failed and putting it into forever cycle otherwise, thus getting the only diagnostic info info this platform allowed me and found out that I read empty dates. Then I tried several approaches (reading line and trimming spaces) but they did not work, looks like there are not only spaces, but linebreaks as well.