instance_id
int64
0
132
instance_name
stringlengths
3
24
instruction
stringlengths
194
12.1k
signature
stringlengths
24
10.6k
test
stringlengths
515
24.4k
100
run_length_encoding
# Instructions Implement run-length encoding and decoding. Run-length encoding (RLE) is a simple form of data compression, where runs (consecutive data elements) are replaced by just one data value and count. For example we can represent the original 53 characters with only 13. ```text "WWWWWWWWWWWWBWWWWWWWWWWWWBBB...
def decode(string): pass def encode(string): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/run-length-encoding/canonical-data.json # File last updated on 2023-07-19 import unittest from run_length_encoding import ( encode, decode, ) class RunLengthEncodingTest(unittest.Te...
101
saddle_points
# Introduction You plan to build a tree house in the woods near your house so that you can watch the sun rise and set. You've obtained data from a local survey company that show the height of every tree in each rectangular section of the map. You need to analyze each grid on the map to find good trees for your tree h...
def saddle_points(matrix): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/saddle-points/canonical-data.json # File last updated on 2023-07-19 import unittest from saddle_points import ( saddle_points, ) def sorted_points(point_list): return sorted(point_l...
102
satellite
# Instructions Imagine you need to transmit a binary tree to a satellite approaching Alpha Centauri and you have limited bandwidth. Since the tree has no repeating items it can be uniquely represented by its [pre-order and in-order traversals][wiki]. Write the software for the satellite to rebuild the tree from the t...
def tree_from_traversals(preorder, inorder): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/satellite/canonical-data.json # File last updated on 2023-07-19 import unittest from satellite import ( tree_from_traversals, ) class SatelliteTest(unittest.TestCase): def test_empt...
103
say
# Instructions Given a number from 0 to 999,999,999,999, spell out that number in English. ## Step 1 Handle the basic case of 0 through 99. If the input to the program is `22`, then the output should be `'twenty-two'`. Your program should complain loudly if given a number outside the blessed range. Some good test...
def say(number): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/say/canonical-data.json # File last updated on 2023-07-19 import unittest from say import ( say, ) class SayTest(unittest.TestCase): def test_zero(self): self.assertEqual(sa...
104
scale_generator
# Instructions ## Chromatic Scales Scales in Western music are based on the chromatic (12-note) scale. This scale can be expressed as the following group of pitches: > A, A♯, B, C, C♯, D, D♯, E, F, F♯, G, G♯ A given sharp note (indicated by a ♯) can also be expressed as the flat of the note above it (indicated by a...
class Scale: def __init__(self, tonic): pass def chromatic(self): pass def interval(self, intervals): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/scale-generator/canonical-data.json # File last updated on 2023-07-19 import unittest from scale_generator import ( Scale, ) class ScaleGeneratorTest(unittest.TestCase): # Test chr...
105
scrabble_score
# Introduction [Scrabble][wikipedia] is a word game where players place letter tiles on a board to form words. Each letter has a value. A word's score is the sum of its letters' values. [wikipedia]: https://en.wikipedia.org/wiki/Scrabble # Instructions Your task is to compute a word's Scrabble score by summing the v...
def score(word): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/scrabble-score/canonical-data.json # File last updated on 2023-07-19 import unittest from scrabble_score import ( score, ) class ScrabbleScoreTest(unittest.TestCase): def test_lower...
106
secret_handshake
# Introduction You are starting a secret coding club with some friends and friends-of-friends. Not everyone knows each other, so you and your friends have decided to create a secret handshake that you can use to recognize that someone is a member. You don't want anyone who isn't in the know to be able to crack the cod...
def commands(binary_str): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/secret-handshake/canonical-data.json # File last updated on 2023-07-19 import unittest from secret_handshake import ( commands, ) class SecretHandshakeTest(unittest.TestCase): def t...
107
series
# Instructions Given a string of digits, output all the contiguous substrings of length `n` in that string in the order that they appear. For example, the string "49142" has the following 3-digit series: - "491" - "914" - "142" And the following 4-digit series: - "4914" - "9142" And if you ask for a 6-digit serie...
def slices(series, length): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/series/canonical-data.json # File last updated on 2023-07-19 import unittest from series import ( slices, ) class SeriesTest(unittest.TestCase): def test_slices_of_one_from_one(self...
108
sgf_parsing
# Instructions Parsing a Smart Game Format string. [SGF][sgf] is a standard format for storing board game files, in particular go. SGF is a fairly simple format. An SGF file usually contains a single tree of nodes where each node is a property list. The property list contains key value pairs, each key can only occur...
class SgfTree: def __init__(self, properties=None, children=None): self.properties = properties or {} self.children = children or [] def __eq__(self, other): if not isinstance(other, SgfTree): return False for key, value in self.properties.items(): if key...
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/sgf-parsing/canonical-data.json # File last updated on 2023-07-19 import unittest from sgf_parsing import ( parse, SgfTree, ) class SgfParsingTest(unittest.TestCase): def test_e...
109
sieve
# Introduction You bought a big box of random computer parts at a garage sale. You've started putting the parts together to build custom computers. You want to test the performance of different combinations of parts, and decide to create your own benchmarking program to see how your computers compare. You choose the ...
def primes(limit): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/sieve/canonical-data.json # File last updated on 2023-07-19 import unittest from sieve import ( primes, ) class SieveTest(unittest.TestCase): def test_no_primes_under_two(self): ...
110
simple_cipher
# Instructions Implement a simple shift cipher like Caesar and a more secure substitution cipher. ## Step 1 "If he had anything confidential to say, he wrote it in cipher, that is, by so changing the order of the letters of the alphabet, that not a word could be made out. If anyone wishes to decipher these, and get ...
class Cipher: def __init__(self, key=None): pass def encode(self, text): pass def decode(self, text): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/simple-cipher/canonical-data.json # File last updated on 2023-07-20 import re import unittest from simple_cipher import ( Cipher, ) class RandomKeyCipherTest(unittest.TestCase): def...
111
simple_linked_list
# Introduction You work for a music streaming company. You've been tasked with creating a playlist feature for your music player application. # Instructions Write a prototype of the music player application. For the prototype, each song will simply be represented by a number. Given a range of numbers (the song IDs)...
class Node: def __init__(self, value): pass def value(self): pass def next(self): pass class LinkedList: def __init__(self, values=[]): pass def __len__(self): pass def head(self): pass def push(self, value): pass def pop(se...
import unittest from simple_linked_list import LinkedList, EmptyListException # No canonical data available for this exercise class SimpleLinkedListTest(unittest.TestCase): def test_empty_list_has_len_zero(self): sut = LinkedList() self.assertEqual(len(sut), 0) def test_singleton_list_has_l...
112
space_age
# Introduction The year is 2525 and you've just embarked on a journey to visit all planets in the Solar System (Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus and Neptune). The first stop is Mercury, where customs require you to fill out a form (bureaucracy is apparently _not_ Earth-specific). As you hand over t...
class SpaceAge: def __init__(self, seconds): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/space-age/canonical-data.json # File last updated on 2023-07-19 import unittest from space_age import ( SpaceAge, ) class SpaceAgeTest(unittest.TestCase): def test_age_on_earth(self...
113
spiral_matrix
# Introduction In a small village near an ancient forest, there was a legend of a hidden treasure buried deep within the woods. Despite numerous attempts, no one had ever succeeded in finding it. This was about to change, however, thanks to a young explorer named Elara. She had discovered an old document containing in...
def spiral_matrix(size): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/spiral-matrix/canonical-data.json # File last updated on 2023-07-19 import unittest from spiral_matrix import ( spiral_matrix, ) class SpiralMatrixTest(unittest.TestCase): def test_...
114
square_root
# Instructions Given a natural radicand, return its square root. Note that the term "radicand" refers to the number for which the root is to be determined. That is, it is the number under the root symbol. Check out the Wikipedia pages on [square root][square-root] and [methods of computing square roots][computing-sq...
def square_root(number): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/square-root/canonical-data.json # File last updated on 2023-07-19 import unittest from square_root import ( square_root, ) class SquareRootTest(unittest.TestCase): def test_root_of_...
115
strain
# Instructions 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 f...
def keep(sequence, predicate): pass def discard(sequence, predicate): pass
import unittest from strain import keep, discard class StrainTest(unittest.TestCase): def test_empty_sequence(self): self.assertEqual(keep([], lambda x: x % 2 == 0), []) def test_empty_keep(self): inp = [2, 4, 6, 8, 10] out = [] self.assertEqual(keep(inp, lambda x: x % 2 == 1...
116
sublist
# Instructions Given any two lists `A` and `B`, determine if: - List `A` is equal to list `B`; or - List `A` contains list `B` (`A` is a superlist of `B`); or - List `A` is contained by list `B` (`A` is a sublist of `B`); or - None of the above is true, thus lists `A` and `B` are unequal Specifically, list `A` is eq...
""" This exercise stub and the test suite contain several enumerated constants. Enumerated constants can be done with a NAME assigned to an arbitrary, but unique value. An integer is traditionally used because it’s memory efficient. It is a common practice to export both constants and functions that work with those co...
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/sublist/canonical-data.json # File last updated on 2023-07-19 import unittest from sublist import ( sublist, SUBLIST, SUPERLIST, EQUAL, UNEQUAL, ) class SublistTest(unit...
117
sum_of_multiples
# Introduction You work for a company that makes an online, fantasy-survival game. When a player finishes a level, they are awarded energy points. The amount of energy awarded depends on which magical items the player found while exploring that level. # Instructions Your task is to write the code that calculates the...
def sum_of_multiples(limit, multiples): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/sum-of-multiples/canonical-data.json # File last updated on 2023-07-19 import unittest from sum_of_multiples import ( sum_of_multiples, ) class SumOfMultiplesTest(unittest.TestCase): ...
118
tournament
# Instructions Tally the results of a small football competition. Based on an input file containing which team played against which and what the outcome was, create a file with a table like this: ```text Team | MP | W | D | L | P Devastating Donkeys | 3 | 2 | 1 | 0 | 7 A...
def tally(rows): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/tournament/canonical-data.json # File last updated on 2023-07-19 import unittest from tournament import ( tally, ) class TournamentTest(unittest.TestCase): def test_just_the_header_...
119
transpose
# Instructions Given an input text output it transposed. Roughly explained, the transpose of a matrix: ```text ABC DEF ``` is given by: ```text AD BE CF ``` Rows become columns and columns become rows. See [transpose][]. If the input has rows of different lengths, this is to be solved as follows: - Pad to the l...
def transpose(lines): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/transpose/canonical-data.json # File last updated on 2023-07-19 import unittest from transpose import ( transpose, ) class TransposeTest(unittest.TestCase): def test_empty_string(se...
120
tree_building
# Instructions Refactor a tree building algorithm. Some web-forums have a tree layout, so posts are presented as a tree. However the posts are typically stored in a database as an unsorted set of records. Thus when presenting the posts to the user the tree structure has to be reconstructed. Your job will be to refac...
class Record: def __init__(self, record_id, parent_id): self.record_id = record_id self.parent_id = parent_id class Node: def __init__(self, node_id): self.node_id = node_id self.children = [] def BuildTree(records): root = None records.sort(key=lambda x: x.record_id)...
import unittest from tree_building import Record, BuildTree class TreeBuildingTest(unittest.TestCase): """ Record(record_id, parent_id): records given to be processed Node(node_id): Node in tree BuildTree(records): records as argument and returns tree BuildTree should raise ValueE...
121
triangle
# Instructions Determine if a triangle is equilateral, isosceles, or scalene. An _equilateral_ triangle has all three sides the same length. An _isosceles_ triangle has at least two sides the same length. (It is sometimes specified as having exactly two sides the same length, but for the purposes of this exercise we...
def equilateral(sides): pass def isosceles(sides): pass def scalene(sides): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/triangle/canonical-data.json # File last updated on 2023-07-19 import unittest from triangle import ( equilateral, isosceles, scalene, ) class EquilateralTriangleTest(unittest.T...
122
trinary
# Instructions Convert a trinary number, represented as a string (e.g. '102012'), to its decimal equivalent using first principles. The program should consider strings specifying an invalid trinary as the value 0. Trinary numbers contain three symbols: 0, 1, and 2. The last place in a trinary number is the 1's plac...
def trinary(string): pass
import unittest from trinary import trinary class TrinaryTest(unittest.TestCase): def test_valid_trinary1(self): self.assertEqual(trinary('0'), 0) def test_valid_trinary2(self): self.assertEqual(trinary('1'), 1) def test_valid_trinary3(self): self.assertEqual(trinary('10'), 3) ...
123
twelve_days
# Instructions Your task in this exercise is to write code that returns the lyrics of the song: "The Twelve Days of Christmas." "The Twelve Days of Christmas" is a common English Christmas carol. Each subsequent verse of the song builds on the previous verse. The lyrics your code returns should _exactly_ match the f...
def recite(start_verse, end_verse): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/twelve-days/canonical-data.json # File last updated on 2023-07-19 import unittest from twelve_days import ( recite, ) # PLEASE TAKE NOTE: Expected result lists for these test cases use *...
124
two_bucket
# Instructions Given two buckets of different size and which bucket to fill first, determine how many actions are required to measure an exact number of liters by strategically transferring fluid between the buckets. There are some rules that your solution must follow: - You can only do one action at a time. - There...
def measure(bucket_one, bucket_two, goal, start_bucket): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/two-bucket/canonical-data.json # File last updated on 2023-07-21 import unittest from two_bucket import ( measure, ) class TwoBucketTest(unittest.TestCase): def test_measure_using_b...
125
two_fer
# Introduction In some English accents, when you say "two for" quickly, it sounds like "two fer". Two-for-one is a way of saying that if you buy one, you also get one for free. So the phrase "two-fer" often implies a two-for-one offer. Imagine a bakery that has a holiday offer where you can buy two cookies for the pr...
def two_fer(name): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/two-fer/canonical-data.json # File last updated on 2023-07-19 import unittest from two_fer import ( two_fer, ) class TwoFerTest(unittest.TestCase): def test_no_name_given(self): ...
126
variable_length_quantity
# Instructions Implement variable length quantity encoding and decoding. The goal of this exercise is to implement [VLQ][vlq] encoding/decoding. In short, the goal of this encoding is to encode integer values in a way that would save bytes. Only the first 7 bits of each byte are significant (right-justified; sort of...
def encode(numbers): pass def decode(bytes_): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/variable-length-quantity/canonical-data.json # File last updated on 2023-07-19 import unittest from variable_length_quantity import ( decode, encode, ) class VariableLengthQuantityT...
127
word_count
# Introduction You teach English as a foreign language to high school students. You've decided to base your entire curriculum on TV shows. You need to analyze which words are used, and how often they're repeated. This will let you choose the simplest shows to start with, and to gradually increase the difficulty as t...
def count_words(sentence): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/word-count/canonical-data.json # File last updated on 2023-07-19 import unittest from word_count import ( count_words, ) class WordCountTest(unittest.TestCase): def test_count_one_w...
128
word_search
# Instructions In word search puzzles you get a square of letters and have to find specific words in them. For example: ```text jefblpepre camdcimgtc oivokprjsm pbwasqroua rixilelhrs wolcqlirpc screeaumgr alxhpburyi jalaycalmp clojurermt ``` There are several programming languages hidden in the above square. Words...
class Point: def __init__(self, x, y): self.x = None self.y = None def __eq__(self, other): return self.x == other.x and self.y == other.y class WordSearch: def __init__(self, puzzle): pass def search(self, word): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/word-search/canonical-data.json # File last updated on 2023-07-19 import unittest from word_search import ( WordSearch, Point, ) class WordSearchTest(unittest.TestCase): def tes...
129
wordy
# Instructions Parse and evaluate simple math word problems returning the answer as an integer. ## Iteration 0 — Numbers Problems with no operations simply evaluate to the number given. > What is 5? Evaluates to 5. ## Iteration 1 — Addition Add two numbers together. > What is 5 plus 13? Evaluates to 18. Handl...
def answer(question): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/wordy/canonical-data.json # File last updated on 2023-07-19 import unittest from wordy import ( answer, ) class WordyTest(unittest.TestCase): def test_just_a_number(self): s...
130
yacht
# Introduction Each year, something new is "all the rage" in your high school. This year it is a dice game: [Yacht][yacht]. The game of Yacht is from the same family as Poker Dice, Generala and particularly Yahtzee, of which it is a precursor. The game consists of twelve rounds. In each, five dice are rolled and the ...
# Score categories. # Change the values as you see fit. YACHT = None ONES = None TWOS = None THREES = None FOURS = None FIVES = None SIXES = None FULL_HOUSE = None FOUR_OF_A_KIND = None LITTLE_STRAIGHT = None BIG_STRAIGHT = None CHOICE = None def score(dice, category): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/yacht/canonical-data.json # File last updated on 2023-07-19 import unittest import yacht class YachtTest(unittest.TestCase): def test_yacht(self): self.assertEqual(yacht.score([5...
131
zebra_puzzle
# Introduction The Zebra Puzzle is a famous logic puzzle in which there are five houses, each painted a different color. The houses have different inhabitants, who have different nationalities, own different pets, drink different beverages and enjoy different hobbies. To help you solve the puzzle, you're given 15 sta...
def drinks_water(): pass def owns_zebra(): pass
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/zebra-puzzle/canonical-data.json # File last updated on 2023-07-19 import unittest from zebra_puzzle import ( drinks_water, owns_zebra, ) class ZebraPuzzleTest(unittest.TestCase): ...
132
zipper
# Instructions Creating a zipper for a binary tree. [Zippers][zipper] are a purely functional way of navigating within a data structure and manipulating it. They essentially contain a data structure and a pointer into that data structure (called the focus). For example given a rose tree (where each node contains a v...
class Zipper: @staticmethod def from_tree(tree): pass def value(self): pass def set_value(self): pass def left(self): pass def set_left(self): pass def right(self): pass def set_right(self): pass def up(self): pas...
# These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/zipper/canonical-data.json # File last updated on 2023-07-19 import unittest from zipper import ( Zipper, ) class ZipperTest(unittest.TestCase): def test_data_is_retained(self): ...