Project Euler 872 - Recursive Tree
Project Euler 872 - Recursive Tree
Official link: https://projecteuler.net/problem=872
Thought Process
Thought Process
After drawing a few trees a few patterns emerge.Â
The height of the tree is log2(n) + 1
The children of node n are always [n-1, n-2, n-4, n-8, n-16, n-2^k]
The children of n-1 are always [n-3, n-5, n-9, etc]
Essentially there are patterns relating to 2^n.
Once you ask yourself the question: What is the parent of node x, then answer becomes clear.
Interactive Code
Interactive Code
Input 2 integers separated by a space (n, x)
Code will output f(n, x)