Commit f0235c10 authored by Adam P. Goucher's avatar Adam P. Goucher
Browse files

Enable enumerated chains to be piped into backtracking code

parent 4cc65e69
Pipeline #66378451 passed with stage
in 22 minutes and 26 seconds
#include <stdint.h>
#include <vector>
#include <string>
#include <iostream>
#include <functional>
......@@ -73,13 +74,68 @@ uint64_t count_colourings(int m, int n, bool increasing, uint64_t verboten, std:
}
std::vector<uint16_t> parse_circuit(std::string circuit) {
std::vector<uint16_t> vec;
uint16_t w = 1;
for (int i = 0; i < circuit.length(); i++) {
char c = circuit[i];
if ((c == '#') || (c == '\n')) { break; }
if (c == '*') { vec.push_back(w); w += 2; }
if ((c >= '0') && (c <= '9')) { vec.push_back((c - '0') * 2); }
}
return vec;
}
uint64_t get_verboten(std::vector<uint16_t> &circuit) {
uint64_t verboten = 1;
for (uint64_t i = 2; i < circuit.size(); i += 2) {
if (circuit[i] & 1) {
int n = (circuit[i] >> 1);
verboten |= ((1ull) << (((n + 1) * (n + 2)) / 2 - 2));
} else if (circuit[i+1] & 1) {
int n = (circuit[i+1] >> 1);
for (int j = 0; j < 2; j++) {
uint16_t c = circuit[circuit[i] + j];
if (c & 1) {
int m = c >> 1;
verboten |= ((1ull) << ((n * (n + 1)) / 2 - 2 + (n - m)));
}
}
}
}
return verboten;
}
int main() {
auto useless = [](uint8_t* cs){(void) cs;};
std::cout << count_colourings(8, 4, true, 0, useless ) << std::endl;
std::cout << count_colourings(9, 4, true, 0, useless ) << std::endl;
std::cout << count_colourings(8, 4, false, 0, useless ) << std::endl;
std::string line;
while (std::getline(std::cin, line)) {
auto circuit = parse_circuit(line);
int i = 0;
for (auto it = circuit.begin(); it != circuit.end(); ++it) {
i += ((*it) & 1);
}
auto verboten = get_verboten(circuit);
auto ncols = count_colourings(i, 4, true, verboten, useless);
std::cout << line << " : " << ncols << std::endl;
}
return 0;
}
......@@ -211,7 +211,7 @@ def trifree_dags(n):
to a triangle-free DAG without increasing the gate count or depth;
for this reason, it suffices to restrict attention to these graphs.
'''
# TODO add this sequence to the OEIS
# TODO submit this as sequence A308634 to the OEIS
dags = [tree2dag(t) for t in ubtrees(n)]
all_dags = []
while len(dags) > 0:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment