Skip to content

Instantly share code, notes, and snippets.

@taroyabuki
taroyabuki / opencl-devices.c
Last active December 15, 2015 10:09
OpenCLに対応するデバイスの列挙 http://blog.unfindable.net/archives/5829
#include <stdio.h>
#include <stdlib.h>
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
#define MAX_PLATFORM_IDS 8
@taroyabuki
taroyabuki / hello-0.w
Last active December 19, 2015 05:59
Literate Programming
@ hello, world! と出力するC言語のプログラムは以下のとおり。
@c
#include <stdio.h>
main()
{
printf("hello, world\n");
}
@taroyabuki
taroyabuki / hello-1.w
Last active December 19, 2015 05:59
Literate Programming
@ hello, world! と出力するC言語のプログラムは以下のとおり。
@c
@<Header files to include@>@/
@<The main program@>
@ 標準入出力のためのライブラリを利用するようにコンパイラに指示する。
@<Header files to include@>=
#include <stdio.h>
@taroyabuki
taroyabuki / hello-2.w
Last active December 19, 2015 05:59
Literate Programming
@*The first C program.
``\.{hello, world!}''と出力するC言語のプログラムは以下のとおり。
@c
@<Header files to include@>@/
@<The main program@>
@ 標準入出力のためのライブラリを利用するようにコンパイラに指示する。
@taroyabuki
taroyabuki / magicsquare2.cpp
Created March 18, 2014 04:37
(結果の検証付き)スパコンで約2時間36分かかったという、5×5の魔方陣の全解列挙を、パソコンで試す(C++)http://blog.unfindable.net/archives/7179
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <ctime>
#include <omp.h>
#include <unordered_set>
using namespace std;
const char* outputfile = "result";
@taroyabuki
taroyabuki / magicsquare4.cc
Created June 7, 2014 15:53
魔方陣の解の数を一瞬で求めるプログラム 4x4の魔方陣の場合 http://blog.unfindable.net/archives/7466
#include <iostream>
const int s = 34;
constexpr int eq(int a, int b) { return a != b ? 0 : a; }
constexpr int check(int used, int x1, int x4, int x13, int x16, int x2, int x3, int x5, int x6, int x7, int x8, int x9, int x10, int x11, int x12, int x14, int x15) {
return (x15 < 1 || x15 > 16) ? 0 :
(((used & (1 << x15)) ? 0 : 1));
}
constexpr int check(int used, int x1, int x4, int x13, int x16, int x2, int x3, int x5, int x6, int x7, int x8, int x9, int x10, int x11, int x12, int x14) {
return (x14 < 1 || x14 > 16) ? 0 :
(((used & (1 << x14)) ? 0 : check(used + (1 << x14), x1, x4, x13, x16, x2, x3, x5, x6, x7, x8, x9, x10, x11, x12, x14, eq(s - x13 - x14 - x16, s - x3 - x7 - x11))));
@taroyabuki
taroyabuki / magicsquare5.cc
Created June 7, 2014 15:54
魔方陣の解の数を一瞬で求めるプログラム 5x5の魔方陣の場合 http://blog.unfindable.net/archives/7466
#include <iostream>
const int s = 65;
constexpr int eq(int a, int b) { return a != b ? 0 : a; }
constexpr int check(int used, int x7, int x9, int x17, int x19, int x13, int x1, int x25, int x5, int x21, int x2, int x3, int x4, int x12, int x22, int x24, int x14, int x23, int x8, int x18, int x6, int x10, int x11, int x15, int x16, int x20) {
return (x20 < 1 || x20 > 25) ? 0 :
(((used & (1 << x20)) ? 0 : 1));
}
constexpr int check(int used, int x7, int x9, int x17, int x19, int x13, int x1, int x25, int x5, int x21, int x2, int x3, int x4, int x12, int x22, int x24, int x14, int x23, int x8, int x18, int x6, int x10, int x11, int x15, int x16) {
return (x16 < 1 || x16 > 25) ? 0 :
(((used & (1 << x16)) ? 0 : check(used + (1 << x16), x7, x9, x17, x19, x13, x1, x25, x5, x21, x2, x3, x4, x12, x22, x24, x14, x23, x8, x18, x6, x10, x11, x15, x16, eq(s - x16 - x17 - x18 - x19, s - x5 - x10 - x15 - x25))));
@taroyabuki
taroyabuki / pythagoras3body.m
Last active October 8, 2024 03:06
ピタゴラス3体問題 (Burrau’s problem of three bodies) https://taroyabuki.github.io/2009/06/26/burraus-problem-of-three-bodies/
(*Mass*)
m = {3, 4, 5};
n = Length@m;
(*Coordination*)
p = Array[{Subscript[px, #][t], Subscript[py, #][t]} &, n];
q = Array[{Subscript[ x, #][t], Subscript[ y, #][t]} &, n];
initialCondition = {
p == {{0, 0}, { 0, 0}, {0, 0}},
@taroyabuki
taroyabuki / pedestrian-eraser.pde
Created July 10, 2014 16:03
ウェブカメラに写る歩行者をProcessingで消す方法 http://blog.unfindable.net/archives/7642
import processing.video.*;
Capture capture;
int t = 0;
int mask = (1 << 8) - 1;
void setup() {
size(640, 480);
background(0);
capture = new Capture(this, 640, 480);
Manipulate[MandelbrotSetPlot[
{center[[1]] - 10^scale + I (center[[2]] - 10^scale),
center[[1]] + 10^scale + I (center[[2]] + 10^scale)},
MaxIterations -> iterations],
{{center, {-0.5, 0}}, Locator},
{{scale, 0, "Scale"}, -9, 1},
{{iterations, 20, "MaxIterations"}, 10, 2000, 10}]