Skip to content

Instantly share code, notes, and snippets.

@saolsen
saolsen / main.rs
Created July 11, 2023 19:20
connect4 monte-carlo tree search with rayon
use rayon::prelude::*;
use thiserror::Error;
const ROWS: usize = 6;
const COLS: usize = 7;
#[derive(Debug)]
pub struct Connect4Action {
pub column: usize,
}
@saolsen
saolsen / Dockerfile
Last active May 11, 2023 18:47
connect4_mcts
FROM debian:stable-slim as get
WORKDIR /bun
RUN apt-get update
RUN apt-get install curl unzip -y
RUN curl --fail --location --progress-bar --output "/bun/bun.zip" "https://github.com/oven-sh/bun/releases/latest/download/bun-linux-x64.zip"
RUN unzip -d /bun -q -o "/bun/bun.zip"
RUN mv /bun/bun-linux-x64/bun /usr/local/bin/bun
RUN chmod 777 /usr/local/bin/bun
@saolsen
saolsen / lldb.log
Created December 28, 2022 15:48
lldb.log
ProcessGDBRemote::StartAsyncThread ()
< 1> send packet: +
ProcessGDBRemote::AsyncThread (arg = 0x1498a7018, pid = 0) thread starting...
ProcessGDBRemote::AsyncThread (arg = 0x1498a7018, pid = 0) listener.WaitForEvent (NULL, event_sp)...
history[1] tid=0x0103 < 1> send packet: +
< 19> send packet: $QStartNoAckMode#b0
< 1> read packet: +
< 6> read packet: $OK#9a
< 1> send packet: +
< 86> send packet: $qSupported:xmlRegisters=i386,arm,mips,arc;multiprocess+;fork-events+;vfork-events+#2e
@saolsen
saolsen / day10.rs
Last active December 11, 2022 18:49
aoc 2022 day10
enum Op {
Noop,
Addx(i32),
}
fn parse<'a>(input: &'a str) -> impl Iterator<Item = Op> + 'a {
input.split("\n").map(|line| {
let mut split = line.split(" ");
let op = split.next().unwrap();
match op {
@saolsen
saolsen / day09.rs
Created December 9, 2022 18:56
aoc 2022 day09
use std::collections::HashSet;
fn parse<'a>(input: &'a str) -> impl Iterator<Item = (&'a str, u32)> + 'a {
input.split("\n").map(|line| {
let mut split = line.split(" ");
let dir = split.next().unwrap();
let steps = split.next().unwrap().parse::<u32>().unwrap();
(dir, steps)
})
}
@saolsen
saolsen / day08.rs
Created December 8, 2022 14:09
aoc 2022 day08
use core::num;
fn parse(input: &str) -> Vec<Vec<u32>> {
let mut grid = vec![];
for line in input.split("\n") {
let mut row = vec![];
for c in line.chars() {
let i = c.to_digit(10).unwrap();
row.push(i);
}
@saolsen
saolsen / day07.rs
Created December 7, 2022 18:38
aoc 2022 day07
use std::{collections::HashMap, iter::Peekable, str::Split};
#[derive(Debug)]
struct Dir<'a> {
path: Vec<&'a str>,
files: HashMap<&'a str, File<'a>>,
}
#[derive(Debug)]
struct File<'a> {
@saolsen
saolsen / day06.rs
Created December 6, 2022 13:20
aoc 2022 day06
use std::collections::HashSet;
fn main() {
let input = include_str!("day06_input.txt");
let data: Vec<char> = input.chars().collect();
// just let HashSet do all the work
let mut message_set = HashSet::new();
for i in 0..data.len() {
if i >= 13 {
@saolsen
saolsen / day05.rs
Created December 5, 2022 13:41
aoc 2022 day05
fn main() {
let input = include_str!("day05_input.txt");
let lines = input.split("\n").collect::<Vec<&str>>();
// find where the file switches from stacks to instructions
let mut split = 0;
for (i, line) in lines.iter().enumerate() {
if line.is_empty() {
split = i;
}
@saolsen
saolsen / day04.rs
Created December 4, 2022 16:09
aoc 2022 day04
fn parse_line(line: &str) -> (i32, i32, i32, i32) {
let mut split = line.split(",");
let left = split.next().unwrap();
let mut ls = left.split("-");
let left_from: i32 = ls.next().unwrap().parse().unwrap();
let left_to: i32 = ls.next().unwrap().parse().unwrap();
let right = split.next().unwrap();
let mut rs = right.split("-");
let right_from: i32 = rs.next().unwrap().parse().unwrap();
let right_to: i32 = rs.next().unwrap().parse().unwrap();