Skip to content

Instantly share code, notes, and snippets.

@dc1394
dc1394 / MyCalendar14seqDirectWrite.cpp
Last active August 29, 2015 14:07
カレンダープログラミングのソースコード
// Myoga S. Tomonaka 様の「14セグメントのドットマトリックスで日付を表示するカレンダー」
// ( https://gist.github.com/Myoga1012/8e56f44ecd710555a06c )
// を、DirectWriteに移植してみました。
// Kenny Kerr 様の
// 「DirectX プログラミング用の最新 C++ ライブラリ」
// ( http://msdn.microsoft.com/ja-jp/magazine/dn201741.aspx )
// を使用させて頂いています。また、このライブラリのサンプルコード
// ( http://dx.codeplex.com/SourceControl/latest )
// を参考にさせて頂いています。
// 例によってC++11とBoostも使用しています。
#include <complex>
#include <iostream>
#include <locale>
#include <string>
int main()
{
std::wstring const haiku = { L"島々に    灯をともしけり春の海       正岡子規" };
std::complex<int> c(3, 0), cp(c);
std::complex<int> const r(-1, 0), i(0, 1);
require 'csv'
require 'json'
require 'net/http'
require 'uri'
def jsontocsv(instance_name)
target_url = 'https://instances.mastodon.xyz/api/instances/history.json?instance=' +
instance_name + '&start=0&end=' + Date.today.to_time.to_i.to_s
parsed = JSON.parse(Net::HTTP.get(URI.parse(target_url)))
#include <iostream> // for std::cout, std::endl
#include <iterator> // for std::distance
#include <boost/range/algorithm/max_element.hpp> // for boost::max_element
int main()
{
auto const height = { 165.5, 155.0, 170.0, 168.0, 50.0, 200.0, 250.0, 2.0, 20.0 };
auto const itr = boost::max_element(height);
std::cout << "身長の最大値は" << *itr << "cmで、生徒の番号は" << std::distance(height.begin(), itr) + 1 << "です。" << std::endl;
@dc1394
dc1394 / find_common_tangent.jl
Last active June 15, 2024 10:02
二つの任意の曲線(関数)の共通接線を求めるプログラム
# 二つの任意の曲線(関数)の、共通接線を求めるJuliaプログラム
# それほど精度が良くないので、使用する際は注意してください
# ライセンスは2-Clause BSDライセンス
using ForwardDiff
using Printf
using Roots
# 内側のfind_xerosで、根を探したときに見つからなかった時に適当に返す値
const FIND_G_ROOT_TMP = 1000.0
# 共通接線の探索範囲
@dc1394
dc1394 / newton.cpp
Last active December 26, 2023 16:08
Twitterの1D-Newton法の速度比較のコード
#include <fstream> // for std::ofstream
#include <iomanip> // for std::setprecision
#include <ios> // for std::scientific
#include <utility> // for std::make_pair, std::pair
#include <vector> // for std::vector
namespace {
std::pair<double, double> Runge_Kutta_4th(double x, double v, double dt, double mass, double k);
double force(double x, double mass, double k);
}
@dc1394
dc1394 / newton.rs
Created December 26, 2023 12:02
Twitterの1D-Newton法の速度比較のコード(Rust版)
use std::fs::File;
use std::io::Write;
fn main() {
let mass = 1.0;
let k = 1.0;
let dt = 1e-2;
let nt = 100000000;
let mut xt = vec![0.0; nt + 1];
@dc1394
dc1394 / newton_array_time.cpp
Last active December 27, 2023 10:09
Twitterの1D-Newton法の速度比較のコード(C++版、動的配列時間計測付き)
#include <chrono> // for std::chrono
#include <fstream> // for std::ofstream
#include <iomanip> // for std::setprecision
#include <ios> // for std::ios::fixed, std::ios::floatfield, std::scientific
#include <iostream> // for std::cout
#include <utility> // for std::make_pair, std::pair
#include <vector> // for std::vector
namespace {
std::pair<double, double> Runge_Kutta_4th(double x, double v, double dt, double mass, double k);
@dc1394
dc1394 / newton_time.cpp
Created December 27, 2023 10:08
Twitterの1D-Newton法の速度比較のコード(C++版時間計測付き)
#include <chrono> // for std::chrono
#include <fstream> // for std::ofstream
#include <iomanip> // for std::setprecision
#include <ios> // for std::ios::fixed, std::ios::floatfield, std::scientific
#include <iostream> // for std::cout
#include <utility> // for std::make_pair, std::pair
#include <vector> // for std::vector
namespace {
std::pair<double, double> Runge_Kutta_4th(double x, double v, double dt, double mass, double k);
@dc1394
dc1394 / newton_time.f90
Created December 27, 2023 10:18
Twitterの1D-Newton法の速度比較のコード(Fortran版、時間計測付き)
program main
implicit none
real(8) :: x, v
real(8),allocatable :: xt(:), vt(:)
real(8) :: mass, k, dt
integer :: i, it, nt, clock_rate
integer, dimension(5) :: cp
real(8) :: elapsed_time
mass = 1d0