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
#!r6rs | |
(import (rnrs (6))) | |
;; Performs a depth-first search without a get-previous-state function, by enumerating | |
;; the paths and restarting at the root for each new path. | |
;; Requires only the memory of the current state and a O(depth-max) memory of other things. | |
;; num-actions: positive-integer? | |
;; Number of children per node. | |
;; get-start-state: none/c -> state? |
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
#lang racket/base | |
(provide latex-math-chars) | |
;;; LaTeX math to Unicode symbols translation dictionaries. | |
;;; Adapted from | |
;;; anaconda/lib/python2.7/site-packages/docutils/utils/math/tex2unichar.py | |
;;; itself generated with ``write_tex2unichar.py`` from the data in | |
;;; http://milde.users.sourceforge.net/LUCR/Math/ | |
;;; Includes commands from: wasysym, stmaryrd, mathdots, mathabx, esint, bbold, amsxtra, amsmath, amssymb, standard LaTeX |
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
#lang racket/base | |
(require plot | |
racket/list | |
racket/dict) | |
(module+ test | |
(require rackunit)) | |
(define (string-ticks string-list) | |
(let* ([N (length string-list)] |
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
#lang racket | |
(define ((foo #:a? [a? #t] #:b? [b? #t]) x) | |
(when b? | |
(displayln "b!")) | |
(if a? | |
(+ x 1) | |
(+ x 2))) | |
(define fooanb (foo #:b? #f)) |
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
#lang racket/base | |
(require racket/gui/base | |
racket/class | |
racket/format) | |
(define NUM-CELL-X 100) | |
(define NUM-CELL-Y 100) | |
(define CELL-SIZE 2) | |
(define XMAX (* NUM-CELL-X CELL-SIZE)) |
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
#lang racket/gui | |
(define my-frame% | |
(class frame% | |
(define/override (on-subwindow-event receiver event) | |
(when (send event button-down?) | |
(displayln (send receiver get-label))) | |
#f) | |
(super-new))) |
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
#lang racket | |
;; proc : procedure? ; procedure to apply | |
;; dict : dict? ; dictionary of keywords and values | |
;; A key can be either a keyword or a symbol that is turned into a keyword. | |
;; largs : list? ; positional arguments | |
;; Returns the result of the application of proc to the positional arguments and the keyword values. | |
(define (keyword-apply/dict proc dict largs) | |
(define alist | |
(sort |
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
#!/usr/bin/python | |
# From: http://nbviewer.ipython.org/url/norvig.com/ipython/xkcd1313.ipynb | |
import re | |
def verify(regex, winners, losers): | |
"Return true iff the regex matches all winners but no losers." | |
missed_winners = {W for W in winners if not re.search(regex, W)} | |
matched_losers = {L for L in losers if re.search(regex, L)} | |
if missed_winners: | |
print "Error: should match but did not:", ', '.join(missed_winners) |
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
#lang racket | |
;;; Run this file with `racket test-big-bang.rkt` | |
;;; then type quickly "asdf" to trigger several successive to-draw events. | |
;;; Drawing the scene is fast, but rendering it on-screen is very slow? | |
(require 2htdp/image | |
2htdp/planetcute | |
2htdp/universe) |
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
(defn | |
#:doc @list{Multiplies @racket[x] by @racket[y]. | |
Use it fruitfully.} | |
#:ex [10 3 => 30] | |
#:ex [0 3 => 0] | |
#:ex [10 => 10] | |
#:ex [0 => 0] | |
;; The function signature | |
(mult [x number?][y number? 1] -> number?) | |
;; And the function body: |