Skip to content

Instantly share code, notes, and snippets.

View koivunej's full-sized avatar

Joonas Koivunen koivunej

View GitHub Profile
@koivunej
koivunej / main.rs
Created December 9, 2023 17:47
aoc 2023 day 09
use std::{io::BufRead, ops::ControlFlow};
fn main() {
let mut context = Context::default();
let mut s = String::new();
let mut input = std::io::stdin().lock();
let mut nums = Vec::new();
@koivunej
koivunej / main.rs
Created December 9, 2023 14:21
aoc 2023 day 08
use std::{collections::HashMap, io::BufRead};
fn main() {
let (instr, adjacent) = parse(std::io::stdin().lock());
let phase1 = solve(&instr, &adjacent);
let phase2 = solve_many(&instr, &adjacent);
assert_eq!(phase1, 14429);
@koivunej
koivunej / main.rs
Created December 9, 2023 13:08
aoc 2023 day 07
use std::io::BufRead;
fn main() {
let mut parsed = parse(std::io::stdin().lock());
let phase1 = total_winnings(&mut parsed);
assert_eq!(phase1, 250232501);
let mut parsed = parsed
@koivunej
koivunej / main.rs
Created December 9, 2023 10:17
aoc 2023 day 06
fn main() {
// Time: 56 71 79 99
// Distance: 334 1135 1350 2430
let input = [(56, 334), (71, 1135), (79, 1350), (99, 2430)];
let phase1 = input
.iter()
.copied()
.map(|(race_millis, minimum_distance)| {
ways_to_win_with_immediate_accel(race_millis, minimum_distance)
@koivunej
koivunej / main.rs
Created December 6, 2023 19:16
aoc 2023 day 05
use std::{collections::BTreeMap, io::BufRead, ops::Range};
fn main() {
let t = parse(std::io::stdin().lock());
println!("{t:?}");
assert_eq!(t.0, 218513636); // unsure how long, had to put the car warming up
assert_ne!(t.1, 81956385, "high");
assert_eq!(t.1, 81956384);
}
@koivunej
koivunej / main.rs
Last active December 3, 2023 08:02
aoc 2023 day 03, buffering hashmappy
use std::collections::HashMap;
fn main() {
const INPUT: &str = include_str!("../input");
let (parts, ratios) = find_parts(INPUT);
let part1 = parts.iter().sum::<u64>();
println!("{part1}");
let part2 = ratios.iter().sum::<u64>();
println!("{part2}");
@koivunej
koivunej / main.rs
Last active December 2, 2023 15:50
aoc 2023 day 01, spider "dfa"
fn main() {
let stdin = std::io::stdin();
let stdin = stdin.lock();
let mut phases = (Phase1::default(), Phase2::default());
ingest(stdin, &mut phases);
println!("{phases:?}");
}
@koivunej
koivunej / main.rs
Last active December 2, 2023 15:23
aoc 2023 day 02, upping the ante with spanned parsing errors
use std::{io::BufRead, ops::Range, str::FromStr};
use broilerplate::InputLines;
use spanstuff::{Spanned, SpannedErr};
fn main() {
let stdin = std::io::stdin();
let stdin = stdin.lock();
let (sum_of_possible_game_ids, min_dices_power) = match solve(stdin, &[12, 13, 14]) {
@koivunej
koivunej / 2023-08-09-asref-arc.md
Last active August 10, 2023 06:50
AsRef<V> trick with Arc<T>

AsRef<V> trick with Arc<T>

Quick "blog post" or note mainly for future myself. I have often wanted to have "Arc projections," which would be like Arc<V> but holding up the same reference count as the original Arc<T>, like:

struct Shared {
  answer: u32
}
@koivunej
koivunej / about.md
Last active February 16, 2017 09:52
Applies on top of 4f939ddf0c9344da646367d46810eb1ac92c5780