Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions exercises/practice/anagram/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Instructions

Your task is to, given a target word and a set of candidate words, to find the subset of the candidates that are anagrams of the target.
Given a target word and one or more candidate words, your task is to find the candidates that are anagrams of the target.

An anagram is a rearrangement of letters to form a new word: for example `"owns"` is an anagram of `"snow"`.
A word is _not_ its own anagram: for example, `"stop"` is not an anagram of `"stop"`.

The target and candidates are words of one or more ASCII alphabetic characters (`A`-`Z` and `a`-`z`).
Lowercase and uppercase characters are equivalent: for example, `"PoTS"` is an anagram of `"sTOp"`, but `StoP` is not an anagram of `sTOp`.
The anagram set is the subset of the candidate set that are anagrams of the target (in any order).
Words in the anagram set should have the same letter case as in the candidate set.
The target word and candidate words are made up of one or more ASCII alphabetic characters (`A`-`Z` and `a`-`z`).
Lowercase and uppercase characters are equivalent: for example, `"PoTS"` is an anagram of `"sTOp"`, but `"StoP"` is not an anagram of `"sTOp"`.
The words you need to find should be taken from the candidate words, using the same letter case.

Given the target `"stone"` and candidates `"stone"`, `"tones"`, `"banana"`, `"tons"`, `"notes"`, `"Seton"`, the anagram set is `"tones"`, `"notes"`, `"Seton"`.
Given the target `"stone"` and the candidate words `"stone"`, `"tones"`, `"banana"`, `"tons"`, `"notes"`, and `"Seton"`, the anagram words you need to find are `"tones"`, `"notes"`, and `"Seton"`.
8 changes: 7 additions & 1 deletion exercises/practice/anagram/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ include = false

[630abb71-a94e-4715-8395-179ec1df9f91]
description = "does not detect an anagram if the original word is repeated"
reimplements = "7cc195ad-e3c7-44ee-9fd2-d3c344806a2c"
include = false
reimplements = "7cc195ad-e3c7-44ee-9fd2-d3c344806a2c"

[9878a1c9-d6ea-4235-ae51-3ea2befd6842]
description = "anagrams must use all letters exactly once"
Expand Down Expand Up @@ -78,3 +78,9 @@ include = false
[33d3f67e-fbb9-49d3-a90e-0beb00861da7]
description = "words other than themselves can be anagrams"
reimplements = "a0705568-628c-4b55-9798-82e4acde51ca"

[a6854f66-eec1-4afd-a137-62ef2870c051]
description = "handles case of greek letters"

[fd3509e5-e3ba-409d-ac3d-a9ac84d13296]
description = "different characters may have the same bytes"
12 changes: 6 additions & 6 deletions exercises/practice/anagram/anagram.vader
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Execute (no matches):
let g:expected = []
AssertEqual g:expected, FindAnagrams(g:candidates, g:subject)

Execute (detects two anagrams):
let g:candidates = ['stream', 'pigeon', 'maters']
let g:subject = "master"
let g:expected = ['stream', 'maters']
AssertEqual g:expected, FindAnagrams(g:candidates, g:subject)

Execute (detects two anagrams):
let g:candidates = ['lemons', 'cherry', 'melons']
let g:subject = "solemn"
Expand Down Expand Up @@ -59,12 +65,6 @@ Execute (detects anagrams using case-insensitive possible matches):
let g:expected = ['Carthorse']
AssertEqual g:expected, FindAnagrams(g:candidates, g:subject)

Execute (does not detect an anagram if the original word is repeated):
let g:candidates = ['goGoGO']
let g:subject = "go"
let g:expected = []
AssertEqual g:expected, FindAnagrams(g:candidates, g:subject)

Execute (anagrams must use all letters exactly once):
let g:candidates = ['patter']
let g:subject = "tapper"
Expand Down
5 changes: 5 additions & 0 deletions exercises/practice/bob/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ description = "alternate silence"

[66953780-165b-4e7e-8ce3-4bcb80b6385a]
description = "multiple line question"
include = false

[5371ef75-d9ea-4103-bcfa-2da973ddec1b]
description = "starting with whitespace"
Expand All @@ -83,3 +84,7 @@ description = "other whitespace"

[12983553-8601-46a8-92fa-fcaa3bc4a2a0]
description = "non-question ending with whitespace"

[2c7278ac-f955-4eb4-bf8f-e33eb4116a15]
description = "multiple line question"
reimplements = "66953780-165b-4e7e-8ce3-4bcb80b6385a"
9 changes: 5 additions & 4 deletions exercises/practice/bob/bob.vader
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ Execute (alternate silence):
let g:expected = "Fine. Be that way!"
AssertEqual g:expected, Response(g:heyBob)

Execute (multiple line question):
let g:heyBob = "\nDoes this cryogenic chamber make me look fat?\nNo."
let g:expected = "Whatever."
AssertEqual g:expected, Response(g:heyBob)

Execute (starting with whitespace):
let g:heyBob = " hmmmmmmm..."
Expand All @@ -123,3 +119,8 @@ Execute (non-question ending with whitespace):
let g:heyBob = "This is a statement ending with whitespace "
let g:expected = "Whatever."
AssertEqual g:expected, Response(g:heyBob)

Execute (multiple line question):
let g:heyBob = "\nDoes this cryogenic chamber make\n me look fat?"
let g:expected = "Sure."
AssertEqual g:expected, Response(g:heyBob)
3 changes: 3 additions & 0 deletions exercises/practice/custom-set/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ description = "Difference (or Complement) of a set is a set of all elements that
[c5ac673e-d707-4db5-8d69-7082c3a5437e]
description = "Difference (or Complement) of a set is a set of all elements that are only in the first set -> difference of two non-empty sets is a set of elements that are only in the first set"

[20d0a38f-7bb7-4c4a-ac15-90c7392ecf2b]
description = "Difference (or Complement) of a set is a set of all elements that are only in the first set -> difference removes all duplicates in the first set"

[c45aed16-5494-455a-9033-5d4c93589dc6]
description = "Union returns a set of all elements in either set -> union of empty sets is an empty set"

Expand Down
6 changes: 6 additions & 0 deletions exercises/practice/custom-set/custom_set.vader
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ Execute (difference of two non-empty sets is a set of elements that are only in
let g:expected = Set([1, 3])
AssertEqual g:expected, g:set1.Difference(g:set2)

Execute (difference removes all duplicates in the first set):
let g:set1 = Set([1, 1])
let g:set2 = Set([1])
let g:expected = Set([])
AssertEqual g:expected, g:set1.Difference(g:set2)

Execute (union of empty sets is an empty set):
let g:set1 = Set([])
let g:set2 = Set([])
Expand Down
15 changes: 10 additions & 5 deletions exercises/practice/flatten-array/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# Instructions

Take a nested list and return a single flattened list with all values except nil/null.
Take a nested array of any depth and return a fully flattened array.

The challenge is to take an arbitrarily-deep nested list-like structure and produce a flattened structure without any nil/null values.
Note that some language tracks may include null-like values in the input array, and the way these values are represented varies by track.
Such values should be excluded from the flattened array.

For example:
Additionally, the input may be of a different data type and contain different types, depending on the track.

input: [1,[2,3,null,4],[null],5]
Check the test suite for details.

output: [1,2,3,4,5]
## Example

input: `[1, [2, 6, null], [[null, [4]], 5]]`

output: `[1, 2, 6, 4, 5]`
7 changes: 7 additions & 0 deletions exercises/practice/flatten-array/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Introduction

A shipment of emergency supplies has arrived, but there's a problem.
To protect from damage, the items — flashlights, first-aid kits, blankets — are packed inside boxes, and some of those boxes are nested several layers deep inside other boxes!

To be prepared for an emergency, everything must be easily accessible in one box.
Can you unpack all the supplies and place them into a single box, so they're ready when needed most?
20 changes: 20 additions & 0 deletions exercises/practice/flatten-array/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,32 @@ description = "null values are omitted from the final result"

[c6cf26de-8ccd-4410-84bd-b9efd88fd2bc]
description = "consecutive null values at the front of the list are omitted from the final result"
include = false

[bc72da10-5f55-4ada-baf3-50e4da02ec8e]
description = "consecutive null values at the front of the array are omitted from the final result"
reimplements = "c6cf26de-8ccd-4410-84bd-b9efd88fd2bc"

[382c5242-587e-4577-b8ce-a5fb51e385a1]
description = "consecutive null values in the middle of the list are omitted from the final result"
include = false

[6991836d-0d9b-4703-80a0-3f1f23eb5981]
description = "consecutive null values in the middle of the array are omitted from the final result"
reimplements = "382c5242-587e-4577-b8ce-a5fb51e385a1"

[ef1d4790-1b1e-4939-a179-51ace0829dbd]
description = "6 level nest list with null values"
include = false

[dc90a09c-5376-449c-a7b3-c2d20d540069]
description = "6 level nested array with null values"
reimplements = "ef1d4790-1b1e-4939-a179-51ace0829dbd"

[85721643-705a-4150-93ab-7ae398e2942d]
description = "all values in nested list are null"
include = false

[51f5d9af-8f7f-4fb5-a156-69e8282cb275]
description = "all values in nested array are null"
reimplements = "85721643-705a-4150-93ab-7ae398e2942d"
8 changes: 4 additions & 4 deletions exercises/practice/flatten-array/flatten_array.vader
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ Execute (null values are omitted from the final result):
let g:expected = [1, 2]
AssertEqual g:expected, Flatten(g:array)

Execute (consecutive null values at the front of the list are omitted from the final result):
Execute (consecutive null values at the front of the array are omitted from the final result):
let g:array = [v:null, v:null, 3]
let g:expected = [3]
AssertEqual g:expected, Flatten(g:array)

Execute (consecutive null values in the middle of the list are omitted from the final result):
Execute (consecutive null values in the middle of the array are omitted from the final result):
let g:array = [1, v:null, v:null, 4]
let g:expected = [1, 4]
AssertEqual g:expected, Flatten(g:array)

Execute (6 level nest list with null values):
Execute (6 level nested array with null values):
let g:array = [0, 2, [[2, 3], 8, [[100]], v:null, [[v:null]]], -2]
let g:expected = [0, 2, 2, 3, 8, 100, -2]
AssertEqual g:expected, Flatten(g:array)

Execute (all values in nested list are null):
Execute (all values in nested array are null):
let g:array = [v:null, [[[v:null]]], v:null, v:null, [[v:null, v:null], v:null], v:null]
let g:expected = []
AssertEqual g:expected, Flatten(g:array)
14 changes: 5 additions & 9 deletions exercises/practice/grains/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# Instructions

Calculate the number of grains of wheat on a chessboard given that the number on each square doubles.
Calculate the number of grains of wheat on a chessboard.

There once was a wise servant who saved the life of a prince.
The king promised to pay whatever the servant could dream up.
Knowing that the king loved chess, the servant told the king he would like to have grains of wheat.
One grain on the first square of a chess board, with the number of grains doubling on each successive square.
A chessboard has 64 squares.
Square 1 has one grain, square 2 has two grains, square 3 has four grains, and so on, doubling each time.

There are 64 squares on a chessboard (where square 1 has one grain, square 2 has two grains, and so on).
Write code that calculates:

Write code that shows:

- how many grains were on a given square, and
- the number of grains on a given square
- the total number of grains on the chessboard
6 changes: 6 additions & 0 deletions exercises/practice/grains/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Introduction

There once was a wise servant who saved the life of a prince.
The king promised to pay whatever the servant could dream up.
Knowing that the king loved chess, the servant told the king he would like to have grains of wheat.
One grain on the first square of a chessboard, with the number of grains doubling on each successive square.
2 changes: 1 addition & 1 deletion exercises/practice/grains/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
},
"blurb": "Calculate the number of grains of wheat on a chessboard given that the number on each square doubles.",
"source": "The CodeRanch Cattle Drive, Assignment 6",
"source_url": "https://coderanch.com/wiki/718824/Grains"
"source_url": "https://web.archive.org/web/20240908084142/https://coderanch.com/wiki/718824/Grains"
}
2 changes: 1 addition & 1 deletion exercises/practice/leap/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
},
"blurb": "Determine whether a given year is a leap year.",
"source": "CodeRanch Cattle Drive, Assignment 3",
"source_url": "https://coderanch.com/t/718816/Leap"
"source_url": "https://web.archive.org/web/20240907033714/https://coderanch.com/t/718816/Leap"
}
3 changes: 3 additions & 0 deletions exercises/practice/pig-latin/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ description = "first letter and ay are moved to the end of words that start with
[bce94a7a-a94e-4e2b-80f4-b2bb02e40f71]
description = "first letter and ay are moved to the end of words that start with consonants -> word beginning with q without a following u"

[e59dbbe8-ccee-4619-a8e9-ce017489bfc0]
description = "first letter and ay are moved to the end of words that start with consonants -> word beginning with consonant and vowel containing qu"

[c01e049a-e3e2-451c-bf8e-e2abb7e438b8]
description = "some letter clusters are treated like a single consonant -> word beginning with ch"

Expand Down
7 changes: 6 additions & 1 deletion exercises/practice/pig-latin/pig_latin.vader
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Execute (word beginning with a):
let g:phrase = "apple"
let g:expected = "appleay"
Expand Down Expand Up @@ -27,7 +28,6 @@ Execute (word beginning with a vowel and followed by a qu):
let g:phrase = "equal"
let g:expected = "equalay"
AssertEqual g:expected, Translate(g:phrase)

Execute (word beginning with p):
let g:phrase = "pig"
let g:expected = "igpay"
Expand All @@ -47,6 +47,11 @@ Execute (word beginning with q without a following u):
let g:phrase = "qat"
let g:expected = "atqay"
AssertEqual g:expected, Translate(g:phrase)

Execute (word beginning with consonant and vowel containing qu):
let g:phrase = "liquid"
let g:expected = "iquidlay"
AssertEqual g:expected, Translate(g:phrase)
Execute (word beginning with ch):
let g:phrase = "chair"
let g:expected = "airchay"
Expand Down
4 changes: 4 additions & 0 deletions exercises/practice/protein-translation/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@ description = "Translation stops if STOP codon in middle of three-codon sequence
[2c2a2a60-401f-4a80-b977-e0715b23b93d]
description = "Translation stops if STOP codon in middle of six-codon sequence"

[f6f92714-769f-4187-9524-e353e8a41a80]
description = "Sequence of two non-STOP codons does not translate to a STOP codon"

[1e75ea2a-f907-4994-ae5c-118632a1cb0f]
description = "Non-existing codon can't translate"

[9eac93f3-627a-4c90-8653-6d0a0595bc6f]
description = "Unknown amino acids, not part of a codon, can't translate"
reimplements = "1e75ea2a-f907-4994-ae5c-118632a1cb0f"

[9d73899f-e68e-4291-b1e2-7bf87c00f024]
description = "Incomplete RNA sequence can't translate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ Execute (Translation stops if STOP codon in middle of six-codon sequence):
let g:expected = ['Tryptophan', 'Cysteine', 'Tyrosine']
AssertEqual g:expected, Proteins(g:strand)

Execute (Sequence of two non-STOP codons does not translate to a STOP codon):
let g:strand = "AUGAUG"
let g:expected = ['Methionine', 'Methionine']
AssertEqual g:expected, Proteins(g:strand)

Execute (Non-existing codon can't translate):
let g:strand = "AAA"
let g:expected = "Invalid codon"
Expand Down
9 changes: 9 additions & 0 deletions exercises/practice/reverse-string/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ description = "a palindrome"

[b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c]
description = "an even-sized word"

[1bed0f8a-13b0-4bd3-9d59-3d0593326fa2]
description = "wide characters"

[93d7e1b8-f60f-4f3c-9559-4056e10d2ead]
description = "grapheme cluster with pre-combined form"

[1028b2c1-6763-4459-8540-2da47ca512d9]
description = "grapheme clusters"
15 changes: 15 additions & 0 deletions exercises/practice/reverse-string/reverse_string.vader
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,18 @@ Execute (an even-sized word):
let g:value = "drawer"
let g:expected = "reward"
AssertEqual g:expected, Reverse(g:value)

Execute (wide characters):
let g:value = "子猫"
let g:expected = "猫子"
AssertEqual g:expected, Reverse(g:value)

Execute (grapheme cluster with pre-combined form):
let g:value = "Würstchenstand"
let g:expected = "dnatsnehctsrüW"
AssertEqual g:expected, Reverse(g:value)

Execute (grapheme clusters):
let g:value = "ผู้เขียนโปรแกรม"
let g:expected = "มรกแรปโนยขีเผู้"
AssertEqual g:expected, Reverse(g:value)
2 changes: 1 addition & 1 deletion exercises/practice/rna-transcription/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
".meta/example.vim"
]
},
"blurb": "Given a DNA strand, return its RNA Complement Transcription.",
"blurb": "Given a DNA strand, return its RNA complement.",
"source": "Hyperphysics",
"source_url": "https://web.archive.org/web/20220408112140/http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html"
}
Loading