Archive for December, 2009

Exploding a symbol

Thursday, December 10th, 2009

Here’s a procedure to turn a symbol into a list of symbols, each made from one character of the original symbol:

(define explode
  (lambda (sym)
    (map string->symbol
         (map (lambda (c) (make-string 1 c))
              (string->list (symbol->string sym))))))

(explode 'boom)

-Lee

print-list-as-line

Tuesday, December 8th, 2009

Here’s a version of that procedure that I wrote in class, by request:

(define print-list-as-line
  (lambda (lst)
    (map (lambda (item)
           (printf "~A " item))
         lst)
    (printf "\n")))

(print-list-as-line '(here is a list))

-Lee

lrm-hitfn

Sunday, December 6th, 2009

(define lrm1-hitfn
  (lambda (mine others)
    (letrec ((lrm-plus
              (lambda (l)
                (cond ((null? l)
                       0)
                      ((not (pair? (car l)))
                       (+ (car l) (lrm-plus (cdr l))))
                      (else (+ (lrm-plus (car l))
                               (lrm-plus (cdr l))))))))
      (cond ((and (> (apply + mine) 7)
                  (< (apply + mine) 12)
                  (member '1 mine))
             #f)
            ((> (apply + mine) 16)
             #f)
            ((and (> (apply + mine) 14)
                  (< (/ (lrm-plus others)
                        (length others)) 5.5))
             #f)
            (else #t)))))

If anyone else has a problem with using greater than and less than signs on the blog, use (without quotes and spaces) “& g t ;” and “& l t ;”

Coke Machine Card Player

Thursday, December 3rd, 2009

This code is very messy, as I wrote it hastily after my previous card-player failed miserably against mr15.

It takes three inputs and keeps hitting until the stand variable exceeds 1, at which it stands.

Soda machine dispenser circuits take three inputs, which is why it’s called the “Coke Machine”.
This awesome AI’s brains (or hard artificial life) are made solely of soda machine circuits arranged in a neural network: Genghis

(define coke-machine
     (lambda (mine others)
    (let ((stand 0))
      (when (< stand 1)
        (cond
          ((> (best-total mine) 18)
            (set! stand (+ stand 2)))
          ((< (- 21 (best-total mine)) 7)
           (set! stand (+ stand (* .1 (modulo (- 21 (best-total mine)) 7)))))
          ((< (best-total (list-ref others (random (length others)))) 10)
           (set! stand (- stand .2)))
          ))
      (if (>= stand 1) #f #t)
      )))

1-dimensional cellular automaton code

Thursday, December 3rd, 2009

Here is the 1-dimensional cellular automaton code that I presented in class.

-Lee