This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
authors = ["icub3d"] | |
name = "day07" | |
version = "0.1.0" | |
edition = "2021" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
anyhow = "1.0.79" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::VecDeque; | |
fn main() { | |
let input = include_str!("../input"); | |
// Part 1 - Once we've added the given features to our Intcode computer, we can simply run it. | |
// We'll want to make sure we get all zeros except for the last value. Then the last value is | |
// the answer. | |
let mut computer = Computer::new_with_program_and_input(input, &[1]); | |
computer.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let input = include_str!("../input"); | |
// For part 1, we can simply run the program with the two given inputs. | |
let mut computer = Computer::new_with_program(input); | |
computer[1] = 12; | |
computer[2] = 2; | |
computer.run(); | |
println!("p1: {}", computer[0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A helper function to print some details about a string. | |
fn string_details(string: &str) { | |
println!("string: {}", string); | |
println!("char details (char: index byte_index bytes)"); | |
// The index and byte_index may be different for non-ASCII characters. | |
for (index, (byte_index, c)) in string.char_indices().enumerate() { | |
println!( | |
" {:?}: {:02} {:02} {:?}", | |
c, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is meant to be an introductory problem. The question is, given | |
// a list of numbers and a number k, return the largest sum of k | |
// consecutive numbers in the list. | |
pub fn largest_continuous_sum(nums: Vec<isize>, k: usize) -> isize { | |
// *state* | |
// | |
// In this case, it's just the max sum we've seen so far. | |
let mut largest = std::isize::MIN; | |
// *iterate* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(dead_code)] | |
#![feature(test)] | |
extern crate test; | |
use std::collections::HashSet; | |
use std::ops::BitXor; | |
use rayon::prelude::*; | |
fn p1_simple(input: &str) -> usize { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://adventofcode.com/2022/day/19 | |
// https://en.wikipedia.org/wiki/Branch_and_bound | |
use std::ops::{Add, Index, IndexMut, Mul, Sub}; | |
// We are going to use rayon here to parallelize the work. This is | |
// especially beneficial for part 1 where there are many blueprints. | |
use rayon::prelude::*; | |
// These are the different mineral types. We'll use them to iterate. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::{BinaryHeap, HashMap}; | |
use std::hash::Hash; | |
#[derive(Clone, Debug, Eq, PartialEq)] | |
struct State<N> | |
where | |
N: Clone + Eq + PartialEq, | |
{ | |
node: N, | |
cost: usize, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
import time | |
# Create our graph. | |
G = nx.Graph() | |
# Add all the nodes. | |
for line in open("input").readlines(): | |
k, vv = line.split(": ") | |
for v in vv.split(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{ops::Sub, str::FromStr}; | |
use nalgebra::{Matrix6, Matrix6x1, RowVector6}; | |
use num::Num; | |
// Represents a point in 3D space. | |
#[derive(Debug, Copy, Clone)] | |
struct Point<N> { | |
x: N, | |
y: N, |
NewerOlder