diff --git a/interview/code/partition.go b/interview/code/partition.go new file mode 100644 index 0000000..b446471 --- /dev/null +++ b/interview/code/partition.go @@ -0,0 +1,41 @@ +// https://www.techiedelight.com/partition-problem +package main + +import ( + "fmt" +) + +func SumSlice(x []int) int { + xSum := 0 + + for _, v := range x { + xSum += v + } + + return xSum +} + +func solver(bucket, x []int, num int) bool { + if SumSlice(x) == (num / 2) { + return true + } + + for idx := range bucket { + tmpBucket := []int{} + tmpBucket = append(tmpBucket, bucket[:idx]...) + tmpBucket = append(tmpBucket, bucket[idx+1:]...) + + tmpX := []int{} + tmpX = append(x, bucket[idx]) + if solver(tmpBucket, tmpX, num) { + return true + } + } + + return false +} + +func main() { + bucket := []int{7, 3, 1, 5, 4, 8} + fmt.Println(solver(bucket, []int{}, SumSlice(bucket))) +} diff --git a/interview/code/rod_cutting.go b/interview/code/rod_cutting.go index b6dd3b0..3a7bba9 100644 --- a/interview/code/rod_cutting.go +++ b/interview/code/rod_cutting.go @@ -1,3 +1,4 @@ +// https://www.techiedelight.com/rot-cutting/ package main import (