Wiki: Hole Specific Tips
GitHub: edit | view

This page contains spoilers!

You might have more fun figuring out some of these tricks yourself.

I tried to catalogue only the "open secrets" that tend to come up on Discord.

12 Days of Christmas
  • The reason Lisp is so short is it has English formatting for numbers built-in (like Twelve).
  • You'll have to compress the text to win in many languages.
  • You don't have to skip the first argument if it's -- in your language: that's a perfectly fine brainfuck program producing no output.
  • If your language has eval, that's probably the way to go.
Catalan's Constant
  • 1/1 − 1/3² + 1/5² − 1/7² + 1/9² … converges so slowly that it's useless for this problem.
  • You'll have to look around the internet for a faster approach (or do a lot of math) :)
  • You can try a "zero-based" instead of "one-based" procedure instead: modify the formula so that instead of 10 → 5 → 16 → 8 → 4 → 2 → 1 you compute 9 → 4 → 15 → 7 → 3 → 1 → 0 (everything offset down by one). The stopping times are the same, but the loop bounds and halt check might be shorter.
Emirp Numbers
  • There are only 36 numbers to print, so hardcoding them might work.
CSS Colors
  • args is always a complete permutation of all possible inputs.
  • So you can use arg => sorted(args).index(arg) as a perfect hash function.
  • Unfortunately this trick doesn't apply to other holes (anymore)
Evil Numbers, Odious Numbers
  • Always exactly one of {2n, 2n+1} is evil (and the other is odious), so you can hardcode 25 bits.
  • OK, here are some bigger spoilers.
  • There is something shorter than t=a;a=b;b+=t; (you can avoid a temp variable in any language).
Happy Numbers
  • There are only 32 numbers to print, and they all fit in a byte, so you can try a "hardcode" approach.
  • − 10a − 9b − 8c − … − 2i (mod 11) is just a + 2b + 3c + … + 9i (mod 11).
Lucky Tickets

You don't need advanced mathematics to solve this in an efficient way. You can create an efficient algorithm to solve it from first principles and it can be fun to find it yourself. But if you are out of ideas and really want a spoiler, see the following Python code.

def lucky_tickets(digits, base):
    You are given an even number of digits and a base.
    The problem is to determine how many integers exist with the given number of digits in the
    given base, where the sum of the first half of the digits is the same as the sum of the second
    half of the digits. This is called the number of lucky tickets.
    half_digits = digits//2

    # Compute the maximum sum of each group of half of the digits.
    max_sum = half_digits * (base - 1)

    # Determine number of times each sum occurs for each group of half of the digits.
    empty_sum_counts = [0] * (max_sum + 1)
    sum_counts = empty_sum_counts.copy()

    # Each of the digits 0 through base - 1 occurs once in the first digit.
    sum_counts[:base] = [1] * base

    # For each additional digit.
    for d in range(1, half_digits):
        # previous_counts is the sum_counts for all numbers consisting of fewer digits.
        previous_counts = sum_counts
        # Start with an array of zeros.
        sum_counts = empty_sum_counts.copy()
        # For each digit b in our base that will contribute to the sum.
        for b in range(base):
            for i in range(d * (base - 1) + 1):
                # Add occurrences of the sum i + b using occurrences of the
                # sum i using only the previous digits.
                sum_counts[i + b] += previous_counts[i]

    # Sum the squares of the counts for each sum of digits in a group.
    # Imagine going through all possible sums of digits in a group.
    # Say that the sum s occurs x = counts[s] times for each group
    # of half of the digits. For each of the x occurrences in the first group,
    # there are x occurrences of that sum in the second group, so add x * x instances
    # where the sum of the two digit groups is the same.
    # The total is the number of lucky tickets.
    return sum(x*x for x in sum_counts)
  • There's a way to compute the correct melds without trying every combination.
  • OK, here are some bigger spoilers.
Niven Numbers
  • There is a shorter formula for two-digit numbers, that also happens to work for 100.
Pernicious Numbers
  • Forget primality: you only have to worry about popcount = 2, 3, or 5.
  • In other words, popcount ≠ 1 (mod 3).
  • There is a really short magic formula, using a bitwise operator.
Prime Numbers
Proximity Grid
  • In some compiled langs you can (sadly) read the source file from /tmp/
United States
  • Try to create some kind of a hash table or an advanced regex.
Vampire Numbers
  • Checking all the numbers will likely time out. Try to find a shortcut, or approach the problem from the opposite direction.
λ, π, τ…
  • If your language has bignums, then usually you want to compute floor(10^1000 * π) and then print that but with a decimal point squeezed in.
  • See primo's answer to a question about how to calculate Conway's constant.