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::hash::Hash; | |
use std::{collections::HashMap, thread, time::Duration}; | |
fn factorial(n: i32) -> i32 { | |
if n <= 1 { | |
return 1; | |
} | |
thread::sleep(Duration::from_millis(100)); | |
factorial(n - 1).wrapping_mul(n) | |
} |
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)] | |
/* | |
we use hashmaps for the linkedlist to sidestep the borrow checker. | |
we use proptest strategy to generate series of operations across the linkedlist and compare to a VecDeque for correctness. | |
We can add subtle bugs and proptest manages to catch them | |
and shrink down to a minimal reproduction which we can then copy and paste to create a new test case. | |
PROPTEST_CASES=1000000 PROPTEST_MAX_SHRINK_ITERS=100000000 cargo test --release | |
cargo test copy_test_case |
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
/* | |
- Blazing fast, highly accurate cheating detection algorithm | |
- by Robert King, https://www.linkedin.com/in/robertkingnz/ | |
- Youtube walkthrough: https://youtu.be/CnIQkIseLGs | |
- X https://x.com/robertkingNZ | |
- BACKGROUND | |
- The Google Code Jam team presented their 90% accurate algorithm after google code jam 2021. | |
- During the contest, Rob discovered a ~100% accurate algorithm and so thought it was worth sharing. |
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://youtu.be/zhF-L_BgCHo | |
use std::sync::{mpsc::channel, Arc, Mutex}; | |
use std::thread; | |
use std::time::Instant; | |
fn is_prime(n: i32) -> bool { | |
if n < 2 { | |
return false; | |
} |
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
// 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 { |
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
// Robert on X: https://x.com/robertkingNZ | |
// Video walkthrough of solution: https://youtu.be/p2L-uvMlFaE?si=9PU_dHG4uDyPFQZz | |
// Problem statement: 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; |
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://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(); |
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
// 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"; |
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
// 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 |
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/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 |
NewerOlder