Skip to content

Instantly share code, notes, and snippets.

@samanthadoran
Last active March 22, 2016 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samanthadoran/9dcccfbb831eefab1ff2 to your computer and use it in GitHub Desktop.
Save samanthadoran/9dcccfbb831eefab1ff2 to your computer and use it in GitHub Desktop.
(in-package :cl-user)
(defpackage #:my-new-package
(:nicknames #:newpack)
(:use :cl :cl-user)
(:export #:mutate))
(in-package :my-new-package)
(defun mutate-step (s acc)
"Generates a progression of an l-system."
(if (equal (car s) nil)
acc
(if (char= (car s) #\A)
(mutate-step (cdr s) (concatenate 'string acc "AB"))
(if (char= (car s) #\B)
(mutate-step (cdr s) (concatenate 'string acc "A"))
nil))))
(defun mutate-private (s iterations goal)
(if (equal iterations goal)
s
(mutate-private (coerce (mutate-step s "") 'list) (+ iterations 1) goal)))
(defun mutate (input goal)
"Generates n goal iterations of an l-system."
(coerce (mutate-private (coerce input 'list) 0 goal) 'string))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment