Skip to content

Instantly share code, notes, and snippets.

@rjp
Last active March 21, 2019 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjp/54d65272051cdec5b723859e0b3ac2d3 to your computer and use it in GitHub Desktop.
Save rjp/54d65272051cdec5b723859e0b3ac2d3 to your computer and use it in GitHub Desktop.
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)
}
}
@rjp
Copy link
Author

rjp commented Mar 21, 2019

Filter the RNN horse race output to avoid anything too like the input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment