Browse Source

Solution for day 5

main
Inga 🏳‍🌈 2 years ago
parent
commit
1e49f31c37
  1. 9
      day05/Cargo.toml
  2. 19
      day05/src/main.rs

9
day05/Cargo.toml

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
[package]
name = "day05"
version = "0.1.0"
authors = ["inga-lovinde <52715130+inga-lovinde@users.noreply.github.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

19
day05/src/main.rs

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
use std::io::{self, BufRead};
fn main() {
let stdin = io::stdin();
let mut tickets: Vec<u16> = Vec::new();
for line_result in stdin.lock().lines() {
let binary_line = line_result.unwrap().replace('F', "0").replace('B', "1").replace('L', "0").replace('R', "1");
tickets.push(u16::from_str_radix(&binary_line, 2).unwrap());
}
println!("max: {}", tickets.iter().max().unwrap());
tickets.sort();
for i in 1..tickets.len() {
if tickets[i] - tickets[i-1] != 1 {
println!("hole: {}-{}", tickets[i-1], tickets[i]);
}
}
}
Loading…
Cancel
Save