Solved


Determine the minimum number of swaps to sort a vector
Cody Problem 1401 asks us to sort a vector with the bubble sort algorithm and count the number of swaps needed. For example, to ...

2 months ago

Solved


Compute flow in a partially full pipe
Problem statement When does the maximum flow occur in a pipe? Intuition might suggest that it occurs when the pipe is flowing f...

2 months ago

Solved


Route a hydrograph through a river section with the Muskingum method
Problem statement Write a function that routes a hydrograph through a river section using the Muskingum method. The input to t...

2 months ago

Solved


Solve an ODE: draining tank
Write a function to compute the time to drain a cylindrical tank of diameter from an initial level to a level . The outflow oc...

2 months ago

Solved


Compute infiltration and runoff under constant precipitation with the Green-Ampt method
Problem statement Write a function that computes infiltration, depression storage, and runoff using the Green-Ampt method. It s...

2 months ago

Solved


Inscribe a circle in a triangle with a side of length equal to the circle’s circumference
A circle of radius is inscribed in a triangle with a side that has a length equal to the circle’s circumference. The center of ...

2 months ago

Solved


Determine whether a hydrograph is a unit hydrograph
A hydrograph describes the runoff response of a catchment or watershed to rainfall. It shows the runoff rate (or flow or discha...

2 months ago

Solved


Compute the average precipitation for a watershed using the Thiessen polygon method
Several methods are available for estimating the average precipitation for a watershed from a few observations at rain gauges. T...

2 months ago

Solved


Compute frequency factors for the normal distribution
In frequency analysis in hydrology, the streamflow corresponding to a specified exceedance probability (or return period ) can...

2 months ago

Solved


Determine flows of given probability using empirical frequency analysis
Write a function that takes as input observations of peak streamflow and exceedance probabilities expressed as percentages an...

2 months ago

Solved


Find patterns in subprime Fibonacci sequences
Lots of Cody problems involve Fibonacci and Collatz sequences. Fibonacci sequences start with two numbers, and later terms are c...

2 months ago

Solved


List unitary divisors of a number
A unitary divisor of a number divides and satisfies gcd(,) = 1. For example, 9 is a unitary divisor of 18 because gcd(9,2) = ...

2 months ago

Solved


List numbers that are not in the Fibonacci sequence
In the list of 4797 Cody problems, 53 deal with or refer to the Fibonacci sequence.* What about the other numbers? Write a funct...

2 months ago

Solved


Determine whether one vector is a subset of another
While bumbling through a pair of problems in the Number Theory group, I wrote code to determine whether a vector is a subset of ...

2 months ago

Solved


Find the length of stream affected by a spill
When a contaminant is spilled into a stream, one might want to know how much of the stream is affected—e.g., the length over whi...

2 months ago

Solved


Count the ways to make Scorigami
Regarding the sport known as American football, some people are such rabid fans that they can tell you the statistics of every p...

2 months ago

Solved


Solve an ODE: concentrations predicted by the cells-in-series model
One approach for predicting mixing and transport of contaminants in a river is the cells-in-series model. The model divides a ri...

2 months ago

Solved


Spell musical triads
Chords form the basis of harmony in music. The most basic chords are triads, or groups of three notes. They are specified by thr...

2 months ago

Solved


Solve an ODE: precocious pair’s porcine pursuit
In our previous encounters with Matilda and Labrun, the scintillating siblings collected candy wrappers, amused others with card...

2 months ago

Solved


Solve an ODE: first-order linear equation
In the fall semester of [redacted], my professor for a course on ordinary differential equations said, “There are two groups of ...

2 months ago

Solved


Solve an ODE: nonlinear third-order equation
Write a function to solve the ordinary differential equation on the domain with , , and either or . The input variable ord ...

2 months ago

Solved


Check whether a Wordle guess is consistent with previous feedback
The game Wordle resembles the classic game Mastermind. Players try to guess a five-letter word, and after each guess they are to...

2 months ago

Solved


Determine whether a player solved a Cody problem
Write a function to determine whether a player has solved the specified Cody problems. The problem numbers are specified as a ve...

2 months ago

Solved


Collect a set of candy wrappers
This past Halloween, the siblings Matilda and Labrun amused (and sometimes confused) their many neighbors with their costumes in...

2 months ago

Solved


Sum of Elements Above the Main Diagonal of a Square Matrix
Given a square matrix as input, write a function that returns the sum of all elements above the main diagonal. If the input mat...

2 months ago

Solved


Multiply binary numbers
Write a function to multiply two binary numbers input as strings. For example, input values of ‘1011’ and ‘101’ should give ’110...

2 months ago

Solved


Pick the die most likely to win
After discussing Rock, Paper, Scissors, Lizard, Spock in The Simpsons and their Mathematical Secrets, Simon Singh writes that in...

2 months ago

Solved


Compute a sum involving the totient over divisors of a number
Write a function to compute the following sum: where is the totient function. The sum is computed over the divisors of (inc...

2 months ago

Solved


Solve an ODE: equation C
Write a function to solve the following ordinary differential equation: with and . The parameter is a constant. The functi...

2 months ago

Solved


Eliminate redundant numbers in text
Occasionally someone might write text such as Briefly explain one (1) common problem that can result from the constant use of ...

2 months ago

Load more