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
1 change: 1 addition & 0 deletions exercises/accumulate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[package]
edition = "2018"
name = "accumulate"
version = "0.0.0"

Expand Down
9 changes: 4 additions & 5 deletions exercises/accumulate/tests/accumulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ fn mutating_closure() {
let mut counter = 0;
let input = vec![-2, 3, 4, -5];
let expected = vec![2, 3, 4, 5];
let result = map(input,
|x: i64| {
counter += 1;
x.abs()
});
let result = map(input, |x: i64| {
counter += 1;
x.abs()
});
assert_eq!(result, expected);
assert_eq!(counter, 4);
}
Expand Down
1 change: 1 addition & 0 deletions exercises/acronym/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[package]
edition = "2018"
name = "acronym"
version = "1.0.0"

Expand Down
2 changes: 1 addition & 1 deletion exercises/acronym/tests/acronym.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extern crate acronym;
use acronym;

#[test]
fn empty() {
Expand Down
1 change: 1 addition & 0 deletions exercises/all-your-base/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[package]
edition = "2018"
name = "allyourbase"
version = "1.0.0"
2 changes: 1 addition & 1 deletion exercises/all-your-base/tests/all-your-base.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extern crate allyourbase as ayb;
use allyourbase as ayb;

#[test]
fn single_bit_one_to_decimal() {
Expand Down
1 change: 1 addition & 0 deletions exercises/allergies/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[package]
edition = "2018"
name = "allergies"
version = "1.1.0"

2 changes: 0 additions & 2 deletions exercises/allergies/tests/allergies.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate allergies;

use allergies::*;

fn compare_allergy_vectors(expected: &[Allergen], actual: &[Allergen]) {
Expand Down
1 change: 1 addition & 0 deletions exercises/alphametics/Cargo-example.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[package]
edition = "2018"
name = "alphametics"
version = "0.0.0"

Expand Down
1 change: 1 addition & 0 deletions exercises/alphametics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[package]
edition = "2018"
name = "alphametics"
version = "1.3.0"
12 changes: 10 additions & 2 deletions exercises/alphametics/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ use std::char;
use std::collections::HashMap;
use std::collections::HashSet;

fn test_equation(coefficients: &HashMap<char, i64>, cant_be_zero: &HashSet<char>, substitutions: &HashMap<char, u8>) -> bool {
fn test_equation(
coefficients: &HashMap<char, i64>,
cant_be_zero: &HashSet<char>,
substitutions: &HashMap<char, u8>,
) -> bool {
if cant_be_zero.iter().any(|d| substitutions[d] == 0) {
return false;
}

coefficients.iter().map(|(d, &coeff)| i64::from(substitutions[d]) * coeff).sum::<i64>() == 0
coefficients
.iter()
.map(|(d, &coeff)| i64::from(substitutions[d]) * coeff)
.sum::<i64>()
== 0
}

fn letter_coefficients(puzzle: &str) -> (HashMap<char, i64>, HashSet<char>) {
Expand Down
7 changes: 5 additions & 2 deletions exercises/alphametics/tests/alphametics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extern crate alphametics;
use alphametics;
use std::collections::HashMap;

fn assert_alphametic_solution_eq(puzzle: &str, solution: &[(char, u8)]) {
Expand Down Expand Up @@ -29,7 +29,10 @@ fn test_leading_zero_solution_is_invalid() {
#[test]
#[ignore]
fn puzzle_with_two_digits_final_carry() {
assert_alphametic_solution_eq("A + A + A + A + A + A + A + A + A + A + A + B == BCC", &[('A', 9), ('B', 1), ('C', 0)]);
assert_alphametic_solution_eq(
"A + A + A + A + A + A + A + A + A + A + A + B == BCC",
&[('A', 9), ('B', 1), ('C', 0)],
);
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions exercises/anagram/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[package]
edition = "2018"
name = "anagram"
version = "0.0.0"
2 changes: 1 addition & 1 deletion exercises/anagram/tests/anagram.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extern crate anagram;
use anagram;

use std::collections::HashSet;
use std::iter::FromIterator;
Expand Down
1 change: 1 addition & 0 deletions exercises/armstrong-numbers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[package]
edition = "2018"
name = "armstrong_numbers"
version = "1.0.0"
3 changes: 2 additions & 1 deletion exercises/armstrong-numbers/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ pub fn is_armstrong_number(num: u32) -> bool {
let l = s.len();
s.chars()
.map(|c| c.to_digit(10).unwrap().pow(l as u32))
.sum::<u32>() == num
.sum::<u32>()
== num
}
1 change: 0 additions & 1 deletion exercises/armstrong-numbers/tests/armstrong-numbers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate armstrong_numbers;
use armstrong_numbers::*;

#[test]
Expand Down
1 change: 1 addition & 0 deletions exercises/atbash-cipher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[package]
edition = "2018"
name = "atbash-cipher"
version = "1.1.0"
2 changes: 1 addition & 1 deletion exercises/atbash-cipher/tests/atbash-cipher.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extern crate atbash_cipher as cipher;
use atbash_cipher as cipher;

#[test]
fn test_encode_yes() {
Expand Down
1 change: 1 addition & 0 deletions exercises/beer-song/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[package]
edition = "2018"
name = "beer-song"
version = "0.0.0"
2 changes: 1 addition & 1 deletion exercises/beer-song/tests/beer-song.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extern crate beer_song as beer;
use beer_song as beer;

#[test]
fn test_verse_0() {
Expand Down
1 change: 1 addition & 0 deletions exercises/binary-search/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[package]
edition = "2018"
name = "binary-search"
version = "1.3.0"

Expand Down
2 changes: 0 additions & 2 deletions exercises/binary-search/tests/binary-search.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate binary_search;

use binary_search::find;

#[test]
Expand Down
1 change: 1 addition & 0 deletions exercises/bob/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[package]
edition = "2018"
name = "bob"
version = "1.4.0"
2 changes: 1 addition & 1 deletion exercises/bob/tests/bob.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extern crate bob;
use bob;

fn process_response_case(phrase: &str, expected_response: &str) {
assert_eq!(bob::reply(phrase), expected_response);
Expand Down
1 change: 1 addition & 0 deletions exercises/book-store/Cargo-example.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[package]
edition = "2018"
name = "book_store"
version = "1.3.0"

Expand Down
1 change: 1 addition & 0 deletions exercises/book-store/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[package]
edition = "2018"
name = "book_store"
version = "1.3.0"

Expand Down
17 changes: 10 additions & 7 deletions exercises/book-store/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ impl Group {
}

fn price(&self) -> Price {
(self.0.borrow().len() as Price) * BOOK_PRICE * match self.0.borrow().len() {
2 => 95,
3 => 90,
4 => 80,
5 => 75,
_ => 100,
} / 100
(self.0.borrow().len() as Price)
* BOOK_PRICE
* match self.0.borrow().len() {
2 => 95,
3 => 90,
4 => 80,
5 => 75,
_ => 100,
}
/ 100
}
}

Expand Down
1 change: 0 additions & 1 deletion exercises/book-store/tests/book-store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//! [script]: https://github.com/exercism/rust/blob/master/bin/init_exercise.py
//! [canonical-data]: https://raw.githubusercontent.com/exercism/problem-specifications/master/exercises/book-store/canonical_data.json

extern crate book_store;
use book_store::*;

/// Process a single test case for the property `total`
Expand Down
1 change: 1 addition & 0 deletions exercises/bowling/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[package]
edition = "2018"
name = "bowling"
version = "1.2.0"
2 changes: 0 additions & 2 deletions exercises/bowling/tests/bowling.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate bowling;

use bowling::*;

#[test]
Expand Down
1 change: 1 addition & 0 deletions exercises/bracket-push/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[package]
edition = "2018"
name = "bracket-push"
version = "1.5.0"
3 changes: 2 additions & 1 deletion exercises/bracket-push/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ impl From<Vec<(char, char)>> for MatchingBrackets {

impl MatchingBrackets {
fn contains(&self, other: &char) -> bool {
let known = self.collection
let known = self
.collection
.keys()
.chain(self.collection.values())
.collect::<Vec<_>>();
Expand Down
5 changes: 4 additions & 1 deletion exercises/bracket-push/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub fn brackets_are_balanced(string: &str) -> bool {
unimplemented!("Check if the string \"{}\" contains balanced brackets", string);
unimplemented!(
"Check if the string \"{}\" contains balanced brackets",
string
);
}
2 changes: 0 additions & 2 deletions exercises/bracket-push/tests/bracket-push.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate bracket_push;

use bracket_push::brackets_are_balanced;

#[test]
Expand Down
1 change: 1 addition & 0 deletions exercises/circular-buffer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[package]
edition = "2018"
name = "circular-buffer"
version = "1.1.0"
1 change: 0 additions & 1 deletion exercises/circular-buffer/tests/circular-buffer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate circular_buffer;
use circular_buffer::{CircularBuffer, Error};

#[test]
Expand Down
1 change: 1 addition & 0 deletions exercises/clock/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[package]
edition = "2018"
name = "clock"
version = "2.4.0"

Expand Down
1 change: 1 addition & 0 deletions exercises/collatz-conjecture/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[package]
edition = "2018"
name = "collatz_conjecture"
version = "1.2.1"
2 changes: 0 additions & 2 deletions exercises/collatz-conjecture/tests/collatz-conjecture.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate collatz_conjecture;

use collatz_conjecture::*;

#[test]
Expand Down
1 change: 1 addition & 0 deletions exercises/crypto-square/Cargo-example.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[package]
edition = "2018"
name = "crypto-square"
version = "0.1.0"

Expand Down
1 change: 1 addition & 0 deletions exercises/crypto-square/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[package]
edition = "2018"
name = "crypto-square"
version = "0.1.0"

Expand Down
1 change: 0 additions & 1 deletion exercises/crypto-square/tests/crypto-square.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate crypto_square;
use crypto_square::encrypt;

fn test(input: &str, output: &str) {
Expand Down
1 change: 1 addition & 0 deletions exercises/custom-set/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[package]
edition = "2018"
name = "custom-set"
version = "1.0.1"
39 changes: 24 additions & 15 deletions exercises/custom-set/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,35 @@ impl<T: Ord + Clone> CustomSet<T> {
}

pub fn intersection(&self, other: &Self) -> CustomSet<T> {
CustomSet::new(&self.collection
.iter()
.cloned()
.filter(|c| other.contains(c))
.collect::<Vec<_>>())
CustomSet::new(
&self
.collection
.iter()
.cloned()
.filter(|c| other.contains(c))
.collect::<Vec<_>>(),
)
}

pub fn union(&self, other: &Self) -> CustomSet<T> {
CustomSet::new(&self.collection
.iter()
.cloned()
.chain(other.collection.iter().cloned())
.collect::<Vec<_>>())
CustomSet::new(
&self
.collection
.iter()
.cloned()
.chain(other.collection.iter().cloned())
.collect::<Vec<_>>(),
)
}

pub fn difference(&self, other: &Self) -> CustomSet<T> {
CustomSet::new(&self.collection
.iter()
.cloned()
.filter(|c| !other.contains(c))
.collect::<Vec<_>>())
CustomSet::new(
&self
.collection
.iter()
.cloned()
.filter(|c| !other.contains(c))
.collect::<Vec<_>>(),
)
}
}
1 change: 1 addition & 0 deletions exercises/decimal/Cargo-example.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[package]
edition = "2018"
name = "decimal"
version = "0.1.0"

Expand Down
1 change: 1 addition & 0 deletions exercises/decimal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[package]
edition = "2018"
name = "decimal"
version = "0.1.0"

Expand Down
3 changes: 2 additions & 1 deletion exercises/decimal/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ impl Decimal {
///
/// This reduces the decimal index, so that the raw values are easier to parse
fn reduce(&mut self) {
let extra_zeroes = self.digits
let extra_zeroes = self
.digits
.to_string() // produce a decimal representation
.chars()
.rev() // trailing values
Expand Down
1 change: 1 addition & 0 deletions exercises/diamond/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[package]
edition = "2018"
name = "diamond"
version = "1.1.0"

Expand Down
Loading