Skip to content

Instantly share code, notes, and snippets.

View komasaru's full-sized avatar

mk-mode komasaru

View GitHub Profile
@komasaru
komasaru / rpn.rb
Created October 2, 2020 01:05
Ruby script to calculate a formula expressed with RPN.
#! /usr/local/bin/ruby
#*********************************************************
# Ruby script to caculate a formula string by RPN.
#*********************************************************
class String
RE_0 = Regexp.new('[=\s]+$')
RE_1 = Regexp.new('\s+')
RE_D = Regexp.new('\d+')
RE_PL = Regexp.new('\+')
@komasaru
komasaru / infix2rpn.rb
Last active October 5, 2020 01:57
Ruby script to convert a formula string to a RPN.
#! /usr/local/bin/ruby
#*********************************************************
# Ruby script to convert string to RPN.
# (Unary operators are not supported)
#*********************************************************
class String
RE_0 = Regexp.new('\s+|\=')
RE_1 = Regexp.new('[\d\.]+|[()*/+\-]')
RE_D = Regexp.new('\d+')
@komasaru
komasaru / vincenty.cpp
Last active September 16, 2020 01:36
C++ source code to calculate geodesical values by Vincenty's formulae.(destination)
#include "vincenty.hpp"
#include <cmath>
#include <iostream>
#include <tuple>
namespace my_lib {
// 定数
constexpr double kA = 6378137.0; // GRS80 長半径
constexpr double kF = 1.0 / 298.257222101; // GRS80 扁平率
@komasaru
komasaru / vincenty.cpp
Created September 16, 2020 01:17
C++ source code to calculate geodesical values by Vincenty's formulae.(distance)
#include "vincenty.hpp"
#include <cmath>
#include <iostream>
#include <tuple>
namespace my_lib {
// 定数
constexpr double kA = 6378137.0; // GRS80 長半径
constexpr double kF = 1.0 / 298.257222101; // GRS80 扁平率
@komasaru
komasaru / calc.cpp
Last active January 21, 2024 22:45
C++ source code to calculate a Kendall's Rank Correlation Coefficient.
#include "calc.hpp"
#include <algorithm> // for std::count
#include <cmath> // for std::sqrt
#include <iostream>
#include <unordered_map>
#include <vector>
Calc::Calc(std::vector<std::vector<double>>& data) {
try {
@komasaru
komasaru / calc.cpp
Last active May 23, 2022 19:53
C++ source code to calculate a Spearman's Rank Correlation Coefficient.
#include "calc.hpp"
#include <algorithm> // for std::count
#include <cmath> // for std::sqrt
#include <iostream>
#include <unordered_map>
#include <vector>
Calc::Calc(std::vector<std::vector<double>>& data) {
try {
@komasaru
komasaru / rank_2.cpp
Last active September 7, 2020 06:22
C++ source code to rank, considering same ranks(mid-rank method).
/***************************************************************
Rank of numbers (integer) (by central rank method)
$ g++ -std=c++17 -Wall -O2 --pedantic-errors -o rank_2 rank_2.cpp
DATE AUTHOR VERSION
2020.09.04 mk-mode.com 1.00 新規作成
Copyright(C) 2020 mk-mode.com All Rights Reserved.
***************************************************************/
@komasaru
komasaru / rank.cpp
Last active September 7, 2020 06:06
C++ source code to rank, considering same ranks.
/***************************************************************
Rank of numbers (integer)
$ g++ -std=c++17 -Wall -O2 --pedantic-errors -o rank rank.cpp
DATE AUTHOR VERSION
2020.08.31 mk-mode.com 1.00 新規作成
Copyright(C) 2020 mk-mode.com All Rights Reserved.
***************************************************************/
@komasaru
komasaru / binomial_coefficients.cpp
Last active September 8, 2020 14:53
C++ source code to calculate binomial coefficients.
/***************************************************************
Binomial coefficients
by GMP(The GNU Multi Presicion Arithmetic Library).
DATE AUTHOR VERSION
2020.08.24 mk-mode.com 1.00 新規作成
Copyright(C) 2020 mk-mode.com All Rights Reserved.
***************************************************************/
#include "common.hpp"
@komasaru
komasaru / is_real.cpp
Last active August 26, 2020 01:44
C++ source code to judge if a string is an real number.
/***************************************************************
Check real number
$ g++ -std=c++17 -Wall -O2 --pedantic-errors -o is_real is_real.cpp
DATE AUTHOR VERSION
2020.08.24 mk-mode.com 1.00 新規作成
Copyright(C) 2020 mk-mode.com All Rights Reserved.
***************************************************************/