Five Quick Quantitative Puzzles with Exact String Answers
Math & Bit ManipulationAuto-graded · 2 test casesLast updated
Solve five short arithmetic and algebra puzzles (units, compounding percentages, linear system, rate, series scaling) and return them in an exact string format.
Five Quick Quantitative Puzzles
Write a function that takes no arguments and returns a list of exactly five strings. Entry i (0-indexed) is the answer to puzzle i + 1 below. The puzzles are independent of each other.
Puzzles
- Cutting a rope. A rope is 4.5 yards long. It is cut into pieces that are each 3 inches long, with nothing left over. How many pieces are there?
- Share trade. Sam buys 100 shares at $100 each. The price goes up by 10%, and Sam sells 50 shares. The new price then falls by 10% of the raised price, and Sam sells his other 50 shares at that lower price. How much money does Sam receive for the second batch of 50 shares?
- Cash drawer. A drawer holds 160 bills. Each bill is either a $10 or a $50, and together they are worth $2,760. How many bills of each kind are there?
- Grading time. A teacher has 4 hours in total to grade 45 papers. The first 5 papers take her 30 minutes. If she splits the leftover time evenly, how many minutes can she spend on each of the remaining papers?
- Scaling a sum of squares. Let
m = 1^2 + 2^2 + ... + 512^2. ExpressS = 2^2 + 4^2 + 6^2 + ... + 1024^2in terms ofm.
Required output format
The returned list must contain these five strings, with exactly this formatting:
| Index | Format |
|---|---|
| 0 | The integer count as plain digits, with no units |
| 1 | A dollar sign, then the amount with a comma as the thousands separator, and no decimals |
| 2 | "<t> ten-dollar bills and <f> fifty-dollar bills", where <t> and <f> are the counts |
| 3 | The number of minutes as a decimal (no trailing zeros beyond what is needed), followed by a space and the word minutes |
| 4 | The coefficient immediately followed by the letter m (for example, 7m) |
Comparison is by exact string match, so spacing, punctuation, and lowercase letters matter.
Constraints
- The function takes no parameters.
- The return value is a
List[str]of length 5. - All numbers are fixed by the puzzles above; there is no input to read.
- Percentage changes compound: the second change applies to the already-changed price.
Examples
Example 1
Input: answer_five_puzzles()
Output: ['54', '$4,950', '131 ten-dollar bills and 29 fifty-dollar bills', '5.25 minutes', '4m']
Hints
Hint 1
Convert every length to the same unit first: one yard is 36 inches, so you can count pieces by dividing total inches by 3.
Hint 2
For the share puzzle, the second 10% change is taken from the raised price, not the original one, so the multipliers are 1.10 and then 0.90. For the drawer, try assuming all 160 bills are $10s and see how much value is missing; each swap to a $50 adds $40.
Hint 3
For the sum of even squares, write each term as (2k)^2 with k running from 1 to 512, then factor out the constant. For the grading puzzle, subtract both the time and the papers already used before dividing.
Worked solution
Easy Try it yourself first — then compare your approach, complexity and edge cases.
Approach
Each puzzle reduces to a short calculation, so the function computes each one and formats the result.
- Rope. Convert to inches first: 4.5 yards x 36 = 162 inches. Dividing by 3 gives 54 pieces. As a check, one yard holds 12 three-inch pieces, and 4.5 x 12 = 54.
- Share trade. Percentage changes multiply. The price goes 100 to 110 (+10%), then to 99 (-10% of 110). The last 50 shares bring in 50 x 99 = $4,950. The proceeds from the first batch are irrelevant to the question. Integer arithmetic avoids floating-point error.
- Cash drawer. Let
tbe the number of $10 bills andfthe number of $50 bills. Thent + f = 160and10t + 50f = 2760. If all 160 bills were $10s, the total would be $1,600, leaving $1,160 unexplained. Each $50 in place of a $10 adds $40, sof = 1160 / 40 = 29andt = 131. - Grading time. Total time is 240 minutes. After 30 minutes spent, 210 minutes remain for 45 - 5 = 40 papers. That is 210 / 40 = 5.25 minutes each. Formatting with
:gprints5.25and would print6rather than6.0for whole numbers. - Sum of even squares. The terms are
(2k)^2 = 4k^2fork = 1..512, because 1024 = 2 x 512. SoS = 4 * (1^2 + ... + 512^2) = 4m. The index range matches the one definingm, so no correction term is needed.
Why it is correct
Every step is an exact identity or an exact integer computation: unit conversion, multiplicative compounding applied to the changed price, solving a two-variable linear system, subtracting used time and used papers before dividing, and factoring a constant out of a sum. The strings are then formatted per the specification.
Complexity
Time O(1) and space O(1), since there is no input and a fixed amount of work.
Reference solution
from typing import List
def answer_five_puzzles() -> List[str]:
# 1) Rope: 4.5 yards = 162 inches, cut into 3-inch pieces
inches = int(4.5 * 36)
pieces = inches // 3
# 2) Shares: +10% then -10% of the new price (integer cents-free math)
price = 100
price = price * 110 // 100 # 110
price = price * 90 // 100 # 99
proceeds = 50 * price # 4950
# 3) Drawer: t + f = 160, 10t + 50f = 2760
total_bills, total_value = 160, 2760
fifties = (total_value - 10 * total_bills) // 40
tens = total_bills - fifties
# 4) Grading: remaining minutes over remaining papers
remaining_minutes = 4 * 60 - 30
remaining_papers = 45 - 5
per_paper = remaining_minutes / remaining_papers # 5.25
# 5) Sum of (2k)^2 for k=1..512 equals 4 * m
coefficient = 2 ** 2
return [
str(pieces),
f"${proceeds:,}",
f"{tens} ten-dollar bills and {fifties} fifty-dollar bills",
f"{per_paper:g} minutes",
f"{coefficient}m",
]