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 |
|---|---|---|---|---|
0 | accumulate | # Instructions
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.
Given the collection of numbers:
- 1, 2, 3, 4, 5
And the op... | def accumulate(collection, operation):
pass
| import unittest
from accumulate import accumulate
class AccumulateTest(unittest.TestCase):
def test_empty_sequence(self):
self.assertEqual(accumulate([], lambda x: x / 2), [])
def test_pow(self):
self.assertEqual(
accumulate([1, 2, 3, 4, 5], lambda x: x * x), [1, 4, 9, 16, 25])
... |
1 | acronym | # Instructions
Convert a phrase to its acronym.
Techies love their TLA (Three Letter Acronyms)!
Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG).
Punctuation is handled as follows: hyphens are word separators (like whitespace); all other pu... | def abbreviate(words):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/acronym/canonical-data.json
# File last updated on 2023-07-20
import unittest
from acronym import (
abbreviate,
)
class AcronymTest(unittest.TestCase):
def test_basic(self):
... |
2 | affine_cipher | # Instructions
Create an implementation of the affine cipher, an ancient encryption system created in the Middle East.
The affine cipher is a type of monoalphabetic substitution cipher.
Each character is mapped to its numeric equivalent, encrypted with a mathematical function and then converted to the letter relating... | def encode(plain_text, a, b):
pass
def decode(ciphered_text, a, b):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/affine-cipher/canonical-data.json
# File last updated on 2023-07-20
import unittest
from affine_cipher import (
decode,
encode,
)
class AffineCipherTest(unittest.TestCase):
def ... |
3 | all_your_base | # Introduction
You've just been hired as professor of mathematics.
Your first week went well, but something is off in your second week.
The problem is that every answer given by your students is wrong!
Luckily, your math skills have allowed you to identify the problem: the student answers _are_ correct, but they're al... | def rebase(input_base, digits, output_base):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/all-your-base/canonical-data.json
# File last updated on 2023-07-20
import unittest
from all_your_base import (
rebase,
)
class AllYourBaseTest(unittest.TestCase):
def test_single_b... |
4 | allergies | # Instructions
Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.
An allergy test produces a single numeric score which contains the information about all the allergies the person has (that they were tested for).
The list of items (and their v... | class Allergies:
def __init__(self, score):
pass
def allergic_to(self, item):
pass
@property
def lst(self):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/allergies/canonical-data.json
# File last updated on 2023-07-20
import unittest
from allergies import (
Allergies,
)
class AllergiesTest(unittest.TestCase):
def test_eggs_not_allerg... |
5 | alphametics | # Instructions
Given an alphametics puzzle, find the correct solution.
[Alphametics][alphametics] is a puzzle where letters in words are replaced with numbers.
For example `SEND + MORE = MONEY`:
```text
S E N D
M O R E +
-----------
M O N E Y
```
Replacing these with valid numbers gives:
```text
9 5 6 7
1... | def solve(puzzle):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/alphametics/canonical-data.json
# File last updated on 2023-07-20
import unittest
from alphametics import (
solve,
)
class AlphameticsTest(unittest.TestCase):
def test_puzzle_with_t... |
6 | anagram | # Introduction
At a garage sale, you find a lovely vintage typewriter at a bargain price!
Excitedly, you rush home, insert a sheet of paper, and start typing away.
However, your excitement wanes when you examine the output: all words are garbled!
For example, it prints "stop" instead of "post" and "least" instead of "... | def find_anagrams(word, candidates):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/anagram/canonical-data.json
# File last updated on 2024-02-28
import unittest
from anagram import (
find_anagrams,
)
class AnagramTest(unittest.TestCase):
def test_no_matches(self):... |
7 | armstrong_numbers | # Instructions
An [Armstrong number][armstrong-number] is a number that is the sum of its own digits each raised to the power of the number of digits.
For example:
- 9 is an Armstrong number, because `9 = 9^1 = 9`
- 10 is _not_ an Armstrong number, because `10 != 1^2 + 0^2 = 1`
- 153 is an Armstrong number, because:... | def is_armstrong_number(number):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/armstrong-numbers/canonical-data.json
# File last updated on 2023-07-20
import unittest
from armstrong_numbers import (
is_armstrong_number,
)
class ArmstrongNumbersTest(unittest.TestCa... |
8 | atbash_cipher | # Instructions
Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.
The Atbash cipher is a simple substitution cipher that relies on transposing all the letters in the alphabet such that the resulting alphabet is backwards.
The first letter is replaced with the last ... | def encode(plain_text):
pass
def decode(ciphered_text):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/atbash-cipher/canonical-data.json
# File last updated on 2023-07-20
import unittest
from atbash_cipher import (
decode,
encode,
)
class AtbashCipherTest(unittest.TestCase):
def ... |
9 | bank_account | # Introduction
After years of filling out forms and waiting, you've finally acquired your banking license.
This means you are now officially eligible to open your own bank, hurray!
Your first priority is to get the IT systems up and running.
After a day of hard work, you can already open and close accounts, as well a... | class BankAccount:
def __init__(self):
pass
def get_balance(self):
pass
def open(self):
pass
def deposit(self, amount):
pass
def withdraw(self, amount):
pass
def close(self):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/bank-account/canonical-data.json
# File last updated on 2023-07-20
import unittest
from bank_account import (
BankAccount,
)
class BankAccountTest(unittest.TestCase):
def test_newly... |
10 | beer_song | # Instructions
Recite the lyrics to that beloved classic, that field-trip favorite: 99 Bottles of Beer on the Wall.
Note that not all verses are identical.
```text
99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.
98 bottles of beer on the wall, 98... | def recite(start, take=1):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/beer-song/canonical-data.json
# File last updated on 2023-07-20
import unittest
from beer_song import (
recite,
)
class BeerSongTest(unittest.TestCase):
def test_first_generic_verse... |
11 | binary | # Instructions
Convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles.
Implement binary to decimal conversion.
Given a binary input string, your program should produce a decimal output.
The program should handle invalid inputs.
## Note
- Implement the conv... | def parse_binary(binary_string):
pass
| """Tests for the binary exercise
Implementation note:
If the argument to parse_binary isn't a valid binary number the
function should raise a ValueError with a meaningful error message.
"""
import unittest
from binary import parse_binary
class BinaryTest(unittest.TestCase):
def test_binary_1_is_decimal_1(self):... |
12 | binary_search | # Introduction
You have stumbled upon a group of mathematicians who are also singer-songwriters.
They have written a song for each of their favorite numbers, and, as you can imagine, they have a lot of favorite numbers (like [0][zero] or [73][seventy-three] or [6174][kaprekars-constant]).
You are curious to hear the ... | def find(search_list, value):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/binary-search/canonical-data.json
# File last updated on 2023-07-20
import unittest
from binary_search import (
find,
)
class BinarySearchTest(unittest.TestCase):
def test_finds_a_v... |
13 | binary_search_tree | # Instructions
Insert and search for numbers in a binary tree.
When we need to represent sorted data, an array does not make a good data structure.
Say we have the array `[1, 3, 4, 5]`, and we add 2 to it so it becomes `[1, 3, 4, 5, 2]`.
Now we must sort the entire array again!
We can improve on this by realizing th... | class TreeNode:
def __init__(self, data, left=None, right=None):
self.data = None
self.left = None
self.right = None
def __str__(self):
return f'TreeNode(data={self.data}, left={self.left}, right={self.right})'
class BinarySearchTree:
def __init__(self, tree_data):
... | # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/binary-search-tree/canonical-data.json
# File last updated on 2023-07-20
import unittest
from binary_search_tree import (
BinarySearchTree,
TreeNode,
)
class BinarySearchTreeTest(un... |
14 | bob | # Introduction
Bob is a [lackadaisical][] teenager.
He likes to think that he's very cool.
And he definitely doesn't get excited about things.
That wouldn't be cool.
When people talk to him, his responses are pretty limited.
[lackadaisical]: https://www.collinsdictionary.com/dictionary/english/lackadaisical
# Instru... | def response(hey_bob):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/bob/canonical-data.json
# File last updated on 2023-07-20
import unittest
from bob import (
response,
)
class BobTest(unittest.TestCase):
def test_stating_something(self):
s... |
15 | book_store | # Instructions
To try and encourage more sales of different books from a popular 5 book series, a bookshop has decided to offer discounts on multiple book purchases.
One copy of any of the five books costs $8.
If, however, you buy two different books, you get a 5% discount on those two books.
If you buy 3 different... | def total(basket):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/book-store/canonical-data.json
# File last updated on 2023-07-20
import unittest
from book_store import (
total,
)
class BookStoreTest(unittest.TestCase):
def test_only_a_single_boo... |
16 | bottle_song | # Instructions
Recite the lyrics to that popular children's repetitive song: Ten Green Bottles.
Note that not all verses are identical.
```text
Ten green bottles hanging on the wall,
Ten green bottles hanging on the wall,
And if one green bottle should accidentally fall,
There'll be nine green bottles hanging on the... | def recite(start, take=1):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/bottle-song/canonical-data.json
# File last updated on 2023-07-20
import unittest
from bottle_song import (
recite,
)
class BottleSongTest(unittest.TestCase):
def test_first_generic... |
17 | bowling | # Instructions
Score a bowling game.
Bowling is a game where players roll a heavy ball to knock down pins arranged in a triangle.
Write code to keep track of the score of a game of bowling.
## Scoring Bowling
The game consists of 10 frames.
A frame is composed of one or two ball throws with 10 pins standing at fram... | class BowlingGame:
def __init__(self):
pass
def roll(self, pins):
pass
def score(self):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/bowling/canonical-data.json
# File last updated on 2023-07-21
import unittest
from bowling import (
BowlingGame,
)
class BowlingTest(unittest.TestCase):
def roll_new_game(self, roll... |
18 | change | # Instructions
Correctly determine the fewest number of coins to be given to a customer such that the sum of the coins' value would equal the correct amount of change.
## For example
- An input of 15 with [1, 5, 10, 25, 100] should return one nickel (5) and one dime (10) or [5, 10]
- An input of 40 with [1, 5, 10, 2... | def find_fewest_coins(coins, target):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/change/canonical-data.json
# File last updated on 2024-03-05
import unittest
from change import (
find_fewest_coins,
)
class ChangeTest(unittest.TestCase):
def test_change_for_1_cen... |
19 | circular_buffer | # Instructions
A circular buffer, cyclic buffer or ring buffer is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end.
A circular buffer first starts empty and of some predefined length.
For example, this is a 7-element buffer:
```text
[ ][ ][ ][ ][ ][ ][ ]
```
Assume that a 1 ... | class BufferFullException(BufferError):
"""Exception raised when CircularBuffer is full.
message: explanation of the error.
"""
def __init__(self, message):
pass
class BufferEmptyException(BufferError):
"""Exception raised when CircularBuffer is empty.
message: explanation of the er... | # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/circular-buffer/canonical-data.json
# File last updated on 2023-07-20
import unittest
from circular_buffer import (
CircularBuffer,
BufferEmptyException,
BufferFullException,
)
... |
20 | clock | # Instructions
Implement a clock that handles times without dates.
You should be able to add and subtract minutes to it.
Two clocks that represent the same time should be equal to each other.
# Instructions append
The tests for this exercise expect your clock will be implemented via a Clock `class` in Python.
If yo... | class Clock:
def __init__(self, hour, minute):
pass
def __repr__(self):
pass
def __str__(self):
pass
def __eq__(self, other):
pass
def __add__(self, minutes):
pass
def __sub__(self, minutes):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/clock/canonical-data.json
# File last updated on 2023-07-20
import unittest
from clock import (
Clock,
)
class ClockTest(unittest.TestCase):
# Create A String Representation
def... |
21 | collatz_conjecture | # Instructions
The Collatz Conjecture or 3x+1 problem can be summarized as follows:
Take any positive integer n.
If n is even, divide n by 2 to get n / 2.
If n is odd, multiply n by 3 and add 1 to get 3n + 1.
Repeat the process indefinitely.
The conjecture states that no matter which number you start with, you will a... | def steps(number):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/collatz-conjecture/canonical-data.json
# File last updated on 2023-07-20
import unittest
from collatz_conjecture import (
steps,
)
class CollatzConjectureTest(unittest.TestCase):
de... |
22 | complex_numbers | # Instructions
A complex number is a number in the form `a + b * i` where `a` and `b` are real and `i` satisfies `i^2 = -1`.
`a` is called the real part and `b` is called the imaginary part of `z`.
The conjugate of the number `a + b * i` is the number `a - b * i`.
The absolute value of a complex number `z = a + b * i... | class ComplexNumber:
def __init__(self, real, imaginary):
pass
def __eq__(self, other):
pass
def __add__(self, other):
pass
def __mul__(self, other):
pass
def __sub__(self, other):
pass
def __truediv__(self, other):
pass
def __abs__(self)... | # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/complex-numbers/canonical-data.json
# File last updated on 2023-07-19
import math
import unittest
from complex_numbers import (
ComplexNumber,
)
class ComplexNumbersTest(unittest.TestCa... |
23 | connect | # Instructions
Compute the result for a game of Hex / Polygon.
The abstract boardgame known as [Hex][hex] / Polygon / CON-TAC-TIX is quite simple in rules, though complex in practice.
Two players place stones on a parallelogram with hexagonal fields.
The player to connect his/her stones to the opposite side first win... |
class ConnectGame:
def __init__(self, board):
pass
def get_winner(self):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/connect/canonical-data.json
# File last updated on 2023-07-19
import unittest
from connect import (
ConnectGame,
)
class ConnectTest(unittest.TestCase):
def test_an_empty_board_has_... |
24 | crypto_square | # Instructions
Implement the classic method for composing secret messages called a square code.
Given an English text, output the encoded version of that text.
First, the input is normalized: the spaces and punctuation are removed from the English text and the message is down-cased.
Then, the normalized characters ... | def cipher_text(plain_text):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/crypto-square/canonical-data.json
# File last updated on 2023-07-19
import unittest
from crypto_square import (
cipher_text,
)
class CryptoSquareTest(unittest.TestCase):
def test_em... |
25 | custom_set | # Instructions
Create a custom set type.
Sometimes it is necessary to define a custom data structure of some type, like a set.
In this exercise you will define your own set.
How it works internally doesn't matter, as long as it behaves like a set of unique elements.
| class CustomSet:
def __init__(self, elements=[]):
pass
def isempty(self):
pass
def __contains__(self, element):
pass
def issubset(self, other):
pass
def isdisjoint(self, other):
pass
def __eq__(self, other):
pass
def add(self, element):
... | # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/custom-set/canonical-data.json
# File last updated on 2024-07-08
import unittest
from custom_set import (
CustomSet,
)
class CustomSetTest(unittest.TestCase):
def test_sets_with_no_... |
26 | darts | # Instructions
Calculate the points scored in a single toss of a Darts game.
[Darts][darts] is a game where players throw darts at a [target][darts-target].
In our particular instance of the game, the target rewards 4 different amounts of points, depending on where the dart lands:
![Our dart scoreboard with values ... | def score(x, y):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/darts/canonical-data.json
# File last updated on 2023-07-19
import unittest
from darts import (
score,
)
class DartsTest(unittest.TestCase):
def test_missed_target(self):
se... |
27 | diamond | # Instructions
The diamond kata takes as its input a letter, and outputs it in a diamond shape.
Given a letter, it prints a diamond starting with 'A', with the supplied letter at the widest point.
## Requirements
- The first row contains one 'A'.
- The last row contains one 'A'.
- All rows, except the first and last... | def rows(letter):
pass
| # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/diamond/canonical-data.json
# File last updated on 2023-07-19
import unittest
from diamond import (
rows,
)
class DiamondTest(unittest.TestCase):
def test_degenerate_case_with_a_sin... |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 29