diff --git a/20201230/main.go b/20201230/main.go new file mode 100644 index 0000000..0ccb252 --- /dev/null +++ b/20201230/main.go @@ -0,0 +1,36 @@ +package main + +func main() { + +} + +func process(nums []int) []int { + var ret []int + c := 0 + for { + if len(ret) == len(nums) { + break + } + n := findNextLarge(c, nums) + ret = append(ret, n) + c++ + } + return ret +} + +func findNextLarge(index int, nums []int) int { + if index > len(nums)-1 { + return -1 + } + src := append(nums[index+1:], nums[:index+1]...) + for i, c := range src { + if c > nums[index] { + x := index + i + 1 + if x > len(nums) { + x -= len(nums) + } + return c + } + } + return -1 +} diff --git a/20201230/main_test.go b/20201230/main_test.go new file mode 100644 index 0000000..6d7d8df --- /dev/null +++ b/20201230/main_test.go @@ -0,0 +1,84 @@ +package main + +import ( + "reflect" + "testing" +) + +func Test_process(t *testing.T) { + type args struct { + nums []int + } + tests := []struct { + name string + args args + want []int + }{ + { + "test1", + args{ + nums: []int{1, 2, 1}, + }, + []int{2, -1, 2}, + }, + { + "test2", + args{ + nums: []int{1}, + }, + []int{-1}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := process(tt.args.nums); !reflect.DeepEqual(got, tt.want) { + t.Errorf("process() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_findNextLarge(t *testing.T) { + type args struct { + index int + nums []int + } + tests := []struct { + name string + args args + want int + }{ + { + "test1", + args{ + 1, + []int{1, 2, 3}, + }, + 3, + }, + { + "test2", + args{ + 0, + []int{1, 2, 3}, + }, + 2, + }, + { + "test3", + args{ + 2, + []int{1, 2, 3}, + }, + -1, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := findNextLarge(tt.args.index, tt.args.nums) + if got != tt.want { + t.Errorf("findNextLarge() got = %v, want %v", got, tt.want) + } + }) + } +}