Skip to content

Instantly share code, notes, and snippets.

View kazoo04's full-sized avatar

Kazuya Gokita kazoo04

  • Garm Inc.
  • Tokyo
View GitHub Profile
@kazoo04
kazoo04 / xorshift.c
Created September 11, 2014 05:58
XorShift
unsigned long xorshift() {
static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
unsigned long t;
t = (x ^ (x << 11));
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
@kazoo04
kazoo04 / detector.cpp
Last active October 15, 2020 09:17
メチャクチャわかりやすい cv::DenseFeatureDetector のサンプル
#include <iostream>
#include <fstream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#define IMAGE_SIZE 280
int main(int argc, char* argv[])
{
@kazoo04
kazoo04 / placement.rb
Last active January 10, 2019 14:59
Dr. Mario: placement viruses
# coding: utf-8
WIDTH = 8
HEIGHT = 16
$field = Array.new(WIDTH).map{Array.new(HEIGHT, :none)}
def cell(x, y, offset_x = 0, offset_y = 0)
_x = x + offset_x
_y = y + offset_y
@kazoo04
kazoo04 / p2p_mahjong.md
Created May 3, 2016 14:11
P2Pで麻雀をする方法

はじめに

P2Pのような中央集権型でない環境や、信頼できるノードが存在しないときは、合意形成が難しいため様々な手法が提案されています。

ここでは、麻雀を例にとり、各クライアントが自身の動作を悪意を持って制御可能な状況下で、 定められた手順通り正しく動作をしていて正しく動作し続けたことを後から検証する方法について述べます。

問題設定

麻雀では山(壁牌)から牌を取り(自摸、ツモ)、手牌に加えたのち1枚を捨てる(打牌)ことを繰り返して役を揃えることを目指します。

import cv2
import numpy as np
def create_template():
templates = []
for text in list('0123456789'):
img = np.zeros((200,200,1), dtype=np.uint8)
cv2.putText(img, text, (100, 100), cv2.FONT_HERSHEY_DUPLEX, 2, 255, 5)
contours, _ = cv2.findContours(img.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
x, y, w, h = cv2.boundingRect(contours[0])
import std.stdio;
import std.array;
import std.utf;
void main() {
string s = "AあBい";
foreach(c; array(s)) {
foreach(b; [c].toUTF8) {
writef("%02x ", b);
}
@kazoo04
kazoo04 / NextPalindrome.scala
Created January 10, 2014 16:55
Next Palindrome
package io.github.kazoo04.palindrome
import scala.annotation.tailrec
object NextPalindrome {
@tailrec
def next(num: Int): Int = {
val n = num + 1
@kazoo04
kazoo04 / yukkuri.rb
Last active December 26, 2015 12:49
answer = "ABABCD"
str = ""
while not (print (str += answer.split('').uniq.sample)[-1] or str.end_with? answer) do end
puts "\ncount = #{str.length}
@kazoo04
kazoo04 / teraari.rb
Created October 24, 2013 05:04 — forked from sasamijp/teraari.rb
# -*- encoding: utf-8 -*-
for n in 0...gets.to_i
print "「てら#{"あり" * n}w」"
end
@kazoo04
kazoo04 / braro.rb
Created October 20, 2013 11:41
@bra_ro_
answer = "ABABCD"
chars = answer.split('').uniq
str = ""
count = 0
while not str.end_with? answer
count += 1
c = chars.sample
print c
str += c