-
Notifications
You must be signed in to change notification settings - Fork 0
/
kyu8_catyears_dogyears.go
57 lines (50 loc) · 1.12 KB
/
kyu8_catyears_dogyears.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Kata Task
//
// I have a cat and a dog;
//
// I got them at the same time as kitten/puppy. That was humanYears years ago;
// Return their respective ages now as [humanYears,catYears,dogYears];
//
// Note:
// humanYears >= 1
// humanYears are whole numbers only
//
// Cat Years
// 15 cat years for first year
// +9 cat years for second year
// +4 cat years for each year after that
//
// Dog Years
// 15 dog years for first year
// +9 dog years for second year
// +5 dog years for each year after that
//
// https://www.codewars.com/kata/5a6663e9fd56cb5ab800008b
//
package kata
func CalculateYears(years int) (result [3]int) {
catYears := 0
dogYears := 0
for i := 1; i <= years; i++ {
switch i {
case 1:
catYears += 15
case 2:
catYears += 9
default:
catYears += 4
}
}
for i := 1; i <= years; i++ {
switch i {
case 1:
dogYears += 15
case 2:
dogYears += 9
default:
dogYears += 5
}
}
result = [3]int{years, catYears, dogYears}
return result
}