Esempio n. 1
0
func permute(s []string) {
	for i := 0; i < fact(len(s)); i++ {
		innerI := i % len(s)
		for j := 0; j < len(s); j++ {
			s[innerI], s[j] = s[j], s[innerI]
			if !arrayutils.ContainsString(permutations, strings.Join(s, " ")) {
				permutations = append(permutations, strings.Join(s, " "))
			}
		}
	}
}
Esempio n. 2
0
//CalculateDistance Calculate shortest distance for given routes
func CalculateDistance() {
	file, _ := os.Open("solutions/distance_input.txt")
	defer file.Close()
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		line := scanner.Text()
		split := strings.Split(line, " ")
		distance, _ := strconv.Atoi(split[4])
		//Adding both way of the connection
		connections[split[0]] = append(connections[split[0]], Targets{split[2], distance})
		connections[split[2]] = append(connections[split[2]], Targets{split[0], distance})
		if !arrayutils.ContainsString(keys, split[0]) {
			keys = append(keys, split[0])
		}
		if !arrayutils.ContainsString(keys, split[2]) {
			keys = append(keys, split[2])
		}
	}
	generatePermutation(keys, len(keys))
	getMinDistances()
}
Esempio n. 3
0
func main() {
	file, _ := os.Open("input.txt")
	defer file.Close()
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		line := scanner.Text()
		split := strings.Split(line, " ")
		like, _ := strconv.Atoi(split[3]) //If lose -> * -1
		if split[2] == "lose" {
			like *= -1
		}
		table[split[0]] = append(table[split[0]], map[string]int{strings.Trim(split[10], "."): like})
		if !arrayutils.ContainsString(keys, split[0]) {
			keys = append(keys, split[0])
		}
	}
	generatePermutation(keys, len(keys))
	fmt.Println("Best seating efficiency:", calculateSeatingEfficiancy())
}
Esempio n. 4
0
//replace does the replacing
func replace() {
	for k, v := range replacements {
		//Get all the indexes for a Key
		indexes := allIndiciesForString(k, molecule)
		for _, i := range indexes {
			//Save the head up to the index
			head := molecule[:i]
			//Save the tail from the index + lenght of the searched key
			tail := molecule[i+len(k):]

			//Create a string for all the replacement possbilities
			for _, com := range v {
				newMol := head + com + tail
				if !arrayutils.ContainsString(combinations, newMol) {
					combinations = append(combinations, newMol)
				}
			}
		}
	}
}