This file contains 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
#lang racket/base | |
;; Unfriendly numbers | |
;; https://www.interviewstreet.com/challenges/dashboard/#problem/4f7272a8b9d15 | |
;; We'll provide a single function to solve this problem. | |
;; | |
;; Note that this module itself can be run as a main program, due to the | |
;; "main" submodule at the bottom of this file. | |
;; |
This file contains 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
#lang racket/base | |
(require racket/gui/base | |
racket/class) | |
(define (do-the-build) | |
(define f (new frame% [label "Building..."])) | |
(define t (new text% [auto-wrap #t])) | |
(define c (new editor-canvas% [parent f] [editor t])) | |
(send f show #t) | |
(void (thread (lambda () |
This file contains 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
#lang racket/base | |
;; http://en.wikipedia.org/wiki/Machine_epsilon | |
;; approximates the machine epsilon | |
(require racket/flonum) | |
(define (compute-machine-epsilon) | |
(let loop ([n 1.0]) | |
(define new-n (fl/ n 2.0)) | |
(cond |
This file contains 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
#lang racket | |
;; Let's create a custom structure for procedures that remember certain things. | |
(struct proc/data (proc data) | |
#:property prop:procedure (lambda (pd . args) | |
(apply (proc/data-proc pd) args))) | |
;; We can manually create such instances... | |
(define f (proc/data | |
;; implementation: |
This file contains 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
#lang racket | |
;; http://stackoverflow.com/questions/12345647/rewrite-this-script-by-designing-an-interpreter-in-racket | |
;; A pexpr is one of the following: | |
;; * a primitive string, | |
;; * a seq, or | |
;; * a repeat | |
(struct seq (bodies) #:transparent) | |
(struct repeat (n body) #:transparent) |
This file contains 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
#lang racket | |
(require rackunit | |
(for-syntax racket/syntax)) | |
;Records - like structs but less ugly and much less efficient | |
(define-syntax (record stx) | |
(syntax-case stx () | |
[(_ name slots ...) | |
(with-syntax ([new-name (format-id #'name "new-~a" (syntax-e #'name))]) |
This file contains 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
#lang racket/base | |
(require racket/stream) | |
;; decimal-to-binary-fraction: positive-real-less-than-1 -> (sequenceof (U 0 1)) | |
;; Computes the binary expansion of the fraction part of a number. | |
(define (decimal-to-binary-fraction n) | |
(let loop ([n n] | |
[current-fraction 1/2]) | |
(cond [(= n 0) |
This file contains 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
#lang racket | |
(require racket/generator) | |
(define-syntax (for/seq stx) | |
(syntax-case stx () | |
[(_ clauses . body) | |
#`(in-generator | |
(for/fold/derived #,stx | |
() | |
clauses |
This file contains 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
#lang racket | |
;; http://www.cforcoding.com/2012/01/interview-programming-problems-done.html | |
;; A little syntax for memoizing functions like Pascal's triangle. | |
(define-syntax (define/memo stx) | |
(syntax-case stx () | |
[(_ (name args ...) body ...) | |
(syntax/loc stx |
This file contains 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
#lang racket | |
;; Counts words, treating tilde-words as escaped words. | |
;; Based on the SO question: | |
;; | |
;; http://stackoverflow.com/questions/12666553/efficient-word-count-method-using-regex-or-something | |
(require rackunit) |
OlderNewer