brain

tamnd's digital brain — notes, problems, research

43815 notes

TAOCP 4.5.3 Exercise 16

Let f_0(z)=\tanh z=\frac{e^z-e^{-z}}{e^z+e^{-z}}, \qquad f_{n+1}(z)=\frac{1}{f_n(z)}-\frac{2n+1}{z}.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 2.4 Exercise 6

The proposed solution captures the high-level idea of PL/I qualification: each item is identified by its full chain of ancestors, and ambiguity is resolved by complete qualification.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.1 Exercise 12

The algorithm in Exercise 11 is Prim’s construction of a minimum-cost spanning tree, but it is stated in a form that repeatedly renumbers vertices and updates an entire cost matrix.

taocpmathematicsalgorithmsvolume-1
CF 104614B - A Musical Question

We are given a fixed capacity for two identical CDs and a list of song durations. Each CD can hold at most c minutes of music, and every song can be placed on at most one CD or skipped entirely.

codeforcescompetitive-programming
TAOCP 1.4.3.1 Exercise 7

The reviewer’s objection targets a genuine modeling mistake in the explanation: not the timing formula itself, but the _interpretation of device occupancy during the delay interval_.

taocpmathematicsalgorithmsvolume-1hard
CF 104617D - Ice Cream Lasagna

We are given a sequence of $n$ layers, and each layer contains a string made of characters $R$ and $G$. Each character represents a candy of a specific color, and the string represents the order in which candies appear inside that layer from top to bottom.

codeforcescompetitive-programming
TAOCP 1.4.3.1 Exercise 3

Let $M$ and $F$ denote the address and field of the instruction, already placed in $rI5$ and $rI3$ by the control routine, and let $X$ denote the index register contents stored in $XREG$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.3.1 Exercise 1

Let the field specification byte be denoted by $x = \mathrm{INST}(4:4)$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.2.5 Exercise 20

Let $x>0$.

taocpmathematicsalgorithmsvolume-1
TAOCP 1.2.5 Exercise 11

Let $\mu=\sum_{k>0}\left\lfloor \frac{n}{2^k}\right\rfloor$ be the exponent of $2$ in $n!$ by equation (8).

taocpmathematicsalgorithmsvolume-1
TAOCP 1.2.5 Exercise 2

From equation (2), p_{nk} = n(n-1)\cdots(n-k+1).

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.5 Exercise 12

The previous solution failed because it implicitly allowed uncontrolled queue duplication and did not establish a genuine worst-case per-operation bound independent of heap size and history.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.5 Exercise 11

We model a List structure as a finite directed, rooted, ordered graph.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.5 Exercise 9

The key correction is to treat pointer updates as **field updates inside each node** and to separate clearly the logical relabeling of pointers from the physical relocation step.

taocpmathematicsalgorithmsvolume-1
CF 104687C - Сумма 1

We are given two integer intervals: one interval defines all valid values of $x$, and the other defines all valid values of $y$. We also have a target sum $n$.

codeforcescompetitive-programming
TAOCP 2.3.5 Exercise 5

A precise combined Schorr–Waite marking procedure is obtained by running a depth-first traversal in which the stack stores continuation states exactly as in Algorithm B, and the pointer-reversal mecha...

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.5 Exercise 1

A List can be described as a finite directed graph whose vertices correspond to memory nodes and whose directed edges correspond to pointer fields such as `RLINK` and `DLINK`.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.5 Exercise 17

Let $T(z)=\sum_{n\ge1} t_n z^n$ be the generating function where $t_n$ counts unlabeled ordered trees with $n$ terminal nodes and no nodes of degree $1$.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.5 Exercise 14

We repair the argument by separating three facts that were previously conflated: 1.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.5 Exercise 13

Maintain two FIFO queues.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.5 Exercise 10

The binary case extends directly.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.5 Exercise 8

Let the complete $t$-ary tree have internal nodes ${1,2,\ldots,n}$, and let q=\left\lfloor \log_t((t-1)n+1)\right\rfloor.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.5 Exercise 4

We prove the statement by induction on $m$.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.5 Exercise 2

The construction follows Huffman’s algorithm applied to the weights in nondecreasing order.

taocpmathematicsalgorithmsvolume-1
TAOCP 1.4.4 Exercise 19

Block $k$ starts input at time $t_k$ satisfying t_1 = 0,\qquad t_k \equiv (k-1)L \pmod P,\qquad t_k \text{ increasing in } k.

taocpmathematicsalgorithmsvolume-1math-hard
CF 104617G - Ice Cream Gambling

We are given two independent lists that interact through a single decision: how many customers we serve using available cones. Each customer has a value $ri$, which represents the profit you would obtain if you successfully serve that customer with a chocolate-mint cone.

codeforcescompetitive-programming
CF 104617E - Cone Coloring

We are given a line of colored dyes, each dye having a positive integer value that represents how “beautiful” it is.

codeforcescompetitive-programming
CF 104617B - Ice Cream Biorhythm

We are given five cubic polynomials. Three of them represent the “status” of three ice cream companies over time, and two represent external factors (UV index and heat index). At a specific hour d, we evaluate all five polynomials.

codeforcescompetitive-programming
TAOCP 1.4.4 Exercise 18

The purpose of the interrupt extension is to eliminate the busy waiting performed by `JRED`.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 1.4.4 Exercise 17

The error in the proposed solution stems from an incorrect output discipline and an underspecified buffer-state structure.

taocpmathematicsalgorithmsvolume-1project
TAOCP 1.4.4 Exercise 13

The key point in Knuth’s buffered coroutine design is that termination is expressed purely through the **buffer–handoff protocol**, not through any external flag or global state.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.4 Exercise 11

The original schedule (Fig.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.4 Exercise 9

The solution does not answer the question asked.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.4 Exercise 8

Section 1.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.4.4 Exercise 6

The subroutine `WORDIN` assumes that a circular pair of buffers is already set up in memory and that index register $6$ always points into the current buffer.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.3.3 Exercise 28

Let the Josephus process on $\{1,\dots,n\}$ use the standard convention: starting from a fixed cyclic order, we repeatedly advance $m-1$ steps in the current cycle and delete the next element.

taocpmathematicsalgorithmsvolume-1math-medium
CF 104617H - Cone Factory

We are given several cone molds placed at distinct integer positions on a line. We are allowed to choose exactly one starting position from which a vertical stream of batter begins flowing downward. The factory also contains horizontal spreader segments.

codeforcescompetitive-programming
TAOCP 1.3.3 Exercise 25

Let T(n)=\sum_{k=1}^{n}(k-1)(n-k)!

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.3.3 Exercise 23

Let a permutation of ${1,\dots,n}$ be chosen uniformly from $S_n$.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 1.3.3 Exercise 22

We correct the argument by deriving the distribution in part (a) directly from the two stated conditions, without assuming Poisson structure or independence in advance.

taocpmathematicsalgorithmsvolume-1hm-hard
CF 104617F - Bing is Chilling

We are given a collection of named ingredients, each of which can either be bought directly for a fixed price or produced using other ingredients according to a recipe. Some ingredients are final targets that Bing needs in order to make his ice cream flavor.

codeforcescompetitive-programming
CF 104617C - Sweet Selections

We are given three independent collections of strings: ice cream flavors, drizzles, and toppings. A dessert consists of exactly two scoops of ice cream, one drizzle, and one topping.

codeforcescompetitive-programming
CF 104617A - Get to the Choppa!

We are given a collection of ice blocks, each tagged with a flavor name and a number that represents how long that block takes to melt.

codeforcescompetitive-programming
CF 104618J - Starfruit Ice Cream

We are asked to choose exactly $n$ distinct cells in an $n times n$ grid. Each chosen cell is a “pouring point” where a unit of milk is placed.

codeforcescompetitive-programming
TAOCP 1.3.3 Exercise 20

Let a permutation of $n$ elements have exactly $\alpha_j$ cycles of length $j$, for $1 \le j \le n$, including $\alpha_1$ singleton cycles written explicitly.

taocpmathematicsalgorithmsvolume-1math-medium
CF 104618I - Magic Sprinkles

We are given a set of points in the plane, each representing a sprinkle placed somewhere above the x-axis, since all y-coordinates are strictly positive. Each sprinkle has a color, either red or blue.

codeforcescompetitive-programming
CF 104618H - Cone Factory

Each cone mold sits at a distinct integer coordinate on the X-axis. From above, every coordinate has an infinitely high dispenser that can drop batter straight down, but in reality only one dispenser can be activated, so initially we only have one vertical stream starting from…

codeforcescompetitive-programming
CF 104618F - Bing is Chilling

We are given a collection of ingredients where each ingredient has two ways of obtaining it. You can either buy it directly at a fixed price, or you can produce it by combining other ingredients, which themselves may also be bought or produced.

codeforcescompetitive-programming
CF 104618G - Ice Cream Gambling

We are given two independent collections that interact through a trading process. One collection represents customers, each customer $i$ willing to pay $ri$ if they successfully receive chocolate-mint ice cream.

codeforcescompetitive-programming
CF 104618E - Cone Coloring

We are given a line of $N$ dyes, each with a positive integer beauty value. From this sequence we want to choose a subset of positions such that no two chosen positions are adjacent in the original line.

codeforcescompetitive-programming
CF 104618D - Ice Cream Lasagna

We are given a vertical stack of $n$ ice cream layers. Each layer is a string over the alphabet ${R, G}$, representing candies in that layer from left to right. The process is strictly sequential: we start from layer 1, then 2, and so on until layer $n$.

codeforcescompetitive-programming
TAOCP 1.3.3 Exercise 18

Let $S_n$ be the set of all permutations of ${1,2,\dots,n}$, chosen uniformly.

taocpmathematicsalgorithmsvolume-1math-hard
CF 104618C - Sweet Selections

We are given three independent lists of strings: available ice cream flavors, available drizzles, and available toppings. A valid dessert consists of choosing exactly two scoops of ice cream, then choosing one drizzle and one topping.

codeforcescompetitive-programming
CF 104619L - Location, Location, Location

We are given a set of points on a 2D grid, each representing a location such as a house or apartment. We must choose a new point $(x, y)$ where a charging station will be built.

codeforcescompetitive-programming
CF 104619K - Kick

We are given a single long string consisting only of lowercase English letters. The task is to count how many times the pattern “kick” appears as a contiguous substring.

codeforcescompetitive-programming
CF 104619H - Heap Structure

We are given a min-heap containing the values from 1 to n, where n is extremely large, up to 10^18, and we focus on the element with rank k in sorted order, which is simply the value k itself.

codeforcescompetitive-programming
CF 104619I - Introversion

We are given a linear table of length $2n$. Each position either already contains a dish of type $1 dots n$ or is empty. Every type appears at most twice in the initial configuration, and whenever it appears twice those two occurrences are not adjacent.

codeforcescompetitive-programming
TAOCP 1.3.3 Exercise 16

Let $T$ be the operation described: 1.

taocpmathematicsalgorithmsvolume-1math-simple
CF 104619J - Java Warriors

We are given a single integer $n$ representing how many ICPC teams Jerry is sending to a contest. Each team requires a fixed registration fee of 4000 dollars. The task is to compute the total amount of money needed to register all teams.

codeforcescompetitive-programming
CF 104619G - Gadget Construction

Codeforces 104619G: Gadget Construction

codeforcescompetitive-programming
CF 104619E - Exponentiation

We are given a positive integer α that is defined as the sum of a number x and its reciprocal 1/x. In other words, x is some (possibly complex) number satisfying x + 1/x = α. From this implicit definition, we are asked to compute the value of x^β + (1/x)^β modulo m.

codeforcescompetitive-programming
CF 104619C - Cutting into Monotone Increasing Sequence

We are given a very long integer written as a string of digits, and we are allowed to insert commas between digits to split it into contiguous chunks. Each chunk is interpreted as a number.

codeforcescompetitive-programming
CF 104619F - Finding Bridges

We are given an undirected simple graph and a sequence of edge deletions. After each deletion, we must report how many bridges remain in the current graph.

codeforcescompetitive-programming
CF 104619D - Divide a Convex

We are given a convex polygon with up to 100000 vertices in order. We must choose two points P and Q, each lying on different edges of the polygon, and draw a segment PQ inside the polygon. This segment splits the polygon into two convex polygons.

codeforcescompetitive-programming
CF 104619B - Better Chance

We are given two independent regional contests, Taoyuan and Jakarta. For each contest, we know two quantities: the recomputed rank of our team inside that contest and a “site score” that summarizes the overall strength and scale of that contest.

codeforcescompetitive-programming
CF 104619A - Advance to Taoyuan Regional

We are given a single calendar date in the year 2023, written as YYYY-MM-DD. This date represents when a programming contest (TOPC) is planned to be held.

codeforcescompetitive-programming
CF 104627D - Clock Gallery

We are given a collection of 24-hour clocks, each showing a precise time down to seconds. Separately, we are told a list of cities, and for each city we know how many seconds ahead or behind Paris it is.

codeforcescompetitive-programming
CF 104627E - Coin Puzzle

I can’t reliably write a correct editorial for this problem yet because the actual problem statement for Codeforces 104627E - Coin Puzzle isn’t included in your prompt.

codeforcescompetitive-programming
CF 104627B - Connect

We are given an $n times n$ grid that starts empty, and two players alternately drop tokens into columns. Each move chooses a column, and the token falls to the lowest available cell in that column, like gravity in Connect Four.

codeforcescompetitive-programming
CF 104627A - Forgery

We are given a grid of characters that represents a sheet of paper, where each cell is either empty or marked. The task is to determine whether the pattern of marked cells could have been produced by a single rectangular stamp that was pressed one or more times onto an…

codeforcescompetitive-programming
TAOCP 1.3.3 Exercise 15

Let $\pi$ be a permutation of $\{1,2,\dots,n\}$.

taocpmathematicsalgorithmsvolume-1math-simple
CF 104627C - Reading Numbers

I can write the full editorial in the exact style you requested, but I need the actual problem statement (or at least a link or summary of the task).

codeforcescompetitive-programming
CF 104630B - Overrandomized

Each test case describes a single hidden permutation of the digits 0 through 9 into uppercase letters. In other words, every digit is represented by exactly one letter, and every letter represents exactly one digit. The server encodes numbers using this unknown substitution.

codeforcescompetitive-programming
CF 104630A - Overexcited Fan

We are working on a grid where both you and a moving target start at known integer coordinates and move in unit time steps along the grid edges.

codeforcescompetitive-programming
CF 104630C - Oversized Pancake Choppers

We are given several circular pancakes that have already been cut into wedge-shaped pieces. Each piece has some angular size, and we are allowed to further split any piece by making radial cuts.

codeforcescompetitive-programming
CF 104631D - Emacs++

We are given a string of balanced parentheses of length K. Every index is a position in a one-dimensional editor.

codeforcescompetitive-programming
CF 104631B - Security Update

We are given a network of computers connected by undirected links. Computer 1 is the source, and every other computer is reachable from it. Each link has an unknown positive integer latency, and these latencies determine how quickly a security update spreads through the network.

codeforcescompetitive-programming
CF 104631C - Wormhole in One

We are given a set of points in the plane, each representing a hole. A ball moves along an infinite straight line once we choose its starting position and direction.

codeforcescompetitive-programming
CF 104631A - Incremental House of Pancakes

We are given two piles of pancakes. The process is a deterministic sequence of customers arriving one by one. The i-th customer always requests exactly i pancakes, and we must satisfy them by taking all pancakes from exactly one of the two stacks.

codeforcescompetitive-programming
TAOCP 1.3.3 Exercise 13

The flaw in the previous response is that it refused the task instead of engaging with the standard definition of Algorithm $J$ in TAOCP §1.

taocpmathematicsalgorithmsvolume-1math-medium
CF 104633O - Which Planet is This?!

We are given two sets of points on a sphere, each point described by latitude and longitude. The latitude is fixed by the planet’s geometry, so it stays identical across both maps.

codeforcescompetitive-programming
CF 104633N - What’s Our Vector, Victor?

We are given several points in a d-dimensional Euclidean space. Each point is a known vector, and for each of them we are also given the exact Euclidean distance to an unknown hidden vector.

codeforcescompetitive-programming
CF 104633L - Sweep Stakes

We are given a rectangular grid where each cell independently contains a mine with a probability that depends only on its row and column indices. Specifically, a cell at position $(i, j)$ is mined with probability $pi + qj$.

codeforcescompetitive-programming
CF 104633M - Trailing Digits

We are given a base price for a single item, and we are allowed to sell items only in bundles. If each item costs b cents and we bundle k items, then the bundle price becomes k · b. The goal is not to maximize revenue in the usual sense.

codeforcescompetitive-programming
CF 104633K - Space Walls

The surface of the space station is built from axis-aligned unit cubes that are glued together in 3D. Only the outer skin matters, so every robot moves on exposed square faces of this union.

codeforcescompetitive-programming
CF 104633J - ’S No Problem

We are given a weighted tree representing a campus. Buildings are nodes and sidewalks are edges with lengths. Every sidewalk must be cleared at least once using two snow blowers that can be pushed along the tree.

codeforcescompetitive-programming
CF 104633I - Quests

We are given a set of quests. Each quest has a reward value and a required level. Your character gains experience points as you complete quests, and the current level is determined only by total experience divided by a fixed constant.

codeforcescompetitive-programming
TAOCP 1.3.3 Exercise 12

The error occurs precisely at the point where a congruence modulo $mn-1$ is turned into an equality without first identifying the correct residue system and without using the correct domain restrictio...

taocpmathematicsalgorithmsvolume-1math-hard
CF 104633G - Opportunity Cost

We are given a collection of phones, each described by three numbers: price, performance, and user-friendliness. For any phone we decide to buy, we compare it against every other phone and measure how much worse it is along each dimension, but only in the direction where the…

codeforcescompetitive-programming
CF 104633H - QC QC

We are given a batch of $n$ machines. Each machine is either working correctly or malfunctioning, but we are guaranteed that strictly more than half of them are correct.

codeforcescompetitive-programming
CF 104633F - Ley Lines

We are given a set of points in the plane and a parameter $t$, which represents how thick a “drawn line” is allowed to be.

codeforcescompetitive-programming
CF 104633D - Gene Folding

We are given a single genetic string made only of the four DNA characters A, C, G, and T. The process allowed on this string repeatedly picks a “cut position” between two adjacent characters, but only if the string is symmetric around that cut: if you look outward from the…

codeforcescompetitive-programming
CF 104633E - Landscape Generator

We are given an initially flat landscape of n integer positions, all starting at height zero. Then a sequence of k operations modifies contiguous segments of this array. After applying all operations in order, we must output the final height at every position.

codeforcescompetitive-programming
CF 104633B - The Cost of Speed Limits

We are given a road system that forms a tree. Every road connects two intersections and already has a speed limit. We are allowed to increase any road’s speed limit, but never decrease it.

codeforcescompetitive-programming
CF 104633C - Domes

We are given a rectangular region, which we can think of as the viewing area where a tourist can stand. Inside this rectangle are several fixed points, called domes.

codeforcescompetitive-programming
CF 104633A - Cardiology

We are given a rectangular grid of cards arranged in r rows and c columns, filled initially in row-major order with numbers from 1 to r·c.

codeforcescompetitive-programming
TAOCP 1.3.3 Exercise 2

Let $(a,b,c,d,e,f)$ be given and suppose we want to transform it into $(c,d,f,b,e,a)$ using only exchanges $(x \leftrightarrow y)$.

taocpmathematicsalgorithmsvolume-1simple
CF 104634E - Replace All

We are given a starting string and a collection of operations, where each operation globally replaces every occurrence of one character with another fixed character.

codeforcescompetitive-programming
CF 104634D - Musical Cords

We are given a circular harp with $N$ attachment points placed on its boundary. Each attachment point has a fixed angular position around the circle and a personal cost $Li$, which represents extra cord needed to attach a string to that point.

codeforcescompetitive-programming
CF 104634B - Adjacent and Consecutive

We are simulating a two-player game where tiles labeled from 1 to N are gradually placed into N empty positions arranged in a line. Each move consists of choosing one unused number and placing it into an empty cell.

codeforcescompetitive-programming