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
475 changes: 255 additions & 220 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions adv2015/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "adv2015"
version = "0.25.1"
version = "0.25.2"
authors = ["Vest <Vest@users.noreply.github.com>"]
edition = "2018"

Expand All @@ -13,8 +13,8 @@ doc = false

[dependencies]
md5 = "0.7.0"
permute = "0.1.0"
permute = "0.2.1"
combinations = "0.1.0"
regex = "1.4.2"
rand = "0.7.3"
regex = "1.7.1"
rand = "0.8.5"
divisors = "0.2.1"
1 change: 0 additions & 1 deletion adv2015/src/day1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,3 @@ mod tests {
assert_eq!(count_position("()()("), None);
}
}

1 change: 0 additions & 1 deletion adv2015/src/day10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,3 @@ mod tests {
assert_eq!(calc_length(&"1".to_string(), 5), 6, "Length of 312211 is 6");
}
}

44 changes: 32 additions & 12 deletions adv2015/src/day11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ struct Password {
impl Password {
fn new_str(input: &str) -> Password {
Password {
state: String::from(input)
state: String::from(input),
}
}

#[allow(dead_code)]
fn new() -> Password {
let mut pwd = Password {
state: String::with_capacity(MAX_LENGTH)
state: String::with_capacity(MAX_LENGTH),
};

for _ in 0..MAX_LENGTH {
Expand Down Expand Up @@ -86,7 +86,11 @@ fn is_increased(input: &str) -> bool {
let prev_ascii = prev_char.unwrap() as u8;
let c_ascii = c as u8;

count = if c_ascii.checked_sub(prev_ascii) == Some(1) { count + 1 } else { 1 };
count = if c_ascii.checked_sub(prev_ascii) == Some(1) {
count + 1
} else {
1
};

if count == 3 {
return true;
Expand All @@ -99,9 +103,7 @@ fn is_increased(input: &str) -> bool {
}

fn is_not_confusing(input: &str) -> bool {
!input.contains(|c| {
c == 'i' || c == 'o' || c == 'l'
})
!input.contains(|c| c == 'i' || c == 'o' || c == 'l')
}

fn has_pairs(input: &str) -> bool {
Expand Down Expand Up @@ -159,7 +161,10 @@ mod tests {
let pwd = Password::new();
let pwd_str = pwd.get_password();

assert_eq!(pwd_str, "aaaaaaaa", "Expected a string with eight 'a' chars");
assert_eq!(
pwd_str, "aaaaaaaa",
"Expected a string with eight 'a' chars"
);
}

#[test]
Expand All @@ -169,7 +174,10 @@ mod tests {

{
let pwd_str = pwd.get_password();
assert_eq!(pwd_str, "aaaaaaab", "Expected a string with seven 'a' chars and one 'b'");
assert_eq!(
pwd_str, "aaaaaaab",
"Expected a string with seven 'a' chars and one 'b'"
);
}
pwd.inc();
pwd.inc();
Expand All @@ -178,7 +186,10 @@ mod tests {

{
let pwd_str = pwd.get_password();
assert_eq!(pwd_str, "aaaaaaaf", "Expected a string with seven 'a' chars and one 'f'");
assert_eq!(
pwd_str, "aaaaaaaf",
"Expected a string with seven 'a' chars and one 'f'"
);
}
}

Expand All @@ -188,7 +199,10 @@ mod tests {
pwd.inc();
let pwd_str = pwd.get_password();

assert_eq!(pwd_str, "zzzzzzzz", "Expected a string with eight 'z' chars");
assert_eq!(
pwd_str, "zzzzzzzz",
"Expected a string with eight 'z' chars"
);
}

#[test]
Expand All @@ -197,14 +211,20 @@ mod tests {
pwd.inc();
let pwd_str = pwd.get_password();

assert_eq!(pwd_str, "aaaaaaaa", "Expected a string with eight 'a' chars");
assert_eq!(
pwd_str, "aaaaaaaa",
"Expected a string with eight 'a' chars"
);
}

#[test]
fn test_password_iter() {
let mut pwd = Password::new();
while let Some(pass) = pwd.next() {
assert_eq!(pass, "aaaaaaab", "Expected a string with seven 'a' chars and one 'b'");
assert_eq!(
pass, "aaaaaaab",
"Expected a string with seven 'a' chars and one 'b'"
);
break;
}
}
Expand Down
32 changes: 22 additions & 10 deletions adv2015/src/day12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ pub fn get_answer_without_red(input: &str) -> i32 {
}

fn extract_numbers(input: &str) -> Vec<i32> {
input.split_terminator(|c| {
c == '[' || c == ']' || c == ',' || c == '"' || c == ':' || c == '{' || c == '}'
})
input
.split_terminator(|c| {
c == '[' || c == ']' || c == ',' || c == '"' || c == ':' || c == '{' || c == '}'
})
.filter(|s| !s.is_empty())
.map(|s| s.parse::<i32>())
.filter(|p| p.is_ok())
Expand All @@ -23,8 +24,7 @@ fn extract_numbers(input: &str) -> Vec<i32> {
}

fn sum_numbers(input: &Vec<i32>) -> i32 {
input.iter()
.sum()
input.iter().sum()
}

fn find_first_json_object(input: &str) -> &str {
Expand Down Expand Up @@ -57,7 +57,11 @@ fn scan_deep(input: &str) -> i32 {
let res = find_first_json_object(input);

if res == "" {
return if input.contains(r#":"red""#) { 0 } else { get_answer(input) };
return if input.contains(r#":"red""#) {
0
} else {
get_answer(input)
};
}

if let Some(i) = input.find(res) {
Expand Down Expand Up @@ -142,7 +146,6 @@ mod tests {
assert_eq!(sum, 6);
}


#[test]
fn test_sum_numbers_2() {
let res = extract_numbers(r#"[]"#);
Expand All @@ -152,10 +155,19 @@ mod tests {

#[test]
fn test_find_json_object() {
assert_eq!(find_first_json_object(r#"[1,{"c":"red","b":2},3]"#), r#"{"c":"red","b":2}"#);
assert_eq!(find_first_json_object(r#"[1,{"c":"red",{"a":1},"b":2},3]"#), r#"{"c":"red",{"a":1},"b":2}"#);
assert_eq!(
find_first_json_object(r#"[1,{"c":"red","b":2},3]"#),
r#"{"c":"red","b":2}"#
);
assert_eq!(
find_first_json_object(r#"[1,{"c":"red",{"a":1},"b":2},3]"#),
r#"{"c":"red",{"a":1},"b":2}"#
);
assert_eq!(find_first_json_object(r#"[1,3]"#), r#""#);
assert_eq!(find_first_json_object(r#"{"d":"red","e":[1,2,3,4],"f":5}"#), r#"{"d":"red","e":[1,2,3,4],"f":5}"#);
assert_eq!(
find_first_json_object(r#"{"d":"red","e":[1,2,3,4],"f":5}"#),
r#"{"d":"red","e":[1,2,3,4],"f":5}"#
);
}

#[test]
Expand Down
Loading