You are viewing a single comment's thread. Return to all comments →
GO (gives the right answers, but it doesnt accept)
.
package main import ( "bufio" "fmt" "os" "strconv" "strings" ) var months = map[int]int{1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31} func main() { d1, m1, y1, d2, m2, y2 := readInput() fmt.Println(findPrimeDates(d1, m1, y1, d2, m2, y2)) } func readInput() (int, int, int, int, int, int) { reader := bufio.NewReader(os.Stdin) line, _ := reader.ReadString('\n') line = strings.TrimSpace(line) dates := strings.Split(line, " ") d1, m1, y1 := getDateInts(dates[0]) d2, m2, y2 := getDateInts(dates[1]) return d1, m1, y1, d2, m2, y2 } func getDateInts(date string) (int, int, int) { values := strings.Split(date, "-") numbers := make([]int, 3) for i, value := range values { number, _ := strconv.Atoi(value) numbers[i] = number } return numbers[0], numbers[1], numbers[2] } func findPrimeDates(d1 int, m1 int, y1 int, d2 int, m2 int, y2 int) int { var primeDates int for true { if d1 > d2 && m1 == m2 && y1 == y2 { break } x := ((d1*100)+m1)*10000 + y1 if x%4 == 0 || x%7 == 0 { primeDates++ } d1++ if d1 > months[m1] { d1 = 1 m1++ if m1 > 12 { m1 = 1 y1++ isLeapYear(y1) } } } return primeDates } func isLeapYear(year int) { if year%400 == 0 { months[2] = 29 } else if year%100 == 0 { months[2] = 28 } else if year%4 == 0 { months[2] = 29 } else { months[2] = 28 } }
Seems like cookies are disabled on this browser, please enable them to open this website
Prime Dates
You are viewing a single comment's thread. Return to all comments →
GO (gives the right answers, but it doesnt accept)
.