Skip to content

Commit

Permalink
Correct char handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tjpalmer committed Dec 9, 2018
1 parent e236547 commit 29104d9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions 2018/02/rust/compare/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use std::fs::File;

fn main() -> Try<()> {
let file = File::open("../../input/input.txt")?;
let mut ids: Vec<String> = Vec::new();
let mut ids: Vec<Vec<char>> = Vec::new();
'lines: for line in BufReader::new(file).lines() {
let id = line?;
let id: Vec<char> = line?.chars().collect();
'others: for other in ids.iter() {
let mut diff_index = -1;
for ((index, c0), c1) in id.char_indices().zip(other.chars()) {
for (index, (c0, c1)) in id.iter().zip(other.iter()).enumerate() {
if c0 != c1 {
if diff_index >= 0 {
// More than one different.
Expand All @@ -20,9 +20,9 @@ fn main() -> Try<()> {
}
if diff_index >= 0 {
// If we get here, it's because we had only one different.
let (a, b) = id.split_at(diff_index as usize);
let (_, c) = b.split_at(1);
println!("{}{}", a, c);
let a: String = id[..diff_index as usize].iter().collect();
let b: String = id[diff_index as usize + 1..].iter().collect();
println!("{}{}", a, b);
break 'lines;
}
}
Expand Down

0 comments on commit 29104d9

Please sign in to comment.