Skip to content

Commit

Permalink
day 24 faster
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar Franzén committed Dec 25, 2017
1 parent c538763 commit 633ea5a
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions digidis-go/day24/day24.go
Expand Up @@ -22,31 +22,30 @@ func main() {
for i, p := range ports {
if p[0] == 0 {
fmt.Printf("starting from %v\n", p)
solve(i, p[1])
solve(i, p[1], 1, p[1]+p[0])
}
if p[1] == 0 {
fmt.Printf("starting from %v\n", p)
solve(i, p[0])
solve(i, p[0], 1, p[1]+p[0])
}
}

fmt.Printf("Maxium strength %v\n", maxS)
fmt.Printf("Maxium strength and length %v\n", maxSL)
fmt.Printf("Maximum strength %v\n", maxS)
fmt.Printf("Maximum strength and length %v\n", maxSL)
}

var maxS, maxL, maxSL int

func solve(start int, next int) {
func solve(start, next, l, s int) {
used[start] = true
for i, p := range ports {
if !used[i] && p[0] == next {
solve(i, p[1])
solve(i, p[1], l+1, s+p[0]+p[1])
}
if !used[i] && p[1] == next {
solve(i, p[0])
solve(i, p[0], l+1, s+p[0]+p[1])
}
}
s, l := calc()
maxS = max(maxS, s)
maxL = max(maxL, l)
if l == maxL && s > maxSL {
Expand All @@ -61,13 +60,3 @@ func max(a, b int) int {
}
return b
}

func calc() (s, l int) {
for i := range used {
if used[i] {
l++
s = s + ports[i][0] + ports[i][1]
}
}
return
}

0 comments on commit 633ea5a

Please sign in to comment.