Advertisement
Guest User

y e e t

a guest
Nov 13th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 2.76 KB | None | 0 0
  1. ;Hersh Kumar
  2. ;Haiku Generator
  3.  
  4. (defun one-of (set)
  5.   (list (random-elt set)))
  6.  
  7. (defun random-elt (choices)
  8.   (elt choices (random (length choices))))
  9.  
  10. (defparameter *nature*
  11.   '(
  12.     (one (is cool warm like rain some fall spring life death mouse lion duck horse))
  13.     (two (windy snowing raining thunder zebra spider))
  14.     (three (animals adventure favorite extinction))
  15.     )
  16.   )
  17.  
  18. (defparameter *school*
  19.   '(
  20.     (one (tests work grades life death are is hate love when grades ))
  21.     (two (knowledge sadness cramming homework english teacher exam whiteboard))
  22.     (three (eraser library studying memorize principal sharpener calendar))
  23.     )
  24.   )
  25.  
  26. (defparameter *halloween*
  27.   '(
  28.     (one (death life send down spine your is was like ghosts ghoul boo cape imp))
  29.     (two (scary spooky shivers spiders cauldron coffin casket cackle costume darkness enchant eyeballs))
  30.     (three (skeletons murderer enchanted fantasy frightening))
  31.     )
  32.   )
  33.  
  34. (defvar *topic* *nature*)
  35.  
  36. (setf *topic* *nature*)
  37. (setf *topic* *school*)
  38. (setf *topic* *halloween*)
  39.  
  40.  
  41. (defun genFive ()
  42.     (let ((total 0))
  43.     (setq words '())
  44.     (loop while (< total 5) do
  45.      (setq rand (random 4))
  46.      (if (<= (+ rand total) 5)
  47.       (cond
  48.           ;if its a one
  49.           ((= rand 1)
  50.             (setq words (cons (random-elt (car (rest (assoc 'one *topic*)))) words))
  51.             (setq total (+ total rand))
  52.             )
  53.           ;if its a two
  54.           ((= rand 2)
  55.             (setq words (cons (random-elt  (car (rest (assoc 'two *topic*)))) words))
  56.             (setq total (+ total rand))
  57.             )
  58.           ;if its a three
  59.           ((= rand 3)
  60.             (setq words (cons (random-elt  (car (rest (assoc 'three *topic*)))) words))
  61.             (setq total (+ total rand))
  62.             )
  63.           )        
  64.       )
  65.      )
  66.     words
  67.     )
  68.   )
  69.  
  70. (defun genSeven ()
  71.   (let ((total 0))
  72.     (setq words '())
  73.     (loop while (< total 7) do
  74.       (setq rand (random 4))
  75.       (if (<= (+ rand total) 7)
  76.         (cond
  77.           ;if its a one
  78.           ((= rand 1)
  79.             (setq words (cons (random-elt (car (rest (assoc 'one *topic*)))) words))
  80.             (setq total (+ total rand))
  81.             )
  82.           ;if its a two
  83.           ((= rand 2)
  84.             (setq words (cons (random-elt  (car (rest (assoc 'two *topic*)))) words))
  85.             (setq total (+ total rand))
  86.             )
  87.           ;if its a three
  88.           ((= rand 3)
  89.             (setq words (cons (random-elt (car (rest (assoc 'three *topic*)))) words))
  90.             (setq total (+ total rand))
  91.             )
  92.           )        
  93.         )
  94.       )
  95.     words
  96.     )
  97.   )
  98.  
  99. (defun Haiku ()
  100.   (format t "~{~a ~}~%" (genFive))
  101.   (format t "~{~a ~}~%" (genSeven))
  102.   (format t "~{~a ~}~%" (genFive))
  103.  
  104.   nil
  105. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement