Some St. Patrick’s Day math

At today’s Gathering 4 Gardner social, Colm Mulcahy presented on two Irish figures in recreational mathematics with whom Martin Gardner corresponded: Victor Meally and Owen O’Shea. Owen O’Shea is the natural successor to Gardner’s “Professor I.J. Matrix” as a prolific generator of numerological coincidences — see for example The Magic Numbers of the Professor (2007). Victor Meally shows up occasionally in Gardner’s Mathematical Games columns, and also in “Problem 3.14” (appropriate for Pi Day!) in The Colossal Book of Short Puzzles and Problems (2006):

Read More

The 2024 Google Summer of Code idea lists are out

As of late February, Google Summer of Code (GSoC) has published its official list of sponsoring open-source organizations, and each organization has independently published its own list of project ideas. People interested in doing a GSoC project (sort of a summer internship for open source software) should submit a proposal application — the quite short application window is March 18 to April 2.

If you’re a fan of my “trivial relocatability” content, or just want to help relocation’s progress into the mainstream of C++, you might be particularly interested in these three GSoC sponsors:

Read More

Sorting integer_sequence at compile time

The other day I was pointed at this excellent set of template-metaprogramming exercises:

The exercises build gradually, from Prepend and Append, to RemoveFirst and RemoveAll, to Sort. The only things I’d have done differently in that sequence are to include PopFront (which is easier) before PopBack (which, unless I’m missing something, is harder); and include Iota (i.e. std::make_index_sequence) after Length.

Read More

Feature requests for the Auto macro

From time to time readers send me “feature requests” for the Auto scope-guard macro (“The Auto macro” (2018-08-11)). Usually, I say “No need!” The neat thing about Auto’s particular syntax is that it’s conceptually just a way to defer code to the end of a scope. Feature requests usually take the form of modifying the deferred code in some way — which is already (and more explicitly) allowed simply by… writing the code that way.

Read More

Infinite Craft

I’m enjoying the heck out of Neal Agarwal’s web game Infinite Craft. This is a “crafting game” where you start with just four elements and repeatedly combine pairs of elements to create new elements — for example, Water plus Fire equals Steam. The clever gimmick is that instead of hard-coding a finite number of possible combinations, Infinite Craft’s backend (certainly looks as if it) simply asks an LLM what the result ought to be. So the combinations literally never run out.

Read More

A note on feature-test macros

Previously on this blog: “C++2a idioms for library feature detection” (2018-10-26).

Every C++ implementation is required to provide feature-test macros indicating which features it supports. These come in two flavors:

  • Core-language macros such as __cpp_generic_lambdas, specified in [cpp.predefined]. These are provided by the compiler vendor via the same mechanism as __FUNCTION__ and __GNUC__.

  • Library macros such as __cpp_lib_ranges_iota, specified in [version.syn]. These are provided by the library vendor via the same mechanism as assert and _GLIBCXX_RELEASE. They all begin with __cpp_lib_. The easiest way to get all of them at once is to #include <version> (since C++20).

Read More

Pentoprimality

Over on /r/askmath a couple days ago, “electricmaster23” posed the following puzzle:

Pack the 12 pentominoes into a 6x10 rectangle, then label each cell of that rectangle with a digit from 1 to 5 such that each pentomino contains all of 1 through 5, and, whenever two adjacent cells belong to different pentominoes, their labels’ sum is a prime number.

Read More

What I’m reading lately: Africa, liberty, economics

In December I reread Mike Resnick’s Galactic Comedy, a trilogy of histories of three sci-fi planets based on the 19th- and 20th-century histories of three different African nations. Paradise is based on Kenya (Selous, Jomo Kenyatta, Mau Mau); Purgatory on Zimbabwe (Cecil Rhodes, Kariba Dam, Second Matabele War, Great Zimbabwe); and Inferno on Uganda (Milton Obote, Idi Amin, expulsion of the Asians). I recommend basically everything Mike Resnick ever wrote.

Read More

Should assignment affect is_trivially_relocatable?

Consider the following piece of code that uses Bloomberg’s bsl::vector:

#include <bsl_vector.h>
using namespace BloombergLP::bslmf;

struct T1 {
    int i_;
    T1(int i) : i_(i) {}
    T1(const T1&) = default;
    void operator=(const T1&) { puts("Assigned"); }
    ~T1() = default;
};
static_assert(!IsBitwiseMoveable<T1>::value);

int main() {
    bsl::vector<T1> v = {1,2};
    v.erase(v.begin());
}

bsl::vector::erase uses T1::operator= to shift element 2 leftward into the position of element 1 (and then destroys the moved-from object in position 2). The program prints “Assigned.”

But that’s because type T1 is not trivially relocatable!

Read More

Holiday puzzle: Anagrams modulo two

At today’s “Gathering 4 Gardner” social, Gordon Lessells presented his annual Christmas puzzle. The mechanism, which he just started playing with a couple of weeks ago, is “cancelling pairs of duplicate letters.” For example, when you cancel each pair of duplicate letters in the word LESSELLS, you throw out EE, LL, and SS and are left with LS. If you cancel each pair of duplicates in TENNESSEE, you’re left with simply T.

Read More

A Dissertation Upon Roast Pig (1822)

Happy Thanksgiving! I haven’t got a reading on roast turkey, but here are some excerpts from Charles Lamb’s “A Dissertation Upon Roast Pig” (London Magazine, September 1822):

I am one of those who freely and ungrudgingly impart a share of the good things of this life which fall to their lot (few as mine are in this kind) to a friend. I protest I take as great an interest in my friend’s pleasures, his relishes and proper satisfactions, as in mine own. “Presents,” I often say “endear Absents.” Hares, pheasants, partridges, snipes, barn-door chickens (those “tame villatic fowl”), capons, plovers, brawn, barrels of oysters, I dispense as freely as I receive them. I love to taste them, as it were, upon the tongue of my friend.

But a stop must be put somewhere. One would not, like Lear, “give everything.” I make my stand upon pig.

Read More