[foth.dev] github

teaser

a small first-semester exercise

Description

A Knobelaufgabe, the kind of small exercise you get on the first problem sheets of a computer science degree. Pen and paper are enough. Each part you solve sets one of the site's hidden bits.

Here is a function in Python. // divides and rounds down, % is the remainder.

def mystery(n):
    if n == 0:
        return 0
    return mystery(n // 2) + n % 2

Exercises

  1. (a) What does mystery(2025) return?

    Decimal, hex (0x3f) and binary (0b101) all work.

  2. (b) What is the smallest n for which mystery(n) returns 10?

    Decimal, hex (0x3f) and binary (0b101) all work.