This file contains hidden or 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
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: |
This file contains hidden or 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
(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 |
This file contains hidden or 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
(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)) |
This file contains hidden or 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
(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 '()) |
This file contains hidden or 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
this.Empty = false; |
This file contains hidden or 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 IEnumerator<IScheminType> GetEnumerator () | |
{ | |
var c = Cdr(); | |
if (!this.Empty) | |
yield return Car(); | |
c = Cdr(); | |
while (!c.Empty || c.quoted) { | |
yield return c.Car(); |
This file contains hidden or 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
/* | |
* Copyright (c) 2011 Alex Fort | |
* All rights reserved. | |
* | |
* Redistribution and use in source and binary forms, with or without | |
* modification, are permitted provided that the following conditions | |
* are met: | |
* 1. Redistributions of source code must retain the above copyright | |
* notice, this list of conditions and the following disclaimer. | |
* 2. Redistributions in binary form must reproduce the above copyright |
This file contains hidden or 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
(define-rewriter or-mine | |
(lambda (expr) | |
(let ((a (cadr expr)) | |
(b (caddr expr))) | |
`(let ((temp ,a)) | |
(if temp | |
temp | |
,b))))) |
This file contains hidden or 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
(define thread-queue '()) | |
(define halt #f) | |
(define (void) (if #f #t)) | |
(define (current-continuation) | |
(call/cc |
This file contains hidden or 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
(define (nqueens n) | |
(define (dec-to n) | |
(let loop ((i n) (l '())) | |
(if (= i 0) l (loop (- i 1) (cons i l))))) | |
(define (try x y z) | |
(if (null? x) | |
(if (null? y) | |
1 | |
0) |