Skip to content

Commit

Permalink
Add string_length.
Browse files Browse the repository at this point in the history
  • Loading branch information
thelmuth committed Nov 4, 2011
1 parent 8bc6e43 commit 7454314
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/clojush.clj
Expand Up @@ -970,6 +970,14 @@ boolean stack."
(pop-item :string (pop-item :integer state)))
state)))

(define-registered string_length
(fn [state]
(if (not (empty? (:string state)))
(push-item (count (stack-ref :string 0 state))
:integer
(pop-item :string state))
state)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; code and exec instructions

Expand Down
7 changes: 7 additions & 0 deletions src/examples/string.clj
Expand Up @@ -23,3 +23,10 @@

; Add string_concat to this example, and make the number of unique characters higher. Maybe only use
; upper case, and try to evolve a string with all 26 letters.



; New GP problem: Take the input string, remove the last 2 characters, and then concat this result with itself.
; The fitness will be the number of non-matching characters in the resulting string. For example,
; desired result of "abcde" would be "abcabc", and a string of "abcabcrrr" would have an error of 3, for
; 3 too many characters, and the string "aaaaaa" would have error of 4, since it gets 2 of the characters right.
7 changes: 5 additions & 2 deletions src/string_tests.clj
Expand Up @@ -8,9 +8,12 @@


; Test strings inserted into code
(println (run-push '(string_rand "these" "are" "strings" string_concat)
#_(println (run-push '(string_rand "these" "are" "strings" string_concat)
(make-push-state) false false))


(println (run-push '("abcde" "HelloWorld" 7 string_take)
#_(println (run-push '("abcde" "HelloWorld" 7 string_take)
(make-push-state)))

#_(println (run-push '("d2" string_length)
(make-push-state)))

0 comments on commit 7454314

Please sign in to comment.