Rust ยท Practice
Rust exercises
13 exercises: 5 easy, 5 medium and 3 hard. Each has a starter file, examples, hints and a solution you can reveal, and your program is checked against every test case. Running Rust in the browser is not available yet: write your program here, then run it locally against the examples.
- Boards to cover a panelEasy
Write a Rust function that returns how many boards of a given width cover a panel, rounding up. Practise function signatures, return values and rounding up.
FunctionsNot started
- Library late feeEasy
Compute a library's overdue fee with a two-day grace period and a cap, using if/else and min in Rust. An exercise in simple branching.
Control flowNot started
- Seed packet labelEasy
Read a plant name, a packet count and seeds per packet, then print a one-line label with the total number of seeds. A first Rust input-and-output exercise.
BasicsNot started
- Ticket machine changeEasy
Turn change in cents into a euros-and-cents string like 3.05 using integer division, remainder and zero padding. Practise integer types and formatting in Rust.
BasicsNot started
- Trip odometerEasy
Keep a running odometer reading across three delivery trips and print it after each one. Practise let mut and updating a variable in place in Rust.
BasicsNot started
- Bakery order tallyMedium
Process add and remove commands for a bakery counter with slice patterns in match, then print the tally in alphabetical order. Practise Rust pattern matching.
Pattern matchingNot started
- Hyphenate product codesMedium
Insert a hyphen wherever a product code switches between letters and digits, for every code on input. Practise walking chars and tracking state in a Rust loop.
StringsNot started
- Longest word in a headlineMedium
Return a borrowed &str for the longest word of each headline, with an explicit lifetime on the function. Practise borrowing instead of copying in Rust.
Ownership and borrowingNot started
- Parcel shipping costMedium
Model parcels with a struct and a zone enum, price each parcel from its zone and weight, and print a total. Practise enums, structs and impl blocks in Rust.
Structs and enumsNot started
- Sum the valid readingsMedium
Sum the lines of a noisy sensor feed that parse as integers and count the ones that do not, by matching on the Result from parse. Practise Result in Rust.
Error handlingNot started
- Busiest stock windowHard
Find the K consecutive hours with the largest total net stock change using a sliding window in O(N). A Rust exercise in prefix sums and running totals.
AlgorithmsNot started
- Jars and lidsHard
Match jars to lids within a tolerance to seal as many jars as possible, using sorting and two pointers. A greedy Rust exercise with a proof sketch.
AlgorithmsNot started
- Shortest gap between revisitsHard
Find the fewest steps between two visits to the same stop on a long delivery route with a HashMap of last-seen positions. A Rust hashing exercise.
CollectionsNot started