Skip to content

Instantly share code, notes, and snippets.

@tetsuok
tetsuok / merge_sort.js
Last active April 3, 2022 13:00
マージソート
'use strict';
// 与えられた配列を昇順にマージソートでソートした配列を返す.
function mergeSort(array) {
if (array.length <= 1) {
return array;
}
const mid = Math.floor(array.length / 2);
const a = array.slice(0, mid); // array[0:mid]
const b = array.slice(mid); // array[mid:]
@tetsuok
tetsuok / primes.js
Last active April 3, 2022 13:39
素因数分解
'use strict';
// 自然数nを素因数分解して、素因数の配列を返す.
function calcPrimeFactor(n) {
const result = [];
let x = n;
for (let i = 2; i * i <= x; i++) {
while (x % i === 0) {
result.push(i);
x /= i;
@tetsuok
tetsuok / scan.h
Created February 13, 2021 17:48
Fast input reader for competitive programming
#pragma once
#include <ctype.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string_view>
#include <type_traits>
@tetsuok
tetsuok / patch.c
Last active September 11, 2016 17:41
/*
* Copyright (c) 2007 Russ Cox.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the
* Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so,
Title Authors
60分でハングルが読める! 「ハングル大好き!」編集部
A smarter way to learn JavaScript Mark Myers
Angular JS Up & Running Shyam Seshadri & Brad Green
Apache実践運用/管理 鶴長鎮一
Async & Performance Kyle Simpson
Data visualization with JavaScript Stephen A. Thomas
Gitによるバージョン管理 岩松信洋
Interactive Data Visualization for the Web Scott Murray
@tetsuok
tetsuok / foil_optimizer.cpp
Created February 7, 2016 23:56 — forked from socantre/foil_optimizer.cpp
CppCon 2015: Chandler Carruth "Tuning C++: Benchmarks, and CPUs, and Compilers! Oh My!" functions to disable compiler optimization
static void escape(void *p) {
asm volatile("" : : "g"(p) : "memory");
}
static void clobber() {
asm volatile("" : : : "memory");
}
@tetsuok
tetsuok / auto.cc
Last active January 25, 2016 09:32
// g++ -std=c++11 auto.cc
#include <vector>
#include <string>
#include <iostream>
static std::vector<std::string> Foo() {
decltype(Foo()) v;
v.push_back("aii");
return v;
}
#include <vector>
#include <stdio.h>
using namespace std;
class Test {
public:
Test(int) { printf("ctor\n"); }
Test(const Test&) { printf("copy ctor\n"); }
};
#include <stdio.h>
class A {
public:
virtual ~A() {}
virtual void f(int) {}
};
class B : public A {
public:
void f(size_t) override {} // error
@tetsuok
tetsuok / nrvo.cc
Last active August 29, 2015 14:21
NRVO
#include <iostream>
class A {
public:
A() {}
~A() { std::cout << "destructed" << std::endl; }
A(const A&) {
std::cout << "copy" << std::endl;
}