11
0
Inspired by The Great API Easter Egg Hunt!
Summary
Your task is to search for a predetermined integer in the "Collatz space" (to be explained later) using the fewest step possible.
Introduction
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 m
and 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 21
and 13
as examples):
Write down the Collatz sequence for m
(in this case, 21
):
21, 64, 32, 16, 8, 4, 2, 1
Write down the Collatz sequence for n
(in this case, 13
):
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 m
and n
. In this case, 8
, namely,
21, 64, 32, 13, 40, 20, 10, 5
So we have Collatz distance between 21
and 13
as C(21,13)=8
.
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 p
and q
, both ends inclusive).
The position of the egg remains constant throughout the game. We'll denote this coordinate as r
.
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 n
.
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 n
th round and hence your guess is an
- "You found it!" if an=r, in which case the game ends and you score
n
. - "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 p=1,q=15
.
- a0=10
- a1=11, response: "Closer"
- a2=13, response: "Farther"
- a3=4, response: "Farther"
- a4=3, response: "Closer"
- a5=5, response: "Same"
- a6=7, response: "Right"
Score: 6
.
Challenge
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 r
s (which should also be included in the answers) win. There are no further tie breakers and we may have multiple winners in the end.
Specs
- To reiterate,
r
lies in the interval[51,562]
. - 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.
Do you have a controller? – user202729 – 2018-04-02T03:27:15.487
Not one that is like the one in the original question. – Weijun Zhou – 2018-04-02T06:42:11.800
1
C(m, n) is the distance of m, n on the Collatz graph.
– tsh – 2018-04-02T09:07:48.330I came up with the concept myself and didn't know Collatz graph. Thank you for telling me that. I will include the information in the question. – Weijun Zhou – 2018-04-02T09:09:27.633