day6 rev
This commit is contained in:
parent
0c4376d503
commit
c5a765e487
@ -2,17 +2,14 @@ use std::fs;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let input = fs::read_to_string("input.txt").unwrap();
|
let input = fs::read_to_string("input.txt").unwrap();
|
||||||
let input: Vec<_> = input.split('\n') // Seperate the Time and Distance lines
|
let input: Vec<_> = input.split('\n') // Separate the Time and Distance lines
|
||||||
.map(|line| {
|
.map(|line| {
|
||||||
&line[line.find(':').unwrap() + 1..] // Drop "Time:" and "Distance:"
|
line[line.find(':').unwrap() + 1..] // Drop "Time:" and "Distance:"
|
||||||
}).map(|line| {
|
.split_whitespace() // Split the numbers into their own elements
|
||||||
line.split_whitespace() // Split the numbers into their own elements
|
|
||||||
.flat_map(|s| s.chars()).collect::<String>() // Combine the strings into a single one
|
.flat_map(|s| s.chars()).collect::<String>() // Combine the strings into a single one
|
||||||
}).map(|num| {
|
.parse::<i64>().expect("Couldn't parse number") // Parse numbers into i32
|
||||||
num.parse::<i64>().expect("Couldn't parse number") // Parse numbers into i32
|
|
||||||
}).collect(); // Collect into Vec
|
}).collect(); // Collect into Vec
|
||||||
|
|
||||||
|
|
||||||
let time = input[0];
|
let time = input[0];
|
||||||
let dist = input[1];
|
let dist = input[1];
|
||||||
let mut valid = 0;
|
let mut valid = 0;
|
||||||
@ -32,11 +29,10 @@ fn main() {
|
|||||||
|
|
||||||
// fn main() {
|
// fn main() {
|
||||||
// let input = fs::read_to_string("input.txt").unwrap();
|
// let input = fs::read_to_string("input.txt").unwrap();
|
||||||
// let input: Vec<_> = input.split('\n') // Seperate the Time and Distance lines
|
// let input: Vec<_> = input.split('\n') // Separate the Time and Distance lines
|
||||||
// .map(|line| {
|
// .map(|line| {
|
||||||
// &line[line.find(':').unwrap() + 1..] // Drop "Time:" and "Distance:"
|
// line[line.find(':').unwrap() + 1..] // Drop "Time:" and "Distance:"
|
||||||
// }).map(|line| {
|
// .split_whitespace() // Split the numbers into their own elements.
|
||||||
// line.split_whitespace() // Split the numbers into their own elements.
|
|
||||||
// .map(|num| num.parse::<i32>().expect("Couldn't parse number")) // Parse numbers into i32
|
// .map(|num| num.parse::<i32>().expect("Couldn't parse number")) // Parse numbers into i32
|
||||||
// .collect::<Vec<_>>()
|
// .collect::<Vec<_>>()
|
||||||
// }).collect(); // collect into Vec
|
// }).collect(); // collect into Vec
|
||||||
|
Loading…
Reference in New Issue
Block a user