This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- desc big int add & mul | |
-- maintainer hugoyu | |
local big_int = {} | |
local min_add_digit_num = 9 | |
local min_mul_digit_num = 5 | |
local function digit_num(v) | |
return #tostring(v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function try_get_upvalue(func, name) | |
local upvalue_index = 1 | |
while true do | |
local u_name, u_value = debug.getupvalue(func, upvalue_index) | |
if not u_name then | |
break | |
elseif u_name == name then | |
return u_name, u_value, upvalue_index | |
end | |
upvalue_index = upvalue_index + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Collections.Generic; | |
using System.Collections.ObjectModel; | |
public class Heap<T> where T : IEquatable<T> | |
{ | |
public static Heap<T> Build(IEnumerable<T> items, Func<T, T, bool> predicate) | |
{ | |
var heap = new Heap<T>(predicate); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using System.Collections.Generic; | |
public static class LCS | |
{ | |
struct LCSInfo | |
{ | |
public int Len; | |
public int BackType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
public static class RLE | |
{ | |
public const byte ESCAPE = 92; // '\' | |
public const byte MAX_DUPLICATE_COUNT = byte.MaxValue; | |
public static byte[] Compress(byte[] input) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
public interface ITuple | |
{ | |
int Length | |
{ | |
get; | |
} | |
object this[int index] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Sample | |
{ | |
static int gsN = 127; // N(N+1)/2 = 8128 < 2^{13} | |
static float gsB = 2 * gsN + 1; | |
static float gsB2 = gsB * gsB; | |
static float gsFactor = (gsN - 1) * Mathf.Sqrt(0.5f); | |
static float gsInvFactor = 1.0f / gsFactor; | |
public static ushort CompressNormal(Vector3 normal) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// desc simple implementation of sparse matrix | |
// maintainer hugoyu | |
#ifndef __sparse_matrix_h__ | |
#define __sparse_matrix_h__ | |
#include <cassert> | |
#include <string> | |
#include "common.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// desc simple implementation of matrix | |
// maintainer hugoyu | |
#ifndef __matrix_h__ | |
#define __matrix_h__ | |
#include <cassert> | |
#include <cstring> // memset | |
#include <memory> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// desc simple calculator constrains implementation | |
// note codes(adjusted) from https://www.codeproject.com/Articles/33617/Arithmetic-in-Generic-Classes-in-C | |
// maintainer hugoyu | |
using System; | |
/// <summary> | |
/// This interface defines all of the operations that can be done in generic classes | |
/// These operations can be assigned to operators in class Number<T> | |
/// </summary> |
NewerOlder