Last active
March 21, 2019 08:51
-
-
Save rjp/54d65272051cdec5b723859e0b3ac2d3 to your computer and use it in GitHub Desktop.
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 ( | |
"bufio" | |
"fmt" | |
"os" | |
"strconv" | |
"strings" | |
) | |
func main() { | |
racefile, err := os.Open("data/races/input.txt") | |
if err != nil { panic(err) } | |
defer racefile.Close() | |
word2line := make(map[string][]int) | |
stopwords := map[string]bool{"TROT":true,"PACE":true,"MOBILE":true} | |
line := 1 | |
races := bufio.NewScanner(racefile) | |
for races.Scan() { | |
race := races.Text() | |
parts := strings.Fields(race) | |
// Assuming this isn't a stopword | |
for i, part := range parts[1:] { | |
if _, ok := stopwords[part]; ok { | |
continue | |
} | |
check := parts[i] + part | |
if _, ok := word2line[check]; !ok { | |
word2line[check] = []int{} | |
} | |
word2line[check] = append(word2line[check], line) | |
} | |
line++ | |
} | |
checking := bufio.NewScanner(os.Stdin) | |
for checking.Scan() { | |
race := checking.Text() | |
parts := strings.Fields(race) | |
badwords := make(map[int]int) | |
words := 0 | |
max := -1 | |
for i, part := range parts[1:] { | |
if _, ok := stopwords[part]; ok { | |
continue | |
} | |
check := parts[i] + part | |
// If we found the word in our existing list, | |
if v, ok := word2line[check]; ok { | |
for _, line := range v { | |
badwords[line] = badwords[line] + 1 | |
if badwords[line] > max { max = badwords[line] } | |
} | |
} | |
words++ | |
} | |
fmt.Printf("%s %d %d %s\n", strconv.FormatBool(max<words/2), words, max, race) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Filter the RNN horse race output to avoid anything too like the input