Inspired by The Great API Easter Egg Hunt!
Your task is to search for a predetermined integer in the "Collatz space" (to be explained later) using the fewest step possible.
This challenge is based on the famous Collatz conjecture that hopefully everyone here at least heard of. Here is a recap taken from Print the Super Collatz numbers.
The Collatz Sequence (also called the 3x + 1 problem) is where you start with any positive integer, for this example we will use 10, and apply this set of steps to it:
if n is even: Divide it by 2 if n is odd: Multiply it by 3 and add 1 repeat until n = 1
The Collatz distance
C(m,n) between the two numbers
n, for the purpose of this challenge, is the distance between two numbers in the Collatz graph(Credits to @tsh for telling me about this concept), which is defined as follows: (using
13 as examples):
Write down the Collatz sequence for
m (in this case,
21, 64, 32, 16, 8, 4, 2, 1
Write down the Collatz sequence for
n(in this case,
13, 40, 20, 10, 5, 16, 8, 4, 2, 1
Now count how many numbers appear only in one of the sequences. This is defined as the Collatz distance between
n. In this case,
21, 64, 32, 13, 40, 20, 10, 5
So we have Collatz distance between
C(m,n) have the following nice properties:
C(m,n)=C(n,m) C(m,n)=0 iff. m=n
Hopefully the definition of
C(m,n) is now clear. Let's start doing egg hunting in the Collatz space!
At the beginning of the game, a controller decides the position of an easter egg, which is expressed by its one-dimensional coordinate: An integer in the interval
[p,q] (in other words, an integer between
q, both ends inclusive).
The position of the egg remains constant throughout the game. We'll denote this coordinate as
You can now make an initial guess a0, and it will be recorded by the controller. This is your 0th round. If you are so lucky that you got it right at the first place (i.e. a0=r), the game ends, and your score is
0(The lower the score, the better). Otherwise, you enter the 1st round and you make a new guess a1, this goes on until you got it right, i.e. an=r, and your score will be
For each round after the 0th, the controller gives you one of the following feedbacks so that you can make a better guess based on the information given. Lets assume you are currently at the
nth round and hence your guess is an
- "You found it!" if an=r, in which case the game ends and you score
- "You are closer :)" if C(an,r)<C(an-1,r)
- "You are circling around the egg" if C(an,r)=C(an-1,r)
- "You are farther away :(" if C(an,r)>C(an-1,r)
To save some bytes, I will call the responses as "Right", "Closer", "Same", "Farther", in the order presented above.
Here is an example game with
- a1=11, response: "Closer"
- a2=13, response: "Farther"
- a3=4, response: "Farther"
- a4=3, response: "Closer"
- a5=5, response: "Same"
- a6=7, response: "Right"
Design a deterministic strategy to play the game for
p=51, q=562 with the best score.
Answers should describe the algorithms in detail. You can attach any code that helps to elucidate the algorithm. This is not codegolf so you are encouraged to write legible code.
Answers should include the worst score they may achieve for all possible cases of
r, and the one with lowest worst score wins. In the case of tie, the algorithms that has a better average score for all possible
rs (which should also be included in the answers) win. There are no further tie breakers and we may have multiple winners in the end.
- To reiterate,
rlies in the interval
- Default loopholes apply.
Bounty (Added after the first answer is posted)
I may personally offer a bounty to an answer where all the guesses are made within the range
[51,562] while still having a reasonably low worst score.