Sign up
Log in
Home
Language tracks
Swift track
Exercises
Exercises on the Swift track
Join the Swift Track
83 exercises to help you master Swift
easy
Hello World
The classical introductory exercise. Just say "Hello, World!"
optional values
text formatting
easy
Two Fer
Create a sentence of the form "One for X, one for me."
optional values
text formatting
easy
Leap
Given a year, report if it is a leap year.
integers
easy
Gigasecond
Given a moment, determine the moment that would be after a gigasecond has passed.
dates
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.
integers
math
easy
RNA Transcription
Given a DNA strand, return its RNA Complement Transcription.
strings
transforming
easy
Sum Of Multiples
Given a number, find the sum of all the multiples of particular numbers up to but not including that number.
lists
transforming
math
easy
Space Age
Given an age in seconds, calculate how old someone is in terms of a given planet's solar years.
discriminated unions
floating point numbers
easy
Bob
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
control flow if else statements
strings
easy
Grains
Calculate the number of grains of wheat on a chessboard given that the number on each square doubles.
integers
easy
Hamming
Calculate the Hamming difference between two DNA strands.
filtering
strings
easy
Nucleotide Count
Given a DNA string, compute how many times each nucleotide occurs in the string.
maps
strings
easy
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.
recursion
transforming
easy
Raindrops
Convert a number to a string, the contents of which depend on the number's factors.
filtering
text formatting
easy
Grade School
Given students' names along with the grade that they are in, create a roster for the school
maps
sorting
easy
ETL
We are going to do the `Transform` step of an Extract-Transform-Load.
maps
transforming
easy
Isogram
Determine if a word or phrase is an isogram.
filtering
strings
easy
List Ops
Implement basic list operations
conditionals
filtering
functional programming
lists
loops
searching
variables
easy
Clock
Implement a clock that handles times without dates.
structural equality
time
easy
Triangle
Determine if a triangle is equilateral, isosceles, or scalene.
discriminated unions
integers
easy
Robot Name
Manage robot factory settings.
randomness
strings
easy
Scrabble Score
Given a word, compute the scrabble score for that word.
transforming
easy
Kindergarten Garden
Given a diagram, determine which plants each child in the kindergarten class is responsible for.
enumerations
parsing
easy
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.
tuples
easy
Strain
Implement the `keep` and `discard` operation on collections. Given a collection and a predicate on the collection's elements, `keep` returns a new collection containing those elements where the predicate is true, while `discard` returns a new collection containing those elements where the predicate is false.
filtering
sequences
easy
Sieve
Use the Sieve of Eratosthenes to find all the primes from 2 up to a given number.
filtering
math
easy
Phone Number
Clean up user-entered phone numbers so that they can be sent SMS messages.
parsing
transforming
easy
Perfect Numbers
Determine if a number is perfect, abundant, or deficient based on Nicomachus' (60 - 120 CE) classification scheme for natural numbers.
discriminated unions
integers
math
easy
Robot Simulator
Write a robot simulator.
records
tuples
easy
Binary Search
Implement a binary search algorithm.
lists
searching
easy
Flatten Array
Take a nested list and return a single list with all values except nil/null
lists
looping
searching
easy
Sublist
Write a function to determine if a list is a sublist of another list.
lists
looping
easy
Secret Handshake
Given a decimal number, convert it to the appropriate sequence of events for a secret handshake.
bitwise operations
lists
easy
Collatz Conjecture
Calculate the number of steps to reach 1 using the Collatz conjecture
integers
math
easy
Diamond
Given a letter, print a diamond starting with 'A' with the supplied letter at the widest point.
strings
easy
ISBN Verifier
Check if a given string is a valid ISBN-10 number.
conditionals
loops
pattern matching
strings
easy
Protein Translation
Translate RNA sequences into proteins.
algorithms
control flow conditionals
control flow loops
strings
easy
Circular Buffer
A data structure that uses a single, fixed-size buffer as if it were connected end-to-end.
arrays
control flow conditionals
control flow loops
data structures
exception handling
lists
easy
Scale Generator
Generate musical scales, given a starting note and a set of intervals.
loops
pattern matching
strings
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.
algorithms
strings
medium
Word Count
Given a phrase, count the occurrences of each word in that phrase.
maps
strings
transforming
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 operations
enumerations
filtering
medium
Beer Song
Produce the lyrics to that beloved classic, that field-trip favorite: 99 Bottles of Beer on the Wall.
conditionals
looping
strings
medium
Twelve Days
Output the lyrics to 'The Twelve Days of Christmas'
algorithms
text formatting
medium
Meetup
Calculate the date of meetups.
dates
medium
Anagram
Given a word and a list of possible anagrams, select the correct sublist.
filtering
strings
medium
Series
Given a string of digits, output all the contiguous substrings of length `n` in that string.
lists
strings
transforming
medium
Simple Linked List
Write a simple linked list implementation that uses Elements and a List
lists
medium
Acronym
Convert a long phrase to its acronym
strings
transforming
medium
Matrix
Given a string representing a matrix of numbers, return the rows and columns of that matrix.
matrices
parsing
medium
All Your Base
Convert a number, represented as a sequence of digits in one base, to any other base.
integers
transforming
math
medium
Largest Series Product
Given a string of digits, calculate the largest product for a contiguous substring of digits of length n.
integers
strings
transforming
math
medium
House
Output the nursery rhyme 'This is the House that Jack Built'.
algorithms
text formatting
medium
Pythagorean Triplet
There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product a * b * c.
integers
records
math
medium
Saddle Points
Detect saddle points in a matrix.
lists
matrices
medium
Pascal's Triangle
Compute Pascal's triangle up to a given number of rows.
lists
recursion
math
medium
Prime Factors
Compute the prime factors of a given natural number.
integers
math
medium
Pangram
Determine if a sentence is a pangram.
searching
strings
medium
Rotational Cipher
Create an implementation of the rotational cipher, also sometimes called the Caesar cipher.
strings
transforming
medium
Say
Given a number from 0 to 999,999,999,999, spell out that number in English.
loops
parsing
text formatting
transforming
medium
Roman Numerals
Write a function to convert from normal numbers to Roman Numerals.
recursion
transforming
medium
Binary Search Tree
Insert and search for numbers in a binary tree.
searching
trees
medium
OCR Numbers
Given a 3 x 4 grid of pipes, underscores, and spaces, determine which number is represented, or whether it is garbled.
parsing
pattern recognition
medium
Linked List
Implement a doubly linked list
lists
medium
Simple Cipher
Implement a simple shift cipher like Caesar and a more secure substitution cipher
algorithms
strings
transforming
medium
Atbash Cipher
Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.
algorithms
strings
transforming
medium
Food Chain
Generate the lyrics of the song 'I Know an Old Lady Who Swallowed a Fly'
algorithms
text formatting
medium
Custom Set
Create a custom set type.
sets
medium
Crypto Square
Implement the classic method for composing secret messages called a square code.
algorithms
strings
transforming
medium
Luhn
Given a number determine whether or not it is valid per the Luhn formula.
algorithms
strings
transforming
medium
Run Length Encoding
Implement run-length encoding and decoding.
algorithms
transforming
medium
Tournament
Tally the results of a small football competition.
parsing
text formatting
medium
Bowling
Score a bowling game
algorithms
medium
Nth Prime
Given a number n, determine what the nth prime is.
math
medium
Palindrome Products
Detect palindrome products in a given range.
algorithms
strings
tuples
math
medium
Pig Latin
Implement a program that translates from English to Pig Latin
strings
transforming
medium
Transpose
Take input text and output it transposed.
strings
transforming
medium
Complex Numbers
Implement complex numbers.
tuples
math
medium
Bracket Push
parsing
strings
medium
Minesweeper
Add the numbers to a minesweeper board
parsing
transforming
medium
Dominoes
Make a chain of dominoes.
lists
tuples
medium
Wordy
Parse and evaluate simple math word problems returning the answer as an integer.
parsing
strings
transforming
hard
Poker
Pick the best hand(s) from a list of poker hands.
discriminated unions
games
parsing
sorting