Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

2010 Homework No. 3 - findsuss

Name: Anonymous 2010-01-15 22:56

Write a program in the language of your choice that takes a string and inputs "SUSSMAN" for every time those characters appear. In case I'm not being clear, that means output "SUSSMAN" for every 3 's's and 1 'u', 'm', 'a', and 'n' in the string. Inputting "ssssumanssssssssssuman", for example, would print "SUSSMAN" twice. "ssuman", however, would print nothing.

I've written an inelegant solution in C, which I'll post in a second. It tends to crash after execution, however, and I cannot for the life of me figure out what I'm doing wrong. It does everything it's supposed to but refuses to terminate politely. Even stranger, it only happens when there is enough characters for two or more sussmen. I guess the problem is in the susscount loop, but I can't figure out where. Mind giving me a hand, /prog/?

Name: Anonymous 2010-01-16 0:42

Actually should be


(defun sussman-count (string search-string
                        &aux (string (string-upcase string))
                           (search-string (string-upcase search-string)))
  (let ((s-len (length search-string))
        (b-len (length string)))
    (do ((index (search search-string string)
                (search search-string string :start2 index))
         (i 0 (1+ i)))
        ((not index) i)
      (when (<= (+ index s-len) b-len)
        (incf index s-len)))))
(defun print-wizardly-sussmans-for-real (string)
  (loop repeat (sussman-count string "sssuman") do (format t "~&SUSSMAN~&")))


but I believe your implementation is more complicated than needed, >>11-kun. "smanuss" should print a Sussman, whether the letters are in order or not. It does depend on how we interpret >>1.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List