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
            line = io.read()    -- word not found; try next line
            pos = 1             -- restart from first position
          end
        end
        return nil            -- no more lines: end of traversal
      end
    end
    
    function prefix (w1, w2)
      return w1 .. ' '.........完整代码请登录后点击上方下载按钮下载查看

网友评论0