Skip to content

Instantly share code, notes, and snippets.

@WilfredTA
WilfredTA / naive-backtrack-word-search.js
Last active February 17, 2019 21:51
The "dumb" version the backtracking algorithm for the word search problem on LeetCode
var exist = function(board, word) {
var seen = [];
var targetCharIdx = 0;
var result = {
found: false
};
existHelper(board, word, seen, result);
return result.found;
};
@WilfredTA
WilfredTA / naive-with-adjacent-branching.js
Created February 26, 2019 04:19
Slightly improved approach to word search using adjacent cell branching rather than checking for adjacent property at the end of path
var exist = function(board, word) {
var seen = [];
var targetCharIdx = 0;
var result = {
found: false
};
for (var i = 0; i < board.length; i++) {
for (var j = 0; j < board[0].length; j++) {
if (board[i][j] === word[targetCharIdx]) {
seen.push([i,j]);
@WilfredTA
WilfredTA / wordSearchImprovement2.js
Created February 26, 2019 06:20
Word search solution with unique cell and adjacent cell branching logic
var exist = function(board, word) {
var seen = [];
var targetCharIdx = 0;
var result = {
found: false
};
for (var i = 0; i < board.length; i++) {
for (var j = 0; j < board[0].length; j++) {
if (board[i][j] === word[targetCharIdx]) {
seen.push([i,j]);
@WilfredTA
WilfredTA / wordSearchImprovement3.js
Created February 26, 2019 06:27
Move word matching from end-of-path to branching logic
var exist = function(board, word) {
var seen = [];
var targetCharIdx = 0;
var result = {
found: false
};
for (var i = 0; i < board.length; i++) {
for (var j = 0; j < board[0].length; j++) {
if (board[i][j] === word[targetCharIdx]) {
@WilfredTA
WilfredTA / wordSearchWithSeenCache.js
Created February 26, 2019 17:16
Word search with branching logic and the addition of a seen cache and early return
var exist = function(board, word) {
var seen = [];
var targetCharIdx = 0;
var result = {
found: false
};
var seenCache = {};
for (var i = 0; i < board.length; i++) {
for (var j = 0; j < board[0].length; j++) {
if (result.found) return result.found;
@WilfredTA
WilfredTA / ckbinterface.js
Last active August 20, 2019 08:34
Some generator code extending js sdk - experiences errors
const fs = require('fs')
const Core = require('@nervosnetwork/ckb-sdk-core').default
class CKBInterface {
constructor(core, nodeUrl, privKey) {
this.core = new Core(nodeUrl)
this.privKey = privKey
@WilfredTA
WilfredTA / udt_proposal_alt.md
Last active February 14, 2020 16:14
An alternative design of user defined fungible token on Nervos Network's Common Knowledge Base

Base Fungible UDT Proposal Draft

Introduction

This document puts forth a proposed standard for Base Fungible user defined tokens (UDT) on Nervos Network’s Common Knowledge Base (CKB).

Relationship Between Properties, Transactions, and Operations

Transactions are the interface in CKB by which users perform operations (produce state changes). Transactions are composed of cells and cells can define type scripts that enforce constraints on any transaction in which the cell is included. Therefore descriptions of CKB operations are descriptions of transaction patterns, which in turn describe specific input, output, and dependency cells, as well as the constraints the input & output cells introduce into a transaction (via their type & lock scripts). The operations and their corresponding transaction patterns are the first two aspects of the standard that this document defines. The third aspect that this draft defines is the UDT extension mechanism through Lock.

@WilfredTA
WilfredTA / udt_proposal.md
Last active February 14, 2020 20:51
Proposal for User Defined Fungible Token standard on CKB

UDT Proposal Draft

Introduction

This document puts forth a proposed standard for user defined tokens (UDT) on Nervos Network’s Common Knowledge Base (CKB).

Transactions are the interface in CKB by which users perform operations (produce state changes). Transactions are composed of cells and cells can define type scripts that enforce constraints on any transaction in which the cell is included. Therefore descriptions of CKB operations are descriptions of transaction patterns. These patterns in turn describe specific input, output, and dependency cells, as well as the constraints the input & output cells introduce into a transaction (via their type & lock scripts). The operations and their corresponding transaction patterns are the first two aspects of the standard that this document defines. The third aspect that this draft defines is the UDT extension mechanism. The base standard is simple, defining only the bare minimum constraints for a fungible token. This will allow greater flexibility and oppor

@WilfredTA
WilfredTA / nat_exp.ath
Created July 20, 2022 03:27
Nat Nullify Test Athena
module Nat {
datatype N := zero | (S N)
declare +: [N N] -> N [200] # precedence 200
declare *: [N N] -> N [300] # precedence 300
declare **: [N N] -> N [400] # precedence 400
declare Nul: [N] -> N
# Some variables to use in definitions & proofs