diff --git a/algs4/src/go/Makefile b/algs4/src/go/Makefile index 06053db..2206cbe 100644 --- a/algs4/src/go/Makefile +++ b/algs4/src/go/Makefile @@ -7,7 +7,8 @@ TARGETS := \ $(REPO_BASE)/algs4-rolls \ $(REPO_BASE)/algs4-randomseq \ $(REPO_BASE)/algs4-average \ - $(REPO_BASE)/algs4-interval2d + $(REPO_BASE)/algs4-interval2d \ + $(REPO_BASE)/algs4-date test: build go test -x $(TARGETS) diff --git a/algs4/src/go/algs4-date/main.go b/algs4/src/go/algs4-date/main.go new file mode 100644 index 0000000..b655014 --- /dev/null +++ b/algs4/src/go/algs4-date/main.go @@ -0,0 +1,39 @@ +package main + +import ( + "errors" + "fmt" + "os" + "strconv" + + "github.com/meatballhat/box-o-sand/algs4/src/go/algs4" +) + +func die(err error) { + fmt.Fprintf(os.Stderr, "ERROR: %v\n", err) + os.Exit(1) +} + +func main() { + if len(os.Args) < 4 { + die(errors.New("We need 3 ints!")) + } + + m, err := strconv.Atoi(os.Args[1]) + if err != nil { + die(err) + } + + d, err := strconv.Atoi(os.Args[2]) + if err != nil { + die(err) + } + + y, err := strconv.Atoi(os.Args[3]) + if err != nil { + die(err) + } + + date := algs4.NewDate(m, d, y) + fmt.Println(date) +} diff --git a/algs4/src/go/algs4/date.go b/algs4/src/go/algs4/date.go new file mode 100644 index 0000000..d0ad2a0 --- /dev/null +++ b/algs4/src/go/algs4/date.go @@ -0,0 +1,23 @@ +package algs4 + +import ( + "fmt" +) + +type Date struct { + Month int + Day int + Year int +} + +func NewDate(m, d, y int) *Date { + return &Date{ + Month: m, + Day: d, + Year: y, + } +} + +func (me *Date) String() string { + return fmt.Sprintf("%d/%d/%d", me.Month, me.Day, me.Year) +}