diff --git a/20201119/main.go b/20201119/main.go new file mode 100644 index 0000000..84c00da --- /dev/null +++ b/20201119/main.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println(multiple(9, 9)) +} + +func multiple(n, m uint64) uint64 { + if m == 1 { + return n + } + return n + multiple(n, m-1) +} + +func multiple2(n, m uint64) uint64 { + sum := n + m-- + if m > 0 { + sum += multiple2(n, m) + } + return sum +} diff --git a/20201119/main_test.go b/20201119/main_test.go new file mode 100644 index 0000000..a1221e4 --- /dev/null +++ b/20201119/main_test.go @@ -0,0 +1,83 @@ +package main + +import "testing" + +func Test_multiple(t *testing.T) { + type args struct { + n uint64 + m uint64 + } + tests := []struct { + name string + args args + want uint64 + }{ + { + "example_1", + args{1, 10}, + 10, + }, + { + "example_2", + args{3, 4}, + 12, + }, + { + "example_3", + args{100, 100}, + 10000, + }, + { + "example_4", + args{300, 100}, + 30000, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := multiple(tt.args.n, tt.args.m); got != tt.want { + t.Errorf("multiple() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_multiple2(t *testing.T) { + type args struct { + n uint64 + m uint64 + } + tests := []struct { + name string + args args + want uint64 + }{ + { + "example_1", + args{1, 10}, + 10, + }, + { + "example_2", + args{3, 4}, + 12, + }, + { + "example_3", + args{100, 100}, + 10000, + }, + { + "example_4", + args{300, 100}, + 30000, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := multiple2(tt.args.n, tt.args.m); got != tt.want { + t.Errorf("multiple2() = %v, want %v", got, tt.want) + } + }) + } +}