On Sun, 19 Feb 2012, SF wrote:
Here's a rough draft that has tons of room for improvement:
#lang racket
(define glider
(string->number "#x\
010000\
001000\
111000\
000000\
000000\
000000\
"))
(define (life s)
(define (c s n)
(if (= -1 n)
0
(+ (if (bitwise-bit-set? 3080 (arithmetic-shift s (* -4 n)))
(expt 16 n)
0)
(c (modulo s (expt 16 n)) (sub1 n)))))
(c (* s #x111000181000111/10000000)
36))
Here's my shortening of the life function above:
(define (life s)
(define (c s n)
(+ (if (bitwise-bit-set? 3080 (quotient s n))
n
0)
(if (= n 1) 0 (c (modulo s n) (/ n 16)))))
(c (* s #x111000181000111/10000000)
(expt 8 48)))
By my count, that packs down to 159 characters.
-- Jeremiah Willcock
____________________
Racket Users list:
http://lists.racket-lang.org/users