Skip to content

Commit

Permalink
day 290: more efficient memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
vaskoz committed Jun 9, 2019
1 parent 2eadef3 commit 4b65726
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions day290/problem.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ func MinimizeQux(input []rune) []rune {
}

func minimizeQux(input []rune) []rune {
copied := make([]rune, len(input))
copy(copied, input)
min := copied
for i := 1; i < len(copied); i++ {
if copied[i] != copied[i-1] {
missing := 'R' + 'G' + 'B' - copied[i] - copied[i-1]
end := append([]rune{missing}, copied[i+1:]...)
candidate := append([]rune{}, copied[:i-1]...)
min := input
for i := 1; i < len(input); i++ {
if input[i] != input[i-1] {
missing := 'R' + 'G' + 'B' - input[i] - input[i-1]
end := append([]rune{missing}, input[i+1:]...)
candidate := append([]rune{}, input[:i-1]...)
candidate = append(candidate, end...)
candidate = minimizeQux(candidate)
if len(candidate) < len(min) {
Expand Down

0 comments on commit 4b65726

Please sign in to comment.