Created
August 13, 2021 10:17
-
-
Save ma6174/0706c570ef0947b17cce17e488fc5367 to your computer and use it in GitHub Desktop.
diff
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
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"os" | |
) | |
func main() { | |
a, err := ioutil.ReadFile(os.Args[1]) | |
if err != nil { | |
log.Panic(err) | |
} | |
b, err := ioutil.ReadFile(os.Args[2]) | |
if err != nil { | |
log.Panic(err) | |
} | |
var same = true | |
var last = 0 | |
for i := 0; i < len(a) && i < len(b); i++ { | |
if (a[i] == b[i]) != same || i == len(a)-1 { | |
fmt.Printf("same:%v\tfrom: %v\tto: %v\tlen: %v\n", same, last, i-1, i-last) | |
same = !same | |
last = i | |
} | |
} | |
sub := len(a) - len(b) | |
if sub > 0 { | |
fmt.Printf(">>>>:\tfrom: %v\tto: %v\tlen: %v\n", len(b), len(a), sub) | |
} else if sub < 0 { | |
fmt.Printf("<<<<:\tfrom: %v\tto: %v\tlen: %v\n", len(a), len(b), -sub) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment