\documentclass[12pt,reqno]{article}

\usepackage{authblk}
\renewcommand{\Authsep}{\protect\\}
\renewcommand{\Authand}{\protect\\}
\renewcommand{\Authands}{\protect\\}
\usepackage{booktabs}
\usepackage{fullpage}
\usepackage{float}
\usepackage{placeins}

\usepackage[usenames]{color}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amscd}
\usepackage{graphicx}

\usepackage[colorlinks=true,
linkcolor=webgreen,
filecolor=webbrown,
citecolor=webgreen]{hyperref}

\definecolor{webgreen}{rgb}{0,.5,0}
\definecolor{webbrown}{rgb}{.6,0,0}

\usepackage{color}
\usepackage{float}

\usepackage{psfig}
\usepackage{graphics}
\usepackage{latexsym}
\usepackage{epsf}
\usepackage{breakurl}

\setlength{\textwidth}{6.5in}
\setlength{\oddsidemargin}{.1in}
\setlength{\evensidemargin}{.1in}
\setlength{\topmargin}{-.1in}
\setlength{\textheight}{8.4in}

\newcommand{\seqnum}[1]{\href{https://oeis.org/#1}{\rm \underline{#1}}}


\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{conjecture}[theorem]{Conjecture}

\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

\begin{document}

\begin{center}
\epsfxsize=4in
\leavevmode\epsffile{logo129.eps}
\end{center}

\newcommand{\newseq}[1]{\textbf{\seqnum{#1}}}
\newcommand{\floor}[1]{\left\lfloor #1\right\rfloor}
\newcommand{\cardres}[2]{\left\langle #1\right\rangle_{#2}}

\begin{center}
\vskip 1cm{\LARGE\bf Integer Sequences from \\
\vskip .1in
Card-Dealing Patterns
}
\vskip 1cm
\large Eric Huang$^1$, Tanya Khovanova$^2$, 
Timur Kilybayev$^1$,
Ryan Li$^1$,
Brandon Ni$^1$,
Leone Seidel$^1$,
Samarth Sharma$^1$,
Nathan Sheffield$^3$,
Vivek Varanasi$^1$,
Alice Yin$^1$,
Boya Yun$^1$, and
William Zelevinsky$^1$ \\
\ \\
\normalsize ${}^1$  PRIMES STEP\\
Department of Mathematics\\
Massachusetts Institute of Technology\\
Room 2-231c\\
77 Massachusetts Avenue\\
Cambridge, MA 02139\\
USA\\
\href{mailto:primes@math.mit.edu}{\texttt{primes@math.mit.edu}}\\
\ \\
${}^2$  Department of Mathematics\\
Massachusetts Institute of Technology\\
Room 2-231c\\
77 Massachusetts Avenue\\
Cambridge, MA 02139-4307\\
USA\\
\href{mailto:tanya@math.mit.edu}{\texttt{tanya@math.mit.edu}}\\
\ \\
${}^3$ Computer Science and Artificial Intelligence Laboratory\\
Massachusetts Institute of Technology\\
32 Vassar Street\\
Cambridge, MA 02139\\
USA\\
\href{mailto:shefna@mit.edu}{\texttt{shefna@mit.edu}}
\end{center}

\newpage

\begin{abstract}
We define a card-dealing procedure by an infinite word with the letters $U$ and $D$: a $U$-move sends the top card to the bottom of the deck, while a $D$-move removes the top card. For each pattern, we study five associated objects: the move-count sequence; the dealing triangle, whose entries give the removal rank of each initial position; its inverse, the Josephus triangle; the initial position of the last card removed; and the removal rank of the initial top card. A single round of the procedure gives simultaneous recursions for all five objects. For periodic patterns, we obtain additional row recurrences, and for the under-down shuffle, we express the dealing triangle
explicitly in terms of the $2$-adic valuation. We collect the resulting OEIS entries, including the 44 sequences introduced in the course of this project.
\end{abstract}

\section{Introduction}
\label{sec:introduction}

A number of card tricks use what is known as the \emph{under-down shuffle} or the related down-under shuffle. Here, the performer alternates between cycling the top card to the bottom of the deck and dealing the top card of the deck. This procedure is typically continued until all cards are dealt.

The under-down shuffle corresponds directly to the classical Josephus problem \cite[Sec.\ 1.3]{graham1994concrete}; related treatments appear in the literature \cite{lloyd83algorithm,schumer2002josephus,wilf91functional}. In the Josephus problem, people numbered $1,\ldots,N$ are arranged in a circle. The procedure starts with person number 1, and, going clockwise, every second person is eliminated until only one person remains \cite{ariyibi2019generalizations,park2018serial,ruskey2012feline,sullivan2012structured,sullivan2018variant}. Appending the survivor to the elimination order gives the order in which a deck initially arranged as $1,\ldots,N$, with $1$ on top, is dealt using the under-down shuffle.

In this paper, we discuss generalizations of the under-down shuffle to other dealing patterns involving a concatenation of the cycling move (under) and the dealing move (down)---for instance, down-under, under-under-down, etc.

We translate these generalizations to the model presented in the Josephus problem: instead of skipping one person between every elimination, we follow some other pattern of skips and eliminations.

Section~\ref{sec:catalog} shows the corresponding OEIS entries \cite{OEIS}; entries introduced by the authors are bolded. A longer version of this work contains additional examples, derivations, and applications to card magic \cite{huang2025card}.

By understanding the order in which this procedure deals cards, the performer can manipulate the initial conditions of a deck to guarantee a particular outcome; for an audience member, this outcome appears to have been produced magically. This paper seeks to quantify the mechanisms behind such results within the broad framework of dealing patterns.

The rest of the paper is organized as follows. Section~\ref{sec:definitions} introduces the patterns and their five associated objects. Section~\ref{sec:roundrecursion} derives simultaneous recursions from one full round of dealing. Section~\ref{sec:periodic} gives additional formulas for periodic patterns. Section~\ref{sec:UD} treats the under-down shuffle explicitly. Finally, Section~\ref{sec:catalog} collects the OEIS identifications and spelling-based applications to card magic.

\section{Patterns and associated sequences}
\label{sec:definitions}

We consider a deck of $N$ face-down cards, with positions numbered $1,\ldots,N$ from top to bottom. There are two types of moves: a $U$-move (under) sends the top card to the bottom of the deck, and a $D$-move (down) removes the top card and places it face up on the table.

A \emph{dealing pattern} is an infinite word
\[
P=p_1p_2p_3\cdots, \qquad p_i\in\{U,D\},
\]
containing infinitely many occurrences of $D$. A finite word used as a pattern denotes its infinite repetition; for example, $UD$ denotes $UDUDUD\cdots$.

To count the number of occurrences of each move, we define
\[
D_P(n)=\#\{i\leq n:p_i=D\},
\qquad
U_P(n)=\#\{i\leq n:p_i=U\}.
\]
Let $d_i(P)$ and $u_i(P)$ denote the positions of the $i$th occurrences of $D$ and $U$, respectively, with $u_i(P)$ defined whenever that occurrence exists. We denote by $\sigma^n P$ a suffix of $P$ with the first $n$ symbols deleted:
\[
\sigma^n P=p_{n+1}p_{n+2}\cdots,
\]
which represents the subsequent list of moves once $n$ moves have already been completed.

A \emph{round} consists of as many moves as there are cards in the deck at the start of that round. Each of these cards is handled exactly once. In the first round, cards originally in positions $d_1(P),\ldots,d_{D_P(N)}(P)$ are removed, while the surviving cards remain, from top to bottom, in the order
\[
u_1(P),\;u_2(P),\;\ldots,\;u_{U_P(N)}(P).
\]
If any cards remain, the next round starts with the first card sent under during the preceding round.

We now define representations for the five properties of a dealing pattern studied in this paper.

\begin{definition}
For a pattern $P$ and a deck of size $N$, we define the following:
\begin{enumerate}
\item $M^P(N)$ is the number of moves needed to remove all $N$ cards, including $U$- and $D$-moves;
\item $J^P_{N,k}$ is the original position of the $k$th card dealt by a down move;
\item $T^P_{N,k}$ is the removal index of the card initially in position $k$;
\item $F^P(N)=J^P_{N,N}$ is the original position of the last card dealt by a down move;
\item $E^P(N)=T^P_{N,1}$ is the removal index of the initial top card.
\end{enumerate}
\end{definition}

In the Josephus interpretation, a $U$-move skips the current person, and a $D$-move eliminates the current person. After either move, if anyone remains, we advance to the next remaining person clockwise. We continue until everyone has been eliminated. The person eliminated last would be the survivor under the usual convention that the process stops when one person remains.

The arrays $T^P$ and $J^P$ are called the \emph{dealing triangle} and the \emph{Josephus triangle}, respectively. Their $N$th rows, denoted by $T^P_N$ and $J^P_N$, are inverse permutations of one another, each containing $N$ entries. In particular, placing the card labeled $T^P_{N,k}$ in initial position $k$ makes the cards come out in the order $1,2,\ldots,N$. When a triangle is regarded as an OEIS sequence, its rows are concatenated.

From our definitions, since only the $D$ move removes cards, the move count for a sequence can easily be determined:
\[
M^P(N)=d_N(P).
\]

\begin{example}
For $P=UD$ and $N=5$, the procedure takes $M^{UD}(5)=10$ moves, and the removal order is
\[
J^{UD}_{5}=(2,\;4,\;1,\;5,\;3),
\]
so
\[
T^{UD}_{5}=(3,\;1,\;5,\;2,\;4),
\qquad F^{UD}(5)=3,
\qquad E^{UD}(5)=3.
\]
\end{example}

\section{The round recursion}
\label{sec:roundrecursion}

After one round, the procedure continues on the remaining deck under a shifted pattern. Using this, we create recursive equations representing all five parameters:

\begin{theorem}
\label{thm:round}
Fix a pattern $P$. For $N\geq 1$, we have
\[
M^P(0)=0,
\qquad
M^P(N)=N+M^{\sigma^N P}(U_P(N)).
\]
For $1\leq k\leq N$,
\[
T^P_{N,k}=
\begin{cases}
D_P(k), & \text{if $p_k=D$;}\\[3pt]
D_P(N)+T^{\sigma^N P}_{U_P(N),U_P(k)}, & \text{if $p_k=U$.}
\end{cases}
\]
For $1\leq k\leq N$,
\[
J^P_{N,k}=
\begin{cases}
d_k(P), & \text{if $1\leq k\leq D_P(N)$;}\\[3pt]
u_{J^{\sigma^N P}_{U_P(N),\,k-D_P(N)}}(P), & \text{if $D_P(N)<k\leq N$.}
\end{cases}
\]
\end{theorem}

\begin{proof}
During the first $N$ moves, each original card is handled exactly once. Cards in positions $d_1(P),\ldots,d_{D_P(N)}(P)$ are removed in that order, while the remaining cards are $u_1(P),\ldots,u_{U_P(N)}(P)$, from top to bottom. The procedure then continues on this remaining deck with pattern $\sigma^N P$. At that point, $N$ moves and $D_P(N)$ removals have occurred. Adding these offsets and translating positions in the remaining deck back to original positions gives the three formulas.
\end{proof}

Taking the last entry of the $N$th row of $J^P$ and the first entry of the $N$th row of $T^P$ gives the following.

\begin{corollary}
\label{cor:FEround}
For $N\geq 1$,
\[
F^P(N) = J^P_{N,N}=
\begin{cases}
N, & \text{if $U_P(N)=0$;}\\[3pt]
u_{F^{\sigma^N P}(U_P(N))}(P), & \text{if $U_P(N)>0$,}
\end{cases}
\]
and
\[
E^P(N)= T^{P}_{N,1} =
\begin{cases}
1, & \text{if $p_1=D$;}\\[3pt]
D_P(N)+E^{\sigma^N P}(U_P(N)), & \text{if $p_1=U$.}
\end{cases}
\]
\end{corollary}

Noticing that cycling through a deck during a dealing round can be represented through modular arithmetic, we define a $1$-indexed version of reduction modulo $N$ with values in $\{1,2,\ldots,N\}$ rather than $\{0,1,\ldots,N-1\}$. Quantitatively, for $N\geq 1$ and an integer $x$, let
\[
\cardres{x}{N}=1+((x-1)\bmod N).
\]
Prepending one move to a pattern gives useful relations among many of the sequences in Section~\ref{sec:catalog}.

\begin{proposition}
\label{prop:prepend}
For every pattern $P$ and $N\geq 1$,
\[
M^{DP}(N)=1+M^P(N-1),
\qquad
M^{UP}(N)=1+M^P(N).
\]
For $1\leq k\leq N$,
\[
T^{DP}_{N,k}=
\begin{cases}
1, & \text{if $k=1$;}\\[3pt]
1+T^P_{N-1,k-1}, & \text{if $k>1$,}
\end{cases}
\qquad
T^{UP}_{N,k}=
\begin{cases}
T^P_{N,N}, & \text{if $k=1$;}\\[3pt]
T^P_{N,k-1}, & \text{if $k>1$,}
\end{cases}
\]
and
\[
J^{DP}_{N,k}=
\begin{cases}
1, & \text{if $k=1$;}\\[3pt]
1+J^P_{N-1,k-1}, & \text{if $k>1$,}
\end{cases}
\qquad
J^{UP}_{N,k}=\cardres{J^P_{N,k}+1}{N}.
\]
Consequently,
\[
F^{DP}(1)=1,
\qquad
F^{DP}(N)=1+F^P(N-1)\quad(N>1),
\qquad
F^{UP}(N)=\cardres{F^P(N)+1}{N},
\]
and
\[
E^{DP}(N)=1,
\qquad
E^{UP}(N)=T^P_{N,N}.
\]
\end{proposition}
\begin{proof}
For $DP$, the first move removes the top card, leaving a deck of size $N-1$ in which original position $k>1$ becomes position $k-1$. The remaining pattern is $P$, and all subsequent removal ranks increase by $1$.

For $UP$, the first move sends the top card to position $N$ and moves every other card from position $k$ to position $k-1$. No card is removed, and the remaining pattern is again $P$. Thus position $j$ in the rotated deck corresponds to original position $\cardres{j+1}{N}$.

In both cases, the prepended move contributes $1$ to the move count. These observations give the identities for $M$, $T$, and $J$; those for $F$ and $E$ follow from their definitions.
\end{proof}

For fixed $k$ and every $N\geq d_k(P)$,
\[
J^P_{N,k}=d_k(P)=M^P(k).
\]
When $N\geq d_k(P)$, the $k$th $D$ occurs during the first round, before any card is handled twice. It therefore removes the card originally in position $d_k(P)$.

\section{Periodic patterns}
\label{sec:periodic}

Let $P$ be periodic with period $p$, and define
\[
d=D_P(p),\qquad s=U_P(p)=p-d,
\]
as well as $\delta_r$ as the position of the $r$th $D$ in one period, for $1\leq r\leq d$.

If $N=qd+r$, where $q\geq 0$ and $1\leq r\leq d$, then
\[
M^P(N)=qp+\delta_r.
\]
The first $q$ complete periods have $qd$ instances of $D$, and the $r$th extra instance is located at position $\delta_r$ in the following period.

One full period provides us with a row recursion for the dealing triangle as well.

\begin{theorem}
\label{thm:periodicT}
Assume $N\geq p$.  For $1\leq k\leq N$,
\[
T^P_{N,k}=
\begin{cases}
D_P(k), & \text{if $k\leq p$ and $p_k=D$;}\\[3pt]
d+T^P_{N-d,N-p+U_P(k)}, & \text{if $k\leq p$ and $p_k=U$;}\\[3pt]
d+T^P_{N-d,k-p}, & \text{if $k>p$.}
\end{cases}
\]
\end{theorem}

\begin{proof}
During the first $p$ moves, all cards occupying the $D$-positions of the period are removed. The remaining stack, from top to bottom, is in the order
\[
p+1,\;p+2,\;\ldots,\;N,\;u_1,\;u_2,\;\ldots,\;u_s.
\]
The pattern starts again since $P$ has period $p$.  A card originally in position $k>p$ moves to position $k-p$, whereas the card occupying the $i$th $U$-position in the period moves to position $N-p+i$.  Since $d$ cards have already been removed, the ranks of the subsequent removals increase by $d$.
\end{proof}

For $q\geq 1$, the familiar problem of removing every $q$th person corresponds to
\[
P=U^{q-1}D.
\]
For this particular case we have $M^P(N)=qN$. The usual one-elimination argument provides us with the Josephus recurrence.

\begin{corollary}
\label{cor:qth}
Let $F_q(N)=F^{U^{q-1}D}(N)$.  Then
\[
F_q(1)=1,
\qquad
F_q(N)=\cardres{F_q(N-1)+q}{N}\quad(N>1).
\]
\end{corollary}

\begin{proof}
After the first card is removed, the process starts again on the remaining $N-1$ cards from the next card in cyclic order. Hence if the position of the last card was relabeled as $F_q(N-1)$, then its original position is $\cardres{F_q(N-1)+q}{N}$.
\end{proof}

For $q=2,3,4,5,6$, these are the OEIS sequences
\[
\seqnum{A006257},\quad
\seqnum{A054995},\quad
\seqnum{A088333},\quad
\seqnum{A181281},\quad
\seqnum{A360268},
\]
respectively.

The residue class of the last card is limited by the $U$-positions of a periodic pattern.

Assume that every period of $P$ contains at least one $U$. If $N\geq u_1(P)$, we have
\[
p_{\cardres{F^P(N)}{p}}=U.
\]
In other words, modulo $p$, the initial position of the last card taken away must be a $U$-position of the period.
Since $N\geq u_1(P)$, at least one card remains after the first round.  Every card whose initial position is a $D$-position of the periodic word is removed during that round, so the last card must begin in a $U$-position.

\section{Under-down shuffle}
\label{sec:UD}

Now, we consider the special case $P=UD$. We write
\[
E(N)=E^{UD}(N),
\qquad
T_{N,k}=T^{UD}_{N,k},
\]
where $\nu_2(n)$ stands for the exponent of the largest power of $2$ dividing $n$. Halbeisen and Hungerb\"uhler
\cite[p.~313, Eq.~(22)]{halbeisen1997josephus} gave an explicit formula for the Josephus permutation when every second element is removed. Translating their formula from zero-based positions to the inverse permutation in our one-based notation gives the odd-position formula below. We include a short direct proof using our recurrences.

\begin{theorem}
\label{thm:UDformula}
For all $N\geq 1$,
\[
E(N)=N-\floor{\frac{N}{2^{\nu_2(N)+1}}}.
\]
Moreover,
\[
T_{N,2j}=j
\qquad
\left(1\leq j\leq \floor{\frac N2}\right),
\]
and
\[
T_{N,2j+1}
=
N-\floor{\frac{N-j}{2^{\nu_2(N-j)+1}}}
\qquad
\left(0\leq j\leq \floor{\frac{N-1}{2}}\right).
\]
\end{theorem}

\begin{proof}
If $N=2m+1$, the first round removes $m$ cards and leaves the initial top card on top of the remaining deck. Since the next move is $D$, this card is removed immediately; hence
\[
E(2m+1)=m+1.
\]
For $N=2m$, the first round deletes $m$ cards and leaves the initial top card as the top card of a pile of $m$ cards with the same dealing pattern $UD$; hence
\[
E(2m)=m+E(m).
\]
For $N=2^a r$ with $r$ being odd, we have $a=\nu_2(N)$. Iterating the recurrence relations for the even case followed by the odd case yields
\[
E(N)=N-\frac{r-1}{2}
=N-\floor{\frac{N}{2^{a+1}}},
\]
which is the first formula.

Each even position $2j$ is a $D$-position in the first round, so $T_{N,2j}=j$. Then, using the result of Theorem~\ref{thm:periodicT} inductively to an odd position, we have
\[
T_{N,2j+1}=j+T_{N-j,1}=j+E(N-j).
\]
Substitution of the formula for $E$ yields the required formula.
\end{proof}

The triangle $T^{UD}$ is \newseq{A378635}; its inverse $J^{UD}$ is \seqnum{A321298}, while the first column $E^{UD}$ is \seqnum{A225381}.  The last-card position is the classical Josephus sequence
\[
F^{UD}(N)=2\left(N-2^{\floor{\log_2 N}}\right)+1,
\]
which is \seqnum{A006257}. Specifically, the last card is initially at the top of the deck when $N$ is a power of $2$, and at the bottom when $N$ is one less than a power of $2$.

\section{OEIS catalog}
\label{sec:catalog}

Now, we list the sequences identified from the previous recursions. We start with periodic and aperiodic patterns, then consider special deck sizes, and finish with spelling applications.

\subsection{Periodic and aperiodic patterns}

Each triangular array is entered into OEIS by reading its rows. Boldface entries are newly added by the authors. First, we consider the periodic patterns listed in Table~\ref{tab:periodicsequences} below.

\begin{table}[ht]
\centering
\scriptsize
\renewcommand{\arraystretch}{1.35}
\resizebox{\textwidth}{!}{
\begin{tabular}{c|c|c|c|c|c}
\toprule
$P$ & $M^P(N)$ & $T^P$ & $J^P$ & $F^P(N)$ & $E^P(N)$ \\
\midrule
$UD$
& $2N$; \seqnum{A005843}
& \newseq{A378635}
& \seqnum{A321298}
& \seqnum{A006257}
& \seqnum{A225381} \\
$DU$
& $2N-1$; \seqnum{A005408}$(N)-2$
& \newseq{A378674}
& \newseq{A378682}
& \seqnum{A152423}
& \seqnum{A000012} \\
$UUD$
& $3N$; \seqnum{A008585}
& \newseq{A380195}
& \newseq{A381667}
& \seqnum{A054995}
& \newseq{A381591} \\
$UDU$
& $3N-1$; \seqnum{A016789}$(N)-3$
& \newseq{A382354}
& \newseq{A382358}
& \newseq{A382355}
& \newseq{A382356} \\
$DUU$
& $3N-2$; \seqnum{A016777}$(N)-3$
& \newseq{A381622}
& \newseq{A381623}
& $\begin{cases}
1, & \text{if $N=1$;}\\[3pt]
F^{UUD}(N-1)+1, & \text{if $N>1$.}
\end{cases}$
& \seqnum{A000012} \\
$UDD$
& \seqnum{A007494}
& \newseq{A382528}
& \newseq{A381049}
& \seqnum{A337191}
& \newseq{A381048} \\
$DUD$
& \seqnum{A032766}
& \newseq{A381050}
& \newseq{A383076}
& \newseq{A381051}
& \seqnum{A000012} \\
$DDU$
& \seqnum{A001651}
& \newseq{A383847}
& \newseq{A383845}
& \newseq{A383846}
& \seqnum{A000012} \\
$UUUD$
& $4N$; \seqnum{A008586}
& \newseq{A384770}
& \newseq{A384772}
& \seqnum{A088333}
& \newseq{A384774} \\
\bottomrule
\end{tabular}}
\caption{Sequences of periodic patterns.  Expressions such as \seqnum{A005408}$(N)-2$ use the OEIS indexing.}
\label{tab:periodicsequences}
\end{table}

In addition to periodic words, we also have three aperiodic patterns. The \textit{arithmetic-progression} pattern $AP$ is
\[
AP=UD\,UUD\,UUUD\,UUUUD\cdots
   =\prod_{m\geq 1}U^m D.
\]
Let $\lambda(m)$ be the number of alphabetical letters in the usual U.S.~English name of $m$, omitting \emph{and} and disregarding spaces, hyphens, and punctuation. The spelling patterns are \textit{SpellUnder-Down} ($SUD$) and \textit{Down-SpellUnder} ($DSU$):
\[
SUD=\prod_{m\geq 1}U^{\lambda(m)}D,
\qquad
DSU=D\,SUD.
\]
Table~\ref{tab:aperiodicsequences} describes the corresponding sequences.
\begin{table}[H]
\centering
\begin{tabular}{c|c|c|c|c|c}
\toprule
$P$ & $M^P(N)$ & $T^P$ & $J^P$ & $F^P(N)$ & $E^P(N)$ \\
\midrule
$AP$
& \seqnum{A000096}
& \newseq{A386639}
& \newseq{A386641}
& \seqnum{A291317}
& \newseq{A386643} \\
$SUD$
& \newseq{A380202}
& \newseq{A380201}
& \newseq{A380247}
& \newseq{A380204}
& \newseq{A380246} \\
$DSU$
& \newseq{A381128}
& \newseq{A381127}
& \newseq{A381114}
& \newseq{A381129}
& \seqnum{A000012} \\
\bottomrule
\end{tabular}
\caption{Sequences for the aperiodic patterns $AP$, $SUD$, and $DSU$.}
\label{tab:aperiodicsequences}
\end{table}

All entries of Tables~\ref{tab:periodicsequences} and~\ref{tab:aperiodicsequences} can be found from Theorem~\ref{thm:round}; in the case of periodic patterns, the rows of $T^P$ have a particularly simple recursion according to Theorem~\ref{thm:periodicT}.

\subsection{Special deck sizes}

Define
\[
\mathcal S_P=\{N\geq 1:F^P(N)=1\},
\qquad
\mathcal L_P=\{N\geq 1:F^P(N)=N\}.
\]
Thus $\mathcal S_P$ contains all the deck sizes where the initial top card is removed last, whereas $\mathcal L_P$ contains all deck sizes where the initial bottom card is removed last.  Proposition~\ref{prop:prepend} gives us
\begin{align*}
\mathcal L_P&=\mathcal S_{UP},\\
\mathcal L_{DP}&=\{1\}\cup\{n+1:n\in\mathcal L_P\}.
\end{align*}
The corresponding OEIS entries are listed below in Table~\ref{tab:specialsizes}.

\begin{table}[ht]
\centering
\small
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{c|c|c}
\toprule
$P$ & $\mathcal S_P$ & $\mathcal L_P$ \\
\midrule
$UD$   & \seqnum{A000079} & \seqnum{A000225} \\
$DU$   & $\{1\}$ & \seqnum{A000079} \\
$UUD$  & \seqnum{A081614} & \seqnum{A182459} \\
$UDU$  & \seqnum{A081615} & \seqnum{A081614} \\
$DUU$  & $\{1\}$ & \seqnum{A081615} \\
$UDD$  & \seqnum{A038754} & \seqnum{A164123} \\
$DUD$  & $\{1\}$ & \seqnum{A062318} \\
$DDU$  & $\{1\}$ & \seqnum{A038754} \\
$UUUD$ & \newseq{A385327} & \newseq{A385333} \\
$SUD$  & \newseq{A385328} & \newseq{A385513} \\
$DSU$  & $\{1\}$ & $\{1\}\cup(1+\newseq{A385513})$ \\
$AP$   & \newseq{A386305} & \newseq{A386312} \\
\bottomrule
\end{tabular}
\caption{Sizes of decks for which the initial top or bottom card is removed last. Only positive terms of the listed OEIS sequences are used. In the $DSU$ row, $1+\newseq{A385513}$ means termwise addition of $1$.}
\label{tab:specialsizes}
\end{table}

For instance, the explicit formula derived in Section~\ref{sec:UD} results in
\[
\mathcal S_{UD}=\{2^m:m\geq0\},
\qquad
\mathcal L_{UD}=\{2^m-1:m\geq1\}.
\]
All other rows can be recursively derived using Corollary~\ref{cor:FEround} and Proposition~\ref{prop:prepend}.

\FloatBarrier

\subsection{Spelling applications}

Now, we discuss a trick based on the $SUD$ dealing. For more tricks and performance advice, see the extended version of our paper~\cite{huang2025card}.

\begin{example}[Second time's the charm]
Take six face-down cards labeled $1,2,\ldots,6$ and arrange them in increasing order from top to bottom. Spell the number names \emph{one}, \emph{two}, \ldots, \emph{six}, moving the top card under for each letter and, after each word, dealing the next card face up onto the top of a single pile. The removal order is
\[
J^{SUD}_{6}=(4,\;2,\;5,\;1,\;3,\;6).
\]
Turn the entire pile over as a unit, so that it is face down, and repeat the procedure, restarting the spelling at \emph{one}. This time the cards are dealt in increasing order. Indeed, one complete deal followed by turning the pile face down reorders the deck according to $J^{SUD}_{6}$. This permutation is the involution $(1\;4)(3\;5)$, so applying it twice restores the initial order. More generally, if $(J^P_N)^n=I$, repeating the procedure $n$ times gives increasing removal order on the $n$th pass, provided that the entire pile is turned over between passes and the pattern restarts at the beginning on every pass.
\end{example}

In addition, there exists a finite spelling pattern based on spelling out the thirteen denominations
\[
\text{ace},\;\text{two},\;\text{three},\;\ldots,\;\text{ten},\;\text{jack},\;\text{queen},\;\text{king}.
\]
Here we encode ace, jack, queen, and king as $1,11,12,13$, respectively. The unique permutation which causes the cards to be removed in increasing order under the resulting SpellUnder-Down procedure is
\[
(3,\;8,\;7,\;1,\;12,\;6,\;4,\;2,\;11,\;13,\;10,\;9,\;5),
\]
which is \newseq{A380248}. In the case that a down move is performed first, the corresponding permutation is
\[
(1,\;11,\;4,\;6,\;2,\;12,\;13,\;8,\;3,\;5,\;7,\;9,\;10),
\]
which is \newseq{A381151}.  This pair of finite permutations comes from the same triangle construction; see our extended paper~\cite{huang2025card} for performance instructions.


\section{Use of AI tools}

We used Grammarly for language editing and ChatGPT for proofreading, mathematical checks, and assistance with LaTeX code. When we received initial reviews of our paper, we used ChatGPT PRO generated suggested revisions. The authors independently wrote the final text, verified the mathematical arguments, and are responsible for the final version.


\section{Acknowledgments}

We appreciate the support of the PRIMES STEP program in this project.  We also would like to thank the referee for the helpful remarks which led to us significantly shortening and streamlining our paper.


\begin{thebibliography}{99}

\bibitem{ariyibi2019generalizations}
D.~Ariyibi, K.~Chang, and P.~E.~Harris,
Generalizations of the feline and Texas chainsaw Josephus problems,
\emph{Open J.~Discrete Math.} \textbf{9} (2019), 144--158.

\bibitem{graham1994concrete}
R.~L.~Graham, D.~E.~Knuth, and O.~Patashnik,
\emph{Concrete Mathematics: A Foundation for Computer Science},
2nd ed., Addison-Wesley, 1994.

\bibitem{halbeisen1997josephus}
L.~Halbeisen and N.~Hungerb\"uhler,
The Josephus problem,
\emph{J.~Th\'eor. Nombres Bordeaux} \textbf{9} (1997), 303--318.

\bibitem{huang2025card}
E.~Huang, T.~Khovanova, T.~Kilybayev, R.~Li, B.~Ni, L.~Seidel,
S.~Sharma, N.~Sheffield, V.~Varanasi, A.~Yin, B.~Yun, and
W.~Zelevinsky,
Card dealing math,
arXiv preprint arXiv:2509.11395 [math.NT], 2025.
Available at \url{https://arxiv.org/abs/2509.11395}.

\bibitem{lloyd83algorithm}
E.~L.~Lloyd,
An $O(n\log m)$ algorithm for the Josephus problem,
\emph{J.~Algorithms} \textbf{4} (1983), 262--270.

\bibitem{wilf91functional}
A.~M.~Odlyzko and H.~S.~Wilf,
Functional iteration and the Josephus problem,
\emph{Glasgow Math.~J.} \textbf{33} (1991), 235--240.

\bibitem{OEIS}
OEIS Foundation Inc.,
\emph{The On-Line Encyclopedia of Integer Sequences},
published electronically at \url{https://oeis.org}.

\bibitem{park2018serial}
J.~W.~Park and R.~Teixeira,
Serial execution Josephus problem,
\emph{Korean J.~Math.} \textbf{26} (2018), 1--7.

\bibitem{ruskey2012feline}
F.~Ruskey and A.~Williams,
The feline Josephus problem,
\emph{Theory Comput.~Syst.} \textbf{50} (2012), 20--34.

\bibitem{schumer2002josephus}
P.~Schumer,
The Josephus problem: once more around,
\emph{Math.~Mag.} \textbf{75} (2002), 12--17.

\bibitem{sullivan2012structured}
S.~Sullivan and T.~Beatty,
Structured shuffles and the Josephus problem,
\emph{Open J.~Discrete Math.} \textbf{2} (2012), 138--141.

\bibitem{sullivan2018variant}
S.~Sullivan and E.~Insko,
A variant on the feline Josephus problem,
arXiv preprint arXiv:1803.11340 [math.CO], 2018.
Available at \url{https://arxiv.org/abs/1803.11340}.

\end{thebibliography}

\bigskip
\hrule
\bigskip

\noindent 2020 \emph{Mathematics Subject Classification:} Primary 11B83; Secondary 05A05.

\noindent \emph{Keywords:} Josephus problem, permutation triangle, card dealing, integer sequence, OEIS.

\bigskip
\hrule
\bigskip

\noindent (Concerned with sequences
\seqnum{A000012},
\seqnum{A000079},
\seqnum{A000096},
\seqnum{A000225},
\seqnum{A001651},
\seqnum{A005408},
\seqnum{A005843},
\seqnum{A006257},
\seqnum{A007494},
\seqnum{A008585},
\seqnum{A008586},
\seqnum{A016777},
\seqnum{A016789},
\seqnum{A032766},
\seqnum{A038754},
\seqnum{A054995},
\seqnum{A062318},
\seqnum{A081614},
\seqnum{A081615},
\seqnum{A088333},
\seqnum{A152423},
\seqnum{A164123},
\seqnum{A181281},
\seqnum{A182459},
\seqnum{A225381},
\seqnum{A291317},
\seqnum{A321298},
\seqnum{A337191},
\seqnum{A360268},
\seqnum{A378635},
\seqnum{A378674},
\seqnum{A378682},
\seqnum{A380195},
\seqnum{A380201},
\seqnum{A380202},
\seqnum{A380204},
\seqnum{A380246},
\seqnum{A380247},
\seqnum{A380248},
\seqnum{A381048},
\seqnum{A381049},
\seqnum{A381050},
\seqnum{A381051},
\seqnum{A381114},
\seqnum{A381127},
\seqnum{A381128},
\seqnum{A381129},
\seqnum{A381151},
\seqnum{A381591},
\seqnum{A381622},
\seqnum{A381623},
\seqnum{A381667},
\seqnum{A382354},
\seqnum{A382355},
\seqnum{A382356},
\seqnum{A382358},
\seqnum{A382528},
\seqnum{A383076},
\seqnum{A383845},
\seqnum{A383846},
\seqnum{A383847},
\seqnum{A384770},
\seqnum{A384772},
\seqnum{A384774},
\seqnum{A385327},
\seqnum{A385328},
\seqnum{A385333},
\seqnum{A385513},
\seqnum{A386305},
\seqnum{A386312},
\seqnum{A386639},
\seqnum{A386641}, and
\seqnum{A386643}.)

\bigskip
\hrule
\bigskip

\vspace*{+.1in}
\noindent
Received  November 11 2025;
revised versions received  September 14 2026;
October 11 2026; October 15 2026.
Published in {\it Journal of Integer Sequences},
October 15 2026.

\bigskip
\hrule
\bigskip

\noindent
Return to \href{https://cs.uwaterloo.ca/journals/JIS/}{Journal of Integer Sequences home page}.
\vskip .1in


\end{document}


                                                                                

