Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
7e28f98
[Sync Iteration] rust/hello-world/1
exercism-solutions-syncer[bot] Sep 23, 2025
6d25030
[Sync Iteration] rust/gigasecond/1
exercism-solutions-syncer[bot] Sep 23, 2025
53c9e68
[Sync Iteration] rust/leap/1
exercism-solutions-syncer[bot] Sep 23, 2025
a29b208
[Sync Iteration] rust/raindrops/1
exercism-solutions-syncer[bot] Sep 23, 2025
b6611cd
[Sync Iteration] rust/raindrops/2
exercism-solutions-syncer[bot] Sep 23, 2025
476f82f
[Sync Iteration] rust/reverse-string/1
exercism-solutions-syncer[bot] Sep 23, 2025
a741ba2
[Sync Iteration] rust/nth-prime/1
exercism-solutions-syncer[bot] Sep 23, 2025
ed745fc
[Sync Iteration] rust/nth-prime/2
exercism-solutions-syncer[bot] Sep 23, 2025
a1d32ee
[Sync Iteration] rust/bob/1
exercism-solutions-syncer[bot] Sep 23, 2025
2747da2
[Sync Iteration] rust/proverb/1
exercism-solutions-syncer[bot] Sep 23, 2025
524f4d5
[Sync Iteration] rust/difference-of-squares/1
exercism-solutions-syncer[bot] Sep 23, 2025
e855871
[Sync Iteration] rust/sum-of-multiples/1
exercism-solutions-syncer[bot] Sep 23, 2025
f2b456e
[Sync Iteration] rust/sum-of-multiples/2
exercism-solutions-syncer[bot] Sep 23, 2025
86509cc
[Sync Iteration] rust/grains/1
exercism-solutions-syncer[bot] Sep 23, 2025
f177a5d
[Sync Iteration] rust/grains/2
exercism-solutions-syncer[bot] Sep 23, 2025
e8e4b50
[Sync Iteration] rust/grains/3
exercism-solutions-syncer[bot] Sep 23, 2025
1521a61
[Sync Iteration] rust/prime-factors/1
exercism-solutions-syncer[bot] Sep 23, 2025
c2c62b2
[Sync Iteration] rust/prime-factors/2
exercism-solutions-syncer[bot] Sep 23, 2025
62de4b3
[Sync Iteration] rust/series/1
exercism-solutions-syncer[bot] Sep 23, 2025
f284de1
[Sync Iteration] rust/armstrong-numbers/1
exercism-solutions-syncer[bot] Sep 23, 2025
c628db4
[Sync Iteration] rust/armstrong-numbers/2
exercism-solutions-syncer[bot] Sep 23, 2025
d9d65a0
[Sync Iteration] rust/collatz-conjecture/1
exercism-solutions-syncer[bot] Sep 23, 2025
7f3a0cc
[Sync Iteration] rust/isogram/1
exercism-solutions-syncer[bot] Sep 23, 2025
82f410b
[Sync Iteration] rust/isbn-verifier/1
exercism-solutions-syncer[bot] Sep 23, 2025
68ee295
[Sync Iteration] rust/clock/1
exercism-solutions-syncer[bot] Sep 23, 2025
c31ef8c
[Sync Iteration] rust/clock/2
exercism-solutions-syncer[bot] Sep 23, 2025
bc22cff
[Sync Iteration] rust/clock/3
exercism-solutions-syncer[bot] Sep 23, 2025
a7d4459
[Sync Iteration] rust/hamming/1
exercism-solutions-syncer[bot] Sep 23, 2025
329d825
[Sync Iteration] rust/nucleotide-count/1
exercism-solutions-syncer[bot] Sep 23, 2025
3da2c5f
[Sync Iteration] rust/nucleotide-count/2
exercism-solutions-syncer[bot] Sep 23, 2025
15852de
[Sync Iteration] rust/luhn/1
exercism-solutions-syncer[bot] Sep 23, 2025
31d16b0
[Sync Iteration] rust/etl/1
exercism-solutions-syncer[bot] Sep 23, 2025
996de49
[Sync Iteration] rust/acronym/1
exercism-solutions-syncer[bot] Sep 23, 2025
011122f
[Sync Iteration] rust/acronym/2
exercism-solutions-syncer[bot] Sep 23, 2025
e8a7650
[Sync Iteration] rust/all-your-base/1
exercism-solutions-syncer[bot] Sep 23, 2025
2d8e3f9
[Sync Iteration] rust/grade-school/1
exercism-solutions-syncer[bot] Sep 23, 2025
920b0b8
[Sync Iteration] rust/binary-search/1
exercism-solutions-syncer[bot] Sep 23, 2025
2252a83
[Sync Iteration] rust/binary-search/2
exercism-solutions-syncer[bot] Sep 23, 2025
3e43134
[Sync Iteration] rust/binary-search/3
exercism-solutions-syncer[bot] Sep 23, 2025
0d91116
[Sync Iteration] rust/matching-brackets/1
exercism-solutions-syncer[bot] Sep 23, 2025
772ca0a
[Sync Iteration] rust/matching-brackets/2
exercism-solutions-syncer[bot] Sep 23, 2025
3d4f5cc
[Sync Iteration] rust/bowling/1
exercism-solutions-syncer[bot] Sep 23, 2025
19d5ef9
[Sync Iteration] rust/bowling/2
exercism-solutions-syncer[bot] Sep 23, 2025
b7a161c
[Sync Iteration] rust/sublist/1
exercism-solutions-syncer[bot] Sep 23, 2025
b6e161d
[Sync Iteration] rust/sublist/2
exercism-solutions-syncer[bot] Sep 23, 2025
8380a84
[Sync Iteration] rust/sublist/3
exercism-solutions-syncer[bot] Sep 23, 2025
b2d00c7
[Sync Iteration] rust/space-age/1
exercism-solutions-syncer[bot] Sep 23, 2025
9721b0e
[Sync Iteration] rust/allergies/1
exercism-solutions-syncer[bot] Sep 23, 2025
4276f55
[Sync Iteration] rust/anagram/1
exercism-solutions-syncer[bot] Sep 23, 2025
0b2d212
[Sync Iteration] rust/anagram/2
exercism-solutions-syncer[bot] Sep 23, 2025
62cc89c
[Sync Iteration] rust/dot-dsl/1
exercism-solutions-syncer[bot] Sep 23, 2025
967e4e0
[Sync Iteration] rust/high-scores/1
exercism-solutions-syncer[bot] Sep 23, 2025
5e19a9c
[Sync Iteration] rust/kindergarten-garden/1
exercism-solutions-syncer[bot] Sep 23, 2025
d9528b5
[Sync Iteration] rust/eliuds-eggs/1
exercism-solutions-syncer[bot] Sep 23, 2025
7682f59
[Sync Iteration] rust/bottle-song/1
exercism-solutions-syncer[bot] Sep 23, 2025
ea4718e
[Sync Iteration] rust/flower-field/1
exercism-solutions-syncer[bot] Sep 23, 2025
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
9 changes: 9 additions & 0 deletions solutions/rust/acronym/1/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "acronym"
version = "0.1.0"
edition = "2024"

