-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (34 loc) · 892 Bytes
/
main.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
package main
import (
"fmt"
"os"
"regexp"
"strconv"
"strings"
"github.com/NimaC/go-merge-intervals/handler"
"github.com/NimaC/go-merge-intervals/interval"
)
// Parse Command Line String Input to List of Intervals
func parseInput(inputInterval string) []interval.Interval {
r := regexp.MustCompile(`\[(?P<Start>[\d]+)\s*,\s*(?P<End>[\d]+)\]+`)
matches := r.FindAllStringSubmatch(inputInterval, -1)
var result []interval.Interval
for _, match := range matches {
start, err := strconv.Atoi(match[1])
if err != nil {
panic(err)
}
end, err := strconv.Atoi(match[2])
if err != nil {
panic(err)
}
result = append(result, interval.Interval{start, end})
}
return result
}
func main() {
argsWithoutProg := strings.Join(os.Args[1:], " ")
inputInterval := parseInput(argsWithoutProg)
result := handler.GetOverlappingIntervals(inputInterval)
fmt.Println(result)
}