Exemplo n.º 1
0
func solver(in *ProblemReader.ProblemReader) string {
	word := []byte(in.Line())
	lastVal = -1

	letterVal := make(map[byte]int)
	for _, c := range word {
		if _, ok := letterVal[c]; !ok {
			letterVal[c] = nextVal()
		}
	}

	base := int64(lastVal + 1)
	if base == 1 {
		base++
	}
	sum := int64(0)
	mul := int64(1)

	//fmt.Println("letterVal: ", letterVal, "word:", word)

	for j := len(word) - 1; j >= 0; j-- {
		sum += mul * int64(letterVal[word[j]])
		//fmt.Println("letter: ", word[j], "val: ", letterVal[word[j]], "mul: ", mul, "sum: ", sum)
		mul *= base
	}
	return fmt.Sprintf("%d", sum)
}
Exemplo n.º 2
0
func solver(in *ProblemReader.ProblemReader) string {
	nums := in.NNums(2)
	board, toWin := nums[0], nums[1]
	assert(toWin <= board)
	lines := make([]string, board)
	for j := 0; j < board; j++ {
		line := []byte(in.Line())
		if len(line) != board {
			log.Fatalf("Expected %#v to be %d long", string(line), board)
		}
		shiftLine(line)
		lines[j] = string(line)
	}
	return winner(lines, toWin)
}
Exemplo n.º 3
0
func solver(in *ProblemReader.ProblemReader) string {
	nums := in.NNums(2)
	existing, toCreate := nums[0], nums[1]

	tree := newTree()

	for j := 0; j < existing; j++ {
		tree.add(in.Line())
	}
	additions := 0
	for j := 0; j < toCreate; j++ {
		additions += tree.add(in.Line())
	}

	return fmt.Sprintf("%d", additions)
}
Exemplo n.º 4
0
func solver(in *ProblemReader.ProblemReader) string {
	line := in.Line()
	scores := make([]int, len(PATTERN))
	for j := range line {
		c := line[j]
		for k := len(PATTERN) - 1; k >= 0; k-- {
			if c == PATTERN[k] {
				if k == 0 {
					scores[k] = (scores[k] + 1) % 10000
				} else {
					scores[k] = (scores[k] + scores[k-1]) % 10000
				}
			}
		}
	}
	return fmt.Sprintf("%04d", scores[len(scores)-1])
}
Exemplo n.º 5
0
func solver(in *ProblemReader.ProblemReader) string {
	nEngines := in.Num()

	engines := make([]string, nEngines)
	for j := 0; j < nEngines; j++ {
		engines[j] = in.Line()
	}

	terms := in.Num()
	available := make(map[string]bool)
	reset(available, engines, "")
	changes := 0
	for j := 0; j < terms; j++ {
		term := in.Line()
		if _, ok := available[term]; ok {
			available[term] = false, false
			if len(available) == 0 {
				changes++
				reset(available, engines, term)
			}
		}
	}
	return fmt.Sprintf("%d", changes)
}