Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

18
LINES

< > BotCompany Repo | #1004715 // Demo Lua Strategy

Lua code

1  
n = 100
2  
3  
function strategy(text)
4  
  local lines = toLines(text)
5  
  print("Lines found: " ..tostring(#lines))
6  
  if #lines > n then
7  
    local i1 = math.random(1, #lines-n)
8  
    local i2 = i1+n
9  
    print(table.concat(lines, "\n", i1, i2))
10  
  end
11  
end
12  
13  
function toLines(str)
14  
  local t = {}
15  
  local function helper(line) table.insert(t, line) return "" end
16  
  helper((str:gsub("(.-)\r?\n", helper)))
17  
  return t
18  
end

test run  test run with input  download  show line numbers   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004715
Snippet name: Demo Lua Strategy
Eternal ID of this version: #1004715/1
Text MD5: 780cc77cb25970f34a8e8d32dff4c9c1
Author: stefan
Category: javax / a.i.
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-27 19:20:38
Source code size: 420 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 799 / 399
Referenced in: [show references]