Last active
August 29, 2015 14:02
-
-
Save whyrusleeping/043e5efcaebd3792299f to your computer and use it in GitHub Desktop.
a quick hack to find explicit ordering in sets
This file contains hidden or 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 ( | |
"os" | |
"bufio" | |
"fmt" | |
) | |
func ReadFile(path string) []string { | |
fi,err := os.Open(path) | |
if err != nil { | |
panic(err) | |
} | |
out := []string{} | |
scan := bufio.NewScanner(fi) | |
for scan.Scan() { | |
out = append(out, scan.Text()) | |
} | |
return out | |
} | |
func CoorVar(arr []string, a, b string) int { | |
ia := -1 | |
ib := -1 | |
for i := 0; i < len(arr); i++ { | |
if arr[i] == a { | |
ia = i | |
} | |
if arr[i] == b { | |
ib = i | |
} | |
} | |
if ia == -1 || ib == -1 { | |
return 0 | |
} | |
if ia < ib { | |
return -1 | |
} else if ia > ib { | |
return 1 | |
} | |
return 0 | |
} | |
func CoorVarSet(set [][]string, a string, b string) int { | |
n := 0 | |
for _,s := range(set) { | |
w := CoorVar(s, a, b) | |
if n == 0 { | |
n = w | |
} else { | |
if n != w { | |
return 0 | |
} | |
} | |
} | |
return n | |
} | |
func main() { | |
set := [][]string{} | |
for _,f := range os.Args[1:] { | |
set = append(set, ReadFile(f)) | |
} | |
for i,s := range(set[0]) { | |
for j,s2 := range(set[0]) { | |
if i != j { | |
val := CoorVarSet(set, s, s2) | |
if val != 0 { | |
fmt.Printf("'%s' -> '%s': %d\n", s,s2, val) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment