trackler 2.2.1.179 → 2.2.1.180
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/problem-specifications/exercises/yacht/description.md +14 -13
- data/tracks/ballerina/config.json +1 -0
- data/tracks/coffeescript/config.json +138 -41
- data/tracks/coffeescript/docs/ABOUT.md +3 -7
- data/tracks/coq/config.json +1 -0
- data/tracks/d/config.json +1 -0
- data/tracks/dart/config.json +1 -0
- data/tracks/elixir/config.json +17 -16
- data/tracks/elixir/docs/ABOUT.md +10 -2
- data/tracks/fortran/config.json +1 -0
- data/tracks/gnu-apl/config.json +1 -0
- data/tracks/go/config.json +13 -0
- data/tracks/go/exercises/list-ops/README.md +27 -0
- data/tracks/go/exercises/list-ops/example.go +99 -0
- data/tracks/go/exercises/list-ops/listops_test.go +291 -0
- data/tracks/groovy/config.json +1 -0
- data/tracks/haxe/config.json +1 -0
- data/tracks/perl5/exercises/leap/.meta/exercise-data.yaml +3 -5
- data/tracks/perl5/exercises/leap/.meta/solutions/Leap.pm +2 -4
- data/tracks/perl5/exercises/leap/Leap.pm +1 -1
- data/tracks/perl5/exercises/leap/leap.t +2 -2
- data/tracks/php/config.json +1 -0
- data/tracks/plsql/config.json +1 -0
- data/tracks/pony/config.json +1 -0
- data/tracks/purescript/config.json +1 -0
- data/tracks/reasonml/config/exercise_readme.go.tmpl +18 -2
- data/tracks/reasonml/exercises/anagram/README.md +15 -4
- data/tracks/reasonml/exercises/armstrong-numbers/README.md +3 -4
- data/tracks/reasonml/exercises/binary-search/README.md +14 -7
- data/tracks/reasonml/exercises/bob/README.md +14 -6
- data/tracks/reasonml/exercises/change/README.md +2 -4
- data/tracks/reasonml/exercises/hello-world/README.md +2 -3
- data/tracks/reasonml/exercises/isogram/README.md +4 -6
- data/tracks/reasonml/exercises/leap/README.md +14 -4
- data/tracks/reasonml/exercises/pangram/README.md +13 -3
- data/tracks/reasonml/exercises/phone-number/README.md +15 -7
- data/tracks/reasonml/exercises/raindrops/README.md +14 -7
- data/tracks/reasonml/exercises/rna-transcription/README.md +13 -3
- data/tracks/reasonml/exercises/roman-numerals/README.md +4 -8
- data/tracks/reasonml/exercises/run-length-encoding/README.md +14 -7
- data/tracks/reasonml/exercises/space-age/README.md +13 -3
- data/tracks/reasonml/exercises/word-count/README.md +18 -8
- data/tracks/rust/.travis.yml +1 -0
- data/tracks/rust/_test/check-exercises-for-authors.sh +10 -0
- data/tracks/rust/bin/format_exercises +2 -0
- data/tracks/rust/exercises/accumulate/Cargo.toml +0 -1
- data/tracks/rust/exercises/accumulate/example.rs +4 -1
- data/tracks/rust/exercises/acronym/example.rs +6 -5
- data/tracks/rust/exercises/acronym/tests/acronym.rs +1 -1
- data/tracks/rust/exercises/all-your-base/example.rs +8 -2
- data/tracks/rust/exercises/allergies/example.rs +28 -6
- data/tracks/rust/exercises/alphametics/example.rs +18 -10
- data/tracks/rust/exercises/anagram/example.rs +8 -4
- data/tracks/rust/exercises/atbash-cipher/example.rs +15 -15
- data/tracks/rust/exercises/beer-song/example.rs +18 -12
- data/tracks/rust/exercises/binary-search/Cargo.toml +0 -1
- data/tracks/rust/exercises/binary-search/example.rs +3 -4
- data/tracks/rust/exercises/bob/example.rs +11 -5
- data/tracks/rust/exercises/book-store/Cargo-example.toml +0 -1
- data/tracks/rust/exercises/book-store/Cargo.toml +0 -1
- data/tracks/rust/exercises/book-store/example.rs +15 -19
- data/tracks/rust/exercises/bowling/example.rs +3 -1
- data/tracks/rust/exercises/bracket-push/example.rs +7 -2
- data/tracks/rust/exercises/circular-buffer/example.rs +1 -1
- data/tracks/rust/exercises/clock/.meta/ALLOWED_TO_NOT_COMPILE +3 -0
- data/tracks/rust/exercises/clock/Cargo.toml +0 -1
- data/tracks/rust/exercises/clock/example.rs +5 -3
- data/tracks/rust/exercises/clock/src/lib.rs +14 -0
- data/tracks/rust/exercises/collatz-conjecture/example.rs +2 -2
- data/tracks/rust/exercises/crypto-square/Cargo-example.toml +0 -1
- data/tracks/rust/exercises/crypto-square/Cargo.toml +0 -1
- data/tracks/rust/exercises/custom-set/example.rs +17 -15
- data/tracks/rust/exercises/decimal/Cargo-example.toml +0 -1
- data/tracks/rust/exercises/decimal/Cargo.toml +0 -1
- data/tracks/rust/exercises/decimal/example.rs +5 -5
- data/tracks/rust/exercises/diamond/Cargo.toml +0 -1
- data/tracks/rust/exercises/difference-of-squares/example.rs +1 -1
- data/tracks/rust/exercises/dominoes/example.rs +20 -19
- data/tracks/rust/exercises/etl/example.rs +4 -3
- data/tracks/rust/exercises/forth/example.rs +29 -45
- data/tracks/rust/exercises/grade-school/example.rs +4 -2
- data/tracks/rust/exercises/hexadecimal/example.rs +2 -4
- data/tracks/rust/exercises/isbn-verifier/example.rs +5 -6
- data/tracks/rust/exercises/isbn-verifier/tests/isbn-verifier.rs +12 -0
- data/tracks/rust/exercises/isogram/example.rs +9 -3
- data/tracks/rust/exercises/largest-series-product/example.rs +2 -1
- data/tracks/rust/exercises/luhn-from/example.rs +3 -1
- data/tracks/rust/exercises/luhn/example.rs +5 -3
- data/tracks/rust/exercises/macros/Cargo.toml +0 -1
- data/tracks/rust/exercises/nth-prime/Cargo.toml +0 -1
- data/tracks/rust/exercises/nth-prime/example.rs +6 -6
- data/tracks/rust/exercises/nucleotide-codons/Cargo.toml +0 -1
- data/tracks/rust/exercises/nucleotide-codons/example.rs +23 -17
- data/tracks/rust/exercises/nucleotide-count/example.rs +15 -5
- data/tracks/rust/exercises/nucleotide-count/src/lib.rs +15 -0
- data/tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs +3 -3
- data/tracks/rust/exercises/palindrome-products/Cargo.toml +0 -1
- data/tracks/rust/exercises/pangram/example.rs +6 -6
- data/tracks/rust/exercises/parallel-letter-frequency/example.rs +7 -4
- data/tracks/rust/exercises/pascals-triangle/example.rs +6 -2
- data/tracks/rust/exercises/perfect-numbers/example.rs +2 -2
- data/tracks/rust/exercises/phone-number/example.rs +11 -15
- data/tracks/rust/exercises/pig-latin/Cargo-example.toml +0 -1
- data/tracks/rust/exercises/pig-latin/Cargo.toml +0 -1
- data/tracks/rust/exercises/pig-latin/example.rs +6 -2
- data/tracks/rust/exercises/poker/Cargo-example.toml +0 -1
- data/tracks/rust/exercises/poker/Cargo.toml +0 -1
- data/tracks/rust/exercises/poker/example.rs +9 -8
- data/tracks/rust/exercises/prime-factors/Cargo.toml +0 -1
- data/tracks/rust/exercises/prime-factors/example.rs +1 -1
- data/tracks/rust/exercises/protein-translation/Cargo.toml +0 -1
- data/tracks/rust/exercises/protein-translation/example.rs +6 -5
- data/tracks/rust/exercises/proverb/Cargo.toml +0 -1
- data/tracks/rust/exercises/proverb/example.rs +0 -1
- data/tracks/rust/exercises/pythagorean-triplet/Cargo.toml +0 -1
- data/tracks/rust/exercises/pythagorean-triplet/example.rs +3 -3
- data/tracks/rust/exercises/queen-attack/example.rs +3 -3
- data/tracks/rust/exercises/react/example.rs +61 -29
- data/tracks/rust/exercises/reverse-string/Cargo.toml +0 -1
- data/tracks/rust/exercises/rna-transcription/example.rs +17 -9
- data/tracks/rust/exercises/robot-name/example.rs +4 -3
- data/tracks/rust/exercises/robot-simulator/example.rs +5 -2
- data/tracks/rust/exercises/roman-numerals/example.rs +15 -14
- data/tracks/rust/exercises/rotational-cipher/Cargo.toml +0 -1
- data/tracks/rust/exercises/rotational-cipher/example.rs +10 -14
- data/tracks/rust/exercises/rotational-cipher/src/lib.rs +7 -1
- data/tracks/rust/exercises/run-length-encoding/Cargo.toml +0 -1
- data/tracks/rust/exercises/run-length-encoding/example.rs +34 -29
- data/tracks/rust/exercises/saddle-points/example.rs +0 -1
- data/tracks/rust/exercises/say/Cargo.toml +0 -1
- data/tracks/rust/exercises/say/example.rs +34 -8
- data/tracks/rust/exercises/series/example.rs +6 -8
- data/tracks/rust/exercises/simple-linked-list/example.rs +0 -2
- data/tracks/rust/exercises/spiral-matrix/example.rs +0 -1
- data/tracks/rust/exercises/tournament/example.rs +33 -20
- data/tracks/rust/exercises/triangle/example.rs +1 -1
- data/tracks/rust/exercises/two-bucket/example.rs +2 -6
- data/tracks/rust/exercises/two-fer/example.rs +3 -3
- data/tracks/rust/exercises/variable-length-quantity/example.rs +2 -3
- data/tracks/rust/exercises/word-count/example.rs +4 -1
- data/tracks/rust/exercises/wordy/example.rs +10 -4
- metadata +7 -2
@@ -17,15 +17,25 @@ each nucleotide with its complement:
|
|
17
17
|
* `C` -> `G`
|
18
18
|
* `T` -> `A`
|
19
19
|
* `A` -> `U`
|
20
|
+
## Source
|
20
21
|
|
21
|
-
|
22
|
+
Hyperphysics [http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html](http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html)
|
22
23
|
|
24
|
+
## Building and testing
|
25
|
+
You will need the node package manager (npm) installed - download from [here](https://www.npmjs.com/get-npm)
|
26
|
+
There is one time setup for each exercise, which may take a few minutes:
|
23
27
|
```
|
24
|
-
npm
|
28
|
+
npm install
|
25
29
|
```
|
26
30
|
|
27
|
-
|
31
|
+
Open two shells, and in the first, start the build process.
|
32
|
+
```
|
33
|
+
npm start
|
34
|
+
```
|
28
35
|
|
36
|
+
In the second, start the tests running.
|
29
37
|
```
|
30
38
|
npm test
|
31
39
|
```
|
40
|
+
|
41
|
+
As you edit the code, the two processes will continually rebuild and rerun the tests.
|
@@ -41,6 +41,9 @@ In Roman numerals 1990 is MCMXC:
|
|
41
41
|
8=VIII
|
42
42
|
|
43
43
|
See also: http://www.novaroma.org/via_romana/numbers.html
|
44
|
+
## Source
|
45
|
+
|
46
|
+
The Roman Numeral Kata [http://codingdojo.org/cgi-bin/index.pl?KataRomanNumerals](http://codingdojo.org/cgi-bin/index.pl?KataRomanNumerals)
|
44
47
|
|
45
48
|
## Building and testing
|
46
49
|
You will need the node package manager (npm) installed - download from [here](https://www.npmjs.com/get-npm)
|
@@ -59,11 +62,4 @@ In the second, start the tests running.
|
|
59
62
|
npm test
|
60
63
|
```
|
61
64
|
|
62
|
-
As you edit the code, the two processes will continually rebuild and rerun the tests.
|
63
|
-
|
64
|
-
## Source
|
65
|
-
|
66
|
-
The Roman Numeral Kata [http://codingdojo.org/cgi-bin/index.pl?KataRomanNumerals](http://codingdojo.org/cgi-bin/index.pl?KataRomanNumerals)
|
67
|
-
|
68
|
-
## Submitting Incomplete Solutions
|
69
|
-
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
65
|
+
As you edit the code, the two processes will continually rebuild and rerun the tests.
|
@@ -22,18 +22,25 @@ For simplicity, you can assume that the unencoded string will only contain
|
|
22
22
|
the letters A through Z (either lower or upper case) and whitespace. This way
|
23
23
|
data to be encoded will never contain any numbers and numbers inside data to
|
24
24
|
be decoded always represent the count for the following character.
|
25
|
+
## Source
|
25
26
|
|
26
|
-
|
27
|
+
Wikipedia [https://en.wikipedia.org/wiki/Run-length_encoding](https://en.wikipedia.org/wiki/Run-length_encoding)
|
28
|
+
|
29
|
+
## Building and testing
|
30
|
+
You will need the node package manager (npm) installed - download from [here](https://www.npmjs.com/get-npm)
|
31
|
+
There is one time setup for each exercise, which may take a few minutes:
|
27
32
|
```
|
28
|
-
npm
|
33
|
+
npm install
|
29
34
|
```
|
30
35
|
|
31
|
-
|
32
|
-
|
36
|
+
Open two shells, and in the first, start the build process.
|
33
37
|
```
|
34
|
-
npm
|
38
|
+
npm start
|
35
39
|
```
|
36
40
|
|
41
|
+
In the second, start the tests running.
|
42
|
+
```
|
43
|
+
npm test
|
44
|
+
```
|
37
45
|
|
38
|
-
|
39
|
-
If you use `vscode`, Press `Windows + Shift + B` it will build automatically
|
46
|
+
As you edit the code, the two processes will continually rebuild and rerun the tests.
|
@@ -16,15 +16,25 @@ be able to say that they're 31.69 Earth-years old.
|
|
16
16
|
|
17
17
|
If you're wondering why Pluto didn't make the cut, go watch [this
|
18
18
|
youtube video](http://www.youtube.com/watch?v=Z_2gbGXzFbs).
|
19
|
+
## Source
|
19
20
|
|
20
|
-
|
21
|
+
Partially inspired by Chapter 1 in Chris Pine's online Learn to Program tutorial. [http://pine.fm/LearnToProgram/?Chapter=01](http://pine.fm/LearnToProgram/?Chapter=01)
|
21
22
|
|
23
|
+
## Building and testing
|
24
|
+
You will need the node package manager (npm) installed - download from [here](https://www.npmjs.com/get-npm)
|
25
|
+
There is one time setup for each exercise, which may take a few minutes:
|
22
26
|
```
|
23
|
-
npm
|
27
|
+
npm install
|
24
28
|
```
|
25
29
|
|
26
|
-
|
30
|
+
Open two shells, and in the first, start the build process.
|
31
|
+
```
|
32
|
+
npm start
|
33
|
+
```
|
27
34
|
|
35
|
+
In the second, start the tests running.
|
28
36
|
```
|
29
37
|
npm test
|
30
38
|
```
|
39
|
+
|
40
|
+
As you edit the code, the two processes will continually rebuild and rerun the tests.
|
@@ -1,24 +1,34 @@
|
|
1
1
|
# Word Count
|
2
|
+
|
2
3
|
Given a phrase, count the occurrences of each word in that phrase.
|
3
4
|
|
4
|
-
For example for the input "olly olly in come free"
|
5
|
+
For example for the input `"olly olly in come free"`
|
5
6
|
|
7
|
+
```text
|
6
8
|
olly: 2
|
7
9
|
in: 1
|
8
10
|
come: 1
|
9
11
|
free: 1
|
12
|
+
```
|
13
|
+
## Source
|
14
|
+
|
15
|
+
This is a classic toy problem, but we were reminded of it by seeing it in the Go Tour.
|
10
16
|
|
11
|
-
|
17
|
+
## Building and testing
|
18
|
+
You will need the node package manager (npm) installed - download from [here](https://www.npmjs.com/get-npm)
|
19
|
+
There is one time setup for each exercise, which may take a few minutes:
|
12
20
|
```
|
13
|
-
npm
|
21
|
+
npm install
|
14
22
|
```
|
15
23
|
|
16
|
-
|
17
|
-
|
24
|
+
Open two shells, and in the first, start the build process.
|
18
25
|
```
|
19
|
-
npm
|
26
|
+
npm start
|
20
27
|
```
|
21
28
|
|
29
|
+
In the second, start the tests running.
|
30
|
+
```
|
31
|
+
npm test
|
32
|
+
```
|
22
33
|
|
23
|
-
|
24
|
-
If you use `vscode`, Press `Windows + Shift + B` it will build automatically
|
34
|
+
As you edit the code, the two processes will continually rebuild and rerun the tests.
|
data/tracks/rust/.travis.yml
CHANGED
@@ -6,7 +6,10 @@ pub fn map_function(values: Vec<i32>, f: &Fn(i32) -> i32) -> Vec<i32> {
|
|
6
6
|
out
|
7
7
|
}
|
8
8
|
|
9
|
-
pub fn map_closure<F>(values: Vec<i32>, f: F) -> Vec<i32>
|
9
|
+
pub fn map_closure<F>(values: Vec<i32>, f: F) -> Vec<i32>
|
10
|
+
where
|
11
|
+
F: Fn(i32) -> i32,
|
12
|
+
{
|
10
13
|
let mut out: Vec<i32> = vec![];
|
11
14
|
for val in values {
|
12
15
|
out.push(f(val))
|
@@ -1,9 +1,10 @@
|
|
1
1
|
pub fn abbreviate(phrase: &str) -> String {
|
2
|
-
phrase
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
phrase
|
3
|
+
.split(|c: char| c.is_whitespace() || !c.is_alphanumeric())
|
4
|
+
.flat_map(|word| split_camel(word))
|
5
|
+
.filter_map(|word| word.chars().next())
|
6
|
+
.collect::<String>()
|
7
|
+
.to_uppercase()
|
7
8
|
}
|
8
9
|
|
9
10
|
fn split_camel(phrase: &str) -> Vec<String> {
|
@@ -38,7 +38,11 @@ pub enum Error {
|
|
38
38
|
/// * Never output leading 0 digits. However, your function must be able to
|
39
39
|
/// process input with leading 0 digits.
|
40
40
|
///
|
41
|
-
pub fn convert<P: AsRef<[Digit]>>(
|
41
|
+
pub fn convert<P: AsRef<[Digit]>>(
|
42
|
+
digits: P,
|
43
|
+
from_base: Digit,
|
44
|
+
to_base: Digit,
|
45
|
+
) -> Result<Vec<Digit>, Error> {
|
42
46
|
// check that both bases are in the correct range
|
43
47
|
if from_base < 2 {
|
44
48
|
return Err(Error::InvalidInputBase);
|
@@ -53,7 +57,9 @@ pub fn convert<P: AsRef<[Digit]>>(digits: P, from_base: Digit, to_base: Digit) -
|
|
53
57
|
}
|
54
58
|
|
55
59
|
// convert all digits into a single large number
|
56
|
-
let mut immediate = digits
|
60
|
+
let mut immediate = digits
|
61
|
+
.as_ref()
|
62
|
+
.iter()
|
57
63
|
.rev()
|
58
64
|
.enumerate()
|
59
65
|
.map(|(i, &num)| num * from_base.pow(i as u32))
|
@@ -1,7 +1,16 @@
|
|
1
1
|
pub struct Allergies(pub usize);
|
2
2
|
|
3
3
|
#[derive(PartialEq, Debug)]
|
4
|
-
pub enum Allergen {
|
4
|
+
pub enum Allergen {
|
5
|
+
Eggs,
|
6
|
+
Peanuts,
|
7
|
+
Shellfish,
|
8
|
+
Strawberries,
|
9
|
+
Tomatoes,
|
10
|
+
Chocolate,
|
11
|
+
Pollen,
|
12
|
+
Cats,
|
13
|
+
}
|
5
14
|
|
6
15
|
impl Allergies {
|
7
16
|
pub fn new(score: usize) -> Allergies {
|
@@ -10,17 +19,30 @@ impl Allergies {
|
|
10
19
|
|
11
20
|
pub fn is_allergic_to(&self, allergen: &Allergen) -> bool {
|
12
21
|
let allergens = Allergies::allergens();
|
13
|
-
let index = allergens
|
22
|
+
let index = allergens
|
23
|
+
.iter()
|
24
|
+
.position(|x: &Allergen| x == allergen)
|
25
|
+
.unwrap();
|
14
26
|
(self.0 & (1 << index)) != 0
|
15
27
|
}
|
16
28
|
|
17
29
|
pub fn allergies(&self) -> Vec<Allergen> {
|
18
|
-
Allergies::allergens()
|
30
|
+
Allergies::allergens()
|
31
|
+
.into_iter()
|
32
|
+
.filter(|allergen| self.is_allergic_to(allergen))
|
33
|
+
.collect()
|
19
34
|
}
|
20
35
|
|
21
36
|
fn allergens() -> Vec<Allergen> {
|
22
|
-
vec![
|
23
|
-
Allergen::
|
24
|
-
Allergen::
|
37
|
+
vec![
|
38
|
+
Allergen::Eggs,
|
39
|
+
Allergen::Peanuts,
|
40
|
+
Allergen::Shellfish,
|
41
|
+
Allergen::Strawberries,
|
42
|
+
Allergen::Tomatoes,
|
43
|
+
Allergen::Chocolate,
|
44
|
+
Allergen::Pollen,
|
45
|
+
Allergen::Cats,
|
46
|
+
]
|
25
47
|
}
|
26
48
|
}
|
@@ -6,14 +6,14 @@ extern crate permutohedron;
|
|
6
6
|
use itertools::Itertools;
|
7
7
|
use permutohedron::Heap as Permutations;
|
8
8
|
|
9
|
-
|
9
|
+
use std::char;
|
10
10
|
use std::collections::HashMap;
|
11
11
|
use std::collections::HashSet;
|
12
|
-
use std::char;
|
13
12
|
|
14
13
|
fn test_equation(puzzle: &str, substitutions: &HashMap<char, u8>) -> bool {
|
15
14
|
// Create a new String with characters changed to numbers
|
16
|
-
let puzzle: String = puzzle
|
15
|
+
let puzzle: String = puzzle
|
16
|
+
.chars()
|
17
17
|
.map(|c| {
|
18
18
|
if let Some(&n) = substitutions.get(&c) {
|
19
19
|
// If the character is in the substitutions, get the number and
|
@@ -33,13 +33,20 @@ fn test_equation(puzzle: &str, substitutions: &HashMap<char, u8>) -> bool {
|
|
33
33
|
let right = equation[1].trim().parse::<u32>().unwrap();
|
34
34
|
|
35
35
|
// Sum the parts on the left side
|
36
|
-
let left: u32 = equation[0]
|
36
|
+
let left: u32 = equation[0]
|
37
|
+
.split('+')
|
38
|
+
.map(str::trim)
|
39
|
+
.map(|n| n.parse::<u32>().unwrap())
|
40
|
+
.sum();
|
37
41
|
|
38
42
|
// Create a String with just the numbers and spaces
|
39
|
-
let just_numbers =
|
40
|
-
|
43
|
+
let just_numbers = puzzle
|
44
|
+
.chars()
|
45
|
+
.filter(|c| c.is_digit(10) || c.is_whitespace())
|
46
|
+
.collect::<String>();
|
41
47
|
// Split this into the numbers and check every number's first character
|
42
|
-
let no_leading_zeroes = just_numbers
|
48
|
+
let no_leading_zeroes = just_numbers
|
49
|
+
.split_whitespace()
|
43
50
|
.all(|number| number.chars().next().unwrap() != '0');
|
44
51
|
|
45
52
|
// Return true if left and right side is equal and the equation doesnt
|
@@ -47,11 +54,12 @@ fn test_equation(puzzle: &str, substitutions: &HashMap<char, u8>) -> bool {
|
|
47
54
|
left == right && no_leading_zeroes
|
48
55
|
}
|
49
56
|
|
50
|
-
|
51
57
|
pub fn solve(puzzle: &str) -> Option<HashMap<char, u8>> {
|
52
58
|
// Get unique letters from the puzzle
|
53
|
-
let letters: HashSet<char> =
|
54
|
-
|
59
|
+
let letters: HashSet<char> = puzzle
|
60
|
+
.chars()
|
61
|
+
.filter(|&c| c.is_alphabetic() && c.is_uppercase())
|
62
|
+
.collect();
|
55
63
|
let letters: Vec<char> = letters.into_iter().collect();
|
56
64
|
|
57
65
|
// All available numbers for substitution
|
@@ -7,8 +7,12 @@ fn sort(word: &String) -> String {
|
|
7
7
|
pub fn anagrams_for<'a>(word: &str, inputs: &[&'a str]) -> Vec<&'a str> {
|
8
8
|
let lower = word.to_lowercase();
|
9
9
|
let sorted = sort(&lower);
|
10
|
-
inputs
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
inputs
|
11
|
+
.iter()
|
12
|
+
.filter(|input| {
|
13
|
+
let input_lower = input.to_lowercase();
|
14
|
+
lower != input_lower && sorted == sort(&input_lower)
|
15
|
+
})
|
16
|
+
.cloned()
|
17
|
+
.collect()
|
14
18
|
}
|
@@ -12,23 +12,23 @@ fn get_transpose(ch: char) -> char {
|
|
12
12
|
|
13
13
|
pub fn encode(plaintext: &str) -> String {
|
14
14
|
plaintext
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
.to_lowercase()
|
16
|
+
.chars()
|
17
|
+
.filter(|&ch| ch.is_ascii())
|
18
|
+
.filter(|&ch| ch.is_alphanumeric())
|
19
|
+
.map(|ch| get_transpose(ch))
|
20
|
+
.collect::<Vec<char>>()
|
21
|
+
.chunks(5)
|
22
|
+
.map(|slice| slice.iter().cloned().collect::<String>())
|
23
|
+
.collect::<Vec<String>>()
|
24
|
+
.join(" ")
|
25
25
|
}
|
26
26
|
|
27
27
|
pub fn decode(ciphertext: &str) -> String {
|
28
28
|
ciphertext
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
.split::<char>(' ')
|
30
|
+
.collect::<String>()
|
31
|
+
.chars()
|
32
|
+
.map(|ch| get_transpose(ch))
|
33
|
+
.collect::<String>()
|
34
34
|
}
|
@@ -1,22 +1,28 @@
|
|
1
1
|
pub fn verse(n: i32) -> String {
|
2
2
|
match n {
|
3
3
|
0 => "No more bottles of beer on the wall, no more bottles of beer.\n\
|
4
|
-
Go to the store and buy some more, 99 bottles of beer on the wall.\n"
|
4
|
+
Go to the store and buy some more, 99 bottles of beer on the wall.\n"
|
5
|
+
.to_string(),
|
5
6
|
1 => "1 bottle of beer on the wall, 1 bottle of beer.\n\
|
6
|
-
Take it down and pass it around, no more bottles of beer on the wall.\n"
|
7
|
+
Take it down and pass it around, no more bottles of beer on the wall.\n"
|
8
|
+
.to_string(),
|
7
9
|
2 => "2 bottles of beer on the wall, 2 bottles of beer.\n\
|
8
|
-
Take one down and pass it around, 1 bottle of beer on the wall.\n"
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
Take one down and pass it around, 1 bottle of beer on the wall.\n"
|
11
|
+
.to_string(),
|
12
|
+
n if n > 2 && n <= 99 => format!(
|
13
|
+
"{n} bottles of beer on the wall, {n} bottles of beer.\n\
|
14
|
+
Take one down and pass it around, {n_minus_1} bottles of beer on the wall.\n",
|
15
|
+
n = n,
|
16
|
+
n_minus_1 = n - 1
|
17
|
+
),
|
18
|
+
_ => panic!(),
|
17
19
|
}
|
18
20
|
}
|
19
21
|
|
20
22
|
pub fn sing(start: i32, end: i32) -> String {
|
21
|
-
(end
|
23
|
+
(end..start + 1)
|
24
|
+
.rev()
|
25
|
+
.map(|n| verse(n))
|
26
|
+
.collect::<Vec<_>>()
|
27
|
+
.join("\n")
|
22
28
|
}
|