Skip to content

Instantly share code, notes, and snippets.

@gwang
gwang / gist:39ffce190d7d3a98b8b8
Last active August 29, 2015 14:14
Rotate a potentially large string about a pivot point
#include <stdlib.h>
#include <stdio.h>
void reverse(char *data, int start, int end)
{
int i; char tmp;
for (i=0; i<(end-start)/2; i++)
{
tmp = data[i+start];
@gwang
gwang / per_com.rb
Last active December 22, 2015 01:28
compute the permutation and combination of a string (or a collection of characters)
def permutation(data, used=nil, prev='')
used = Array.new(data.size) if used == nil
(0..data.size-1).each do |i|
result = prev
if used[i] == false || used[i] == nil
used[i] = true
result += data[i]
if result.length == data.size
puts result
@gwang
gwang / bingo.txt
Created May 11, 2012 04:43
Multiplication Bingo in Tcl Using SAPI
{0 {{0 0} {0 1} {0 2} {0 3} {0 4} {0 5} {0 6} {0 7} {0 8} {0 9} {0 10} {0 11} {0 12} {1 0} {2 0} {3 0} {4 0} {5 0} {6 0} {7 0} {8 0} {9 0} {10 0} {11 0} {12 0}}}
{1 {{1 1}}}
{2 {{1 2} {2 1}}}
{3 {{1 3} {3 1}}}
{4 {{1 4} {2 2} {4 1}}}
{5 {{1 5} {5 1}}}
{6 {{1 6} {2 3} {3 2} {6 1}}}
{7 {{1 7} {7 1}}}
{8 {{1 8} {2 4} {4 2} {8 1}}}
{9 {{1 9} {3 3} {9 1}}}
@gwang
gwang / gist:2657578
Created May 11, 2012 04:40
Multiplication Bingo in Ruby Using SAPI
# Using Windows SAPI
require 'win32/sapi5'
include Win32
v = SpVoice.new
data = Hash.new
(0..12).each { |i|
(0..12).each { |j|
p = i*j
data[p] = Array.new if data[p].nil?