  A preferred method to detect the curl-component, or B-mode, signature of
inflationary gravitational waves (IGWs) in the cosmic microwave background
(CMB) polarization, in the absence of foregrounds and lensing, is a prolonged
integration over a single patch of sky of a few square degrees. In practice,
however, foregrounds abound and the sensitivity to B modes can be improved
considerably by finding the region of sky cleanest of foregrounds. The best
strategy to detect B modes thus involves a tradeoff between exploration (to
find lower-foreground patches) and exploitation (through prolonged
integration). This problem is akin to the multi-armed bandit (MAB) problem in
probability theory, wherein a gambler faces a series of slot machines with
unknown winning odds and must develop a strategy to maximize his/her winnings
with some finite number of pulls. While the optimal MAB strategy remains to be
determined, a number of algorithms have been developed in an effort to maximize
the winnings. Here, based on this resemblance, we tackle the search for IGW B
modes with single frequency experiments in the presence of spatially-varying
foregrounds by developing adaptive survey strategies to optimize the
sensitivity to IGW B modes. We demonstrate, using realistic foreground models
and taking lensing-induced B modes into account, that adaptive experiments can
substantially improve the upper bound on the tensor-to-scalar ratio (by factors
of 2--3 in single frequency experiments, and possibly even more). Similar
techniques can be applied to other surveys, including 21-cm measurements of
signatures of the epoch of reionization, searches for a stochastic primordial
gravitational wave background, deep-field imaging by the James Webb Space
Telescope or various radio interferometers, and transient follow-up searches.
