Smaller or greater? – episode II

Suppose you play the following game: Someone holds a set of cards with the numbers {1,2,…,N} in random order, opens up the first card and asks if the next card is greater or smaller. Every time you predict correctly, you get one point, while every wrong prediction gives a point to the opponent – the card holder. The first card gives no points. What is the best strategy?

I still don’t seem to possess a theoretical solution to the problem, neither the time to look for one, but I will try to use R as a helping hand. So I will create a tiny script that calculates the win rate for a given problem dimension. First, the package gtools need to be installed. In Debian it exists in the repositories, but in any case you can install it within the program.

Let’s go to the coding now. Note that this little script hasn’t been optimised in terms of neither elegance nor efficiency. Also, care should be taken regarding the dimension, since the number of permutations grows rapidly. The function “permutations” from the package gtools is used to create a matrix with all permutations as rows. Then, for each row a serial check is performed and the decision is being based on probabilities, as explained in episode I. Finally, the win rate is printed out.

For dimension greater than 10 the script takes too long to finish. So, the next step will be a theoretical investigation. I wonder if, given a code optimisation, it would be possible to solve the problem with the whole set of 52 playing cards (as stated in episode I) using R. What do you think?