Jump to content
  • 0

Help Tables concatenation


Yelay12
 Share

Question

I want to know search results multiple tables(in following code) concatenate into only one Table.Please help me how to write script and combine followed script. Thanks.

--Code is here

gg.setRanges(-2080896)

search = {}
v = 1
for i = 7,700,7 do
search[v] = i
v = v + 1
end
print(search[1])
res = {}
for i = 1, 100 do
gg.searchNumber(search[i], gg.TYPE_DOUBLE)
res[i] = gg.getResults(gg.getResultsCount())
gg.clearResults()
end

Edited by Yelay12
Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

It's not a good idea to do that for many results (like 100k-200k+), since you will most likely run out of memory, but you can test how it goes in your case. Here is a function to concatenate results from table of tables with results: 

function concatResults(resultsList)
  local mergedResults = {}
  local index = 0
  for _, results in ipairs(resultsList) do
    for __, result in ipairs(results) do
      index = index + 1
      mergedResults[index] = result
    end 
  end
  return mergedResults
end

And example of it's usage: 

local resultsList = {}
for i = 7, 700, 7 do
  gg.clearResults()
  gg.searchNumber(tostring(i), gg.TYPE_DOUBLE)
  resultsList[#resultsList + 1] = gg.getResults(gg.getResultsCount())
end
local allResults = concatResults(resultsList)
Link to comment
Share on other sites

  • 0
10 hours ago, CmP said:

It's not a good idea to do that for many results (like 100k-200k+), since you will most likely run out of memory, but you can test how it goes in your case. Here is a function to concatenate results from table of tables with results: 

function concatResults(resultsList)
  local mergedResults = {}
  local index = 0
  for _, results in ipairs(resultsList) do
    for __, result in ipairs(results) do
      index = index + 1
      mergedResults[index] = result
    end 
  end
  return mergedResults
end

And example of it's usage: 

local resultsList = {}
for i = 7, 700, 7 do
  gg.clearResults()
  gg.searchNumber(tostring(i), gg.TYPE_DOUBLE)
  resultsList[#resultsList + 1] = gg.getResults(gg.getResultsCount())
end
local allResults = concatResults(resultsList)

Thank for your answer. My game hasn't many result for this 100 search results only 10k - 20k total.

Link to comment
Share on other sites

  • 0
16 hours ago, SCHERR said:

Could you explain more on what you want to achieve? Explain what your code does and what the result you want should look like

If I understand correctly, you want to concatenate `search` and `res`:

for index,value in pairs(search) do
     search[index] = res[index] -- this will overwrite `search`
     -- switch their places if you want `res` to be overwritten instead:
     -- res[index] = search[index]
end

print(search)

 

Thank for your answer.

Link to comment
Share on other sites

  • 0
13 hours ago, CmP said:

It's not a good idea to do that for many results (like 100k-200k+), since you will most likely run out of memory, but you can test how it goes in your case. Here is a function to concatenate results from table of tables with results: 

function concatResults(resultsList)
  local mergedResults = {}
  local index = 0
  for _, results in ipairs(resultsList) do
    for __, result in ipairs(results) do
      index = index + 1
      mergedResults[index] = result
    end 
  end
  return mergedResults
end

And example of it's usage: 

local resultsList = {}
for i = 7, 700, 7 do
  gg.clearResults()
  gg.searchNumber(tostring(i), gg.TYPE_DOUBLE)
  resultsList[#resultsList + 1] = gg.getResults(gg.getResultsCount())
end
local allResults = concatResults(resultsList)

@CmP

Bro, Do you have any idea for my searchresults to get. I want to search value within the 7 to 700 range and that value divided by 7 is with remainder zero. Please help and how to write script.Thank.

Link to comment
Share on other sites

  • 0
18 hours ago, Yelay12 said:

I want to search value within the 7 to 700 range and that value divided by 7 is with remainder zero.

If you mean how to do it without concatenating tables with results from separate searches for each value (and potentially significantly faster), it may be done by searching multiple values at once with range searches. The idea is to make initial search from lowest target value to highest, then N - 1 refine searches to exclude ranges of values that are between target values, so that only target values remain at the end. Below is an example implementation of this idea for your case (untested, may require minor changes if doesn't work as is).

local function interpretAsInteger(double)
  return string.unpack("I8", string.pack("d", double))
end

local function interpretAsDouble(integer)
  return string.unpack("d", string.pack("I8", integer))
end

local function convertToString(double)
  return string.format("%.17g", double)
end

local function getNextDoubleStr(doubleValue)
  local intValue = interpretAsInteger(doubleValue)
  local nextDouble = interpretAsDouble(intValue + 1)
  return convertToString(nextDouble)
end

local function getPreviousDoubleStr(doubleValue)
  local intValue = interpretAsInteger(doubleValue)
  local previousDouble = interpretAsDouble(intValue - 1)
  return convertToString(previousDouble)
end

local function searchMultipleDoubleValues(values)
  if #values < 2 then
    return
  end
  table.sort(values)
  local initialSearchStr = convertToString(values[1]) .. "~" .. convertToString(values[#values])
  gg.clearResults()
  gg.searchNumber(initialSearchStr, gg.TYPE_DOUBLE)
  for i = 1, #values - 1 do
    local excludedRangeLowerBound = getNextDoubleStr(values[i])
    local excludedRangeUpperBound = getPreviousDoubleStr(values[i + 1])
    local excludedRangeSearchStr = excludedRangeLowerBound .. "~" .. excludedRangeUpperBound
    gg.refineNumber(excludedRangeSearchStr, gg.TYPE_DOUBLE, false, gg.SIGN_NOT_EQUAL)
  end
end

local valuesToSearch = {}
for value = 7, 700, 7 do
  valuesToSearch[#valuesToSearch + 1] = value
end
searchMultipleDoubleValues(valuesToSearch)
local resultsCount = gg.getResultsCount()
print("Found " .. resultsCount .. " results")
Edited by CmP
Link to comment
Share on other sites

  • 0
5 hours ago, CmP said:

If you mean how to do it without concatenating tables with results from separate searches for each value (and potentially significantly faster), it may be done by searching multiple values at once with range searches. The idea is to make initial search from lowest target value to highest, then N - 1 refine searches to exclude ranges of values that are between target values, so that only target values remain at the end. Below is an example implementation of this idea for your case (untested, may require minor changes if doesn't work as is).

local function interpretAsInteger(double)
  return string.unpack("I8", string.pack("d", double))
end

local function interpretAsDouble(integer)
  return string.unpack("d", string.pack("I8", integer))
end

local function convertToString(double)
  return string.format("%.17g", double)
end

local function getNextDoubleStr(doubleValue)
  local intValue = interpretAsInteger(doubleValue)
  local nextDouble = interpretAsDouble(intValue + 1)
  return convertToString(nextDouble)
end

local function getPreviousDoubleStr(doubleValue)
  local intValue = interpretAsInteger(doubleValue)
  local previousDouble = interpretAsDouble(intValue - 1)
  return convertToString(previousDouble)
end

local function searchMultipleDoubleValues(values)
  if #values < 2 then
    return
  end
  table.sort(values)
  local initialSearchStr = convertToString(values[1]) .. "~" .. convertToString(values[#values])
  gg.clearResults()
  gg.searchNumber(initialSearchStr, gg.TYPE_DOUBLE)
  for i = 1, #values - 1 do
    local excludedRangeLowerBound = getNextDoubleStr(values[i])
    local excludedRangeUpperBound = getPreviousDoubleStr(values[i + 1])
    local excludedRangeSearchStr = excludedRangeLowerBound .. "~" .. excludedRangeUpperBound
    gg.refineNumber(excludedRangeSearchStr, gg.TYPE_DOUBLE, false, gg.SIGN_NOT_EQUAL)
  end
end

local valuesToSearch = {}
for value = 7, 700, 7 do
  valuesToSearch[#valuesToSearch + 1] = value
end
searchMultipleDoubleValues(valuesToSearch)
local resultsCount = gg.getResultsCount()
print("Found " .. resultsCount .. " results")

Thank bro.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.