Last active
March 22, 2016 18:04
-
-
Save samanthadoran/9dcccfbb831eefab1ff2 to your computer and use it in GitHub Desktop.
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
(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