# Not all libraries from crates.io are available in Exercism's test runner.
# The full list of available libraries is here:
# https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml
[dependencies]
25 changes: 25 additions & 0 deletions solutions/rust/acronym/1/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
fn find_camel_case(word:&str) -> String {
let mut camel_case_letter = String::new();
let ch_word:Vec<char> = word.chars().collect();
for (index, ch) in ch_word.iter().enumerate() {
if let Some(next_ch) = ch_word.get(index+1) {
if ch.is_uppercase() && index > 0 && !next_ch.is_uppercase() {
camel_case_letter.push(*ch);
}
}
}
camel_case_letter
}


pub fn abbreviate(phrase: &str) -> String {
let mut acronym = String::new();
let word_list:Vec<&str> = phrase.split(&[' ', '-', '_'][..]).map(|word| word.trim()).collect();
for word in word_list {
if let Some(acr) = word.chars().nth(0) {
acronym.push(acr);
acronym.push_str(&find_camel_case(word));
}
}
acronym.to_uppercase()
}
9 changes: 9 additions & 0 deletions solutions/rust/acronym/2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "acronym"
version = "0.1.0"
edition = "2024"

# Not all libraries from crates.io are available in Exercism's test runner.
# The full list of available libraries is here:
# https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml
[dependencies]
25 changes: 25 additions & 0 deletions solutions/rust/acronym/2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
fn find_camel_case(word:&str) -> String {
let mut camel_case_letter = String::new();
let ch_word:Vec<char> = word.chars().collect();
for (index, ch) in ch_word.iter().enumerate() {
if let Some(next_ch) = ch_word.get(index+1) {
if ch.is_uppercase() && index > 0 && !next_ch.is_uppercase() {
camel_case_letter.push(*ch);
}
}
}
camel_case_letter
}


