The Pieces That Aren’t There
The blue corner looked promising until I turned it around: sky on one side, ocean on the other. I left it in the tray and made a note of the gap instead. An incomplete puzzle deserves a record of what is missing, not just a celebration of what fits.
A left outer join does exactly that for two collections of records. Start with every position in a list, then attach a piece when its position appears in the placement list. Positions without a match stay in the result. The term comes from relational databases, which brought joins into everyday programming as SQL spread through the 1990s.
slots = ["A1", "A2", "B1", "B2"]
placements = %{"A1" => "red roof", "B1" => "blue sky"}
Enum.each(slots, fn slot ->
piece = Map.get(placements, slot, "missing")
IO.puts("#{slot}: #{piece}")
end)
The result keeps all four positions in order, including the two gaps:
A1: red roof
A2: missing
B1: blue sky
B2: missing
Bash can produce the same little inventory using an associative array. Run this with Bash 4 or later:
#!/usr/bin/env bash
declare -a slots=(A1 A2 B1 B2)
declare -A placements=([A1]='red roof' [B1]='blue sky')
for slot in "${slots[@]}"; do
if [[ ${placements[$slot]+present} ]]; then
printf '%s: %s\n' "$slot" "${placements[$slot]}"
else
printf '%s: missing\n' "$slot"
fi
done
Both examples assume at most one placed piece per position. A database join can return several rows for a position if several records share its key; that might be useful for tracking candidates, but it would change the meaning of this inventory. Neither program decides whether a piece actually fits. It records the placements I have accepted, leaving the ambiguous blue piece on the table for another look.