P2Pのような中央集権型でない環境や、信頼できるノードが存在しないときは、合意形成が難しいため様々な手法が提案されています。
ここでは、麻雀を例にとり、各クライアントが自身の動作を悪意を持って制御可能な状況下で、 定められた手順通り正しく動作をしていて正しく動作し続けたことを後から検証する方法について述べます。
麻雀では山(壁牌)から牌を取り(自摸、ツモ)、手牌に加えたのち1枚を捨てる(打牌)ことを繰り返して役を揃えることを目指します。
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)); |
#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[]) | |
{ |
# 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 |
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); | |
} |
package io.github.kazoo04.palindrome | |
import scala.annotation.tailrec | |
object NextPalindrome { | |
@tailrec | |
def next(num: Int): Int = { | |
val n = num + 1 |
answer = "ABABCD" | |
str = "" | |
while not (print (str += answer.split('').uniq.sample)[-1] or str.end_with? answer) do end | |
puts "\ncount = #{str.length} |
# -*- encoding: utf-8 -*- | |
for n in 0...gets.to_i | |
print "「てら#{"あり" * n}w」" | |
end |
answer = "ABABCD" | |
chars = answer.split('').uniq | |
str = "" | |
count = 0 | |
while not str.end_with? answer | |
count += 1 | |
c = chars.sample | |
print c | |
str += c |