Commit 3e4215a5 authored by Jonathan Klimt's avatar Jonathan Klimt

Some code cleanup

parent cc36fb9d
extern crate termion;
use self::termion::color;
// use std::io::BufRead;
// use std::io::BufReader;
use std::io::Error;
use std::fs::File;
// use std::io;
use std::io::prelude::*;
#[derive(Default, Debug, Clone, PartialEq)]
struct Claim {
id: usize,
}
fn main() -> Result<(), Error> {
let mut f = File::open("input.txt")?;
......@@ -25,14 +14,12 @@ fn main() -> Result<(), Error> {
while let Some(tmp) = react_once(&mut s) {
s = tmp;
}
println!("last cars: {}", s.chars().skip(s.len() - 20).collect::<String>() );
println!("Length of fully reacted polymer: {}", s.len());
let mut shortest_len = s.len();
for c in (0..26).map(|x| (x + 'a' as u8) as char){
let mut new_s : String = s.chars().filter(|x| x.to_lowercase().next().unwrap() != c ).collect();
while let Some(tmp) = react_once(&mut new_s) {
new_s = tmp;
// println!("new str: {} len: {}", s.chars().take(40).collect::<String>(), s.len());
}
if new_s.len() < shortest_len{
shortest_len = new_s.len();
......@@ -62,7 +49,6 @@ fn react_once (s: &String) -> Option<(String)>{
}
new_s.push(c);
}
// new_s.push(c_iter);
if changes == 0 {
None
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment