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 | |
;a file is a structure (make-file n s x) where n is a symbol, s is a number, and x is some scheme value | |
(define-struct file (name size content)) | |
;a dir is a structure (make-dir n ds fs) where n is a symbol and ds is a list of directories and fs is a list of files | |
(define-struct dir (name dirs files)) | |
; a list of files is either empty or (cons f lof) where f is a file and lof is a list of files |
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
;; 12.4 Rearranging words | |
;; a 'word' is either | |
;; 1 - empty, or | |
;; 2 - (cons a w) where a is a symbol | |
;; ('a, 'b,..., 'z) and w is a word | |
;; examples: | |
(define noword empty) | |
(define red (cons 'r (cons 'e (cons 'd empty)))) |
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
(defun blogTemplate () | |
[["!doctype html"] | |
['html | |
['head | |
['meta {charset 'utf-8}] | |
['title this.title]] | |
['body | |
['section | |
['h1 this.title] | |
['div {class 'articles} (Don.mapRender articleTemplate this.articles)]]]]]) |
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
-- translating http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-35.html#node_chap_28 to Haskell, | |
-- making use of Maybe, pattern matching, and type aliases | |
-- 28.1 Finding routes in a cycle-free directed graph | |
type Node = Char | |
type Graph = [(Node,[Node])] | |
type Route = [Node] |
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
-- 28.2 - Queen problem from HTDP | |
-- I took a few liberties here, thought constraint propagation might be faster | |
-- 'placement (buildBoard x) y' where x is the width/height of the chessboard in cells | |
-- and y is the number of queens to be placed, returns the first solution if that many | |
-- queens can be placed without cross-threatening, or Nothing if there is no solution | |
-- a Board consists of a list of positions of free tiles, and a list of positions of placed queens | |
type Posn = (Int, Int) | |
type Queens = [Posn] | |
type FreeTiles = [Posn] |
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 | |
;; ## DIFFERENCE LISTS | |
;; # Constructors | |
;; Diff a is [a] -> [a] | |
;; implemented as - diff :: a... -> ([a] -> [a]) | |
(define diff | |
(λ ls (curry append ls))) |
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
{- | |
DIFF-TREE SORT | |
I did this as a learning exercise. | |
I assume it has been discovered before. | |
It is an attempted optimisation of tree sort. | |
It uses a naive binary tree, | |
but each node keeps a list of same-values, | |
and difference lists |
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
arr = Array:: | |
arrSlice = arr.slice | |
curry = -> | |
args = arrSlice.call arguments | |
-> | |
args2 = arrSlice.call arguments | |
args[0].apply @, args.slice(1).concat(args2) | |
sum = -> |
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 "connive.rkt") | |
; https://github.com/twfarland/connive | |
; Reddit ranking algorithms | |
; Story ranking (hot ranking) | |
; http://amix.dk/blog/post/19588 | |
; Submission time greatly affects score | |
(:= epoch (current-seconds)) |
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
# Finding the start and finish indexes of the | |
# longest subpalindrome of a given string. | |
# My solution - does war & peace in approx 3.2 sec on my 2.4GHz macbook | |
def longest_subpalindrome_slice(text): | |
text = text.lower() | |
textlen = len(text) |
OlderNewer