Skip to content

Instantly share code, notes, and snippets.

@mhgp
mhgp / fold
Last active November 23, 2016 09:46
Rust で解く 1 から max までのすべての自然数の最小公倍数 ref: http://qiita.com/mhgp/items/711a7bb8e00bff607660
///a と b の最大公約数を求める
fn gcd(a: usize, b: usize) -> usize {
if a % b == 0 {
b
} else {
gcd(b, a % b)
}
}
///ループ処理
@mhgp
mhgp / sha2.rs
Created November 5, 2016 13:37
Rust で SHA-2 を実装してみた
use std::boxed::Box;
macro_rules! Ch {
($x:expr, $y:expr, $z:expr) => { ($x & $y) ^ (!$x & $z) };
}
macro_rules! Maj {
($x:expr, $y:expr, $z:expr) => { ($x & $y) ^ ($x & $z) ^ ($y & $z) };
}
@mhgp
mhgp / check.rs
Last active September 20, 2019 08:06
Rust でも愛を生む二人を探す
use std::path::Path;
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
/// &str 型から char 型に変換
/// # Panics
/// 文字列が1文字ではなかった場合、 panic を発生させる。
fn get_char(s: &str) -> char {