Finding God

February 16, 2016

(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))

Pages: 1 2 3

10 Responses to “Finding God”

  1. (same before but not linked)

    import Data.Char
    
    -- Convert pure text to word lists removing symbols
    asWords :: [String] -> [[String]]
    asWords = map $ words . map r where r c | isAlpha c = c
                                            | otherwise = ' '
    
    -- Lookup last row indexed word
    jump :: [[String]] -> Int -> Maybe String
    jump []           _ = Nothing
    jump [(x:_)]      0 = Just x
    jump ((x:xs):xss) 0 = jump (xs:xss) (length x)
    jump ([]:xss)     n = jump xss n
    jump ((x:xs):xss) n = jump (xs:xss) (n - 1)
    
    -- With some word check if obey the law
    obey :: String -> [[String]] -> Bool
    obey _ [] = False
    obey w xs@(x:_) = all (Just w ==) $ (jump xs) <$> [1..length x]
    
    
    -- Example
    text =
        "In the beginning God created the heaven and the earth.\n\
        \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.\n\
        \And God said, Let there be light: and there was light"
    
    main = print $ obey "God" $ asWords $ lines text
    
  2. matthew said

    Here’s a simulation: assume words have a uniformly random number of letters from 1 to n. We take two starting points within n words of each other (it doesn’t really matter what the exact distance is, we use -1 and 1 so the average starting value is 0), we then generate two series of random words until the two series coincide (after which they are identical). We can do that by always extending the sequence with the lowest current value. Each time we extend a sequence the probability that we hit the other value is exactly 1/n (since the two sequence values are never more that n away from each other) so the expected number of times we extend a sequence is exactly n, with expected final value n(n+1)/4 and this is the result of the simulation. Of course, real words don’t have such uniformly distributed lengths, but this seems to give a good insight into why the trick (usually) works:

    import random
    trials = 100000; n = 10; total = 0; final = 0
    for i in range(trials):
    count = 0; a = -1; b = 1
    while True:
    assert(abs(a-b) 0)
    count += 1
    if a < b: a += 1 + random.randrange(n)
    else: b += 1 + random.randrange(n)
    if a == b: break
    total += count
    final += a

    print(1.0*total/trials,1.0*final/trials) # eg. (10.01902, 27.55609)
    [/code]

  3. matthew said

    Not sure what happened there. Let’s try again:

    import random
    trials = 100000; n = 10; total = 0; final = 0
    for i in range(trials):
    count = 0; a = -1; b = 1
    while True:
    assert(abs(a-b) 0)
    count += 1
    if a < b: a += 1 + random.randrange(n)
    else: b += 1 + random.randrange(n)
    if a == b: break
    total += count
    final += a

    print(1.0*total/trials,1.0*final/trials)
    [/code]

  4. matthew said

    import random
    trials = 100000; n = 10; total = 0; final = 0
    for i in range(trials):
    count = 0; a = -1; b = 1
    while True:
    assert(abs(a-b) 0)
    count += 1
    if a < b: a += 1 + random.randrange(n)
    else: b += 1 + random.randrange(n)
    if a == b: break
    total += count
    final += a

    print(1.0*total/trials,1.0*final/trials)
    [/code]

  5. matthew said
    import random
    trials = 100000; n = 10; total = 0; final = 0
    for i in range(trials):
        count = 0; a = -1; b = 1
        while True:
            assert(abs(a-b) <= n)
            assert(abs(a-b) > 0)
            count += 1
            if b > a: a += 1 + random.randrange(n)
            else: b += 1 + random.randrange(n)
            if a == b: break
        total += count
        final += a
    
    print(1.0*total/trials,1.0*final/trials)
    
  6. matthew said

    The code formatter didn’t like the “a < b” – not normally a problem.

    Sorry about the spam, feel free to delete.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: