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

31
LINES

< > BotCompany Repo | #633 // Find single translator chain

Lua code

get("#175") -- tableToString
get("#349") -- table functions

startID = input or error("Need snippet ID as input")

function makeChain(id, seen, result)
  if not seen[id] then
    seen[id] = true
    
    local refs = getTitleReferences(id)
    --print("Refs: "..tableToString(refs))
    for r in all(refs) do
      local title = getSnippetTitle(r)
      if not hasNTTitle("Invalidate "..r) and (title:find("^A translation of ") or title:find("^Translation of ")) then
        local _, _, translatorID = title:find(" with #([0-9]+)")
        table.insert(result, translatorID)
        print("r:", r)
        print("translator:", translatorID)
        makeChain(r, seen, result)
        goto out
      end
    end
    ::out::
  end
end

result = {}
makeChain(startID, {}, result)
result = "!"..table.concat(result, " ")
print(result)
return result

Author comment

Began life as a copy of #536

test run  test run with input  download  show line numbers   

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

No comments. add comment

Snippet ID: #633
Snippet name: Find single translator chain
Eternal ID of this version: #633/1
Text MD5: 693a1e2fcf22cf7d9f13c94dec717083
Author: stefan
Category:
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-06-21 21:20:18
Source code size: 875 bytes / 31 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 884 / 176
Referenced in: [show references]