Skip to content

Instantly share code, notes, and snippets.

@quangnle
quangnle / expgen.fs
Last active August 29, 2015 14:17
Expression generator selective brackets updated
let rnd = System.Random()
[<AbstractClass>]
type Exp() =
abstract Value:int with get
abstract ExpString:string
default this.Value = 0
default this.ExpString = this.Value.ToString()
type ValueExp (value:int) =
@quangnle
quangnle / expgen.html
Last active February 3, 2017 11:01
expression generator on javascript
<html>
<head>
<title> Expression Generator </title>
<script>
function expr(value, left, op, right, hasParentheses){
this.value = value;
this.left = left;
this.right = right;
this.op = op;
@quangnle
quangnle / gf.fs
Last active August 29, 2015 14:18
find largest prime factor of integer
let rec gf a k =
if k = 1 then a
else
if a % k = 0 then gf k (k / 2)
else gf a (k - 1)
let greatestFactor a = gf a (a/2)
let v = greatestFactor 75
printfn "%d" v
@quangnle
quangnle / wildcardmatch2.fs
Last active March 9, 2016 03:46
masked matching direct recursive
let rec directmatch (s:string) (d:string) (i:int) (j:int) (prev:int) =
if i = s.Length then true
else
if s.[i] = '*' then directmatch s d (i + 1) j i
else
if j < d.Length then
if s.[i] = d.[j] then directmatch s d (i + 1) (j + 1) prev
else directmatch s d (prev + 1) (j - i + prev + 2) prev
else false
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EightQueen
{
class Program
{
@quangnle
quangnle / threadpool.cs
Created March 9, 2016 03:44
my tiny threadpool
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ThreadPool
{
class Program
using System;
using System.Collections.Generic;
using System.IO;
class Program
{
static long Solve(int n, int m, int[] c)
{
long[,] C = new long[n + 1, m];
for (var i = 0; i <= n; i++)
public class CharMapper
{
private static char[][] _dictionary = new char[14][]{ new char[] {'a', 'á', 'à', 'ả', 'ã', 'ạ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ă', 'ắ', 'ằ', 'ả', 'ẵ', 'ặ'},
new char[] {'d', 'đ'},
new char[] {'e', 'é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', 'ệ'},
new char[] {'i', 'í', 'ì', 'ỉ', 'ĩ', 'ị'},
new char[] {'o', 'ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ'},
new char[] {'u', 'ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', 'ự'},
new char[] {'y', 'ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ'},
new char[] {'A', 'Á', 'À', 'Ả', 'Ã', 'Ạ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ'
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Tuenti5
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tuenti7
{
class Program