Skip to content

Instantly share code, notes, and snippets.

@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 / 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}]
@taroyabuki
taroyabuki / onepage-aj16.tex
Last active August 29, 2015 14:04
Adobe-Japan1-6のすべてのグリフを1ページで http://blog.unfindable.net/archives/7785
\documentclass[a4paper]{jsarticle}
\usepackage[top=5mm,right=0mm,bottom=0mm,left=4mm]{geometry}
\usepackage{otf}
\usepackage{color}
\usepackage{pgffor}
\pagestyle{empty}
\openup -0.2mm
\newlength{\unit}
\setlength\unit{1.4mm}
\newcount \i
factor[n_] := Reverse[Flatten[
Map[Table[#[[1]], {#[[2]]}] &, FactorInteger[n]]]]
On[Assert];
Assert[factor[24] == {3, 2, 2, 2}];
draw[origin_, frame_, delta_, {p_, rest___}, start_] := {
Circle[origin, frame],
With[{r = If[p == 1, 1, frame Sin[Pi/p]/(1 + Sin[Pi/p])]},
Table[
960939379918958884971672962127852754715004339660129306651505519271702802395266424689642842174350718121267153782770623355993237280874144307891325963941337723487857735749823926629715517173716995165232890538221612403238855866184013235585136048828693337902491454229288667081096184496091705183454067827731551705405381627380967602565625016981482083418783163849115590225610003652351370343874461848378737238198224849863465033159410054974700593138339226497249461751545728366702369745461014655997933798537483143786841806593422227898388722980000748404719
@taroyabuki
taroyabuki / codeiq_q153.py
Last active December 11, 2015 19:28
CodeIQ「NumpyとScipyで統計基本復習」https://codeiq.jp/ace/tsuji_shingo/q153
# -*- coding: utf-8 -*-
import numpy as np
import scipy.stats as ss
import matplotlib.pyplot as plt
ss.binom.rvs(10, 0.3)
np.random.binomial(10, 0.3)
@taroyabuki
taroyabuki / bug_in_table.m
Last active December 11, 2015 21:18
http://blog.unfindable.net/archives/5410Bug in Mathematica 8.0.4, 9.0.0, 9.0.1 for Microsoft Windows (64-bit) (December 12, 2012).To avoid this issue, you need run the following command:SetSystemOptions["CompileOptions" -> {"TableCompileLength Infinity}]
f[] := With[{p = RandomVariate[NormalDistribution[]]}, If[0 <= p, p, f[]]]
data = Table[f[], {249}]; (* no problem *)
data2 = Table[f[], {250}]; (* crash! *)
g[] := With[{p = RandomVariate[BinomialDistribution[10, 1/10]]}, If[0 <= p, p, g[]]]
data = Table[g[], {249}]; (* no problem *)