Skip to content

Instantly share code, notes, and snippets.

@tomtung
tomtung / SRM144-BinaryCode.cs
Created November 12, 2012 08:27
TopCoder Algorithm
using System.Text;
public class BinaryCode
{
public string[] decode(string message)
{
int[] messageInts = new int[message.Length];
{
for (int i = 0; i < message.Length; i += 1)
messageInts[i] = message[i] - '0';
@tomtung
tomtung / example.scala
Created October 23, 2012 08:13
Forward-backward Algorithm For Part-of-speech Tagging
// Example: distinguishing between vowels and consonants
val corpus =
Seq( // I swear these are all English words
"antidisestablishmentarian", "ablutophobia", "automatonophobia", "autotonsorialist",
"arachibutyrophobia", "automysophobia", "batrachophagous", "ballistocardiograph",
"blandiloquence", "brachydactylous", "bathythermograph", "cacodemomania",
"caesaropapism", "catapedamania", "cheiloproclitic", "chronosynchronicity",
"dendrochronology", "deorsumversion", "dermatoglyphics", "dolichocephalic",
"dysmorphophobia", "eellogofusciouhipoppokunurious", "electroencephalograph", "epiphenomenalism",
@tomtung
tomtung / gist:3765178
Created September 22, 2012 05:00
a parser and interpreter for the CFWAE language
;; http://www.cs.brown.edu/courses/csci1730/2012/Assignments/Interpreter/
#lang plai
(define-type Binding
[binding (name symbol?) (named-expr CFWAE?)])
(define-type CFWAE
[num (n number?)]
[binop (op procedure?) (lhs CFWAE?) (rhs CFWAE?)]
@tomtung
tomtung / Week1 - Ruby.rb
Created June 13, 2012 08:45
Seven Languages in Seven Weeks
#!/usr/bin/ruby
############# Day 1 #############
# Print the string “Hello, world.”
puts 'Hello, world'
# For the string “Hello, Ruby”, find the index of the word“Ruby”.
puts 'Hello, Ruby'.index('Ruby')
@tomtung
tomtung / Rfc822DateTimeParser.cs
Created April 13, 2012 15:49
Rfc822DateTimeParser - Parse Date-Time In RFC-822 Format
//* ------------------------------------------------------------------------
//* Rfc822DateTimeParser - Parse Date-Time In RFC-822 Format
//* Copyright (C) 2009 Tom Dong
//*
//* This library is free software; you can redistribute it and/or
//* modify it under the terms of the GNU Lesser General Public
//* License as published by the Free Software Foundation; either
//* version 2.1 of the License, or (at your option) any later version.
//* ------------------------------------------------------------------------
@tomtung
tomtung / saas-class-homework-ruby-basics.rb
Created March 4, 2012 15:30
SaaS Class Homework: Ruby Basics
# Homework 1 - Part 1
def palindrome?(string)
string = string.downcase.gsub(/\W/, '')
string == string.reverse
end
def count_words(string)
Hash[
string.downcase.scan(/\w+/).
group_by{|s| s}.