Skip to content

Instantly share code, notes, and snippets.

@fhiyo
fhiyo / quicksort.rb
Last active December 26, 2023 16:16
Rubyで quicksort (末尾再帰除去)
def qsort(nums)
execute(nums, 0, nums.size - 1)
end
def execute(nums, left, right)
while left < right
pivot = partition(nums, left, right)
if pivot - left <= right - pivot
execute(nums, left, pivot - 1)
left = pivot + 1
@fhiyo
fhiyo / k_permutations.rs
Last active May 1, 2022 17:54
Generate k-permutations in Rust
// rustc 1.48.0 (7eac88abb 2020-11-16)
struct PermutationIterator<T> {
v: Vec<(usize, T)>,
k: usize,
finished: bool,
}
impl<T> PermutationIterator<T> {
fn new<I: Iterator<Item = T>>(iter: I, k: usize) -> PermutationIterator<T> {
@fhiyo
fhiyo / .latexmkrc
Last active January 10, 2022 14:05
傾向スコアがバランシングスコアであることの証明
$latex = 'platex';
$bibtex = 'pbibtex';
$dvipdf = 'dvipdfmx %O -o %D %S';
$makeindex = 'mendex -U %O -o %D %S';
$pdf_mode = 3;
@fhiyo
fhiyo / viterbi.cpp
Created February 16, 2020 06:17
viterbiアルゴリズムの実装例
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
using ld = long double;
// ref: https://mieruca-ai.com/ai/viterbi_algorithm/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fhiyo
fhiyo / time-series-sample.ipynb
Created October 11, 2018 14:58
A time-series' pseudo-correction sample.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fhiyo
fhiyo / clean_download_dir.sh
Created September 9, 2018 04:34
Clean your Downloads directory.
#!/usr/bin/env bash
## Description:
## Author : fhiyo
## Email : fhiyo1201@gmail.com
set -u
declare -r SCRIPT_NAME=$( basename ${BASH_SOURCE[0]} )
@fhiyo
fhiyo / opencv-prewitt-sample.py
Created August 21, 2018 21:11
opencvによるエッジ抽出のサンプル
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import cv2
import numpy as np
def main():
gray = cv2.imread('lena_std.png', 0) # 入力画像をグレースケールで読み込み
# gray = np.asarray([[0, 0, 1, 1], [0, 0, 1, 7], [1, 0, 8, 8], [0, 1, 8, 9]], dtype=np.uint8)
@fhiyo
fhiyo / house-prices-with-julia.ipynb
Last active April 15, 2018 17:02
(Kaggle's house prices competition) sample randomForest regression with Julia
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fhiyo
fhiyo / how-to-decide-sample-size.ipynb
Created April 6, 2018 16:03
How to decide sample size
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.