pub fn abbreviate(phrase: &str) -> String {
let mut acronym = String::new();
let word_list:Vec<&str> = phrase.split(&[' ', '-', '_'][..]).map(|word| word.trim()).collect();
for word in word_list {
if let Some(acr) = word.chars().next() {
acronym.push(acr);
acronym.push_str(&find_camel_case(word));
}
}
acronym.to_uppercase()
}
9 changes: 9 additions & 0 deletions solutions/rust/all-your-base/1/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "allyourbase"
version = "0.1.0"
edition = "2024"

# Not all libraries from crates.io are available in Exercism's test runner.
# The full list of available libraries is here:
# https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml
[dependencies]
33 changes: 33 additions & 0 deletions solutions/rust/all-your-base/1/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#[derive(Debug, PartialEq, Eq)]
pub enum Error {
InvalidInputBase,
InvalidOutputBase,
InvalidDigit(u32),
}

pub fn convert(number: &[u32], from_base: u32, to_base: u32) -> Result<Vec<u32>, Error> {
if from_base < 2 {
return Err(Error::InvalidInputBase)
}
if to_base < 2 {
return Err(Error::InvalidOutputBase)
}
let mut value = 0_u128;
for &d in number {
if d >= from_base {
return Err(Error::InvalidDigit(d))
}
value = value * from_base as u128 + d as u128;
}
if value == 0 {
return Ok(vec![0])
}
let mut output:Vec<u32> = Vec::new();
let mut n = value;
while n > 0 {
output.push((n % to_base as u128) as u32);
n /= to_base as u128;
}
output.reverse();
Ok(output)
}
9 changes: 9 additions & 0 deletions solutions/rust/allergies/1/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "allergies"
version = "0.1.0"
edition = "2024"

# Not all libraries from crates.io are available in Exercism's test runner.
# The full list of available libraries is here:
# https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml
[dependencies]
57 changes: 57 additions & 0 deletions solutions/rust/allergies/1/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Allergen {
Eggs,
Peanuts,
Shellfish,
Strawberries,
Tomatoes,
Chocolate,
Pollen,
Cats,
}

pub struct Allergies {
score: u32,
}

impl Allergies {
pub fn new(score: u32) -> Self {
Self { score: score & 0xFF }
}

pub fn is_allergic_to(&self, allergen: &Allergen) -> bool {
let mask = Self::allergen_score(allergen);
(self.score & mask) != 0
}

pub fn allergies(&self) -> Vec<Allergen> {
let all = [
Allergen::Eggs,
Allergen::Peanuts,
Allergen::Shellfish,
Allergen::Strawberries,
Allergen::Tomatoes,
Allergen::Chocolate,
Allergen::Pollen,
Allergen::Cats,
];

all.iter()
.cloned()
.filter(|a| self.is_allergic_to(a))
.collect()
}

fn allergen_score(allergen: &Allergen) -> u32 {
match allergen {
Allergen::Eggs => 1,
Allergen::Peanuts => 2,
Allergen::Shellfish => 4,
Allergen::Strawberries => 8,
Allergen::Tomatoes => 16,
Allergen::Chocolate => 32,
Allergen::Pollen => 64,
Allergen::Cats => 128,
}
}
}
9 changes: 9 additions & 0 deletions solutions/rust/anagram/1/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "anagram"
version = "0.1.0"
edition = "2024"

# Not all libraries from crates.io are available in Exercism's test runner.
# The full list of available libraries is here:
# https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml
[dependencies]
24 changes: 24 additions & 0 deletions solutions/rust/anagram/1/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::collections::{HashSet, HashMap};

pub fn anagrams_for<'a>(word: &str, possible_anagrams: &[&'a str]) -> HashSet<&'a str> {
let mut anagram_set:HashSet<&str> = HashSet::new();
for possible_word in possible_anagrams {
if word.to_lowercase().eq(&possible_word.to_lowercase()) {
continue;
}
if word_freq_map(&word) == word_freq_map(&possible_word) {
anagram_set.insert(&possible_word);
}else {
continue;
}
}
anagram_set
}

