package
0.0.0-20190403020015-393222b97125
Repository: https://github.com/shady831213/algorithms.git
Documentation: pkg.go.dev
# README
Double adjustable Euclidean traveling salesman
CLRS 15-1
Solution:
Pretty Print
CLRS 15-2
Solution:
M - (j-i) - (Li+...+Lj) >= 0 : alignedIdx[i][j] = (M - (j-i) - (Li+...+Lj))^3
M - (j-i) - (Li+...+Lj) < 0 : alignedIdx[i][j] = min(alignedIdx[i][k], alignedIdx[k+1][j]) i<=k<j
Levenshtein Distance
CLRS 15-3
Solution:
c[i][j] = MIN(c[m,n], MIN(c[i,n]+cost(kill))), 0<=i
Gene alignment copy : -1 replace : 1 insert : 2 delete : 2 twiddle : Max kill : Max
OOP pattern:
//base method and data
type lDCompute interface {
updateCost(int, int, *lDComputor) (int)
preOpIdx(int, int, *lDComputor) (int, int)
}
type lDOperation struct {
name string
cost int
lDCompute
}
func (op *lDOperation)init(name string, cost int)(*lDOperation) {
op.name = name
op.cost = cost
return op
}
//operations
type copy struct {
lDOperation//base
}
func (c *copy)init(cost int)(*copy) {
op:=c.lDOperation.init("copy", cost)
op.lDCompute = c
return c
}
func (c *copy) updateCost(i int, j int, ldc *lDComputor) (int) {
//...
}
func (c *copy) preOpIdx(i int, j int, ldc *lDComputor) (int, int) {
//...
}
func newCopy(cost int)(*copy) {
return new(copy).init(cost)
}
//object
copyObj := newCopy(1)
//base type pointer
var op *lDOperation
op = &newCopy(1).lDOperation
Chess Game
CLRS 15-6
Solution:
score[i][j] = max(score[i-1][j-1],score[i-1][j],score[i-1][j+1]) + board[i][j]