婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 比特幣上的數(shù)獨游戲合約的實現(xiàn)代碼

比特幣上的數(shù)獨游戲合約的實現(xiàn)代碼

熱門標(biāo)簽:合肥阿里辦理400電話號 怎么去掉地圖標(biāo)注文字 廊坊地圖標(biāo)注申請入口 地圖標(biāo)注資源分享注冊 襄陽外呼增值業(yè)務(wù)線路解決方案 北京外呼系統(tǒng)咨詢電話 海南人工外呼系統(tǒng)哪家好 慶陽外呼系統(tǒng)定制開發(fā) 高德地圖標(biāo)注公司位置需要錢嗎

我們在 Bitcoin SV 上實現(xiàn)了一個數(shù)獨游戲智能合約,利用之前介紹過的一種合約范式可以將游戲中尋找解題方案的過程外包上鏈。因為求解數(shù)獨問題的計算工作量會隨著其行列數(shù)快速增長,實際上它也是一個 NP-完全 問題。不過我們可以借由比特幣智能合約巧妙地尋求答案,只需要驗證答案提供者所給出的解答是否滿足要求即可,這樣即可以將復(fù)雜的求解計算過程實現(xiàn)鏈下外包。

sCrypt 合約代碼如下:

import "util.scrypt";
import "array.scrypt";

contract Sudoku {

 bytes board;

 static const int N = 9;
 static bytes EMPTY = b'00';

 constructor(bytes board) {
  this.board = board;
 }

 function merge(bytes solution) : bytes {
  bytes newBoard = this.board;
  int i = 0;
  loop (N) {
   int j = 0;
   loop (N) {

    int value = this.readValue(newBoard, i, j);
    int inputValue = this.readValue(solution, i, j);
    if (value == 0) {
     require(inputValue = 9);
     newBoard = this.setValue(newBoard, i, j, inputValue);
    } else {
     require(value == inputValue);
    }
    j++;
   }

   i++;
  }
  return newBoard;
 }

 public function solve(bytes solution) {

  require(len(solution) == Sudoku.N * Sudoku.N);

  bytes newBord = this.merge(solution);

  Array rowArray = new Array();
  Array colArray = new Array();
  Array squareArray = new Array();

  int i = 0;
  loop (N) {
   int j = 0;

   loop (N) {
    // check for duplicate

    // in a row
    int rowElem = this.readValue(newBord, i, j);
    require(rowArray.indexOf(rowElem) == -1);
    rowArray.push(rowElem);

    // in a column
    int colElem = this.readValue(newBord, j, i);
    require(colArray.indexOf(colElem) == -1);
    colArray.push(colElem);

    // in a subgrid
    int squareElem = this.readSquareValue(newBord, i, j);
    require(squareArray.indexOf(squareElem) == -1);
    squareArray.push(squareElem);

    j++;
   }

   rowArray.clear();
   colArray.clear();
   squareArray.clear();

   i++;
  }

  require(true);
 }

 static function readValue(bytes board, int i, int j): int {
  return Util.fromLEUnsigned(Util.getElemAt(board, Sudoku.index(i, j)));
 }

 static function setValue(bytes board, int i, int j, int value): bytes {
  return Util.setElemAt(board, this.index(i, j), Util.toLEUnsigned(value, 1));
 }

 static function readSquareValue(bytes board, int i, int j): int {
  return Util.fromLEUnsigned(Util.getElemAt(board, Sudoku.indexSquare(i, j)));
 }


 static function index(int row, int col) : int {
  return row * Sudoku.N + col;
 }

 static function indexSquare(int i, int j) : int {
  int row = i / 3 * 3 + j / 3;
  int col = i % 3 * 3 + j % 3;
  return Sudoku.index(row, col);
 }
}

到此這篇關(guān)于比特幣上的數(shù)獨游戲合約的實現(xiàn)代碼的文章就介紹到這了,更多相關(guān)比特幣數(shù)獨游戲合約內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • python程序?qū)崿F(xiàn)BTC(比特幣)挖礦的完整代碼
  • C++實現(xiàn)比特幣系統(tǒng)的源碼
  • Python實現(xiàn)類似比特幣的加密貨幣區(qū)塊鏈的創(chuàng)建與交易實例
  • C++實現(xiàn)區(qū)塊鏈的源碼
  • Go語言開發(fā)區(qū)塊鏈只需180行代碼(推薦)
  • JavaScript實現(xiàn)區(qū)塊鏈
  • 普通人如何在區(qū)塊鏈行業(yè)賺錢
  • 使用go實現(xiàn)簡易比特幣區(qū)塊鏈公鏈功能

標(biāo)簽:哈密 臺州 鶴崗 株洲 平頂山 鎮(zhèn)江 商丘 綿陽

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《比特幣上的數(shù)獨游戲合約的實現(xiàn)代碼》,本文關(guān)鍵詞  比特,幣,上,的,數(shù)獨,游戲,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《比特幣上的數(shù)獨游戲合約的實現(xiàn)代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于比特幣上的數(shù)獨游戲合約的實現(xiàn)代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 汝阳县| 永定县| 呼和浩特市| 昌黎县| 黄陵县| 绥芬河市| 济阳县| 鹤峰县| 莱芜市| 额济纳旗| 景东| 安陆市| 沂水县| 合阳县| 维西| 平顺县| 兰州市| 任丘市| 永嘉县| 长泰县| 腾冲县| 石楼县| 深泽县| 嘉义县| 托克托县| 宁远县| 阳城县| 广安市| 兰西县| 临洮县| 宁波市| 苗栗市| 库伦旗| 湖口县| 青川县| 淮北市| 二手房| 建水县| 中西区| 乡城县| 洪江市|