x86-64 machine code, 38 32 31 bytes
48 B9 64 12 33 20 9F A1 52 B8 31 C0 99 B6 06 88 EA 48 C1 C1 07 14 04 29 D7 99 79 F3 24 05 C3
Try it online!
Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes the year number in EDI and returns a value in EAX: 4 for kings, 0 for queens, and 1 for the interregnum.
In assembly:
f:
mov rcx, 18<<8 | 50<<1 | 46<<58 | 10<<51 | 42<<44 | 12<<37 | 124<<30 | 64<<23 | 51<<16
# Put this constant in RCX.
xor eax, eax # Set EAX to 0.
cdq # Set EDX to 0 by sign-extending EAX.
mov dh, 6 # Set the second-lowest byte of EDX to 6.
repeat:
mov dl, ch # Set the low byte of EDX to the second-lowest byte of RCX.
rol rcx, 7 # Rotate RCX left by 7 bits.
adc al, 4 # Add 4+CF to AL.
sub edi, edx # Subtract EDX from EDI.
cdq # Set EDX to 0 by sign-extending EAX.
jns repeat # Jump back to repeat if the subtraction's result is nonnegative.
and al, 5 # Keep only the 1s bit and the 4s bit of AL.
ret # Return.
The basic way this works is to decrease the given number by 1554, 50, 46, 10, 42, 12, 124, 64, 51, 137, stopping when the result is negative, so that the loop executes a different number of times for each period of constant output.
The years of change were assigned to make all the period lengths even, except the last two. This allows the values to be stored in 7 bits each, so that nine can fit into a 64-bit register, while extracting 8 bits at a time (which includes the previous value's low bit) and still functioning correctly.
The 10th value extracted (for Elizabeth II's reign) entirely overlaps the 1st and 9th values, so we can only control its high bit, by assigning the year 1952. But because only years up to 2022 have to be handled, it is OK for this value to be higher than necessary.
The 1st value, which is 1554, is created by setting the second-lowest byte before the loop and then inserting the low byte within the loop (saving 2 bytes compared to pre-setting the whole thing).
To handle the interregnum, notice that the low bit of RCX ends up being 1 only when the given year is during the interregnum or the king period that follows it, and that is the same bit that gets copied into CF by the ROL
instruction. An ADC
instruction adds 4+CF to AL with each iteration, so that the 4s bit alternates between 0 and 1, while the 1s bit stays 0 initially, then becomes 1 for the interregnum and becomes 0 again for the next period, and stays 0 thereafter. At the end, an AND
instruction picks out those two bits.