This file contains hidden or 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 num::{One, Zero}; | |
| use std::ops; | |
| #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | |
| pub enum Tropical { | |
| Value(u64), | |
| Infty, | |
| } | |
| impl Zero for Tropical { |
This file contains hidden or 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
| function* empty<T>(): Generator<T, void> {} | |
| function* once<T>(elem: T): Generator<T, void> { | |
| yield elem; | |
| } | |
| function* onceWith<T>(fn: () => T): Generator<T, void> { | |
| yield fn(); | |
| } |
This file contains hidden or 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
| export interface State { | |
| /* Type your state definition. */ | |
| } | |
| export const initialState = (): State => ({ | |
| /* Type your initial state. */ | |
| }); | |
| const reducers = { | |
| /* Type your reducer by key of the action name. */ |
This file contains hidden or 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
| macro_rules! pairs { | |
| ($macro:ident; $($items:literal),*) => { | |
| pairs!(@ $macro; $($items),*; $($items),*); | |
| }; | |
| (@ $macro:ident; $x:literal; $($ys:literal),*) => { | |
| $( | |
| $macro!($x, $ys); | |
| )* | |
| }; | |
| (@ $macro:ident; $x:literal, $($xs:literal),*; $($ys:literal),*) => { |
This file contains hidden or 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
| value=(quad quit queue quote) | |
| second_value=(queue queen) | |
| # 先頭から最短マッチした部分を削除 | |
| echo ${value#q*e} | |
| # quad quit ue | |
| # 先頭から最長マッチした部分を削除 | |
| echo ${value##q*e} | |
| # quad quit |
This file contains hidden or 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 num::{traits::Pow, One, Zero}; | |
| use serde::{Deserialize, Serialize}; | |
| const R: u64 = 1 << 32; | |
| /// Find `modulo_inv` which satisifes `modulo * modulo_inv ≡ -1 (mod R)`. | |
| const fn find_neg_inv(modulo: u32) -> u32 { | |
| let mut inv_mod = 0u32; | |
| let mut t = 0; | |
| let mut i = 1u32; |
This file contains hidden or 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
| /// Find values where satisify `a * p + b * q = gcd`. | |
| pub fn ext_gcd(a: u64, b: u64) -> ExtGcd { | |
| let mut s = (0i64, 1i64); | |
| let mut t = (1i64, 0i64); | |
| let mut r = (as_i64(b), as_i64(a)); | |
| while r.0 != 0 { | |
| let q = r.1 / r.0; | |
| let f = |mut r: (i64, i64)| { | |
| std::mem::swap(&mut r.0, &mut r.1); |
This file contains hidden or 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
| /// The regular expression tree. | |
| #[derive(Debug, Clone, PartialEq, Eq, Hash)] | |
| pub enum RegExp { | |
| /// Declares a variable of the match result. | |
| Var(String, Box<RegExp>), | |
| /// Matching pattern of a chatacter. | |
| Let(char), | |
| /// Or pattern of patterns. | |
| Or(Box<RegExp>, Box<RegExp>), | |
| /// Concatenated pattern of patterns. |
This file contains hidden or 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
| print('''<header> | |
| ここをもうちょっとシンプルに変えてっと | |
| え、なにこのエラー・・・ | |
| </header>''') | |
| try: | |
| uglyCode() | |
| except: | |
| print('よくあるError') | |
| try: |
This file contains hidden or 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
| #[derive(Debug, Clone, Copy, PartialEq)] | |
| pub struct NonNanF64(f64); | |
| impl NonNanF64 { | |
| /// # Safety | |
| /// | |
| /// The value must not be `NaN`. | |
| pub const unsafe fn new_unchecked(f: f64) -> Self { | |
| // SAFETY: this is guaranteed to be safe by the caller. | |
| Self(f) |