lua编写一个马尔可夫链代码

代码语言:lua

所属分类:

代码描述:lua编写一个马尔可夫链代码

代码标签: 马尔可夫

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

  -- Markov Chain Program in Lua
   
   
function allwords ()
     
--local line = io.read()    -- current line
     
local line="bfw is a good site"
     
local pos = 1             -- current position in the line
     
return function ()        -- iterator function
       
while line do           -- repeat while there are lines
         
local s, e = string.find(line, "%w+", pos)
         
if s then      -- found a word?
            pos
= e + 1  -- update next position
           
return string.sub(line, s, e)   -- return the word
         
else
           
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0