Sign up
Log in
Home
Language tracks
Rust track
Exercises
Join the Rust Track
Exercises on the Rust track
88 exercises to help you master Rust
easy
Hello World
The classical introductory exercise. Just say "Hello, World!"
println
easy
Gigasecond
Calculate the moment when someone has lived for 10^9 seconds.
crates
easy
Leap
Given a year, report if it is a leap year.
booleans
conditionals
easy
Raindrops
Convert a number to a string, the contents of which depend on the number's factors.
case or format
mutable string
easy
Reverse String
Reverse a string
iterator
str
string
easy
Nth Prime
Given a number n, determine what the nth prime is.
loops
primes
math
easy
Bob
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
chars
string functions
easy
Beer Song
Produce the lyrics to that beloved classic, that field-trip favorite: 99 Bottles of Beer on the Wall.
case
loop
string concatenation
vector optional
easy
Proverb
For want of a horseshoe nail, a kingdom was lost, or so the saying goes. Output the full text of this proverbial rhyme.
format
easy
Difference Of Squares
Find the difference between the square of the sum and the sum of the squares of the first N natural numbers.
fold
map
math
easy
Sum Of Multiples
Given a number, find the sum of all the multiples of particular numbers up to but not including that number.
algorithm
borrowing
math
easy
Grains
Calculate the number of grains of wheat on a chessboard given that the number on each square doubles.
panic
easy
Pythagorean Triplet
There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product a * b * c.
option
math
easy
Prime Factors
Compute the prime factors of a given natural number.
math
easy
Series
Given a string of digits, output all the contiguous substrings of length `n` in that string.
strings
vectors
easy
Armstrong Numbers
Determine if a number is an Armstrong number
math
easy
Collatz Conjecture
Calculate the number of steps to reach 1 using the Collatz conjecture
option
math
easy
Diffie Hellman
Diffie-Hellman key exchange.
math
medium
Saddle Points
Detect saddle points in a matrix.
iterators
vectors
medium
Isogram
Determine if a word or phrase is an isogram.
chars
iterators
strings
medium
Say
Given a number from 0 to 999,999,999,999, spell out that number in English.
modulus
string concatenation
medium
Run Length Encoding
Implement run-length encoding and decoding.
conversion between string and int
loop
string concatenation
use of primitive char
medium
Isbn Verifier
Check if a given string is a valid ISBN-10 number.
conversion between string and int
loop
medium
Perfect Numbers
Determine if a number is perfect, abundant, or deficient based on Nicomachus' (60 - 120 CE) classification scheme for natural numbers.
math
medium
Clock
Implement a clock that handles times without dates.
derive
struct
traits
medium
Dot Dsl
Write a Domain Specific Language similar to the Graphviz dot language
builder pattern
derive
modules
struct
medium
Hamming
Calculate the Hamming difference between two DNA strands.
result
medium
Simple Linked List
Write a simple linked list implementation that uses Elements and a List
lists
struct
type conversion
medium
Pascals Triangle
Compute Pascal's triangle up to a given number of rows.
index optional
vec
math
medium
Scrabble Score
Given a word, compute the scrabble score for that word.
chaining higher order functions
hashmap optional
medium
Pangram
Determine if a sentence is a pangram.
ascii optional
filter
medium
Nucleotide Count
Given a DNA string, compute how many times each nucleotide occurs in the string.
entry api
filter
match
mutablity
result
medium
Luhn
Given a number determine whether or not it is valid per the Luhn formula.
higher order functions
iterators
str to digits
medium
Largest Series Product
Given a string of digits, calculate the largest product for a contiguous substring of digits of length n.
char
higher order functions
result
windows
math
medium
Word Count
Given a phrase, count the occurrences of each word in that phrase.
chars
entry api
hashmap
str vs string
medium
Atbash Cipher
Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.
ascii
chars
iterators
primitive types
str vs string
medium
Crypto Square
Implement the classic method for composing secret messages called a square code.
arrays
ascii
chars
iterators
primitive types
str vs string
transforming
medium
Rotational Cipher
Create an implementation of the rotational cipher, also sometimes called the Caesar cipher.
ascii
chars
iterators
primitive types
str vs string
medium
Simple Cipher
Implement a simple shift cipher like Caesar and a more secure substitution cipher
ascii
chars
str vs string
medium
Etl
We are going to do the `Transform` step of an Extract-Transform-Load.
btree
medium
Accumulate
Implement the `accumulate` operation, which, given a collection and an operation to perform on each element of the collection, returns a new collection containing the result of applying that operation to each element of the input collection.
function pointer
medium
Acronym
Convert a long phrase to its acronym
filter
flat map
loops
map
vec
medium
Sieve
Use the Sieve of Eratosthenes to find all the primes from 2 up to a given number.
map
vector
while let optional
math
medium
Rna Transcription
Given a DNA strand, return its RNA Complement Transcription.
match
result
str vs string
struct
medium
Triangle
Determine if a triangle is equilateral, isosceles, or scalene.
struct
medium
Roman Numerals
Write a function to convert from normal numbers to Roman Numerals.
loops
mutable
results
struct
traits
medium
All Your Base
Convert a number, represented as a sequence of digits in one base, to any other base.
enumerate
fold
map
result
math
medium
Grade School
Given students' names along with the grade that they are in, create a roster for the school
entry api
option
struct
vec
medium
Binary Search
Implement a binary search algorithm.
option
slices
trait optional
medium
Robot Simulator
Write a robot simulator.
enum
immutability
medium
Bracket Push
Make sure the brackets and braces all match.
from trait
stack or recursion
medium
Luhn From
Luhn: Using the From Trait
from trait
higher order functions
iterators
str to digits
medium
Queen Attack
Given the position of two queens on a chess board, indicate whether or not they are positioned so that they can attack each other.
result
struct
trait optional
medium
Bowling
Score a bowling game
goofy bowling logic
result
struct
medium
Sublist
Write a function to determine if a list is a sublist of another list.
enum
generic over type
medium
Space Age
Given an age in seconds, calculate how old someone is in terms of a given planet's solar years.
custom trait
default trait implementation
from trait
medium
Luhn Trait
Luhn: Using a Custom Trait
custom trait
higher order functions
iterators
str to digits
medium
Macros
Implement a macro using macros-by-example
hashmap
macros
macros by example
medium
Allergies
Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.
bitwise probably
enum
filter
struct
vectors
medium
Variable Length Quantity
Implement variable length quantity encoding and decoding.
bitwise
encodings
result
slices
medium
Phone Number
Clean up user-entered phone numbers so that they can be sent SMS messages.
format
iters
match
option
unwrap or
medium
Wordy
Parse and evaluate simple math word problems returning the answer as an integer.
operators optional
result
string parsing
medium
Tournament
Tally the results of a small football competition.
enum
hashmap
sorting
structs
medium
Custom Set
Create a custom set type.
equality
generic over type
struct
vector
medium
Alphametics
Write a function to solve alphametics puzzles.
combinations
external crates optional
string parsing
medium
Two Bucket
Given two buckets of different size, demonstrate how to measure an exact number of liters.
algorithm
loops
medium
Pig Latin
Implement a program that translates from English to Pig Latin
ascii
regular expressions
strings
medium
Diamond
Given a letter, print a diamond starting with 'A' with the supplied letter at the widest point.
parsing
str
string
medium
Spiral Matrix
Given the size, return a square matrix of numbers in spiral order.
matrix
nested structures
medium
Palindrome Products
Detect palindrome products in a given range.
calculation
string comparison
structs
math
medium
Poker
Pick the best hand(s) from a list of poker hands.
enum
lifetimes
string parsing
struct
traits
medium
Grep
Search a file for lines matching a regular expression pattern. Return the line number and contents of each matching line.
conditionals
failure crate
file io
result
string functions
string parsing
utf
medium
Decimal
Implement a Decimal type
bigint
external crates optional
string parsing
struct
traits
medium
Anagram
Given a word and a list of possible anagrams, select the correct sublist.
iter
lifetimes
loops
str vs string
vector
medium
Protein Translation
Translate RNA sequences into proteins.
hash map
lifetimes
result
struct
medium
Robot Name
Manage robot factory settings.
lifetimes
randomness
self mut
slices
struct
medium
Book Store
To try and encourage more sales of different books from a popular 5 book series, a bookshop has decided to offer discounts of multiple-book purchases.
algorithms
groups
set theory
hard
Ocr Numbers
Given a 3 x 4 grid of pipes, underscores, and spaces, determine which number is represented, or whether it is garbled.
chunks
lines
slices
hard
Minesweeper
Add the numbers to a minesweeper board
board state
hard
Dominoes
Make a chain of dominoes.
graph theory
searching
hard
Parallel Letter Frequency
Count the frequency of letters in texts using parallel computation.
multi threading
hard
Rectangles
Count the rectangles in an ASCII diagram.
algorithm
enum
structs
traits
hard
Forth
Implement an evaluator for a very simple subset of Forth
parser reimplementation
hard
Circular Buffer
A data structure that uses a single, fixed-size buffer as if it were connected end-to-end.
buffer reimplementation
generics
hard
React
Implement a basic reactive system.
closures
generics
lifetimes
easy
Two Fer
Create a sentence of the form "One for X, one for me."
match
strings
Nucleotide Codons
Write a function that returns the name of an amino acid a particular codon, possibly using shorthand, encodes for.
misc
Hexadecimal
Convert a hexadecimal number, represented as a string (e.g. "10af8c"), to its decimal equivalent using first principles (i.e. no, you may not use built-in or external libraries to accomplish the conversion).
misc