; finding god

(define (drop n xs)
  (let loop ((n n) (xs xs))
    (if (or (zero? n) (null? xs)) xs
      (loop (- n 1) (cdr xs)))))

(define bible '(
  In the beginning God created the heaven and the earth

  And the earth was without form and void and darkness
    was upon the face of the deep
  And the Spirit of God moved upon the face of the waters

  And God said Let there be light and there was light))

(define alice '(
  Alice was beginning to get very tired of sitting
  by her sister on the bank and of having nothing
  to do once or twice she had peeped into the book
  her sister was reading))

(define twinkle '(
  Twinkle twinkle little star
  How I wonder what you are
  Up above the world so high
  Like a diamond in the sky
  Twinkle twinkle little star
  How I wonder what you are))

(define huck-finn '(
  You dont know about me without you have read a book
  by the name of The Adventures of Tom Sawyer but that
  aint no matter That book was made by Mr Mark Twain
  and he told the truth mainly There was things which
  he stretched but mainly he told the truth That is
  nothing I never seen anybody but lied one time or
  another without it was Aunt Polly or the widow or
  maybe Mary Aunt Polly Toms Aunt Polly she is and
  Mary and the Widow Douglas is all told about in
  that book which is mostly a true book with some
  stretchers as I said before))

(define trees '(
  I think that I shall never see
  A poem lovely as a tree

  A tree whose hungry mouth is prest
  Against the earths sweet flowing breast

  A tree that looks at God all day
  And lifts her leafy arms to pray

  A tree that may in Summer wear
  A nest of robins in her hair

  Upon whose bosom snow has lain
  Who intimately lives with rain

  Poems are made by fools like me
  But only God can make a tree))

(define psalm23 '(
  The Lord is my shepherd I shall not want

  He maketh me to lie down in green pastures
  he leadeth me beside the still waters

  He restoreth my soul he leadeth me in the
  paths of righteousness for his names sake

  Yea though I walk through the valley of
  the shadow of death I will fear no evil
  for thou art with me thy rod and thy
  staff they comfort me.

  Thou preparest a table before me in the
  presence of mine enemies thou anointest
  my head with oil my cup runneth over

  Surely goodness and mercy shall follow
  me all the days of my life and I will
  dwell in the house of the Lord for ever))

(define scheme '(
  Programming languages should be designed not by
  piling feature on top of feature but by removing
  the weaknesses and restrictions that make additional
  features appear necessary Scheme demonstrates that a
  very small number of rules for forming expressions
  with no restrictions on how they are composed
  suffice to form a practical and efficient programming
  language that is flexible enough to support most of
  the major programming paradigms in use today))

(define (chain words)
  (let loop ((words words) (chain (list (car words))))
    (let* ((count (string-length (symbol->string (car words))))
           (text (drop count words)))
      (if (null? text) (reverse chain)
        (loop text (cons (car text) chain))))))

(define (chains words)
  (let loop ((words words) (chains (list)))
    (if (null? words) (reverse chains)
      (loop (cdr words) (cons (chain words) chains)))))

(define (count chains)
  (let ((prev (car (reverse (car chains)))))
    (let loop ((chains chains) (count 0))
      (cond ((null? chains) count)
            ((not (equal? (car (reverse (car chains))) prev))
              count)
            (else (loop (cdr chains) (+ count 1)))))))

(define (obey? words)
  (< 1/3 (/ (count (chains words)) (length words))))

(display (chains alice)) (newline)

(display (obey? bible)) (newline)
(display (obey? alice)) (newline)
(display (obey? twinkle)) (newline)
(display (obey? huck-finn)) (newline)
(display (obey? trees)) (newline)
(display (obey? psalm23)) (newline)
(display (obey? scheme)) (newline)