d3p1 optimized
This commit is contained in:
		| @@ -8,22 +8,18 @@ fn main() { | |||||||
|     let mut sum: u64 = 0; |     let mut sum: u64 = 0; | ||||||
|     for line in input.lines() { |     for line in input.lines() { | ||||||
|         let mut left_chars: HashSet<char> = HashSet::new(); |         let mut left_chars: HashSet<char> = HashSet::new(); | ||||||
|         let mut dupe_chars: HashSet<char> = HashSet::new(); |  | ||||||
|  |  | ||||||
|         for (i, c) in line.char_indices() { |         for (i, c) in line.char_indices() { | ||||||
|             if i < line.len()/2 { |             if i < line.len()/2 { | ||||||
|                 left_chars.insert(c); |                 left_chars.insert(c); | ||||||
|             } else if left_chars.contains(&c) { |             } else if left_chars.contains(&c) { | ||||||
|                 dupe_chars.insert(c); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         for c in dupe_chars { |  | ||||||
|                 if c >= 'a' && c <= 'z' { |                 if c >= 'a' && c <= 'z' { | ||||||
|                     sum += (c as u64) - ('a' as u64) + 1; |                     sum += (c as u64) - ('a' as u64) + 1; | ||||||
|                 } else { |                 } else { | ||||||
|                     sum += (c as u64) - ('A' as u64) + 27; |                     sum += (c as u64) - ('A' as u64) + 27; | ||||||
|                 } |                 } | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user