Skip to content

Instantly share code, notes, and snippets.

View imphasing's full-sized avatar

I'm phasing imphasing

  • Flower Mound, TX
View GitHub Profile
public IEnumerator<IScheminType> GetEnumerator ()
{
var c = Cdr();
if (!this.Empty)
yield return Car();
c = Cdr();
while (!c.Empty || c.quoted) {
yield return c.Car();
this.Empty = false;
(define (fib n)
(fib-iter 1 0 n))
(define (fib-iter a b count)
(if (= count 0)
b
(fib-iter (+ a b) a (- count 1))))
(define fibs '())
(define-macro (do init test . expr)
(let ((bindings (map (lambda (x) (cons (car x) (list (cadr x)))) init))
(steps (map (lambda (x) (if (< 2 (length x)) (caddr x) (car x))) init))
(condition (car test))
(endresult (cdr test))
(loop-name (gensym)))
`(let ,loop-name ,bindings
(if (not ,condition)
(begin ,(car expr) ,(cons loop-name steps))
(define-rewriter do
(lambda (form rename)
(let ((bindings (map (lambda (x) (cons (car x) (list (cadr x)))) (cadr form)))
(steps (map (lambda (x) (if (< 2 (length x)) (caddr x) (car x))) (cadr form)))
(condition (car (car (cddr form))))
(endresult (cadr (car (cddr form))))
(expr (cdddr form))
(loop-name (gensym)))
`(,(rename 'let) ,loop-name ,bindings
String Reduction (25 Points)
Given a string consisting of a,b and c's, we can perform the following operation: Take any two adjacent distinct characters and replace it with the third character. For example, if 'a' and 'c' are adjacent, they can replaced with 'b'. What is the smallest string which can result by applying this operation repeatedly?
Input:
The first line contains the number of test cases T. T test cases follow. Each case contains the string you start with.
Output:
Output T lines, one for each test case containing the smallest length of the resultant string after applying the operations optimally.
Constraints:
def get_suffixes(str)
suffixes = Array.new(str.length) {|i| str[str.length - 1 - i, i + 1]}
end
@imphasing
imphasing / ConsistentHash.cs
Created March 26, 2012 16:54
ConsistentHash
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
/*
* Example Usage:
*
* List<string> urls = new List<string> { "/img/something.jpg", "/img/nothing.jpg", "/static/res.html", "/script/test.js" };
@imphasing
imphasing / HashTable.cs
Created March 30, 2012 14:57
HashTable
using System;
using System.Collections.Generic;
namespace HashTable
{
class HashTable<TKey, TValue>
{
private int count;
private int size;
private List<KeyValuePair<TKey, TValue>>[] values;
+[,+[-[>+>+<<-]>[<+>-]+>>++++++++[<-------->-]<-[<[-]>>>+[<+<+>>-]<[>+<-]<[<++>
>>+[<+<->>-]<[>+<-]]>[<]<]>>[-]<<<[[-]<[>>+>+<<<-]>>[<<+>>-]>>++++++++[<-------
->-]<->>++++[<++++++++>-]<-<[>>>+<<[>+>[-]<<-]>[<+>-]>[<<<<<+>>>>++++[<++++++++
>-]>-]<<-<-]>[<<<<[-]>>>>[<<<<->>>>-]]<<++++[<<++++++++>>-]<<-[>>+>+<<<-]>>[<<+
>>-]+>>+++++[<----->-]<-[<[-]>>>+[<+<->>-]<[>+<-]<[<++>>>+[<+<+>>-]<[>+<-]]>[<]
<]>>[-]<<<[[-]<<[>>+>+<<<-]>>[<<+>>-]+>------------[<[-]>>>+[<+<->>-]<[>+<-]<[<
++>>>+[<+<+>>-]<[>+<-]]>[<]<]>>[-]<<<<<------------->>[[-]+++++[<<+++++>>-]<<+>
>]<[>++++[<<++++++++>>-]<-]>]<[-]++++++++[<++++++++>-]<+>]<.[-]+>>+<]>[[-]<]<]