Project Euler 209 - Circular Logic
Official link: https://projecteuler.net/problem=209
Official link: https://projecteuler.net/problem=209
The hardest part of this problem for me was understanding it, so I'll explain that a bit. (Note: ^ is the symbol for XOR, & is the symbol for AND)
We are looking for all functions τ such that τ(a, b, c, d, e, f) & τ(b, c, d, e, f, a ^ (b & c)) = 0.
Now in general for a function T with n variables we have 2^n possible inputs (0 or 1 for each variable), and since the outcome of T(a, b, c, .... ) is either 0 or 1, this means in total we have 2^(2^n) possible functions T that can exist, or in our case 2^(2^6).
Simply searching through all τ is clearly infeasible, however notice that (b, c, d, e, f, a ^ (b & c)) is determined by (a, b, c, d, e, f) and what this means is that we can limit our options of τ by finding cycles of tuples. For example one such cycle is (1, 0, 1, 0, 1, 0) -> (0, 1, 0, 1, 0, 1) -> (1, 0, 1, 0, 1, 0).
Simpler Example:
Find the number of 1-input binary truth tables, T, such that T(a) & T(a ^ 1) = 0. Notice that this implies that T(a ^ 1) & T((a ^ 1) ^ 1) = 0, this is where we create a cycle, since if a = 0 then a ^ 1 = 1 then (a ^ 1) ^ 1 = 0 and similarly for a = 1 we get the same cycle.
If T(1) = 1
Then by our definition it must be that T(0) = 0, so this is one function T.
If T(1) = 0
By our definition, T(0) can be either 0 or 1, these are 2 new functions T
In total there are 3 functions T which satisfy this simpler example.
Applying the same logic we find cycles of (a, b, c, d, e, f), the longest cycle has length 46, which means there are still too many τ to test manually, but computing for small examples shows that the number of possible functions for an n length cycles is equal to L(n) denoting the Lucas Numbers which are easily computed from the Fibonacci numbers using L(n) = F(n + 1) + F(n - 1). Since each cycle is independent from each other we just multiply the number of functions satisfying each cycle to get the final answer.
There is no interactive code for this problem, instead I give my code which is pretty self explanatory.