Updates
This commit is contained in:
8
december_14/Cargo.toml
Normal file
8
december_14/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "december_14"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
18
december_14/example.txt
Normal file
18
december_14/example.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
NNCB
|
||||
|
||||
CH -> B
|
||||
HH -> N
|
||||
CB -> H
|
||||
NH -> C
|
||||
HB -> C
|
||||
HC -> B
|
||||
HN -> C
|
||||
NN -> C
|
||||
BH -> H
|
||||
NC -> B
|
||||
NB -> B
|
||||
BN -> B
|
||||
BB -> N
|
||||
BC -> B
|
||||
CC -> N
|
||||
CN -> C
|
||||
102
december_14/input.txt
Normal file
102
december_14/input.txt
Normal file
@@ -0,0 +1,102 @@
|
||||
PHOSBSKBBBFSPPPCCCHN
|
||||
|
||||
KO -> H
|
||||
OK -> P
|
||||
BO -> C
|
||||
SH -> V
|
||||
PC -> F
|
||||
NK -> N
|
||||
PH -> K
|
||||
VH -> S
|
||||
NN -> S
|
||||
VC -> P
|
||||
OF -> O
|
||||
HH -> S
|
||||
VP -> K
|
||||
KP -> O
|
||||
NP -> F
|
||||
SS -> V
|
||||
HP -> S
|
||||
PS -> F
|
||||
BV -> P
|
||||
KS -> H
|
||||
SO -> H
|
||||
NF -> N
|
||||
CO -> V
|
||||
HK -> F
|
||||
OO -> N
|
||||
KN -> F
|
||||
SP -> V
|
||||
OP -> S
|
||||
OV -> V
|
||||
HO -> V
|
||||
PK -> N
|
||||
FF -> N
|
||||
CV -> S
|
||||
PP -> B
|
||||
CF -> P
|
||||
HF -> B
|
||||
BN -> C
|
||||
FH -> S
|
||||
ON -> K
|
||||
SN -> N
|
||||
CP -> N
|
||||
OB -> O
|
||||
HC -> F
|
||||
KH -> P
|
||||
OS -> S
|
||||
NS -> C
|
||||
BK -> H
|
||||
PB -> P
|
||||
SV -> F
|
||||
FV -> C
|
||||
BC -> K
|
||||
HS -> N
|
||||
PF -> V
|
||||
NC -> N
|
||||
CH -> H
|
||||
VF -> H
|
||||
KK -> B
|
||||
OH -> K
|
||||
HB -> C
|
||||
SC -> B
|
||||
VK -> C
|
||||
FP -> C
|
||||
SK -> N
|
||||
VO -> K
|
||||
FB -> S
|
||||
KB -> N
|
||||
BS -> S
|
||||
VS -> C
|
||||
CN -> K
|
||||
KF -> F
|
||||
NB -> O
|
||||
BB -> C
|
||||
CS -> C
|
||||
FC -> K
|
||||
NO -> B
|
||||
SB -> C
|
||||
CB -> N
|
||||
BP -> S
|
||||
NV -> H
|
||||
NH -> N
|
||||
PV -> K
|
||||
PO -> C
|
||||
VB -> O
|
||||
FK -> P
|
||||
HV -> O
|
||||
KC -> S
|
||||
VV -> O
|
||||
VN -> H
|
||||
BH -> K
|
||||
FS -> O
|
||||
KV -> K
|
||||
HN -> P
|
||||
OC -> B
|
||||
SF -> V
|
||||
CC -> F
|
||||
CK -> P
|
||||
FO -> C
|
||||
PN -> K
|
||||
BF -> C
|
||||
FN -> O
|
||||
66
december_14/src/main.rs
Normal file
66
december_14/src/main.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader};
|
||||
use std::io::prelude::*;
|
||||
|
||||
const STEPS: u32 = 40;
|
||||
|
||||
fn main(){
|
||||
let file = File::open("./input.txt").expect("Read failed");
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut line_vec = Vec::new();
|
||||
|
||||
for line in reader.lines() {
|
||||
line_vec.push(line.unwrap());
|
||||
}
|
||||
|
||||
let mut input_seq: Vec<char> = line_vec[0].chars().collect();
|
||||
let mut rules: Vec<( (char, char) , char )> = Vec::new();
|
||||
|
||||
for i in 2..line_vec.len() {
|
||||
let split_vec: Vec<&str> = line_vec[i].split(" -> ").collect();
|
||||
let input_vec: Vec<char> = split_vec[0].to_owned().chars().collect();
|
||||
let input_tuple = (input_vec[0], input_vec[1]);
|
||||
|
||||
let output = split_vec[1].chars().collect::<Vec<char>>()[0];
|
||||
|
||||
rules.push( ( input_tuple, output ) );
|
||||
}
|
||||
|
||||
for step in 0..STEPS {
|
||||
let mut output_seq: Vec<char> = Vec::new();
|
||||
for i in 0..input_seq.len() - 1 {
|
||||
let first = input_seq[i];
|
||||
let second = input_seq[i + 1];
|
||||
|
||||
output_seq.push(first);
|
||||
for rule in &rules {
|
||||
let r_in = rule.0;
|
||||
let r_out = rule.1;
|
||||
if first == r_in.0 && second == r_in.1 {
|
||||
output_seq.push(r_out);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
output_seq.push(input_seq[input_seq.len()-1]);
|
||||
|
||||
println!("Step: {}", step);
|
||||
input_seq = output_seq;
|
||||
}
|
||||
|
||||
let mut counts = BTreeMap::new();
|
||||
for word in input_seq.iter() {
|
||||
*counts.entry(word).or_insert(0) += 1;
|
||||
}
|
||||
|
||||
let max = counts.iter().max_by_key(|&(_, count)| count);
|
||||
let min = counts.iter().min_by_key(|&(_, count)| count);
|
||||
|
||||
println!("Max: {:?}, Min: {:?}, Diff: {}", min.unwrap(), max.unwrap(), max.unwrap().1 - min.unwrap().1) ;
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user