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.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/problem-specifications/exercises/yacht/description.md +14 -13
  4. data/tracks/ballerina/config.json +1 -0
  5. data/tracks/coffeescript/config.json +138 -41
  6. data/tracks/coffeescript/docs/ABOUT.md +3 -7
  7. data/tracks/coq/config.json +1 -0
  8. data/tracks/d/config.json +1 -0
  9. data/tracks/dart/config.json +1 -0
  10. data/tracks/elixir/config.json +17 -16
  11. data/tracks/elixir/docs/ABOUT.md +10 -2
  12. data/tracks/fortran/config.json +1 -0
  13. data/tracks/gnu-apl/config.json +1 -0
  14. data/tracks/go/config.json +13 -0
  15. data/tracks/go/exercises/list-ops/README.md +27 -0
  16. data/tracks/go/exercises/list-ops/example.go +99 -0
  17. data/tracks/go/exercises/list-ops/listops_test.go +291 -0
  18. data/tracks/groovy/config.json +1 -0
  19. data/tracks/haxe/config.json +1 -0
  20. data/tracks/perl5/exercises/leap/.meta/exercise-data.yaml +3 -5
  21. data/tracks/perl5/exercises/leap/.meta/solutions/Leap.pm +2 -4
  22. data/tracks/perl5/exercises/leap/Leap.pm +1 -1
  23. data/tracks/perl5/exercises/leap/leap.t +2 -2
  24. data/tracks/php/config.json +1 -0
  25. data/tracks/plsql/config.json +1 -0
  26. data/tracks/pony/config.json +1 -0
  27. data/tracks/purescript/config.json +1 -0
  28. data/tracks/reasonml/config/exercise_readme.go.tmpl +18 -2
  29. data/tracks/reasonml/exercises/anagram/README.md +15 -4
  30. data/tracks/reasonml/exercises/armstrong-numbers/README.md +3 -4
  31. data/tracks/reasonml/exercises/binary-search/README.md +14 -7
  32. data/tracks/reasonml/exercises/bob/README.md +14 -6
  33. data/tracks/reasonml/exercises/change/README.md +2 -4
  34. data/tracks/reasonml/exercises/hello-world/README.md +2 -3
  35. data/tracks/reasonml/exercises/isogram/README.md +4 -6
  36. data/tracks/reasonml/exercises/leap/README.md +14 -4
  37. data/tracks/reasonml/exercises/pangram/README.md +13 -3
  38. data/tracks/reasonml/exercises/phone-number/README.md +15 -7
  39. data/tracks/reasonml/exercises/raindrops/README.md +14 -7
  40. data/tracks/reasonml/exercises/rna-transcription/README.md +13 -3
  41. data/tracks/reasonml/exercises/roman-numerals/README.md +4 -8
  42. data/tracks/reasonml/exercises/run-length-encoding/README.md +14 -7
  43. data/tracks/reasonml/exercises/space-age/README.md +13 -3
  44. data/tracks/reasonml/exercises/word-count/README.md +18 -8
  45. data/tracks/rust/.travis.yml +1 -0
  46. data/tracks/rust/_test/check-exercises-for-authors.sh +10 -0
  47. data/tracks/rust/bin/format_exercises +2 -0
  48. data/tracks/rust/exercises/accumulate/Cargo.toml +0 -1
  49. data/tracks/rust/exercises/accumulate/example.rs +4 -1
  50. data/tracks/rust/exercises/acronym/example.rs +6 -5
  51. data/tracks/rust/exercises/acronym/tests/acronym.rs +1 -1
  52. data/tracks/rust/exercises/all-your-base/example.rs +8 -2
  53. data/tracks/rust/exercises/allergies/example.rs +28 -6
  54. data/tracks/rust/exercises/alphametics/example.rs +18 -10
  55. data/tracks/rust/exercises/anagram/example.rs +8 -4
  56. data/tracks/rust/exercises/atbash-cipher/example.rs +15 -15
  57. data/tracks/rust/exercises/beer-song/example.rs +18 -12
  58. data/tracks/rust/exercises/binary-search/Cargo.toml +0 -1
  59. data/tracks/rust/exercises/binary-search/example.rs +3 -4
  60. data/tracks/rust/exercises/bob/example.rs +11 -5
  61. data/tracks/rust/exercises/book-store/Cargo-example.toml +0 -1
  62. data/tracks/rust/exercises/book-store/Cargo.toml +0 -1
  63. data/tracks/rust/exercises/book-store/example.rs +15 -19
  64. data/tracks/rust/exercises/bowling/example.rs +3 -1
  65. data/tracks/rust/exercises/bracket-push/example.rs +7 -2
  66. data/tracks/rust/exercises/circular-buffer/example.rs +1 -1
  67. data/tracks/rust/exercises/clock/.meta/ALLOWED_TO_NOT_COMPILE +3 -0
  68. data/tracks/rust/exercises/clock/Cargo.toml +0 -1
  69. data/tracks/rust/exercises/clock/example.rs +5 -3
  70. data/tracks/rust/exercises/clock/src/lib.rs +14 -0
  71. data/tracks/rust/exercises/collatz-conjecture/example.rs +2 -2
  72. data/tracks/rust/exercises/crypto-square/Cargo-example.toml +0 -1
  73. data/tracks/rust/exercises/crypto-square/Cargo.toml +0 -1
  74. data/tracks/rust/exercises/custom-set/example.rs +17 -15
  75. data/tracks/rust/exercises/decimal/Cargo-example.toml +0 -1
  76. data/tracks/rust/exercises/decimal/Cargo.toml +0 -1
  77. data/tracks/rust/exercises/decimal/example.rs +5 -5
  78. data/tracks/rust/exercises/diamond/Cargo.toml +0 -1
  79. data/tracks/rust/exercises/difference-of-squares/example.rs +1 -1
  80. data/tracks/rust/exercises/dominoes/example.rs +20 -19
  81. data/tracks/rust/exercises/etl/example.rs +4 -3
  82. data/tracks/rust/exercises/forth/example.rs +29 -45
  83. data/tracks/rust/exercises/grade-school/example.rs +4 -2
  84. data/tracks/rust/exercises/hexadecimal/example.rs +2 -4
  85. data/tracks/rust/exercises/isbn-verifier/example.rs +5 -6
  86. data/tracks/rust/exercises/isbn-verifier/tests/isbn-verifier.rs +12 -0
  87. data/tracks/rust/exercises/isogram/example.rs +9 -3
  88. data/tracks/rust/exercises/largest-series-product/example.rs +2 -1
  89. data/tracks/rust/exercises/luhn-from/example.rs +3 -1
  90. data/tracks/rust/exercises/luhn/example.rs +5 -3
  91. data/tracks/rust/exercises/macros/Cargo.toml +0 -1
  92. data/tracks/rust/exercises/nth-prime/Cargo.toml +0 -1
  93. data/tracks/rust/exercises/nth-prime/example.rs +6 -6
  94. data/tracks/rust/exercises/nucleotide-codons/Cargo.toml +0 -1
  95. data/tracks/rust/exercises/nucleotide-codons/example.rs +23 -17
  96. data/tracks/rust/exercises/nucleotide-count/example.rs +15 -5
  97. data/tracks/rust/exercises/nucleotide-count/src/lib.rs +15 -0
  98. data/tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs +3 -3
  99. data/tracks/rust/exercises/palindrome-products/Cargo.toml +0 -1
  100. data/tracks/rust/exercises/pangram/example.rs +6 -6
  101. data/tracks/rust/exercises/parallel-letter-frequency/example.rs +7 -4
  102. data/tracks/rust/exercises/pascals-triangle/example.rs +6 -2
  103. data/tracks/rust/exercises/perfect-numbers/example.rs +2 -2
  104. data/tracks/rust/exercises/phone-number/example.rs +11 -15
  105. data/tracks/rust/exercises/pig-latin/Cargo-example.toml +0 -1
  106. data/tracks/rust/exercises/pig-latin/Cargo.toml +0 -1
  107. data/tracks/rust/exercises/pig-latin/example.rs +6 -2
  108. data/tracks/rust/exercises/poker/Cargo-example.toml +0 -1
  109. data/tracks/rust/exercises/poker/Cargo.toml +0 -1
  110. data/tracks/rust/exercises/poker/example.rs +9 -8
  111. data/tracks/rust/exercises/prime-factors/Cargo.toml +0 -1
  112. data/tracks/rust/exercises/prime-factors/example.rs +1 -1
  113. data/tracks/rust/exercises/protein-translation/Cargo.toml +0 -1
  114. data/tracks/rust/exercises/protein-translation/example.rs +6 -5
  115. data/tracks/rust/exercises/proverb/Cargo.toml +0 -1
  116. data/tracks/rust/exercises/proverb/example.rs +0 -1
  117. data/tracks/rust/exercises/pythagorean-triplet/Cargo.toml +0 -1
  118. data/tracks/rust/exercises/pythagorean-triplet/example.rs +3 -3
  119. data/tracks/rust/exercises/queen-attack/example.rs +3 -3
  120. data/tracks/rust/exercises/react/example.rs +61 -29
  121. data/tracks/rust/exercises/reverse-string/Cargo.toml +0 -1
  122. data/tracks/rust/exercises/rna-transcription/example.rs +17 -9
  123. data/tracks/rust/exercises/robot-name/example.rs +4 -3
  124. data/tracks/rust/exercises/robot-simulator/example.rs +5 -2
  125. data/tracks/rust/exercises/roman-numerals/example.rs +15 -14
  126. data/tracks/rust/exercises/rotational-cipher/Cargo.toml +0 -1
  127. data/tracks/rust/exercises/rotational-cipher/example.rs +10 -14
  128. data/tracks/rust/exercises/rotational-cipher/src/lib.rs +7 -1
  129. data/tracks/rust/exercises/run-length-encoding/Cargo.toml +0 -1
  130. data/tracks/rust/exercises/run-length-encoding/example.rs +34 -29
  131. data/tracks/rust/exercises/saddle-points/example.rs +0 -1
  132. data/tracks/rust/exercises/say/Cargo.toml +0 -1
  133. data/tracks/rust/exercises/say/example.rs +34 -8
  134. data/tracks/rust/exercises/series/example.rs +6 -8
  135. data/tracks/rust/exercises/simple-linked-list/example.rs +0 -2
  136. data/tracks/rust/exercises/spiral-matrix/example.rs +0 -1
  137. data/tracks/rust/exercises/tournament/example.rs +33 -20
  138. data/tracks/rust/exercises/triangle/example.rs +1 -1
  139. data/tracks/rust/exercises/two-bucket/example.rs +2 -6
  140. data/tracks/rust/exercises/two-fer/example.rs +3 -3
  141. data/tracks/rust/exercises/variable-length-quantity/example.rs +2 -3
  142. data/tracks/rust/exercises/word-count/example.rs +4 -1
  143. data/tracks/rust/exercises/wordy/example.rs +10 -4
  144. 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
- # Build + Watch
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 start
28
+ npm install
25
29
  ```
26
30
 
27
- # Test + Watch
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
- # Build
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 run build
33
+ npm install
29
34
  ```
30
35
 
31
- # Build + Watch
32
-
36
+ Open two shells, and in the first, start the build process.
33
37
  ```
34
- npm run start
38
+ npm start
35
39
  ```
36
40
 
41
+ In the second, start the tests running.
42
+ ```
43
+ npm test
44
+ ```
37
45
 
38
- # Editor
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
- # Build + Watch
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 start
27
+ npm install
24
28
  ```
25
29
 
26
- # Test + Watch
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
- # Build
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 run build
21
+ npm install
14
22
  ```
15
23
 
16
- # Build + Watch
17
-
24
+ Open two shells, and in the first, start the build process.
18
25
  ```
19
- npm run start
26
+ npm start
20
27
  ```
21
28
 
29
+ In the second, start the tests running.
30
+ ```
31
+ npm test
32
+ ```
22
33
 
23
- # Editor
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.
@@ -10,6 +10,7 @@ script:
10
10
  - "sh ./_test/ensure-readmes-are-updated.sh"
11
11
  - "./bin/configlet lint ."
12
12
  - "./_test/verify-exercise-difficulties.sh"
13
+ - "./_test/check-exercises-for-authors.sh"
13
14
  sudo: false
14
15
  rust:
15
16
  - stable
@@ -0,0 +1,10 @@
1
+ #!/bin/sh
2
+
3
+ repo=$(cd "$(dirname "$0")/.." && pwd)
4
+
5
+ grep -rnw "$repo/exercises/" --include="*.toml" -e "authors"
6
+
7
+ if [ $? -eq 0 ]; then
8
+ echo "Found 'authors' field in exercises";
9
+ exit 1;
10
+ fi
@@ -25,6 +25,8 @@ for exercise_dir in ${EXERCISES_PATH}/*; do
25
25
  cd "$exercise_dir"
26
26
 
27
27
  cargo fmt
28
+
29
+ [ -f example.rs ] && rustfmt example.rs
28
30
  )
29
31
  fi
30
32
 
@@ -1,6 +1,5 @@
1
1
  [package]
2
2
  name = "accumulate"
3
3
  version = "0.0.0"
4
- authors = ["sacherjj <sacherjj@gmail.com>"]
5
4
 
6
5
  [dependencies]
@@ -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> where F: Fn(i32) -> 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.split(|c: char| c.is_whitespace() || !c.is_alphanumeric())
3
- .flat_map(|word| split_camel(word))
4
- .filter_map(|word| word.chars().next())
5
- .collect::<String>()
6
- .to_uppercase()
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> {
@@ -2,7 +2,7 @@ extern crate acronym;
2
2
 
3
3
  #[test]
4
4
  fn empty() {
5
- assert_eq!(acronym::abbreviate(""), "");
5
+ assert_eq!(acronym::abbreviate(""), "");
6
6
  }
7
7
 
8
8
  #[test]
@@ -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]>>(digits: P, from_base: Digit, to_base: Digit) -> Result<Vec<Digit>, Error> {
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.as_ref().iter()
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 { Eggs, Peanuts, Shellfish, Strawberries, Tomatoes, Chocolate, Pollen, Cats }
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.iter().position(|x: &Allergen| x == allergen).unwrap();
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().into_iter().filter(|allergen| self.is_allergic_to(allergen)).collect()
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![Allergen::Eggs, Allergen::Peanuts, Allergen::Shellfish,
23
- Allergen::Strawberries, Allergen::Tomatoes, Allergen::Chocolate,
24
- Allergen::Pollen, Allergen::Cats]
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.chars()
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].split('+').map(str::trim).map(|n| n.parse::<u32>().unwrap()).sum();
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
- puzzle.chars().filter(|c| c.is_digit(10) || c.is_whitespace()).collect::<String>();
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.split_whitespace()
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
- puzzle.chars().filter(|&c| c.is_alphabetic() && c.is_uppercase()).collect();
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.iter().filter(|input| {
11
- let input_lower = input.to_lowercase();
12
- lower != input_lower && sorted == sort(&input_lower)
13
- }).cloned().collect()
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
- .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(" ")
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
- .split::<char>(' ')
30
- .collect::<String>()
31
- .chars()
32
- .map(|ch| get_transpose(ch))
33
- .collect::<String>()
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".to_string(),
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".to_string(),
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".to_string(),
9
- n if n > 2 && n <= 99 =>
10
- format!(
11
- "{n} bottles of beer on the wall, {n} bottles of beer.\n\
12
- Take one down and pass it around, {n_minus_1} bottles of beer on the wall.\n",
13
- n=n,
14
- n_minus_1=n - 1),
15
- _ =>
16
- panic!(),
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 .. start + 1).rev().map(|n| verse(n)).collect::<Vec<_>>().join("\n")
23
+ (end..start + 1)
24
+ .rev()
25
+ .map(|n| verse(n))
26
+ .collect::<Vec<_>>()
27
+ .join("\n")
22
28
  }