7
\$\begingroup\$

\$BB\$ is the busy beaver function, an uncomputable function. Write a program which when given an integer \$n\$ as input, will output \$BB(n)\$, with at least \$\frac 2 3\$ probability. You can do whatever (return something wrong, infinite loop, explode, etc.) in other cases.

To help you compute it, you're given a function that randomly returns 0 or 1 (false or true, etc.). You can decide the exact probability that it returns 0, but all returns of calls should be independent.

Shortest code wins.

Notes

  • The exact definition of BB doesn't matter much so not clearly defined above.
  • If you encode some code into the randomness, they add nothing to length of your solution(actually it's hard to define code and data here). You should, when constructing the coin, show the code, though.
\$\endgroup\$
12
  • 7
    \$\begingroup\$ As touched on the busy beaver function is not a singular function. It's exact values depend on what model of computation we use. E.g. the busy beaver function for a two symbol single tape Turing machine. You should make it clear in the challenge, what is required of answers here. \$\endgroup\$
    – Wheat Wizard
    Commented Jan 17, 2022 at 11:07
  • \$\begingroup\$ so whats the output or input if there's any? \$\endgroup\$
    – DialFrost
    Commented Jan 17, 2022 at 11:08
  • 1
    \$\begingroup\$ How is this possible? As I understand it, this would mean that we can solve the halting problem with an arbitrarily small chance of failure, which seems impossible. Proof: given a program p use a busy beaver number to give an upper bound for time before halting, then simulate, and decide if the program halts. By doing the busy beaver calculation in parallel multiple times, we can make the chance of failure arbitrarily small. The fact that the calculation might not halt doesn't matter, since we can just wait for half of the calculations to terminate. \$\endgroup\$
    – AnttiP
    Commented Jan 17, 2022 at 13:10
  • 1
    \$\begingroup\$ but "The exact definition of BB doesn't matter much so not clearly defined above". If it's not open ended, shouldn't BB(n) be explicitly defined? \$\endgroup\$ Commented Jan 17, 2022 at 13:56
  • 5
    \$\begingroup\$ I guess I just don't get this. \$\endgroup\$ Commented Jan 17, 2022 at 14:26

1 Answer 1

2
\$\begingroup\$

Python 3.8 (pre-release), 68 66 bytes

lambda x:eval(sum(r()for _ in"X"*4**900).to_bytes(225,"big")[:99])

Try it online!

-2 bytes thanks to @l4m2

r is the random function. Its probability of outputting one encodes a 99-byte code snippet, which is evaluated. This code snippet can then read much more data from the randomness, and basically you can encode any program you want into the randomness stream.

Here is a practical demonstration

Example (less than) 99-byte snippet:

eval((sum(r()for _ in"X"*2**88001)>>80000).to_bytes(1000,"big")[99:])

As you can see, there is no limit to what kind of code we can run

To actually solve the busy beaver problem, the rest of the randomness is dedicated to just storing the answers to the question (that is, the busy beaver numbers).

The probability of failure depends on the first calculation. I think it succeeds with more than 2/3 probability, but i could be wrong. I'll check and add a proof later. Nevertheless, if it fails the criteria, this only results in some adjusting to the magic constants.

For the encoding of the busy beaver numbers, we first use the following encoding (I'm using a list of primes as an example)

[2,3,5,7,...]

Is converted into

110111011111011111110...

Finally, in order to account for the table-maker's dilemma, we replace1 with 10 and 0 with 01, resulting in 101001101010011010101010011010101010101001...

Then we execute the following code:

def get_raw_bit(p):
 # A lot of tries
 tries = 2**(2**p)
 hits = sum(r() for _ in range(2**tries))
 hits >> (tries - p)
def get_bit(p):
 code_len = 1000
 get_bit(code_len + 2*p)
pos = 0
p = -1
while pos < x:
 count = 0
 while get_bit(p:=p + 1):
  count+= 1
print(count)
\$\endgroup\$
7
  • \$\begingroup\$ Seems you need infinite layers of such construction and use form [BB(5)] if x==5 else [eval] \$\endgroup\$
    – l4m2
    Commented Jan 17, 2022 at 14:47
  • \$\begingroup\$ Can you not shr 997 and comment the quite random part? \$\endgroup\$
    – l4m2
    Commented Jan 17, 2022 at 14:50
  • \$\begingroup\$ @l4m2 RE: [BB(5)] if x==5 else [eval] No, not really. After the first two layers or so, you can make a reader function that reads the bitstream encoded in the randomness. The bitstream can have the following format: "110111011111110111111111110...". This would encode the list [2, 3, 5, 7, 11, ...] for example. Instead of the primes you encode the busy beaver numbers. You can do [BB(5)] if x==5 else [eval] but it's a bit more complicated. You can't directly store the numbers in decimal, because they get so big so fast. The comment idea is good though \$\endgroup\$
    – AnttiP
    Commented Jan 17, 2022 at 14:53
  • 1
    \$\begingroup\$ @l4m2 I did the calculations, it doesn't work. There are 3 characters that break the comment, namely the null byte, the line feed, and the carriage return. This means that the evaluated string can only contain 34 totally random characters, before the chance of the comment breaking becomes over 2/3. A good rule of thumb is that the length of the non-random part is roughly the same as the random part. So we can only use 34 characters for the code, which doesn't help at all. \$\endgroup\$
    – AnttiP
    Commented Jan 17, 2022 at 15:14
  • 1
    \$\begingroup\$ Slicing after to_bytes seems 2 bytes shorter \$\endgroup\$
    – l4m2
    Commented Jan 17, 2022 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.