Solution for the magic-trick and cookie-clicker problems.