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 React, { useMemo } from "react"; | |
import ReactDOM from "react-dom"; | |
import useLocalStorage from "@rehooks/local-storage"; | |
import { grams, kilograms } from "@buge/ts-units/mass"; | |
function App() { | |
const [value, setValue, deleteValue] = useLocalStorage("hello", kilograms(0)); | |
const [v1, v2] = useMemo( | |
() => [value.amount ?? "<null>", value.unit?.symbol ?? "<null>"], | |
[value] |
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::cmp::Ordering; | |
const INPUT: &str = include_str!("../input"); | |
type Num = u64; | |
fn check_it(arr: &[Num], number: Num) -> bool { | |
arr.iter() | |
.enumerate() | |
.flat_map(|(i, a)| arr[i + 1..].iter().map(move |b| (a, b))) |
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::BTreeSet; | |
const INPUT: &str = include_str!("../input"); | |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | |
enum Opcode { | |
Acc, | |
Jmp, | |
Nop, | |
} |
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
#![feature(or_insert_with_key, option_unwrap_none)] | |
use std::collections::HashMap; | |
use petgraph::graph::{DiGraph, NodeIndex}; | |
use petgraph::visit::{self, IntoNeighborsDirected, IntoNodeIdentifiers}; | |
use petgraph::Direction; | |
use regex::Regex; | |
const INPUT: &str = include_str!("../input"); |
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::HashMap; | |
use petgraph::{algo, Directed, Direction, Graph, Undirected}; | |
const INPUT: &str = include_str!("../input"); | |
type MyGraph = Graph<String, (), Directed>; | |
type MyUnGraph = Graph<String, (), Undirected>; | |
fn parse_directed(s: &str) -> MyGraph { |
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 intcode::IntCode; | |
const INPUT: &str = include_str!("../input"); | |
fn parse(s: &str) -> Vec<i32> { | |
s.split(',').map(|x| x.parse().unwrap()).collect() | |
} | |
fn main() { | |
let input = parse(INPUT); |
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::mem; | |
use std::ops::Range; | |
const INPUT: &str = "307237-769058"; | |
struct ExtractConsecutive<'a> { | |
string: &'a str, | |
} | |
impl<'a> Iterator for ExtractConsecutive<'a> { |
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::{HashMap, HashSet}; | |
const INPUT: &str = include_str!("../input"); | |
#[derive(Clone)] | |
enum Movement { | |
Up, | |
Down, | |
Left, | |
Right, |
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
const INPUT: &str = include_str!("../input"); | |
fn parse(s: &str) -> Vec<u32> { | |
s.split(',').map(|x| x.parse().unwrap()).collect() | |
} | |
fn solve_a(memory: &mut [u32]) { | |
const OPS: &[fn(u32, u32) -> u32] = &[ | |
|_, _| panic!("unsupported opcode"), | |
|a, b| a + b, |
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
const INPUT: &str = include_str!("../input"); | |
fn parse(s: &str) -> Vec<u32> { | |
s.lines().map(|x| x.parse().unwrap()).collect() | |
} | |
fn required_fuel(st: u32) -> Option<u32> { | |
(st / 3).checked_sub(2) | |
} | |
fn solve_a(v: &[u32]) -> u32 { |
NewerOlder