Add D16P1

This commit is contained in:
kageru 2019-12-16 11:27:26 +01:00
parent 0ec95b96d3
commit d1591f6909
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
3 changed files with 30 additions and 0 deletions

9
2019/16/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "day16"
version = "0.1.0"
authors = ["kageru <kageru@encode.moe>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

1
2019/16/input Normal file
View File

@ -0,0 +1 @@
59768092839927758565191298625215106371890118051426250855924764194411528004718709886402903435569627982485301921649240820059827161024631612290005106304724846680415690183371469037418126383450370741078684974598662642956794012825271487329243583117537873565332166744128845006806878717955946534158837370451935919790469815143341599820016469368684893122766857261426799636559525003877090579845725676481276977781270627558901433501565337409716858949203430181103278194428546385063911239478804717744977998841434061688000383456176494210691861957243370245170223862304663932874454624234226361642678259020094801774825694423060700312504286475305674864442250709029812379

20
2019/16/src/main.rs Normal file
View File

@ -0,0 +1,20 @@
use std::io::{stdin, BufRead};
use std::iter::*;
#[rustfmt::skip]
fn read_input() -> Vec<i16> {
stdin().lock().lines().next().unwrap().unwrap().chars().map(|c| c.to_string().parse().unwrap()).collect()
}
#[rustfmt::skip]
fn main() {
let mut last_phase = read_input();
//let mut last_phase: Vec<i16> = "80871224585914546619083218645595".chars().map(|c| c.to_string().parse().unwrap()).collect();
for _ in 0..100 {
last_phase = (1..=last_phase.len()).map(|i| {
let mut pattern = [0i16, 1, 0, -1].iter().flat_map(|x| repeat(x).take(i)).cycle().skip(1);
last_phase.iter().map(|x| x*pattern.next().unwrap()).sum::<i16>().abs() % 10
}).collect();
}
println!("Part 1: {}", last_phase.iter().take(8).map(|n| n.to_string()).collect::<String>());
}