Skip to content

Instantly share code, notes, and snippets.

View robert-king's full-sized avatar

Robert King robert-king

View GitHub Profile
@robert-king
robert-king / advent_of_code_day_2_over_engineered.rs
Created December 3, 2023 00:55
Advent of code day 2, over engineered
// youtube walkthrough: https://youtu.be/mRW8Kbb1YlA?si=lBe4mNvfBYxe9ALl
const DATA: &str = "Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green";
#[derive(Debug)]
enum Color {
@robert-king
robert-king / road_to_nutella.rs
Last active September 26, 2023 22:26
Problem D: Road to Nutella
// https://twitter.com/robertkingNZ
// https://www.youtube.com/@RobertKing/
// https://www.facebook.com/codingcompetitions/hacker-cup/2023/practice-round/problems/D
use std::thread;
use std::collections::{HashSet, VecDeque};
use std::io::{StdinLock, StdoutLock};
use segment_tree::SegmentPoint;
use segment_tree::ops::Min;
@robert-king
robert-king / treasure.rs
Created April 15, 2023 08:03
codejam treasure problem
/**
* https://codingcompetitions.withgoogle.com/codejam/round/0000000000432dfc/0000000000433101
* @robertkingnz
**/
use std::collections::{HashMap, HashSet};
fn get_line() -> String {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
@robert-king
robert-king / walk-dir-zod-rust-script.rs
Last active January 26, 2023 23:33
walk-dir-zod-rust-script
// youtube: https://youtu.be/dbEY6j98llw
// twitter: https://twitter.com/robertkingNZ
use std::collections::HashMap;
use std::fs;
fn main() {
let mut map = HashMap::new();
let zod_location = "/Users/rk/WebstormProjects/thred-cloud/tauri/node_modules/zod";
@robert-king
robert-king / advent_of_code_2022_day_16.rs
Created December 16, 2022 19:18
advent of code 2022 day 16
// live coding: https://youtu.be/IlZFxkTrlW0
// twitter: https://twitter.com/robertkingNZ
// problem: https://adventofcode.com/2022/day/16
use std::collections::{HashSet, HashMap};
use regex::Regex;
const _EX: &str = "Valve RU has flow rate=0; tunnels lead to valves YH, ID
Valve QK has flow rate=24; tunnels lead to valves PQ, PP
Valve RP has flow rate=11; tunnels lead to valves RM, BA, RI, EM
@robert-king
robert-king / advent_of_code_2022_day_15.rs
Created December 15, 2022 19:52
Fast solution to advent of code 2022 day 15
// https://adventofcode.com/2022/day/15
// https://www.youtube.com/@robertking
use std::collections::{BTreeMap, HashSet};
use regex::Regex;
const INPUT: &str = "Sensor at x=3391837, y=2528277: closest beacon is at x=3448416, y=2478759
Sensor at x=399473, y=1167503: closest beacon is at x=1188862, y=2000000
Sensor at x=3769110, y=2896086: closest beacon is at x=4076658, y=2478123
Sensor at x=900438, y=3835648: closest beacon is at x=-435606, y=3506717
@robert-king
robert-king / meta_hackercup_a2_perfectly_balanced.rs
Created October 1, 2022 00:18
Problem A2: Perfectly Balanced - Chapter 2
/*
https://www.facebook.com/codingcompetitions/hacker-cup/2022/round-2/problems/A2
https://youtu.be/CsSGu51V7YQ
*/
use std::collections::HashSet;
use rand::{thread_rng, Rng};
use std::io;
use std::io::Read;
use crate::fenwick_tree::FenwickTree;
# https://youtu.be/zo_UHPI78H8
# @robertkingNZ
# thred.co.nz
"""
Problem statement screenshot in comments below.
Problem N (page 29) https://prog4fun.csse.canterbury.ac.nz/pluginfile.php/11232/mod_quiz/intro/NZPC2022-v1.pdf
There's a clone of the contest on our prog4fun server: https://prog4fun.csse.canterbury.ac.nz.
This is a public server that anyone can register on with any credentials.
Once registered they should enrol themselves in the "course" Programming Contest Problem Archive and they'll then be able to access the clone of NZPC-2022 here:
@robert-king
robert-king / lemonade_life.rs
Created September 12, 2022 02:28
meta hacker cup 2022, round 1, lemonade life
// https://www.facebook.com/codingcompetitions/hacker-cup/2022/round-1/problems/C
fn bad(i: usize, j: usize, k: usize, t: &Vec<Vec<i64>>) -> bool {
let rise1 = t[j][1] - t[i][1];
let rise2 = t[k][1] - t[i][1];
let run1 = t[j][0] - t[i][0];
let run2 = t[k][0] - t[i][0];
if run1 == 0 {
return false;
}
@robert-king
robert-king / second-flight.rs
Created August 29, 2022 19:14
meta hacker cup: Problem D: Second Flight
// @robertkingnz
// https://www.youtube.com/c/RobertKing/videos
// https://www.facebook.com/codingcompetitions/hacker-cup/2022/qualification-round/problems/D
use std::collections::{HashMap};
use std::mem;
fn main() {
let (r, w) = (std::io::stdin(), std::io::stdout());
let mut sc = IO::new(r.lock(), w.lock());