cange folder names

This commit is contained in:
2023-12-07 12:30:36 -05:00
parent c5a765e487
commit 8272d3b62c
24 changed files with 0 additions and 0 deletions

7
day06/Cargo.lock generated Normal file
View File

@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day6"
version = "0.1.0"

8
day06/Cargo.toml Normal file
View File

@@ -0,0 +1,8 @@
[package]
name = "day6"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

2
day06/input.txt Normal file
View File

@@ -0,0 +1,2 @@
Time: 63 78 94 68
Distance: 411 1274 2047 1035

56
day06/src/main.rs Normal file
View File

@@ -0,0 +1,56 @@
use std::fs;
fn main() {
let input = fs::read_to_string("input.txt").unwrap();
let input: Vec<_> = input.split('\n') // Separate the Time and Distance lines
.map(|line| {
line[line.find(':').unwrap() + 1..] // Drop "Time:" and "Distance:"
.split_whitespace() // Split the numbers into their own elements
.flat_map(|s| s.chars()).collect::<String>() // Combine the strings into a single one
.parse::<i64>().expect("Couldn't parse number") // Parse numbers into i32
}).collect(); // Collect into Vec
let time = input[0];
let dist = input[1];
let mut valid = 0;
for remaining_time in 0..time {
if (time - remaining_time) * remaining_time > dist {
valid += 1;
}
}
println!("{}", valid);
}
// use std::fs;
// fn main() {
// let input = fs::read_to_string("input.txt").unwrap();
// let input: Vec<_> = input.split('\n') // Separate the Time and Distance lines
// .map(|line| {
// line[line.find(':').unwrap() + 1..] // Drop "Time:" and "Distance:"
// .split_whitespace() // Split the numbers into their own elements.
// .map(|num| num.parse::<i32>().expect("Couldn't parse number")) // Parse numbers into i32
// .collect::<Vec<_>>()
// }).collect(); // collect into Vec
// let mut valid_total = 1;
// for round in 0..input.first().unwrap().len() {
// let time = input[0][round];
// let dist = input[1][round];
// let mut valid = 0;
// for remaining_time in 0..time {
// if (time - remaining_time) * remaining_time > dist {
// valid += 1;
// }
// }
// valid_total *= valid;
// }
// println!("{}", valid_total);
// }