Skip to content

Instantly share code, notes, and snippets.

@marti1125
Created April 13, 2019 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marti1125/9ba6895e0e3cc0eb805249e999d8a005 to your computer and use it in GitHub Desktop.
Save marti1125/9ba6895e0e3cc0eb805249e999d8a005 to your computer and use it in GitHub Desktop.
centuryFromYear
func centuryFromYear(year int) int {
r := 1
s := strconv.Itoa(year)
if len(s) == 4 {
a := string(s[0:2])
b := string(s[2:4])
c, _ := strconv.Atoi(a)
d, _ := strconv.Atoi(b)
if d > 0 {
c = c + 1
}
r = c
}
if len(s) == 3 {
a := string(s[0:1])
b := string(s[1:3])
c, _ := strconv.Atoi(a)
d, _ := strconv.Atoi(b)
if d > 0 {
c = c + 1
}
r = c
}
return r
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment