Created
June 7, 2019 08:02
-
-
Save akiradeveloper/b7c7b0dbce7734d9a17e82a8729298e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public editDistance(that: Table): number { | |
let dist = 0; | |
// swap distance | |
let xs = this.asColorSeq(); | |
let ys = that.asColorSeq(); | |
let n = xs.length; | |
for (let i=0; i<n; i++) { | |
if (xs[i] != ys[i]) { | |
dist += 0.5; | |
} | |
} | |
// flip distacne | |
let xxs = [ ...this.array2d.array1d ]; | |
xxs.sort((a,b) => { return a.i - b.i}); | |
let yys = [ ...that.array2d.array1d ]; | |
yys.sort((a,b) => { return a.i - b.i}); | |
for (let i=0; i<n; i++) { | |
if (xxs[i].flipped != yys[i].flipped) { | |
dist += 1; | |
} | |
} | |
return dist; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment