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
@@ -1,6 +1,5 @@
1
1
  [package]
2
2
  name = "binary-search"
3
3
  version = "1.1.0"
4
- authors = ["<marco.stahl@mailbox.org>"]
5
4
 
6
5
  [dependencies]
@@ -1,10 +1,9 @@
1
1
  use std::cmp::Ordering;
2
2
 
3
3
  pub fn find<C, T>(elements: C, needle: T) -> Option<usize>
4
- where
5
- C: AsRef<[T]>,
6
- T: Ord,
7
-
4
+ where
5
+ C: AsRef<[T]>,
6
+ T: Ord,
8
7
  {
9
8
  let mut base = 0usize;
10
9
  let mut slice: &[T] = elements.as_ref();
@@ -1,9 +1,15 @@
1
1
  pub fn reply(message: &str) -> &str {
2
- if is_silence(message) { "Fine. Be that way!" }
3
- else if is_yelling(message) && is_question(message) { "Calm down, I know what I'm doing!" }
4
- else if is_yelling(message) { "Whoa, chill out!" }
5
- else if is_question(message) { "Sure." }
6
- else { "Whatever." }
2
+ if is_silence(message) {
3
+ "Fine. Be that way!"
4
+ } else if is_yelling(message) && is_question(message) {
5
+ "Calm down, I know what I'm doing!"
6
+ } else if is_yelling(message) {
7
+ "Whoa, chill out!"
8
+ } else if is_question(message) {
9
+ "Sure."
10
+ } else {
11
+ "Whatever."
12
+ }
7
13
  }
8
14
 
9
15
  fn is_silence(message: &str) -> bool {
@@ -1,6 +1,5 @@
1
1
  [package]
2
2
  name = "book_store"
3
3
  version = "1.3.0"
4
- authors = ["Peter Goodspeed-Niklaus <peter.r.goodspeedniklaus@gmail.com>"]
5
4
 
6
5
  [dependencies]
@@ -1,6 +1,5 @@
1
1
  [package]
2
2
  name = "book_store"
3
3
  version = "1.3.0"
4
- authors = ["Peter Goodspeed-Niklaus <peter.r.goodspeedniklaus@gmail.com>"]
5
4
 
6
5
  [dependencies]
@@ -1,9 +1,9 @@
1
+ use std::cell::RefCell;
1
2
  use std::cmp::Ordering;
2
- use std::collections::{BTreeSet, HashSet};
3
3
  use std::collections::hash_map::DefaultHasher;
4
+ use std::collections::{BTreeSet, HashSet};
4
5
  use std::hash::{Hash, Hasher};
5
6
  use std::mem;
6
- use std::cell::RefCell;
7
7
 
8
8
  type Book = usize;
9
9
  type GroupedBasket = Vec<Group>;
@@ -25,18 +25,16 @@ impl Group {
25
25
  }
26
26
 
27
27
  fn price(&self) -> Price {
28
- (self.0.borrow().len() as Price) * BOOK_PRICE *
29
- match self.0.borrow().len() {
30
- 2 => 95,
31
- 3 => 90,
32
- 4 => 80,
33
- 5 => 75,
34
- _ => 100,
35
- } / 100
28
+ (self.0.borrow().len() as Price) * BOOK_PRICE * match self.0.borrow().len() {
29
+ 2 => 95,
30
+ 3 => 90,
31
+ 4 => 80,
32
+ 5 => 75,
33
+ _ => 100,
34
+ } / 100
36
35
  }
37
36
  }
38
37
 
39
-
40
38
  impl Ord for Group {
41
39
  // we want to order groups first by qty contained DESC, then by lowest value ASC
42
40
  fn cmp(&self, other: &Group) -> Ordering {
@@ -45,14 +43,12 @@ impl Ord for Group {
45
43
  if self.0.borrow().len() == 0 {
46
44
  Ordering::Equal
47
45
  } else {
48
- self.0.borrow().iter().next().unwrap().cmp(
49
- other
50
- .0
51
- .borrow()
52
- .iter()
53
- .next()
54
- .unwrap(),
55
- )
46
+ self.0
47
+ .borrow()
48
+ .iter()
49
+ .next()
50
+ .unwrap()
51
+ .cmp(other.0.borrow().iter().next().unwrap())
56
52
  }
57
53
  }
58
54
  otherwise => otherwise,
@@ -98,7 +98,9 @@ impl Frame {
98
98
 
99
99
  impl BowlingGame {
100
100
  pub fn new() -> Self {
101
- BowlingGame { frames: vec![Frame::new()] }
101
+ BowlingGame {
102
+ frames: vec![Frame::new()],
103
+ }
102
104
  }
103
105
 
104
106
  pub fn roll(&mut self, pins: u16) -> Result<(), Error> {
@@ -45,13 +45,18 @@ pub struct MatchingBrackets {
45
45
 
46
46
  impl From<Vec<(char, char)>> for MatchingBrackets {
47
47
  fn from(v: Vec<(char, char)>) -> Self {
48
- MatchingBrackets { collection: v.into_iter().collect::<HashMap<char, char>>() }
48
+ MatchingBrackets {
49
+ collection: v.into_iter().collect::<HashMap<char, char>>(),
50
+ }
49
51
  }
50
52
  }
51
53
 
52
54
  impl MatchingBrackets {
53
55
  fn contains(&self, other: &char) -> bool {
54
- let known = self.collection.keys().chain(self.collection.values()).collect::<Vec<_>>();
56
+ let known = self.collection
57
+ .keys()
58
+ .chain(self.collection.values())
59
+ .collect::<Vec<_>>();
55
60
  known.contains(&other)
56
61
  }
57
62
 
@@ -19,7 +19,7 @@ impl<T: Default + Clone> CircularBuffer<T> {
19
19
  buffer: vec![T::default(); size + 1],
20
20
  size: size + 1,
21
21
  start: 0,
22
- end: 0
22
+ end: 0,
23
23
  }
24
24
  }
25
25
 
@@ -0,0 +1,3 @@
1
+ Stub doesn't compile because there is no to_string() implementation.
2
+ This exercise is an introduction to derived and self-implemented traits,
3
+ therefore adding template for a trait would reduce student learning.
@@ -1,6 +1,5 @@
1
1
  [package]
2
2
  name = "clock"
3
3
  version = "1.0.0"
4
- authors = ["sacherjj <sacherjj@gmail.com>"]
5
4
 
6
5
  [dependencies]
@@ -1,8 +1,8 @@
1
1
  use std::fmt;
2
2
 
3
- #[derive(Eq,PartialEq,Debug)]
3
+ #[derive(Eq, PartialEq, Debug)]
4
4
  pub struct Clock {
5
- minutes: i32
5
+ minutes: i32,
6
6
  }
7
7
 
8
8
  impl fmt::Display for Clock {
@@ -23,7 +23,9 @@ impl Clock {
23
23
  while mins < 0 {
24
24
  mins += 1440;
25
25
  }
26
- Clock { minutes: mins % 1440 }
26
+ Clock {
27
+ minutes: mins % 1440,
28
+ }
27
29
  }
28
30
 
29
31
  pub fn add_minutes(&mut self, minutes: i32) -> Self {
@@ -1 +1,15 @@
1
+ pub struct Clock;
1
2
 
3
+ impl Clock {
4
+ pub fn new(hours: i32, minutes: i32) -> Self {
5
+ unimplemented!(
6
+ "Construct a new Clock from {} hours and {} minutes",
7
+ hours,
8
+ minutes
9
+ );
10
+ }
11
+
12
+ pub fn add_minutes(self, minutes: i32) -> Self {
13
+ unimplemented!("Add {} minutes to existing Clock time", minutes);
14
+ }
15
+ }
@@ -1,10 +1,10 @@
1
1
  pub fn collatz_positive(n: u64) -> u64 {
2
2
  if n == 1 {
3
3
  0
4
- } else {
4
+ } else {
5
5
  1 + match n % 2 {
6
6
  0 => collatz_positive(n / 2),
7
- _ => collatz_positive(n * 3 + 1)
7
+ _ => collatz_positive(n * 3 + 1),
8
8
  }
9
9
  }
10
10
  }
@@ -1,7 +1,6 @@
1
1
  [package]
2
2
  name = "crypto-square"
3
3
  version = "0.1.0"
4
- authors = ["Peter Goodspeed-Niklaus <peter.r.goodspeedniklaus@gmail.com>"]
5
4
 
6
5
  [dependencies]
7
6
  itertools = "0.6.1"
@@ -1,6 +1,5 @@
1
1
  [package]
2
2
  name = "crypto-square"
3
3
  version = "0.1.0"
4
- authors = ["Peter Goodspeed-Niklaus <peter.r.goodspeedniklaus@gmail.com>"]
5
4
 
6
5
  [dependencies]
@@ -5,14 +5,16 @@ pub struct CustomSet<T> {
5
5
 
6
6
  impl<T: Ord + Clone> PartialEq for CustomSet<T> {
7
7
  fn eq(&self, other: &Self) -> bool {
8
- self.collection.iter().all(|x| other.contains(&x)) &&
9
- other.collection.iter().all(|x| self.contains(&x))
8
+ self.collection.iter().all(|x| other.contains(&x))
9
+ && other.collection.iter().all(|x| self.contains(&x))
10
10
  }
11
11
  }
12
12
 
13
13
  impl<T: Ord + Clone> CustomSet<T> {
14
14
  pub fn new(inputs: &[T]) -> CustomSet<T> {
15
- let mut s = CustomSet { collection: Vec::new() };
15
+ let mut s = CustomSet {
16
+ collection: Vec::new(),
17
+ };
16
18
  for input in inputs {
17
19
  s.add(input.clone());
18
20
  }
@@ -43,25 +45,25 @@ impl<T: Ord + Clone> CustomSet<T> {
43
45
 
44
46
  pub fn intersection(&self, other: &Self) -> CustomSet<T> {
45
47
  CustomSet::new(&self.collection
46
- .iter()
47
- .cloned()
48
- .filter(|c| other.contains(c))
49
- .collect::<Vec<_>>())
48
+ .iter()
49
+ .cloned()
50
+ .filter(|c| other.contains(c))
51
+ .collect::<Vec<_>>())
50
52
  }
51
53
 
52
54
  pub fn union(&self, other: &Self) -> CustomSet<T> {
53
55
  CustomSet::new(&self.collection
54
- .iter()
55
- .cloned()
56
- .chain(other.collection.iter().cloned())
57
- .collect::<Vec<_>>())
56
+ .iter()
57
+ .cloned()
58
+ .chain(other.collection.iter().cloned())
59
+ .collect::<Vec<_>>())
58
60
  }
59
61
 
60
62
  pub fn difference(&self, other: &Self) -> CustomSet<T> {
61
63
  CustomSet::new(&self.collection
62
- .iter()
63
- .cloned()
64
- .filter(|c| !other.contains(c))
65
- .collect::<Vec<_>>())
64
+ .iter()
65
+ .cloned()
66
+ .filter(|c| !other.contains(c))
67
+ .collect::<Vec<_>>())
66
68
  }
67
69
  }
@@ -1,7 +1,6 @@
1
1
  [package]
2
2
  name = "decimal"
3
3
  version = "0.1.0"
4
- authors = ["Peter Goodspeed-Niklaus <peter.r.goodspeedniklaus@gmail.com>"]
5
4
 
6
5
  [dependencies]
7
6
  try_opt = "0.1.1"
@@ -1,6 +1,5 @@
1
1
  [package]
2
2
  name = "decimal"
3
3
  version = "0.1.0"
4
- authors = ["Peter Goodspeed-Niklaus <peter.r.goodspeedniklaus@gmail.com>"]
5
4
 
6
5
  [dependencies]
@@ -1,6 +1,6 @@
1
1
  use std::cmp::Ordering;
2
2
  use std::fmt;
3
- use std::ops::{Add, Sub, Mul};
3
+ use std::ops::{Add, Mul, Sub};
4
4
 
5
5
  #[macro_use]
6
6
  extern crate try_opt;
@@ -71,8 +71,8 @@ impl Decimal {
71
71
  let precision_difference =
72
72
  (higher_precision.decimal_index - lower_precision.decimal_index) as usize;
73
73
 
74
- lower_precision.digits = &lower_precision.digits *
75
- pow(BigInt::from(10_usize), precision_difference);
74
+ lower_precision.digits =
75
+ &lower_precision.digits * pow(BigInt::from(10_usize), precision_difference);
76
76
  lower_precision.decimal_index += precision_difference;
77
77
  }
78
78
  if one.decimal_index < two.decimal_index {
@@ -111,7 +111,7 @@ macro_rules! auto_impl_decimal_ops {
111
111
  )
112
112
  }
113
113
  }
114
- }
114
+ };
115
115
  }
116
116
 
117
117
  auto_impl_decimal_ops!(Add, add, |s, o| s + o, |s, _| s);
@@ -136,7 +136,7 @@ macro_rules! auto_impl_decimal_cow {
136
136
  }
137
137
  }
138
138
  }
139
- }
139
+ };
140
140
  }
141
141
 
142
142
  auto_impl_decimal_cow!(PartialEq, eq, |a, b| a == b, bool);
@@ -1,6 +1,5 @@
1
1
  [package]
2
2
  name = "diamond"
3
3
  version = "1.1.0"
4
- authors = ["Kirill Meng <kimeng@htwg-konstanz.de>"]
5
4
 
6
5
  [dependencies]
@@ -4,7 +4,7 @@ pub fn square_of_sum(n: usize) -> usize {
4
4
  }
5
5
 
6
6
  pub fn sum_of_squares(n: usize) -> usize {
7
- (0..n+1).map(|x| x*x).fold(0, |accum, x| accum + x)
7
+ (0..n + 1).map(|x| x * x).fold(0, |accum, x| accum + x)
8
8
  }
9
9
 
10
10
  pub fn difference(n: usize) -> usize {
@@ -8,29 +8,30 @@ pub type Domino = (usize, usize);
8
8
  /// dots and row dots. Positions are mirrored ((3,4) == (4,3)), except for positions with equal row
9
9
  /// and column numbers.
10
10
  struct AvailabilityTable {
11
- m: Vec<usize>
11
+ m: Vec<usize>,
12
12
  }
13
13
 
14
14
  impl AvailabilityTable {
15
15
  fn new() -> AvailabilityTable {
16
- AvailabilityTable { m: iter::repeat(0).take(6 * 6).collect() }
16
+ AvailabilityTable {
17
+ m: iter::repeat(0).take(6 * 6).collect(),
18
+ }
17
19
  }
18
20
 
19
21
  fn get(&self, x: usize, y: usize) -> usize {
20
- self.m[(x-1) * 6 + (y-1)]
22
+ self.m[(x - 1) * 6 + (y - 1)]
21
23
  }
22
24
 
23
25
  fn set(&mut self, x: usize, y: usize, v: usize) {
24
26
  let m = &mut self.m[..];
25
- m[(x-1) * 6 + (y-1)] = v;
27
+ m[(x - 1) * 6 + (y - 1)] = v;
26
28
  }
27
29
 
28
30
  fn add(&mut self, x: usize, y: usize) {
29
31
  if x == y {
30
32
  let n = self.get(x, y);
31
33
  self.set(x, y, n + 1) // Along the diagonal
32
- }
33
- else {
34
+ } else {
34
35
  let m = self.get(x, y);
35
36
  self.set(x, y, m + 1);
36
37
  let n = self.get(y, x);
@@ -43,25 +44,23 @@ impl AvailabilityTable {
43
44
  if x == y {
44
45
  let n = self.get(x, y);
45
46
  self.set(x, y, n - 1) // Along the diagonal
46
- }
47
- else {
47
+ } else {
48
48
  let m = self.get(x, y);
49
49
  self.set(x, y, m - 1);
50
50
  let n = self.get(y, x);
51
51
  self.set(y, x, n - 1);
52
52
  }
53
- }
54
- else {
53
+ } else {
55
54
  // For this toy code hard explicit fail is best
56
55
  panic!("remove for 0 stones: ({:?}, {:?})", x, y)
57
56
  }
58
57
  }
59
58
 
60
59
  fn pop_first(&mut self, x: usize) -> Option<usize> {
61
- for y in 1 .. 7 {
60
+ for y in 1..7 {
62
61
  if self.get(x, y) > 0 {
63
62
  self.remove(x, y);
64
- return Some(y)
63
+ return Some(y);
65
64
  }
66
65
  }
67
66
  None
@@ -70,12 +69,16 @@ impl AvailabilityTable {
70
69
 
71
70
  pub fn chain(dominoes: &[Domino]) -> Option<Vec<Domino>> {
72
71
  match dominoes.len() {
73
- 0 => Some(vec!()),
74
- 1 => if dominoes[0].0 == dominoes[0].1 { Some(vec![dominoes[0]]) } else { None },
72
+ 0 => Some(vec![]),
73
+ 1 => if dominoes[0].0 == dominoes[0].1 {
74
+ Some(vec![dominoes[0]])
75
+ } else {
76
+ None
77
+ },
75
78
  _ => {
76
79
  // First check if the total number of each amount of dots is even, if not it's not
77
80
  // possible to complete a cycle. This follows from that it's an Eulerian path.
78
- let mut v: Vec<usize> = vec!(0, 0, 0, 0, 0, 0);
81
+ let mut v: Vec<usize> = vec![0, 0, 0, 0, 0, 0];
79
82
  // Keep the mutable borrow in a small scope here to allow v.iter().
80
83
  {
81
84
  let vs = &mut v[..];
@@ -86,14 +89,13 @@ pub fn chain(dominoes: &[Domino]) -> Option<Vec<Domino>> {
86
89
  }
87
90
  for n in v.iter() {
88
91
  if n % 2 != 0 {
89
- return None
92
+ return None;
90
93
  }
91
94
  }
92
95
  let chain = chain_worker(dominoes);
93
96
  if chain.len() == dominoes.len() {
94
97
  Some(chain)
95
- }
96
- else {
98
+ } else {
97
99
  None
98
100
  }
99
101
  }
@@ -106,7 +108,6 @@ fn chain_worker(dominoes: &[Domino]) -> Vec<Domino> {
106
108
  let mut t = AvailabilityTable::new();
107
109
  for dom in doms.iter() {
108
110
  t.add(dom.0, dom.1)
109
-
110
111
  }
111
112
  let mut v: Vec<Domino> = Vec::new();
112
113
  v.push(first);