diff --git a/01/main.rs b/01/main.rs new file mode 100644 index 0000000..93528c2 --- /dev/null +++ b/01/main.rs @@ -0,0 +1,31 @@ +#![allow(dead_code)] +use std::fs::File; +use std::io; +use std::io::BufRead; +use std::path::Path; +use std::time::Instant; + +fn main() { + let now = Instant::now(); + part_one(); + let part_one_duration = now.elapsed(); + part_two(); + let part_two_duration = now.elapsed(); + println!( + "p1: {}ms, p2: {}ms", + part_one_duration.as_millis(), + part_two_duration.as_millis() + ); +} + +fn read_lines

(filename: P) -> io::Result>> +where + P: AsRef, +{ + let file = File::open(filename)?; + Ok(io::BufReader::new(file).lines()) +} + +fn part_one() {} + +fn part_two() {} diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..f8391cc --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "adventofcode2022" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..24c4eee --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "AdventOfCode2022" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/main.rs.tmpl b/main.rs.tmpl new file mode 100644 index 0000000..93528c2 --- /dev/null +++ b/main.rs.tmpl @@ -0,0 +1,31 @@ +#![allow(dead_code)] +use std::fs::File; +use std::io; +use std::io::BufRead; +use std::path::Path; +use std::time::Instant; + +fn main() { + let now = Instant::now(); + part_one(); + let part_one_duration = now.elapsed(); + part_two(); + let part_two_duration = now.elapsed(); + println!( + "p1: {}ms, p2: {}ms", + part_one_duration.as_millis(), + part_two_duration.as_millis() + ); +} + +fn read_lines

(filename: P) -> io::Result>> +where + P: AsRef, +{ + let file = File::open(filename)?; + Ok(io::BufReader::new(file).lines()) +} + +fn part_one() {} + +fn part_two() {} diff --git a/new.sh b/new.sh old mode 100644 new mode 100755 index 4efbb32..ebd58c6 --- a/new.sh +++ b/new.sh @@ -9,7 +9,7 @@ if [ "${1}" != "" ]; then if [ ! -f "${padded}/inputs/input" ]; then curl -s -H "Cookie: session=`cat .cookie`" https://adventofcode.com/${__year}/day/${1##0}/input > "${padded}/inputs/input" fi - if [ ! -f "${padded}/main.go" ]; then - cp -n main.go.tmpl ${padded}/main.go + if [ ! -f "${padded}/main.rs" ]; then + cp -n main.rs.tmpl ${padded}/main.rs fi fi diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..bc15aa9 --- /dev/null +++ b/run.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [ "${1}" != "" ]; then + padded=$(printf "%02g" ${1}) + cd ${padded} + rustc main.rs && ./main && rm main + cd - > /dev/null +fi