local data = [[Unable to rest their eyes on a colorful photograph or boldface heading that could be easily skimmed and forgotten about, Americans collectively recoiled Monday when confronted with a solid block of uninterrupted text. Dumbfounded citizens from Maine to California gazed helplessly at the frightening chunk of print, unsure of what to do next. Without an illustration, chart, or embedded YouTube video to ease them in, millions were frozen in place, terrified by the sight of one long, unbroken string of English words. "Why won't it just tell me what it's about?" said Boston resident Charlyne Thomson, who was bombarded with the overwhelming mass of black text late Monday afternoon. "There are no bullet points, no highlighted parts. I've looked everywhere—there's nothing here but words." "Ow," Thomson added after reading the first and last lines in an attempt to get the gist of whatever the article, review, or possibly recipe was about. At 3:16 p.m., a deafening sigh was heard across the country as the nation grappled with the daunting cascade of syllables, whose unfamiliar letter-upon-letter structure stretched on for an endless 500 words. Children wailed for the attention of their bewildered parents, businesses were shuttered, and local governments ground to a halt as Americans scanned the text in vain for a web link to click on. Sources also reported a 450 percent rise in temple rubbing and under-the-breath cursing around this time. "It demands so much of my time and concentration," said Chicago resident Dale Huza, who was confronted by the confusing mound of words early Monday afternoon. "This large block of text, it expects me to figure everything out on my own, and I hate it." "I've never seen anything like it," said Mark Shelton, a high school teacher from St. Paul, MN who stared blankly at the page in front of him for several minutes before finally holding it up to his ear. "What does it want from us?" As the public grows more desperate, scholars are working to randomly italicize different sections of the text, hoping the italics will land on the important parts and allow everyone to go on with their day. For now, though, millions of panicked and exhausted Americans continue to repetitively search the single column of print from top to bottom and right to left, looking for even the slightest semblance of meaning or perhaps a blurb. Some have speculated that the never-ending flood of sentences may be a news article, medical study, urgent product recall notice, letter, user agreement, or even a binding contract of some kind. But until the news does a segment in which they take sections of the text and read them aloud in a slow, calm voice while highlighting those same words on the screen, no one can say for sure. There are some, however, who remain unfazed by the virtual hailstorm of alternating consonants and vowels, and are determined to ignore it. "I'm sure if it's important enough, they'll let us know some other way," Detroit local Janet Landsman said. "After all, it can't be that serious. If there were anything worthwhile buried deep in that block of impenetrable English, it would at least have an accompanying photo of a celebrity or a large humorous title containing a pop culture reference." Added Landsman, "Whatever it is, I'm pretty sure it doesn't even have a point."]] local suppress =1 local maxgen = 100 local word_table = {} function insert (i, value) --If a entry does not exist, create it if not word_table[i] then word_table[i] = {} end --Insert the value into the table table.insert(word_table[i], value) end function find_next_word(data, pos) local s, e = string.find(data, "%w+[']?", pos) if e == nil then return nil end local str = string.sub(data, s, e) pos = e + 1 return str, pos end function makePair(w1, w2) return w1 .. " " .. w2 end function push_to_table(w1, w2, str) -- Inserts pair into table and swaps -- w2 -> w1 and str -> w2 -- not necessary just clean insert(makePair(w1,w2), str) if not suppress then io.write("Added entry at " .. makePair(w1,w2) .. ": " .. str .. "\n"); end return w2, str end function markov_2 (data) local w1 = "\n" local w2 = "\n" local pos = 0 local str = "" -- Create Initial Table From Block if not suppress then io.write("\n-------------\n Entry Log\n-------------\n\n") end str, pos = find_next_word(data, pos); w1, w2 = push_to_table(w1, w2, str) while pos ~= nil do str, pos = find_next_word(data, pos) if not pos then break end w1, w2 = push_to_table(w1, w2, str) end w1, w2 = push_to_table(w1, w2, "\n") --List Pairs with multiple choices if not suppress then io.write("\n--------------------\n Multiple choices\n--------------------\n\n") for k, v in pairs(word_table) do if table.getn(v) > 1 then io.write(k .. "\n") end end end -- Begin Creating Markov Chain io.write("\n----------------\n Markov Chain\n----------------\n") local x = {} pos = 2 table.insert(x, "\n"); table.insert(x, word_table["\n \n"][1]); while table.getn(x) < maxgen do local wewlad = makePair(x[pos-1], x[pos]); local r = math.random(table.getn(word_table[wewlad])) table.insert(x, word_table[wewlad][r]) if word_table[wewlad][r] == "\n" then break end pos = pos + 1 end for i, v in ipairs(x) do io.write(v .. " ") end end markov_2(data);

2 Responses

Its a WIP
Now it works

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.