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
#![deny(overflowing_literals)] | |
#![allow(dead_code)] | |
fn count_steps(target: u64) -> usize { | |
use std::cmp::Ordering; | |
if target == 0 || target == 1 { | |
return 0; | |
} |
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
#![deny(overflowing_literals)] | |
type Input = u32; | |
const BOUND: Input = 1_000_000; | |
const _ENSURE_NO_OVERFLOW: Input = BOUND * 3; | |
#[derive(Debug, PartialEq, Eq)] | |
enum CountStepsError { | |
Zero, |
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
//Превратить в ошибку компиляции переполнение литералов | |
//и ошибки при вычислении констант | |
#![deny(overflowing_literals, const_err)] | |
type Points = u64; | |
const BOUND: Points = 1_000; | |
#[derive(Debug, PartialEq, Eq)] | |
enum Argument { | |
First, |
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 std::cmp; | |
use std::collections::{BTreeSet, HashMap, HashSet}; | |
type Float = f64; | |
// Тип вероятности -- newtype вокруг f64. | |
// (https://github.com/rust-unofficial/patterns/blob/master/patterns/newtype.md) | |
// В отличие от f64, имеет полный порядок | |
#[derive(Debug, Clone, Copy)] | |
struct Probability(Float); |
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
#![deny(overflowing_literals, const_err)] | |
// Возвращает Some(C(n, k)) | |
// или None, если k > n | |
fn bin_coeff(n: u64, k: u64) -> Option<u64> { | |
let k = n.checked_sub(k)?.min(k); | |
let answer = (1..=n).rev() | |
.zip(1..=k) | |
.fold(1, |acc, (num, denum)| acc * num / denum); |
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
extern crate petgraph; | |
type Float = f64; | |
#[derive(Debug, PartialEq, PartialOrd, Clone, Copy)] | |
struct Probability(Float); | |
#[derive(Debug, PartialEq, Eq)] | |
enum ProbabilityError { | |
Malformed, |
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, PartialEq, Eq)] | |
enum GraphCheckError { /// Тип возможных ошибок при проверке графа | |
/// Ряд с указанным номером имеет длину, не совпадающую с количеством рядов | |
InvalidRow(usize), | |
} | |
fn check_if_simple_graph(adj: &[&[usize]]) -> Result<bool, GraphCheckError> { | |
let vertices = adj.len(); | |
// Убеждаемся, что матрица смежности квадратная |
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
#![deny(overflowing_literals, exceeding_bitshifts, const_err)] | |
/// Булеан (множество всех подмножеств) конечного | |
/// множества натуральных чисел. | |
/// Вместо множества множеств хранит размер | |
/// изначального множества, по которому булеан | |
/// легко строится. | |
#[derive(Debug, PartialEq, Eq, Clone, Copy)] | |
struct IntPowerSet(usize); |
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
import pytest | |
def power_set(size): | |
if size == 0: | |
raise ValueError("Size can't be zero") | |
if size > 10: | |
raise ValueError("Size is too big") | |
sets = [""] | |
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
#![deny(overflowing_literals, const_err)] | |
type Num = i32; | |
const LOW: Num = 1; | |
const HIGH: Num = 1_000_000; | |
#[derive(Debug, PartialEq, Eq)] | |
enum Argument { | |
First, |