fn word_freq_map(word:&str)-> HashMap<char, usize> {
let mut word_map = HashMap::new();
for char in word.to_lowercase().chars() {
*word_map.entry(char).or_insert(0) += 1
}
word_map
}
9 changes: 9 additions & 0 deletions solutions/rust/anagram/2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "anagram"
version = "0.1.0"
edition = "2024"

# Not all libraries from crates.io are available in Exercism's test runner.
# The full list of available libraries is here:
# https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml
[dependencies]
24 changes: 24 additions & 0 deletions solutions/rust/anagram/2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::collections::{HashSet, HashMap};

pub fn anagrams_for<'a>(word: &str, possible_anagrams: &[&'a str]) -> HashSet<&'a str> {
let mut anagram_set:HashSet<&str> = HashSet::new();
for possible_word in possible_anagrams {
if word.to_lowercase().eq(&possible_word.to_lowercase()) {
continue;
}
if word_freq_map(word) == word_freq_map(possible_word) {
anagram_set.insert(possible_word);
}else {
continue;
}
}
anagram_set
}

fn word_freq_map(word:&str)-> HashMap<char, usize> {
let mut word_map = HashMap::new();
for char in word.to_lowercase().chars() {
*word_map.entry(char).or_insert(0) += 1
}
word_map
}
9 changes: 9 additions & 0 deletions solutions/rust/armstrong-numbers/1/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "armstrong_numbers"
version = "0.1.0"
edition = "2024"

# Not all libraries from crates.io are available in Exercism's test runner.
# The full list of available libraries is here:
# https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml
[dependencies]
14 changes: 14 additions & 0 deletions solutions/rust/armstrong-numbers/1/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub fn is_armstrong_number(num: u32) -> bool {
let mut number = 0u32;
let num_str = num.to_string();
let power = num_str.len() as u32;
for digit_char in num_str.chars() {
let digit = digit_char.to_digit(10).unwrap();
number += digit.pow(power);
}
if number == num {
true
} else {
false
}
}
9 changes: 9 additions & 0 deletions solutions/rust/armstrong-numbers/2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "armstrong_numbers"
version = "0.1.0"
edition = "2024"

# Not all libraries from crates.io are available in Exercism's test runner.
# The full list of available libraries is here:
# https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml
[dependencies]
10 changes: 10 additions & 0 deletions solutions/rust/armstrong-numbers/2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pub fn is_armstrong_number(num: u32) -> bool {
let mut number = 0u32;
let num_str = num.to_string();
let power = num_str.len() as u32;
for digit_char in num_str.chars() {
let digit = digit_char.to_digit(10).unwrap();
number += digit.pow(power);
}
number == num
}
15 changes: 15 additions & 0 deletions solutions/rust/binary-search/1/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "binary_search"
version = "0.1.0"
edition = "2024"

# Not all libraries from crates.io are available in Exercism's test runner.
# The full list of available libraries is here:
# https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml
[dependencies]

[features]
generic = []

[lints.clippy]
needless_borrows_for_generic_args = "allow"
31 changes: 31 additions & 0 deletions solutions/rust/binary-search/1/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
pub fn find<C, T>(array: C, key: T) -> Option<usize>
where
C : AsRef<[T]>,
T:PartialEq + PartialOrd + Copy
{
let slice = array.as_ref();
if slice.is_empty() { return None}
let mid = (0 + slice.len() - 1) / 2;
binary_search(slice, key, mid)
}

fn binary_search<T:PartialEq + PartialOrd + Copy>(array: &[T], key:T, mut index:usize) -> Option<usize> {
let current_mid_index= (0 + array.len() - 1) / 2;
let middle_value = array[current_mid_index];
let left_list = &array[..current_mid_index];
let right_list = &array[current_mid_index+1..];
let left_list_len = left_list.len();
let right_list_len = right_list.len();
if middle_value == key {
return Some(index)
} else if key < middle_value && left_list_len > 0 {
index = (0 + left_list_len - 1) / 2;
return binary_search(left_list, key, index)
} else if key > middle_value && right_list_len > 0 {
index = index + ((0 + right_list_len - 1) / 2) + 1;
return binary_search(right_list, key, index)
}
else {
None
}
}
15 changes: 15 additions & 0 deletions solutions/rust/binary-search/2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "binary_search"
version = "0.1.0"
edition = "2024"

# Not all libraries from crates.io are available in Exercism's test runner.
# The full list of available libraries is here:
# https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml
[dependencies]

[features]
generic = []

[lints.clippy]
needless_borrows_for_generic_args = "allow"
Loading